Sign in to follow this  
Conny14156

DX11 An Invalid parameter was passed to the returning function?

Recommended Posts

Conny14156    279
Hi, Am trying to follow
http://www.braynzarsoft.net/index.php?p=D3D11BD
This tutorial but I keep getting
An Invalid parameter was passed to the returning function.
When my code try to run
hr = D3d11Device->CreateVertexShader(VSBuffer->GetBufferPointer(), VSBuffer->GetBufferSize(), NULL, &VS);
I get a error message saying that An Invalid parameter was passed to the returning function and am not sure why :(
Thank you if you could explain it to me I also copy pasted my code in here if it was needed


[CODE]
#include <Windows.h>
#include <d3d11.h>
#include <D3DX11.h>
#include <D3DX10.h>
#include <xnamath.h>
#include <DxErr.h>
#pragma comment(lib, "DXErr.lib")
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "d3dx11.lib")
#pragma comment(lib, "d3dx10.lib")
bool InitializeWindow(HINSTANCE hInstance,int showWnd,int windowWidth, int windowHeight,bool windowed);
int messageLoop();
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam);

HRESULT hr;
HWND hWnd = NULL;
const int windowWidth = 800;
const int windowHeight = 600;
//3DirectX
bool InitDirect3D11App(HINSTANCE hInstance);
void ReleaseObjects();
bool InitScene();
void UpdateScene();
void DrawScene();

