DX10 볼륨 렌더러를 DX10 버전으로 이식하려고합니다. 현재, 나는 다음과 같은 오류에 붙어있어 :HLSL (DX9-> DX10 포트)의 쉐이더 리소스 사용
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 ]
내 생각 엔 내가 올바른 방법으로 쉐이더에 2D 및/또는 3D 텍스처 (쉐이더 자원)를 전송하고 있지 않다이다; 또는 올바른 (dx10) 방식으로 사용하지 마십시오. DX9 코드는 다음과 같습니다 (이 질문을 위해 단순화되었습니다) :
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
실제 데이터가있는 3D 볼륨 텍스처도 비슷한 방식으로 전송됩니다. 대응하는 픽셀 쉐이더 코드 : DX10에서
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);
}
우리는 (지금까지 내가 이해) 쉐이더 코드의 일부를 단순화 할 수 있습니다. 빈 텍스처를 만들고이 텍스처를 map()/unmap()으로 채 웁니다. 다음으로 셰이더 리소스로 내 PS에 바인딩합니다.
// 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);
바인드 쉐이더 : 쉐이더에서
// 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);
사용 :이 오류가 있음을 단지 추측이라고
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;
}
참고 C++ 및 쉐이더 코드는 다음이 될 이 코드에 의해 소개되었습니다. 위의 코드가 올바른 것으로 보이는 경우 댓글로도 응답하십시오. 이 경우 솔루션을 찾기위한 새로운 방향이 가치있게됩니다.