GSdx-d3d: Support depth as texture.

- Create depth as typeless format and bind shader resource flag.
- Create depth and shader resource view using proper typed formats.
This commit is contained in:
Kojin 2018-12-04 00:20:41 -05:00 committed by lightningterror
parent eb3a423f80
commit ade00f8a70
2 changed files with 30 additions and 10 deletions

View File

@ -552,7 +552,7 @@ GSTexture* GSDevice11::CreateSurface(int type, int w, int h, bool msaa, int form
desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
break;
case GSTexture::DepthStencil:
desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
desc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;
break;
case GSTexture::Texture:
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
@ -599,7 +599,7 @@ GSTexture* GSDevice11::CreateRenderTarget(int w, int h, bool msaa, int format)
GSTexture* GSDevice11::CreateDepthStencil(int w, int h, bool msaa, int format)
{
return __super::CreateDepthStencil(w, h, msaa, format ? format : DXGI_FORMAT_D32_FLOAT_S8X24_UINT); // DXGI_FORMAT_R32G8X24_TYPELESS
return __super::CreateDepthStencil(w, h, msaa, format ? format : DXGI_FORMAT_R32G8X24_TYPELESS);
}
GSTexture* GSDevice11::CreateTexture(int w, int h, int format)
@ -637,12 +637,7 @@ GSTexture* GSDevice11::CopyOffscreen(GSTexture* src, const GSVector4& sRect, int
format = DXGI_FORMAT_R8G8B8A8_UNORM;
}
if(format != DXGI_FORMAT_R8G8B8A8_UNORM && format != DXGI_FORMAT_R16_UINT && format != DXGI_FORMAT_R32_UINT)
{
ASSERT(0);
return false;
}
ASSERT(format == DXGI_FORMAT_R8G8B8A8_UNORM || format == DXGI_FORMAT_R16_UINT || format == DXGI_FORMAT_R32_UINT);
if(GSTexture* rt = CreateRenderTarget(w, h, false, format))
{

View File

@ -210,7 +210,20 @@ GSTexture11::operator ID3D11ShaderResourceView*()
{
ASSERT(!m_msaa);
m_dev->CreateShaderResourceView(m_texture, NULL, &m_srv);
if(m_desc.Format == DXGI_FORMAT_R32G8X24_TYPELESS)
{
D3D11_SHADER_RESOURCE_VIEW_DESC srvd = {};
srvd.Format = DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS;
srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srvd.Texture2D.MipLevels = 1;
m_dev->CreateShaderResourceView(m_texture, &srvd, &m_srv);
}
else
{
m_dev->CreateShaderResourceView(m_texture, NULL, &m_srv);
}
}
return m_srv;
@ -244,7 +257,19 @@ GSTexture11::operator ID3D11DepthStencilView*()
{
if(!m_dsv && m_dev && m_texture)
{
m_dev->CreateDepthStencilView(m_texture, NULL, &m_dsv);
if(m_desc.Format == DXGI_FORMAT_R32G8X24_TYPELESS)
{
D3D11_DEPTH_STENCIL_VIEW_DESC dsvd = {};
dsvd.Format = DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
dsvd.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
m_dev->CreateDepthStencilView(m_texture, &dsvd, &m_dsv);
}
else
{
m_dev->CreateDepthStencilView(m_texture, NULL, &m_dsv);
}
}
return m_dsv;