IDXGISwapChain* SwapChain;
ID3D11Device* D3d11Device;
ID3D11DeviceContext* D3d11DevCon;
ID3D11RenderTargetView* renderTargetView;
ID3D11Buffer* TriangleVertBuffer;
ID3D11VertexShader* VS;
ID3D11PixelShader* PS;
ID3D10Blob* VSBuffer;
ID3D10Blob* PSBuffer;
ID3D11InputLayout* VertLayout;
struct Vertex //Overloaded Vertex Structure
{
Vertex(){}
Vertex(float x, float y, float z)
: pos(x,y,z){}
XMFLOAT3 pos;
};
D3D11_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
UINT numElements = ARRAYSIZE(layout);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance,LPSTR lpCmnLine, int nShowCmd)
{
if(!InitializeWindow(hInstance,nShowCmd,windowWidth,windowHeight,true))
{
MessageBox(0,"Window Initilize Failed","Error",MB_OK);
return 0;
}
if(!InitDirect3D11App(hInstance))
{
MessageBox(0,"DirectX Init Failed","Error",MB_OK);
return 0;
}
if(!InitScene())
{
MessageBox(0,"Scene Init Failed","Error",MB_OK);
return 0;
}
messageLoop();
ReleaseObjects();
return 0;
}
int messageLoop()
{
MSG msg;
ZeroMemory(&msg,sizeof(MSG));
while(true)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT)
{
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);

}
else
{
UpdateScene();
DrawScene();
}
}
return (int) msg.wParam;
}
bool InitializeWindow(HINSTANCE hInstance,int showWnd,int windowWidth, int windowHeight,bool windowed)
{

LPCTSTR WndClassName = "FusionEmptyWindowClass";
LPCTSTR windowTitleBar = "Fusion Empty:Placement Phase";
WNDCLASSEX wc;

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = NULL;
wc.cbWndExtra = NULL;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+2);
wc.lpszMenuName = NULL;
wc.lpszClassName = WndClassName;
wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL,"Error Registering The Window Class","Error",MB_OK | MB_ICONERROR);
return 0;
}
hWnd = CreateWindowEx
(
NULL,
WndClassName,
windowTitleBar,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
windowWidth,
windowHeight,
NULL,
NULL,
hInstance,
NULL
);
if (!hWnd)
{
MessageBox(NULL, "Error creating window",
"Error", MB_OK | MB_ICONERROR);
return 0;
}
ShowWindow(hWnd,showWnd);
UpdateWindow(hWnd);
return true;
}
bool InitDirect3D11App(HINSTANCE hInstace)
{
//Buffer describer
DXGI_MODE_DESC BufferDesc;

ZeroMemory(&BufferDesc,sizeof(DXGI_MODE_DESC));
BufferDesc.Width = windowWidth;
BufferDesc.Height = windowHeight;
BufferDesc.RefreshRate.Numerator= 60;
BufferDesc.RefreshRate.Denominator= 1;
BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;


//Describe our SwapChain
DXGI_SWAP_CHAIN_DESC SwapChainDesc;

ZeroMemory(&SwapChainDesc,sizeof(DXGI_SWAP_CHAIN_DESC));

SwapChainDesc.BufferDesc = BufferDesc;
SwapChainDesc.SampleDesc.Count = 1;
SwapChainDesc.SampleDesc.Quality = 0;
SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
SwapChainDesc.BufferCount = 2;
SwapChainDesc.OutputWindow = hWnd;
SwapChainDesc.Windowed = true;
SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

//Creating the SwapChain
hr = D3D11CreateDeviceAndSwapChain
(
NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,NULL,NULL,NULL,
D3D11_SDK_VERSION,
&SwapChainDesc,
&SwapChain,
&D3d11Device,
NULL,
&D3d11DevCon
);
if(FAILED(hr))
{
MessageBox(NULL,DXGetErrorDescription(hr),TEXT("D3D11CreateDeviceAndSwapChain"),MB_OK);
return 0;

}
//BackBuffer Creating
ID3D11Texture2D* BackBuffer;
hr = SwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (void**)&BackBuffer );
if(FAILED(hr))
{
MessageBox(NULL, DXGetErrorDescription(hr),TEXT("SwapChain->GetBuffer"), MB_OK);
return 0;
}
//Rendering Target
hr = D3d11Device->CreateRenderTargetView(BackBuffer,NULL,&renderTargetView);
BackBuffer->Release();
if(FAILED(hr))
{
MessageBox(NULL,DXGetErrorDescription(hr),TEXT("D3d11Device->CreateRenderTargetView"),MB_OK);
return 0;
}
//Targeting Render target
D3d11DevCon->OMSetRenderTargets( 1, &renderTargetView, NULL ); // <----------------- SET NOT GET!!!!!!
//Set the target
return true;

}
bool InitScene()
{

[size=5][u][b]//Compile Shaders from shader file 5 or 4 = VERSION
hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "VS", "vs_5_0", 0, 0, 0, &VSBuffer, 0, 0);
if(FAILED(hr))
{
MessageBox(NULL,DXGetErrorDescription(hr),"D3DX11CompileFromFile",MB_OK);
}
hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, 0, &VSBuffer, 0, 0);
if(FAILED(hr))
{
MessageBox(NULL,DXGetErrorDescription(hr),"D3DX11CompileFromFile",MB_OK);
}[/b][/u][/size]

//Create the Shader Objects
//The problem
hr = D3d11Device->CreateVertexShader(VSBuffer->GetBufferPointer(), VSBuffer->GetBufferSize(), NULL, &VS);
if(FAILED(hr))
{
MessageBox(NULL,DXGetErrorDescription(hr),"D3d11Device->CreateVertexShader",MB_OK);
}
hr = D3d11Device->CreatePixelShader(PSBuffer->GetBufferPointer(), PSBuffer->GetBufferSize(), NULL, &PS);
if(FAILED(hr))
{
MessageBox(NULL,DXGetErrorDescription(hr),"D3d11Device->CreatePixelShader",MB_OK);
}
//Set Vertex and Pixel Shaders
D3d11DevCon->VSSetShader(VS, 0, 0);
D3d11DevCon->PSSetShader(PS, 0, 0);
//Create the vertex buffer
Vertex v[] =
{
Vertex( 0.0f, 0.5f, 0.5f ),
Vertex( 0.5f, -0.5f, 0.5f ),
Vertex( -0.5f, -0.5f, 0.5f ),
};
D3D11_BUFFER_DESC vertexBufferDesc;
ZeroMemory( &vertexBufferDesc, sizeof(vertexBufferDesc) );
vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
vertexBufferDesc.ByteWidth = sizeof( Vertex ) * 3;
vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vertexBufferDesc.CPUAccessFlags = 0;
vertexBufferDesc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA vertexBufferData;
ZeroMemory( &vertexBufferData, sizeof(vertexBufferData) );
vertexBufferData.pSysMem = v;
hr = D3d11Device->CreateBuffer( &vertexBufferDesc, &vertexBufferData, &TriangleVertBuffer);
//Set the vertex buffer
UINT stride = sizeof( Vertex );
UINT offset = 0;
D3d11DevCon->IASetVertexBuffers( 0, 1, &TriangleVertBuffer, &stride, &offset );
//Create the Input Layout
hr = D3d11Device->CreateInputLayout( layout, numElements, VSBuffer->GetBufferPointer(),
VSBuffer->GetBufferSize(), &VertLayout );
//Set the Input Layout
D3d11DevCon->IASetInputLayout( VertLayout );
//Set Primitive Topology
D3d11DevCon->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
//Create the Viewport
D3D11_VIEWPORT viewport;
ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = windowWidth;
viewport.Height = windowHeight;
//Set the Viewport
D3d11DevCon->RSSetViewports(1, &viewport);

