Jump to content

  • Log In with Google      Sign In   
  • Create Account


andyhansen

Member Since 24 Nov 2010
Offline Last Active Jun 08 2012 08:34 PM

Topics I've Started

Effect reflection stack error - Effects11

28 May 2012 - 12:16 PM

I am attempting to use the reflection features of the effects11 library to retrieve the argument list for a pass's vertex shader.
When I call GetInputSignatureElementDesc() I get a runtime check error, "Run-Time Check Failure #2 - Stack around the variable ParamDesc was corrupted."

Is this something other people have experienced? I'm hoping it isn't due to a memory error buried somewhere in my code.

Here is the code where I compile the effect an try to read in a parameter.


	DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
	// Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders.
	// Setting this flag improves the shader debugging experience, but still allows
	// the shaders to be optimized and to run exactly the way they will run in
	// the release configuration of this program.
	dwShaderFlags |= D3DCOMPILE_DEBUG;
#endif

ID3DBlob* pErrorBlob;
ID3DBlob* compiled;

HRESULT hr=D3DX11CompileFromFile(file.c_str(),NULL,NULL,NULL,GetProfile(device).c_str(),dwShaderFlags,NULL,NULL,&compiled,&pErrorBlob,NULL);

	if( FAILED(hr) )
	{
		if( pErrorBlob != NULL ){
throw runtime_error((char*)pErrorBlob->GetBufferPointer());
if( pErrorBlob ) pErrorBlob->Release();
}
else{
throw runtime_error("Failed to compile effect "+StringUtil::WstrToStr(file));
}
	}

hr=D3DX11CreateEffectFromMemory(compiled->GetBufferPointer(),compiled->GetBufferSize(),NULL,device.GetDevice(),&effect);

compiled->Release();

if(FAILED(hr)){
throw runtime_error("Failed to create effect from file");
}

UINT i=0;
ID3DX11EffectTechnique* technique=effect->GetTechniqueByIndex(i++);

while(technique->IsValid()){
   D3DX11_PASS_SHADER_DESC vsDesc;
   technique->GetPassByIndex(0)->GetVertexShaderDesc(&vsDesc);
   D3D11_SIGNATURE_PARAMETER_DESC paramDesc;
   vsDesc.pShaderVariable->GetInputSignatureElementDesc(vsDesc.ShaderIndex,0,&paramDesc);
   technique=effect->GetTechniqueByIndex(i++);
}

Right now I'm just trying to read the first parameter of the first pass of each technique to see if it will work. After the runtime error is triggered, I can hover my mouse over paramDesc, and it seems to have at least some of the correct data in it. I can't find any actual examples of how to do effect reflection, so I may be doing something wrong.

Shadow map Texture format

05 August 2011 - 01:52 PM

I'm currently working on implementing shadow mapping. I'm using DirectX 11 at feature level 9.1 since that is what my laptop supports. It seems the texture formats supported as render targets at this feature level is pretty limited.

The table here shows what is supported.
http://msdn.microsoft.com/en-us/library/ff471324%28v=vs.85%29.aspx

R8G8B8A8_UNORM
R8G8B8A8_UNORM_SRGB

These seem to be the only supported render target formats. This means that I can only store 8 bits of depth precision, rather than using the full 32. What would be ideal is if I could use R32_FLOAT.
Is there a way I can somehow use R8G8B8A8_UNORM or R8G8B8A8_UNORM_SRGB, but use all 32 bits to store a single value, rather than only 8 bits?

Skybox rendering

23 July 2011 - 09:43 PM

I've been trying to implement skybox rendering. I have it mostly working, except that when I move the camera, the polygons of my skybox will sometimes flicker out of view, showing the backdrop color behind it.

I'm using a textured cube with the vertex order reversed to represent the skybox.

I'm setting the depthstencilstate to this:

DepthEnable=TRUE;
DepthWriteMask=D3D11_DEPTH_WRITE_MASK_ALL;
DepthFunc=D3D11_COMPARISON_LESS_EQUAL;
StencilEnable=FALSE;
StencilReadMask=D3D11_DEFAULT_STENCIL_READ_MASK;
StencilWriteMask=D3D11_DEFAULT_STENCIL_WRITE_MASK;


