我正在尝试使用深度缓冲区作为我的着色器中第二遍的纹理。
根据official documentation("将深度模板缓冲区作为纹理读取" 段落),我已将D3D11_TEXTURE2D_DESC.Format
设置为{ {1}}(之前是DXGI_FORMAT_R24G8_TYPELESS
,当我没有使用深度缓冲区作为纹理时):
DXGI_FORMAT_D24_UNORM_S8_UINT
D3D11_TEXTURE2D_DESC descDepth;
ZeroMemory(&descDepth, sizeof(descDepth));
descDepth.Width = width;
descDepth.Height = height;
descDepth.MipLevels = 1;
descDepth.ArraySize = 1;
descDepth.Format = DXGI_FORMAT_R24G8_TYPELESS; //normally it was DXGI_FORMAT_D24_UNORM_S8_UINT
descDepth.SampleDesc.Count = antiAliasing.getCount();
descDepth.SampleDesc.Quality = antiAliasing.getQuality();
descDepth.Usage = D3D11_USAGE_DEFAULT;
descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;
descDepth.CPUAccessFlags = 0;
descDepth.MiscFlags = 0;
ID3D11Texture2D* depthStencil = NULL;
result = device->CreateTexture2D(&descDepth, NULL, &depthStencil);
成功了。然后我尝试为我的缓冲区创建着色器资源视图:
results
不幸的是,这会产生错误:
D3D11错误:ID3D11Device :: CreateShaderResourceView:格式(0x29, 创建视图时,R32_FLOAT)无效;它不是一个完整的 资源格式的合格格式castable(0x2c, R24G8_TYPELESS)。 [STATE_CREATION错误#127: CREATESHADERRESOURCEVIEW_INVALIDFORMAT]
D3D11错误:ID3D11Device :: CreateShaderResourceView:返回E_INVALIDARG, 意味着传递了无效参数。 [STATE_CREATION错误#131: CREATESHADERRESOURCEVIEW_INVALIDARG_RETURN]
我也尝试将D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc;
//setup the description of the shader resource view
shaderResourceViewDesc.Format = DXGI_FORMAT_R32_FLOAT;
shaderResourceViewDesc.ViewDimension = antiAliasing.isOn() ? D3D11_SRV_DIMENSION_TEXTURE2DMS : D3D11_SRV_DIMENSION_TEXTURE2D;
shaderResourceViewDesc.Texture2D.MostDetailedMip = 0;
shaderResourceViewDesc.Texture2D.MipLevels = 1;
//create the shader resource view.
device->CreateShaderResourceView(depthStencil, &shaderResourceViewDesc, &depthStencilShaderResourceView);
,DXGI_FORMAT_R24G8_TYPELESS
和DXGI_FORMAT_D24_UNORM_S8_UINT
作为DXGI_FORMAT_R8G8B8A8_UNORM
。
问题出在哪里?我正在关注文档而我没有看到它。
答案 0 :(得分:1)
DXGI_FORMAT_R24G8_TYPELESS
和DXGI_FORMAT_R32_FLOAT
格式不兼容'。该无类型格式仅与DXGI_FORMAT_D24_UNORM_S8_UINT
,DXGI_FORMAT_R24_UNORM_X8_TYPELESS
和DXGI_FORMAT_X24_TYPELESS_G8_UINT
DXGI_FORMAT_R32_TYPELESS
与DXGI_FORMAT_D32_FLOAT
和DXGI_FORMAT_R32_FLOAT