return true;
}
void UpdateScene()
{

}
void DrawScene()
{
float bgColor[4] = {(0.0f, 0.0f, 0.0f, 0.0f)};
D3d11DevCon->ClearRenderTargetView(renderTargetView, bgColor);
D3d11DevCon->Draw( 3, 0 );
SwapChain->Present(0,0);
}
void ReleaseObjects()
{
//Window Release
SwapChain->Release();
D3d11Device->Release();
D3d11DevCon->Release();
//Rendering Release
TriangleVertBuffer->Release();
VS->Release();
PS->Release();
VSBuffer->Release();
PSBuffer->Release();
VertLayout->Release();

}
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_KEYDOWN:
{
if(wParam == VK_ESCAPE)
{
if(MessageBox(0,"Are you sure you want to Quit","Really", MB_YESNO | MB_ICONQUESTION) == IDYES)
{
DestroyWindow(hWnd);
}
}
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;

}
}
return DefWindowProc(hWnd,msg,wParam,lParam);
}
[/CODE]

Share this post


Link to post
Share on other sites
Steve_Segreto    2080
I've noticed it is possible to successfully compile a shader into object code (array of DWORDs) and still have CreateVertexShader() fail with INVALID_PARAMETER if the original shader had invalid numbers of instructions, samplers, constants, etc.

What does the shader you are submitting look like? Edited by Steve_Segreto

Share this post


Link to post
Share on other sites
eppo    4877
Perhaps your hardware simply doesn't support shader model 5?

Create the D3D11 device with the debug layer enabled (D3D11_CREATE_DEVICE_DEBUG device flag). This should give you more insight as to what could be wrong. Edited by eppo

Share this post


Link to post
Share on other sites
Conny14156    279
I also tried version 4, but it gave me the same error and I tried both on my lappy and station computer, my laptop should support version 5, cause atleast that what google said >.<, But I will try the Debug flag tommorow,unable to do it at the moment :( Edited by Conny14156

Share this post


Link to post
Share on other sites
Conny14156    279
[quote name='eppo' timestamp='1354055062' post='5004704']
Perhaps your hardware simply doesn't support shader model 5?

Create the D3D11 device with the debug layer enabled (D3D11_CREATE_DEVICE_DEBUG device flag). This should give you more insight as to what could be wrong.
[/quote]
This may seems a stupid question but is this the correct way?
hr = D3D11CreateDeviceAndSwapChain
(
NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
D3D11_CREATE_DEVICE_DEBUG,
NULL,
NULL,
D3D11_SDK_VERSION,
&amp;SwapChainDesc,
&amp;SwapChain,
&amp;D3d11Device,
NULL,
&amp;D3d11DevCon
);

I get no "compiler error" when I do this but nothing else really changed o.o Edited by Conny14156

Share this post


Link to post
Share on other sites
Conny14156    279
I tested a few things today and it seems like D3d11Device->CreatePixelShader somehow is the source of my problem, am not sure why but if I remove this my compiler doesnt complains any more about the CreateVertexShader but something else. Is it possible that the PixelShader returns onto the vertex and thus creating the problem? or is it cause I have DxErr included? I notice that in the the tutorial source file he does not have it cause it looks cleaner that way, but is it also the cause of my error?

Share this post


Link to post
Share on other sites
Stuntdk    511
When you compile your pixelshader you are providing a pointer to the Vertexbuffer rather than the Pixelbuffer.
[source lang="cpp"]hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, 0, &VSBuffer, 0, 0);[/source]
Should be:
[source lang="cpp"]hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, 0, &PSBuffer, 0, 0);[/source]

