Question

I'm trying to port my DX9 volume renderer to a DX10 version. Currently, i'm stuck at the following error:

D3D10: ERROR: ID3D10Device::DrawIndexed: 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 ]

My guess is that I'm not sending the 2D and/or 3D textures (shader resources) to the shader in the correct way; or do not use them in the correct (dx10) way. The DX9 code was something like the following (simplified for the sake of this question):

HRESULT hr; int nVertexShaderIndex = 0;

// Setup the 2D Dependent Lookup Texture
hr = m_pDevice->SetTexture(0, lookupTexture); // lookupTexture is a LPDIRECT3DTEXTURE9
if (hr != D3D_OK) {
        //handle error
}

m_pDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
m_pDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
m_pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
m_pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);

// Maximum Intensity 
m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE);    // Enable Alpha blend
m_pDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE);    // 1 * SRC color
m_pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE);   // 1 * DST color
m_pDevice->SetRenderState( D3DRS_BLENDOP, D3DBLENDOP_MAX);   // MAX blend
m_pDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );           // Disable Z

A 3D volume texture with the actual data is send in a similar manner. The corresponding pixel shader code:

PS_OUTPUT Main(VS_OUTPUT vsIn,
               uniform sampler2D lookupTexture : TEXUNIT0,
               uniform sampler3D dataTexture   : TEXUNIT1)
{
  PS_OUTPUT psOut; 
  float dataValue;

  psOut.color = SampleWith2DLookup(vsIn.TexCoord0,
                                   lookupTexture,
                                   dataTexture,
                                   dataValue);
  return psOut;
}

float4 LookupIn2DTexture(float value, 
                         uniform sampler2D lookupTexture)
{
  float2 lutCoord;
  float4 outColor;

  // Build a 2D Coordinate for lookup
  lutCoord[0] = value;
  lutCoord[1] = 0.0f; 

  outColor = tex2D(lookupTexture, lutCoord);
  return(outColor);
}


float4 SampleWith2DLookup(const float3 TexCoord, 
                          uniform sampler2D lookupTexture, 
                          uniform sampler3D dataTexture,
                          out float dataValue)
{
  float  value;
  float4 outputColor;

  value = Sample(TexCoord, dataTexture);
  outputColor = LookupIn2DTexture(value, lookupTexture);

  dataValue = value;

  return(outputColor);
}

In DX10 we can simplify some of the shader code (as far as I understand). I create an empty texture and fill this texture with map()/unmap(). Next I bind it as a shader resource to my PS. The c++ and shader code become the following:

// CREATE THE EMPTY TEXTURE
D3D10_TEXTURE2D_DESC desc;
ZeroMemory(&desc, sizeof(desc));
desc.Width = 4096;
desc.Height = 1;
desc.ArraySize = 1;
desc.MipLevels = 1;
desc.Format = GetHardwareResourceFormatDX10();
desc.Usage = D3D10_USAGE_DYNAMIC;
desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
desc.SampleDesc.Count = 1;      

hr = m_pDeviceDX10->CreateTexture2D(&desc, NULL, &lookupTexture);

bind to shader:

// SEND TO SHADER 
ID3D10ShaderResourceView* pTexDepSurface = NULL;
D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc;
D3D10_TEXTURE2D_DESC desc;
pTexDep->GetDesc( &desc );
srvDesc.Format = desc.Format;
srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = desc.MipLevels;
srvDesc.Texture2D.MostDetailedMip = desc.MipLevels -1;
hr = m_pDeviceDX10->CreateShaderResourceView(pTexDep, &srvDesc, &pTexDepSurface);
if (FAILED(hr)) {
        //handle here
}
m_pDeviceDX10->PSSetShaderResources(0,1, &pTexDepSurface);

Use in shader:

Texture2D LookupTexture : register(t0);
SamplerState LookupSampler : register(s0);

Texture2D VolumeTexture : register(t1);
SamplerState VolumeSampler : register(s1);

PS_OUTPUT Main(VS_OUTPUT vsIn,
               uniform sampler2D lookupTexture : TEXUNIT0,
               uniform sampler3D dataTexture   : TEXUNIT1)
{
  PS_OUTPUT psOut; 
  float dataValue;

  dataValue = VolumeTexture.Sample(VolumeSampler,vsIn.TexCoord0);
  psOut.color = LookupTexture.Sample(LookupSampler,dataValue);
  return psOut;
}

Note that it is just an educated guess that the error is introduced by this code. If the code above looks correct to you, please respond so as well (in comments). In that case, a new direction to find a solution would be valued.

Was it helpful?

Solution

After a day's work I did find my problem; I forgot to recompile my updated shaders. So the DX9 version was still loaded instead of the DX10 version of the shader, very stupid, but also very common mistake.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top