My vertex shader looks like this:

VS_OUT VS(float3 Pos : POSITION, float2 Tex: TEXCOORD0)
{
	VS_OUT output = (VS_OUT)0;
	output.posH=mul(float4(Pos,1),World);
	//make z and w the same so that the depth is always considered 1
	output.posH=mul(output.posH,ViewProjection).xyww;
	output.tex0=Tex;
	return output;
}


I'm rendering the skybox after everything else. Could this just be a problem with my graphics card? I'm currently running on an intel integrated card on my laptop with dx9.

It all works perfectly except for when I start to move or rotate the camera.


Edit: I was able to try it on another computer, and the problem disappeared. So it must have something to do with the intel card. Is there any way I could prevent this problem from occurring though?

Optimizing CPU cache use in render loop

09 June 2011 - 01:34 PM

I've been working on optimizing my render loop to make the best use of the CPU cache.

Right now I'm simply keeping a vector of pointers to each object to be rendered. I then iterate through the vector and call each objects Render() method. Inside the render method, each object updates the World matrix that is passed to the shader, then performs the draw call on its geometry.

I'm thinking this is very cache inefficient, since each rendered object could be located anywhere in memory.

I want to change up the way I do rendering by storing all needed data in a contiguous array.

For example

struct Model{
XMFLOAT4X4world;
ID3D11Buffer* index;
ID3D11Buffer* vertices;
short iIndexCount;



};
Model data[ModelCount];

Then I would loop through data[] and perform the draw call on the data contained at each contiguous location of memory. I would think that this would improve cache usage a lot. The only thing I wonder about is what cache hit the actual draw call would entail. The structure is storing pointers to the index and vertex buffer. Would issuing the draw call cause problems? Would it be better for me to use a command list while looping through the data[] array, and then call the command list after the loop?

Or is there an even better way to setup a render loop? I'm open to suggestions.

(KernelBase.dll) Microsoft C++ exception: _com_error at memory location 0x0021e7dc..

05 March 2011 - 04:45 PM

I've been working on porting my DirectX Framework over to DX11. At runtime I've been getting the following type of error:
First-chance exception at 0x75b69617 (KernelBase.dll) in Engine.exe: Microsoft C++ exception: _com_error at memory location 0x0021e7dc..

Multiple of these exceptions are thrown. It occurs when I call: D3D11CreateDeviceAndSwapChain

//Create the swap chain parameters
	DXGI_SWAP_CHAIN_DESC sd;
	ZeroMemory(&sd,sizeof(sd));
	sd.BufferCount=1;
	sd.BufferDesc.Width=Engine->GetWindow()->GetWindowWidth();
	sd.BufferDesc.Height=Engine->GetWindow()->GetWindowHeight();
	sd.BufferDesc.Format=DXGI_FORMAT_R8G8B8A8_UNORM;
	sd.BufferDesc.RefreshRate.Numerator=60;
	sd.BufferDesc.RefreshRate.Denominator=1;
	sd.BufferUsage=DXGI_USAGE_RENDER_TARGET_OUTPUT;
	sd.OutputWindow=Engine->GetWindow()->GetHandle();
	sd.SampleDesc.Count=1;
	sd.SampleDesc.Quality=0;
	sd.Windowed=(Engine->GetWindow()->GetWindowMode()==CWindow::WINDOW);
	//create the swap chain
	UINT flags=0;
	D3D_FEATURE_LEVEL fl;
	#if defined(DEBUG) || defined(_DEBUG)
		flags |= D3D11_CREATE_DEVICE_DEBUG;
    #endif
	if(FAILED(D3D11CreateDeviceAndSwapChain(NULL,D3D_DRIVER_TYPE_HARDWARE,NULL,0,NULL,NULL,D3D11_SDK_VERSION,&sd,&pSwapChain,&pDevice,&fl,&pImmediateContext))){
		Engine->ShowError("Failed to create d3d device.");
		return;
	}

I'm using VS C++ 2010 professional. I created the project as an empty Win32 project. Does anyone have any ideas? I've been working at this for hours.

PARTNERS