   [DirectX 10] View dimensions problem
  I'm implementing light pre-pass technique described by Wolfgang Engel, but Im having a problem I never had before.This is the error:D3D10: ERROR: ID3D10Device::Draw: The view dimension declared in the shader code does not match the view type bound to slot 0 of the Pixel Shader unit. This 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 ]This is my shader:#include "Lighting.fx"cbuffer cbPerFrame{float3 gEyePosW;float4x4 gInvViewProj;Light gLight;int gLightType;}//normal map with specular powerTexture2D gNormalMap;Texture2D gDepthMap;SamplerState gTriPointSam{Filter = MIN_MAG_MIP_POINT;AddressU = CLAMP;    AddressV = CLAMP;};struct VS_IN{float3 posL : POSITION;float2 texC : TEXCOORD;};struct VS_OUT{float4 posH : SV_POSITION;float2 texC : TEXCOORD0;};VS_OUT VS(VS_IN vIn){VS_OUT vOut;vOut.posH = float4(vIn.posL, 1.0f);vOut.texC = vIn.texC;return vOut;}float4 PS(VS_OUT pIn) : SV_TARGET{float4 normalData = gNormalMap.Sample(gTriPointSam, pIn.texC);float3 normal = 2.0f * normalData.xyz - 1.0f;float4 specPower = normalData.a * 255.0f;float depth = gDepthMap.Sample(gTriPointSam, pIn.texC).r;float4 position;position.x = pIn.texC.x * 2.0f - 1.0f;position.y = -(pIn.texC.y * 2.0f - 1.0f);position.z = depth;position.w = 1.0f;position = mul(position, gInvViewProj);position /= position.w;SurfaceInfo v = {position, normal, specPower};float3 litColor;float shadowFactor = 1.0f;if(gLightType == 0){   litColor = ParallelLight(v, gLight, gEyePosW, shadowFactor);}else if(gLightType == 1){litColor = PointLight(v, gLight, gEyePosW, shadowFactor);}else{litColor = SpotLight(v, gLight, gEyePosW, shadowFactor);}return float4(litColor, 1.0f);}technique10 LightBufferTech{    pass P0    {   SetVertexShader( CompileShader( vs_4_0, VS() ) );   SetGeometryShader( NULL );   SetPixelShader( CompileShader( ps_4_0, PS() ) );    }}
  This means you screwed something up when you created the shader resource view for your texture. When you call ID3D10Device::CreateShaderResourceView and you pass the D3D10_SHADER_RESOURCE_VIEW_DESC struct, you need to set the ViewDimension member to D3D10_SRV_DIMENSION_TEXTURE2D in order to sample the texture as a Texture2D. You'll also need to set the D3D10_TEX2D_SRV struct to appropriate values.If you've created just a regular Texture2D, you should be able to just pas NULL for the pDesc parameter and it will do those things for you.   ;  This is how I created the Light Buffer:ID3D10Texture2D* lightBuffer = 0;D3D10_TEXTURE2D_DESC texDesc;texDesc.Width    = 1440;texDesc.Height   = 900;texDesc.MipLevels= 1;texDesc.ArraySize= 1;texDesc.Format   = DXGI_FORMAT_R8G8B8A8_UNORM;texDesc.SampleDesc.Count   = 8;  texDesc.SampleDesc.Quality = 16;  texDesc.Usage    = D3D10_USAGE_DEFAULT;texDesc.BindFlags= D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;texDesc.CPUAccessFlags= 0; texDesc.MiscFlags= D3D10_RESOURCE_MISC_GENERATE_MIPS;if(FAILED(d3dDevice->CreateTexture2D(&texDesc, 0, &lightBuffer))){MessageBox(0, "Error creating Light Buffer Texture", "Error", MB_OK);return E_FAIL;}if(FAILED(d3dDevice->CreateRenderTargetView(lightBuffer, 0, &mLightBufferRT))){MessageBox(0, "Error creating Light Buffer Render Target", "Error", MB_OK);return E_FAIL;}if(FAILED(d3dDevice->CreateShaderResourceView(lightBuffer, 0, &mLightBufferRV))){MessageBox(0, "Error creating Light Buffer Shader Resource", "Error", MB_OK);return E_FAIL;}lightBuffer->Release();Normal map:ID3D10Texture2D* normalsMap = 0;D3D10_TEXTURE2D_DESC texDesc;texDesc.Width    = 1440;texDesc.Height   = 900;texDesc.MipLevels= 1;texDesc.ArraySize= 1;texDesc.Format   = DXGI_FORMAT_R8G8B8A8_UNORM;texDesc.SampleDesc.Count   = 8;  texDesc.SampleDesc.Quality = 16;  texDesc.Usage    = D3D10_USAGE_DEFAULT;texDesc.BindFlags= D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;texDesc.CPUAccessFlags= 0; texDesc.MiscFlags= D3D10_RESOURCE_MISC_GENERATE_MIPS;if(FAILED(d3dDevice-&gt;CreateTexture2D(&texDesc, 0, &normalsMap))){MessageBox(0, "Error creating Normals Map Texture", "Error", MB_OK);return E_FAIL;}if(FAILED(d3dDevice-&gt;CreateRenderTargetView(normalsMap, 0, &mNormalMapRT))){MessageBox(0, "Error creating Normals Map Render Target", "Error", MB_OK);return E_FAIL;}if(FAILED(d3dDevice-&gt;CreateShaderResourceView(normalsMap, 0, &mNormalMapRV))){MessageBox(0, "Error creating Normals Map Shader Resource", "Error", MB_OK);return E_FAIL;}normalsMap-&gt;Release();Depth map:ID3D10Texture2D* depthMap = 0;D3D10_TEXTURE2D_DESC texDesc;texDesc.Width    = 1440;texDesc.Height   = 900;texDesc.MipLevels= 1;texDesc.ArraySize= 1;texDesc.Format   = DXGI_FORMAT_R8G8B8A8_UNORM;texDesc.SampleDesc.Count   = 8;  texDesc.SampleDesc.Quality = 16;  texDesc.Usage    = D3D10_USAGE_DEFAULT;texDesc.BindFlags= D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;texDesc.CPUAccessFlags= 0; texDesc.MiscFlags= D3D10_RESOURCE_MISC_GENERATE_MIPS;if(FAILED(d3dDevice->CreateTexture2D(&texDesc, 0, &depthMap))){MessageBox(0, "Error creating Depth Map Texture", "Error", MB_OK);return E_FAIL;}if(FAILED(d3dDevice->CreateRenderTargetView(depthMap, 0, &mDepthMapRT))){MessageBox(0, "Error creating Depth Map Render Target", "Error", MB_OK);return E_FAIL;}if(FAILED(d3dDevice->CreateShaderResourceView(depthMap, 0, &mDepthMapRV))){MessageBox(0, "Error creating Depth Map Shader Resource", "Error", MB_OK);return E_FAIL;}depthMap->Release();;  Your resources are multisampled. This means that if you pass NULL for the pDesc parameter of CreateShaderResourceView, you will end up with a view dimension of D3D10_SRV_DIMENSION_TEXTURE2DMS. To sample this in your shader you need to declare a Texture2DMS in your shader, not Texture2D. You must also use Load() on the Texture2DMS object, and specify which subsample you want.;  Well I dont know how to use the Load function...Can you please tell me?;  Docs on Load are here;  Ok, can you see if I have done everything right?I set me resources to Texture2DMS and it doesn't worked, then I set them to Texture2DMS<float> and it worked but I dont understand why the <float4>...Also how do I choose the sample index...#include "Lighting.fx"cbuffer cbPerFrame{float3 gEyePosW;float4x4 gInvViewProj;Light gLight;int gLightType;}//normal map with specular powerTexture2DMS<float4> gNormalMap;Texture2DMS<float4> gDepthMap;struct VS_IN{float3 posL : POSITION;float2 texC : TEXCOORD;};struct VS_OUT{float4 posH : SV_POSITION;float2 texC : TEXCOORD0;};VS_OUT VS(VS_IN vIn){VS_OUT vOut;vOut.posH = float4(vIn.posL, 1.0f);vOut.texC = vIn.texC;return vOut;}float4 PS(VS_OUT pIn) : SV_TARGET{float4 normalData = gNormalMap.Load(pIn.texC, 0);float3 normal = 2.0f * normalData.xyz - 1.0f;float4 specPower = normalData.a * 255.0f;float depth = gDepthMap.Load(pIn.texC, 0).r;float4 position;position.x = pIn.texC.x * 2.0f - 1.0f;position.y = -(pIn.texC.y * 2.0f - 1.0f);position.z = depth;position.w = 1.0f;position = mul(position, gInvViewProj);position /= position.w;SurfaceInfo v = {position, normal, specPower};float3 litColor;float shadowFactor = 1.0f;if(gLightType == 0){   litColor = ParallelLight(v, gLight, gEyePosW, shadowFactor);}else if(gLightType == 1){litColor = PointLight(v, gLight, gEyePosW, shadowFactor);}else{litColor = SpotLight(v, gLight, gEyePosW, shadowFactor);}return float4(0.0f, 0.0f, 0.0f, 1.0f);}technique10 LightBufferTech{    pass P0    {   SetVertexShader( CompileShader( vs_4_0, VS() ) );   SetGeometryShader( NULL );   SetPixelShader( CompileShader( ps_4_0, PS() ) );    }};  All texture objects are actually pseudo templates.  You can provide that data type explicitly that  you expect to load from them, otherwise the compiler just makes a guess.  This can be useful for debugging purposes with the shader pipeline validator.MultiSample objects also accept a sample count parameter, like this:Texture2DMS<float4,8> ....;  // Indicates 8 samples. The docs should have information on the different sample patterns and I think each IHV has some of their own that you an query for.Your pixel shader program can execute at either pixel frequency or sample frequency depending on how your shader is written.   