Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Creating a fetchable texture from our zbuffer snapshot
  • Loading branch information
Redotix committed Jun 23, 2024
commit 9bbd2b5692a4f00a8df547420b3a940550322d9a
3 changes: 3 additions & 0 deletions src/Layers/xrRender/HW.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class CHW
ID3D11RenderTargetView* pBaseRT; // combine with DX9 pBaseRT via typedef
ID3D11DepthStencilView* pBaseZB;

D3D_TEXTURE2D_DESC* pBaseZBTexDesc;
D3D_DEPTH_STENCIL_VIEW_DESC* pBaseZBDesc;

CHWCaps Caps;

D3D_DRIVER_TYPE m_DriverType; // DevT equivalent
Expand Down
15 changes: 15 additions & 0 deletions src/Layers/xrRender/r__dsgraph_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,21 @@ void R_dsgraph_structure::r_dsgraph_render_hud(bool NoPS)
Device.mFullTransform.mul(Device.mProject, Device.mView);
RCache.set_xform_project(Device.mProject);

ID3D11Texture2D* pRt_tempzbTexture = nullptr;
HW.pDevice->CreateTexture2D(HW.pBaseZBTexDesc, nullptr, &pRt_tempzbTexture);
RImplementation.Target->rt_tempzb->pSurface = pRt_tempzbTexture;

ID3D11Resource* pResource = nullptr;
ID3D11Texture2D* pTexture2D = nullptr;

HW.pBaseZB->GetResource(&pResource);

pResource->QueryInterface(__uuidof(ID3D11Texture2D), (void**)&pTexture2D);

HW.pContext->CopyResource(pTexture2D, RImplementation.Target->rt_tempzb->pTexture->surface_get());

pResource->Release();

// Rendering
rmNear();
if (!NoPS)
Expand Down
55 changes: 30 additions & 25 deletions src/Layers/xrRenderDX10/dx10HW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@ void CHW::DestroyDevice()

_SHOW_REF("refCount:pBaseRT", pBaseRT);
_RELEASE(pBaseRT);

pBaseTEXZB->Release();

//#ifdef DEBUG
// _SHOW_REF ("refCount:dwDebugSB",dwDebugSB);
// _RELEASE (dwDebugSB);
Expand Down Expand Up @@ -516,6 +519,8 @@ void CHW::Reset(HWND hwnd)
_RELEASE(pBaseZB);
_RELEASE(pBaseRT);

pBaseTEXZB->Release();

CHK_DX(m_pSwapChain->ResizeBuffers(
cd.BufferCount,
desc.Width,
Expand Down Expand Up @@ -1029,31 +1034,31 @@ void CHW::UpdateViews()
pBuffer->Release();
R_CHK(R);

// Create Depth/stencil buffer
// HACK: DX10: hard depth buffer format
//R_CHK (pDevice->GetDepthStencilSurface (&pBaseZB));
ID3DTexture2D* pDepthStencil = NULL;
D3D_TEXTURE2D_DESC descDepth;
descDepth.Width = sd.BufferDesc.Width;
descDepth.Height = sd.BufferDesc.Height;
descDepth.MipLevels = 1;
descDepth.ArraySize = 1;
descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
descDepth.SampleDesc.Count = 1;
descDepth.SampleDesc.Quality = 0;
descDepth.Usage = D3D_USAGE_DEFAULT;
descDepth.BindFlags = D3D_BIND_DEPTH_STENCIL;
descDepth.CPUAccessFlags = 0;
descDepth.MiscFlags = 0;
R = pDevice->CreateTexture2D(&descDepth, // Texture desc
NULL, // Initial data
&pDepthStencil); // [out] Texture
R_CHK(R);

// Create Depth/stencil view
R = pDevice->CreateDepthStencilView(pDepthStencil, NULL, &pBaseZB);
R_CHK(R);
//Create texture resource
ID3D11Texture2D* pBaseTEXZB;
D3D_TEXTURE2D_DESC texDesc;
texDesc.Width = sd.BufferDesc.Width;
texDesc.Height = sd.BufferDesc.Height;
texDesc.MipLevels = 1;
texDesc.ArraySize = 1;
texDesc.Format = DXGI_FORMAT_R24G8_TYPELESS;
texDesc.SampleDesc.Count = 1;
texDesc.SampleDesc.Quality = 0;
texDesc.Usage = D3D_USAGE_DEFAULT;
texDesc.BindFlags = D3D_BIND_DEPTH_STENCIL | D3D_BIND_SHADER_RESOURCE | D3D_BIND_RENDER_TARGET;
texDesc.CPUAccessFlags = 0;
texDesc.MiscFlags = 0;

//Create DSV
D3D_DEPTH_STENCIL_VIEW_DESC dsvDesc;
#if defined(USE_DX11) //dirty hack so it doesnt crash DX10
dsvDesc.Flags = 0;
#endif
dsvDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
dsvDesc.ViewDimension = D3D_DSV_DIMENSION_TEXTURE2D;
dsvDesc.Texture2D.MipSlice = 0;

pDepthStencil->Release();
R_CHK(pDevice->CreateTexture2D(&texDesc, NULL, &pBaseTEXZB));
R_CHK(pDevice->CreateDepthStencilView(pBaseTEXZB, &dsvDesc, &pBaseZB));
}
#endif
2 changes: 2 additions & 0 deletions src/Layers/xrRenderPC_R4/r4_rendertarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ CRenderTarget::CRenderTarget()
u32 w = Device.dwWidth, h = Device.dwHeight;
rt_Position.create(r2_RT_P, w, h, D3DFMT_A16B16G16R16F, SampleCount);

rt_tempzb.create("$user$temp_zb", w, h, D3DFMT_D24S8);

if (RImplementation.o.dx10_msaa)
rt_MSAADepth.create(r2_RT_MSAAdepth, w, h, D3DFMT_D24S8, SampleCount);

Expand Down
2 changes: 2 additions & 0 deletions src/Layers/xrRenderPC_R4/r4_rendertarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ class CRenderTarget : public IRender_Target
ref_rt rt_ssfx_accum;
ref_rt rt_ssfx_hud;

ref_rt rt_tempzb;

ref_shader s_ssfx_dumb;

// Igor: for async screenshots
Expand Down