Sign in to follow this  
link3978

The Pixel Shader unit expects a Shader Resource View at Slot 0, but none is bound.

Recommended Posts

Hi all, I am stumped. When I try to render a mesh using diffuse textures for all the submeshes, my mesh is colored all black and I get this debug output from d3d: "The Pixel Shader unit expects a Shader Resource View at Slot 0, but none is bound." I googled around but didn't find any information that helped me. I am using the "D3D10_BIND_SHADER_RESOURCE" flag when using D3DX10CreateTextureFromFile() method. I don't really know what else to explain so I will paste the code that creates the diffuse texture and it's resource view, and the code a snippet of rendering code.
		// Create Diffuse Texture View
		ID3D10Device* pd3dDevice = DXUTGetD3D10Device();

		D3DX10_IMAGE_INFO srcInfo;
		D3DX10_IMAGE_LOAD_INFO loadInfo;
		ZeroMemory( &loadInfo, sizeof(D3DX10_IMAGE_LOAD_INFO) );

		D3DX10GetImageInfoFromFile( mpDiffuseTxFilePathName.c_str(), NULL, &srcInfo, NULL );
		loadInfo.pSrcInfo = &srcInfo;
		loadInfo.Format = loadInfo.pSrcInfo->Format;
		loadInfo.BindFlags = D3D10_BIND_SHADER_RESOURCE;

		V_RETURN(D3DX10CreateTextureFromFile( pd3dDevice, mpDiffuseTxFilePathName.c_str(), &loadInfo, NULL, ( ID3D10Resource** )&mpDiffuseTx, NULL ));
		
		D3D10_SHADER_RESOURCE_VIEW_DESC SRVDesc;
		SRVDesc.Format = loadInfo.pSrcInfo->Format;
		SRVDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
		SRVDesc.Texture2D.MostDetailedMip = 0;
		SRVDesc.Texture2D.MipLevels = loadInfo.pSrcInfo->MipLevels;

		V_RETURN(pd3dDevice->CreateShaderResourceView( mpDiffuseTx, &SRVDesc, &mpDiffuseTxRV ));
Rendering code
			D3D10_TECHNIQUE_DESC techDesc;
			pTechnique->GetDesc( &techDesc );

			SubMesh10* pSubMesh;
			Material10* pMaterial;
			ID3D10ShaderResourceView* pDiffuseRV = NULL;
			D3D10_PRIMITIVE_TOPOLOGY primType;
			for( UINT passIndex = 0; passIndex < techDesc.Passes; ++passIndex )
			{
				for( INT meshIndex = 0; meshIndex < pMesh->GetNumSubMeshes(); ++meshIndex )
				{
					pSubMesh = pMesh->GetSubMesh( meshIndex );
					pMaterial = pSubMesh->GetMaterial();

					primType = pSubMesh->GetPrimitiveType();
					pd3dDevice->IASetPrimitiveTopology( primType );

					pDiffuseRV = pMaterial->GetDiffuseResourceView();
					pTxDiffuseVariable->SetResource( pDiffuseRV );

					pTechnique->GetPassByIndex( passIndex )->Apply( NULL );

					INT indexBufferLength = pSubMesh->GetIndexBufferLength();
					INT startIndexLocation = pSubMesh->GetStartIndexLocation();
					INT baseVertexLocation = pSubMesh->GetBaseVertexLocation();
					pd3dDevice->DrawIndexed( indexBufferLength, startIndexLocation, baseVertexLocation );
				}
			}
Thanks for any help! [Edited by - link3978 on September 14, 2009 8:06:21 PM]

Share this post


Link to post
Share on other sites
How are the variables mpDiffuseTxRV and pDiffuseRV related? Are you sure that pDiffuseRV is not null at the time you call pTxDiffuseVariable->SetResource (step to the line with the debugger and see)?

The error itself is very simple - there is no resource (texture, in this case) bound at resource slot 0 even though the pixel shader expects one to be there. If you call SetShaderResource (the effect framework calls this as a result of pTxDiffuseVariable->SetResource) with 0 as the resource handle, the corresponding slot will be emptied.

Share this post


Link to post
Share on other sites
Thanks for the reply. Yes I am sure pDiffuseRV("pDiffuseRV = pMaterial->GetDiffuseResourceView();") is not NULL, I just stepped through it.

You asked how pDiffuseRV and mpDiffuseTxRV are related. They are the same just mpDiffuseTxRV is inside a Material10 object.

This line "pDiffuseRV = pMaterial->GetDiffuseResourceView();" calls this method:


ID3D10ShaderResourceView* GetDiffuseResourceView()
{
return mpDiffuseTxRV;
}


Also, here are the data members to my Material10 class:


private:
wstring mpDiffuseTxFilePathName;
ID3D10Texture2D* mpDiffuseTx;
ID3D10ShaderResourceView* mpDiffuseTxRV;

Share this post


Link to post
Share on other sites
You have to bind the resource view to an input slot of the pixel shader, this is done by adding something like this to your Material class:


void Material::BindResources(ID3D10Device* device)
{
device->PSSetShaderResources(0, 1, &shaderResourceView);
}

Share this post


Link to post
Share on other sites
Yay, the solution poped into my head right after I replyed to you.

It turns out I had forgotten I had changed the name of the Texture2D in my .fx file (it previously was "g_TxDiffuse", but I changed it to "TxDiffuse").

I needed to change the line from:

mpTxDiffuseVariable = mpEffect->GetVariableByName( "g_TxDiffuse" )->AsShaderResource();


to:


mpTxDiffuseVariable = mpEffect->GetVariableByName( "TxDiffuse" )->AsShaderResource();


Thanks for your help!

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