Share this post


Link to post
Share on other sites
Conny14156    279
[quote name='Stuntdk' timestamp='1354169683' post='5005204']
When you compile your pixelshader you are providing a pointer to the Vertexbuffer rather than the Pixelbuffer.
[source lang="cpp"]hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, 0, &amp;VSBuffer, 0, 0);[/source]
Should be:
[source lang="cpp"]hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, 0, &amp;PSBuffer, 0, 0);[/source]
[/quote]

Yeha I noticed that to early today, biggest fail ever :(. but thank you :3. Edited by Conny14156

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By gomidas
      I am trying to add normal map to my project I have an example of a cube: 
      I have normal in my shader I think. Then I set shader resource view for texture (NOT BUMP)
                  device.ImmediateContext.PixelShader.SetShaderResource(0, textureView);             device.ImmediateContext.Draw(VerticesCount,0); What should I do to set my normal map or how it is done in dx11 generally example c++?
    • By fighting_falcon93
      Imagine that we have a vertex structure that looks like this:
      struct Vertex { XMFLOAT3 position; XMFLOAT4 color; }; The vertex shader looks like this:
      cbuffer MatrixBuffer { matrix world; matrix view; matrix projection; }; struct VertexInput { float4 position : POSITION; float4 color : COLOR; }; struct PixelInput { float4 position : SV_POSITION; float4 color : COLOR; }; PixelInput main(VertexInput input) { PixelInput output; input.position.w = 1.0f; output.position = mul(input.position, world); output.position = mul(output.position, view); output.position = mul(output.position, projection); output.color = input.color; return output; } And the pixel shader looks like this:
      struct PixelInput { float4 position : SV_POSITION; float4 color : COLOR; }; float4 main(PixelInput input) : SV_TARGET { return input.color; } Now let's create a quad consisting of 2 triangles and the vertices A, B, C and D:
      // Vertex A. vertices[0].position = XMFLOAT3(-1.0f, 1.0f, 0.0f); vertices[0].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // Vertex B. vertices[1].position = XMFLOAT3( 1.0f, 1.0f, 0.0f); vertices[1].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // Vertex C. vertices[2].position = XMFLOAT3(-1.0f, -1.0f, 0.0f); vertices[2].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // Vertex D. vertices[3].position = XMFLOAT3( 1.0f, -1.0f, 0.0f); vertices[3].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // 1st triangle. indices[0] = 0; // Vertex A. indices[1] = 3; // Vertex D. indices[2] = 2; // Vertex C. // 2nd triangle. indices[3] = 0; // Vertex A. indices[4] = 1; // Vertex B. indices[5] = 3; // Vertex D. This will result in a grey quad as shown in the image below. I've outlined the edges in red color to better illustrate the triangles:

      Now imagine that we’d want our quad to have a different color in vertex A:
      // Vertex A. vertices[0].position = XMFLOAT3(-1.0f, 1.0f, 0.0f); vertices[0].color = XMFLOAT4( 0.0f, 0.0f, 0.0f, 1.0f);
      That works as expected since there’s now an interpolation between the black color in vertex A and the grey color in vertices B, C and D. Let’s revert the previus changes and instead change the color of vertex C:
      // Vertex C. vertices[2].position = XMFLOAT3(-1.0f, -1.0f, 0.0f); vertices[2].color = XMFLOAT4( 0.0f, 0.0f, 0.0f, 1.0f);
      As you can see, the interpolation is only done half of the way across the first triangle and not across the entire quad. This is because there's no edge between vertex C and vertex B.
      Which brings us to my question:
      I want the interpolation to go across the entire quad and not only across the triangle. So regardless of which vertex we decide to change the color of, the color interpolation should always go across the entire quad. Is there any efficient way of achieving this without adding more vertices and triangles?
      An illustration of what I'm trying to achieve is shown in the image below:

       
      Background
      This is just a very brief explanation of the problems background in case that would make it easier for you to understand the problems roots and maybe help you with finding a better solution to the problem.
      I'm trying to texture a terrain mesh in DirectX11. It's working, but I'm a bit unsatisfied with the result. When changing the terrain texture of a single vertex, the interpolation with the other vertices results in a hexagon shape instead of a squared shape:

      As the red arrows illustrate, I'd like the texture to be interpolated all the way into the corners of the quads.
    • By -Tau-
      Hello, I'm close to releasing my first game to Steam however, my game keeps failing the review process because it keeps crashing. The problem is that the game doesn't crash on my computer, on my laptop, on our family computer, on fathers laptop and i also gave 3 beta keys to people i know and they said the game hasn't crashed.
      Steam reports that the game doesn't crash on startup but few frames after a level has been started.
      What could cause something like this? I have no way of debugging this as the game works fine on every computer i have.
       
      Game is written in C++, using DirectX 11 and DXUT framework.
    • By haiiry
      I'm trying to get, basically, screenshot (each 1 second, without saving) of Direct3D11 application. Code works fine on my PC(Intel CPU, Radeon GPU) but crashes after few iterations on 2 others (Intel CPU + Intel integrated GPU, Intel CPU + Nvidia GPU).
      void extractBitmap(void* texture) { if (texture) { ID3D11Texture2D* d3dtex = (ID3D11Texture2D*)texture; ID3D11Texture2D* pNewTexture = NULL; D3D11_TEXTURE2D_DESC desc; d3dtex->GetDesc(&desc); desc.BindFlags = 0; desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; desc.Usage = D3D11_USAGE_STAGING; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; HRESULT hRes = D3D11Device->CreateTexture2D(&desc, NULL, &pNewTexture); if (FAILED(hRes)) { printCon(std::string("CreateTexture2D FAILED:" + format_error(hRes)).c_str()); if (hRes == DXGI_ERROR_DEVICE_REMOVED) printCon(std::string("DXGI_ERROR_DEVICE_REMOVED -- " + format_error(D3D11Device->GetDeviceRemovedReason())).c_str()); } else { if (pNewTexture) { D3D11DeviceContext->CopyResource(pNewTexture, d3dtex); // Wokring with texture pNewTexture->Release(); } } } return; } D3D11SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast< void** >(&pBackBuffer)); extractBitmap(pBackBuffer); pBackBuffer->Release(); Crash log:
      CreateTexture2D FAILED:887a0005 DXGI_ERROR_DEVICE_REMOVED -- 887a0020 Once I comment out 
      D3D11DeviceContext->CopyResource(pNewTexture, d3dtex); 
      code works fine on all 3 PC's.
    • By Fluffy10
      Hi i'm new to this forum and was wondering if there are any good places to start learning directX 11. I bought Frank D Luna's book but it's really outdated and the projects won't even compile. I was excited to start learning from this book because it gives detailed explanations on the functions being used as well as the mathematics. Are there any tutorials / courses /books that are up to date which goes over the 3D math and functions in a detailed manner? Or where does anyone here learn directX 11? I've followed some tutorials from this website http://www.directxtutorial.com/LessonList.aspx?listid=11 which did a nice job but it doesn't explain what's happening with the math so I feel like I'm not actually learning, and it only goes up until color blending. Rasteriks tutorials doesn't go over the functions much at all or the math involved either. I'd really appreciate it if anyone can point me in the right direction, I feel really lost. Thank you
  • Popular Now