Issue with Cubemap Shader Resource View Mismatch

Started by
8 comments, last by 21st Century Moose 8 years, 8 months ago

I've been getting this debug info error in the output window of VS 2013.


D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: The Shader Resource View dimension declared in the shader code (TEXTURE2D) does not match the view type bound to slot 1 of the Pixel Shader unit (TEXTURECUBE).  This mismatch is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching). [ EXECUTION ERROR #354: DEVICE_DRAW_VIEW_DIMENSION_MISMATCH]

The cubemap is created at 256 x 256. I have diffuse, normal, specular, parallax bound to slot 0 and if there is a reflection map (Cube map) then i have it bounded to slot 1.

Mesh draw call:


ID3D11ShaderResourceView *textures[3] = { diffusemap.getShaderResourceView(), normalMap.getShaderResourceView(), displacementMap.getShaderResourceView() };
	canvas->getDeviceContext()->PSSetShaderResources(0, 3, textures);

	additionalSRV = reflectionMap.getShaderResourceView();
	if (additionalSRV)
		canvas->getDeviceContext()->PSSetShaderResources(1, 1, &additionalSRV);

Why would the debug info give me this error?

Game Engine's WIP Videos - http://www.youtube.com/sicgames88
SIC Games @ GitHub - https://github.com/SICGames?tab=repositories
Simple D2D1 Font Wrapper for D3D11 - https://github.com/SICGames/D2DFontX
Advertisement

Because you're declaring it as Texture2D instead of TextureCube in the shader.

Declaring it as TextureCube

basicshader.hlsl


SamplerState ss : register(s0);
Texture2D textures[3] : register(t0);
TextureCube envmapTexture;

But I think you're right about something actually - because if the reflection map doesn't exist it's still calling upon envmaptexture.sample to something that's not there. Hold on I'll give you an update - gotta update material and mesh calls - then I'll get back to you on this issue. There needs to be a check to see if there's a relfectionmap enabled in the material constant buffer. I'll get back to you one second.

Game Engine's WIP Videos - http://www.youtube.com/sicgames88
SIC Games @ GitHub - https://github.com/SICGames?tab=repositories
Simple D2D1 Font Wrapper for D3D11 - https://github.com/SICGames/D2DFontX

Look closely:

canvas->getDeviceContext()->PSSetShaderResources(0, 3, textures);
canvas->getDeviceContext()->PSSetShaderResources(1, 1, &additionalSRV);

Basically you bind diffuse to slot 0, normal to slot 1, displacement to slot 2, then reflection to slot 1 again.

ah now I see what is going on. That has always tripped me up badly! So it should more look like this:


canvas->getDeviceContext()->PSSetShaderResrouces(0,3,textures);
canvas->getDeviceContext()->PSSetShaderResrouces(4,1,&additionalSRV);
Game Engine's WIP Videos - http://www.youtube.com/sicgames88
SIC Games @ GitHub - https://github.com/SICGames?tab=repositories
Simple D2D1 Font Wrapper for D3D11 - https://github.com/SICGames/D2DFontX

No more of those errrors any more! That was tripping me up horribly! This is good because next time someone has a similar issue they can always check this topic out and learn how to correct it.

Game Engine's WIP Videos - http://www.youtube.com/sicgames88
SIC Games @ GitHub - https://github.com/SICGames?tab=repositories
Simple D2D1 Font Wrapper for D3D11 - https://github.com/SICGames/D2DFontX

canvas->getDeviceContext()->PSSetShaderResrouces(0,3,textures);
canvas->getDeviceContext()->PSSetShaderResrouces(3,1,&additionalSRV);



L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

that's what I meant L. Spiro thanks

Game Engine's WIP Videos - http://www.youtube.com/sicgames88
SIC Games @ GitHub - https://github.com/SICGames?tab=repositories
Simple D2D1 Font Wrapper for D3D11 - https://github.com/SICGames/D2DFontX

For what it's worth...

Texture2D textures[3] : register(t0);

Your original code would have worked if you'd declared this as:

Texture2DArray textures : register(t0);

And then called CreateTexture2D with ArraySize 3, and with the proviso that each of your diffuse, normal, specular, and parallax layers should be the same size.

I guess that this kind of usage was what you actually originally intended; unfortunately the terminology used here (i.e use of the word "array") can sometimes be a litle misleading.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement