Skip to content

Commit 9bbd2b5

Browse files
committed
Creating a fetchable texture from our zbuffer snapshot
1 parent d5edebb commit 9bbd2b5

File tree

5 files changed

+52
-25
lines changed

5 files changed

+52
-25
lines changed

src/Layers/xrRender/HW.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class CHW
6464
ID3D11RenderTargetView* pBaseRT; // combine with DX9 pBaseRT via typedef
6565
ID3D11DepthStencilView* pBaseZB;
6666

67+
D3D_TEXTURE2D_DESC* pBaseZBTexDesc;
68+
D3D_DEPTH_STENCIL_VIEW_DESC* pBaseZBDesc;
69+
6770
CHWCaps Caps;
6871

6972
D3D_DRIVER_TYPE m_DriverType; // DevT equivalent

src/Layers/xrRender/r__dsgraph_render.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,21 @@ void R_dsgraph_structure::r_dsgraph_render_hud(bool NoPS)
531531
Device.mFullTransform.mul(Device.mProject, Device.mView);
532532
RCache.set_xform_project(Device.mProject);
533533

534+
ID3D11Texture2D* pRt_tempzbTexture = nullptr;
535+
HW.pDevice->CreateTexture2D(HW.pBaseZBTexDesc, nullptr, &pRt_tempzbTexture);
536+
RImplementation.Target->rt_tempzb->pSurface = pRt_tempzbTexture;
537+
538+
ID3D11Resource* pResource = nullptr;
539+
ID3D11Texture2D* pTexture2D = nullptr;
540+
541+
HW.pBaseZB->GetResource(&pResource);
542+
543+
pResource->QueryInterface(__uuidof(ID3D11Texture2D), (void**)&pTexture2D);
544+
545+
HW.pContext->CopyResource(pTexture2D, RImplementation.Target->rt_tempzb->pTexture->surface_get());
546+
547+
pResource->Release();
548+
534549
// Rendering
535550
rmNear();
536551
if (!NoPS)

src/Layers/xrRenderDX10/dx10HW.cpp

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,9 @@ void CHW::DestroyDevice()
451451

452452
_SHOW_REF("refCount:pBaseRT", pBaseRT);
453453
_RELEASE(pBaseRT);
454+
455+
pBaseTEXZB->Release();
456+
454457
//#ifdef DEBUG
455458
// _SHOW_REF ("refCount:dwDebugSB",dwDebugSB);
456459
// _RELEASE (dwDebugSB);
@@ -516,6 +519,8 @@ void CHW::Reset(HWND hwnd)
516519
_RELEASE(pBaseZB);
517520
_RELEASE(pBaseRT);
518521

522+
pBaseTEXZB->Release();
523+
519524
CHK_DX(m_pSwapChain->ResizeBuffers(
520525
cd.BufferCount,
521526
desc.Width,
@@ -1029,31 +1034,31 @@ void CHW::UpdateViews()
10291034
pBuffer->Release();
10301035
R_CHK(R);
10311036

1032-
// Create Depth/stencil buffer
1033-
// HACK: DX10: hard depth buffer format
1034-
//R_CHK (pDevice->GetDepthStencilSurface (&pBaseZB));
1035-
ID3DTexture2D* pDepthStencil = NULL;
1036-
D3D_TEXTURE2D_DESC descDepth;
1037-
descDepth.Width = sd.BufferDesc.Width;
1038-
descDepth.Height = sd.BufferDesc.Height;
1039-
descDepth.MipLevels = 1;
1040-
descDepth.ArraySize = 1;
1041-
descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1042-
descDepth.SampleDesc.Count = 1;
1043-
descDepth.SampleDesc.Quality = 0;
1044-
descDepth.Usage = D3D_USAGE_DEFAULT;
1045-
descDepth.BindFlags = D3D_BIND_DEPTH_STENCIL;
1046-
descDepth.CPUAccessFlags = 0;
1047-
descDepth.MiscFlags = 0;
1048-
R = pDevice->CreateTexture2D(&descDepth, // Texture desc
1049-
NULL, // Initial data
1050-
&pDepthStencil); // [out] Texture
1051-
R_CHK(R);
1052-
1053-
// Create Depth/stencil view
1054-
R = pDevice->CreateDepthStencilView(pDepthStencil, NULL, &pBaseZB);
1055-
R_CHK(R);
1037+
//Create texture resource
1038+
ID3D11Texture2D* pBaseTEXZB;
1039+
D3D_TEXTURE2D_DESC texDesc;
1040+
texDesc.Width = sd.BufferDesc.Width;
1041+
texDesc.Height = sd.BufferDesc.Height;
1042+
texDesc.MipLevels = 1;
1043+
texDesc.ArraySize = 1;
1044+
texDesc.Format = DXGI_FORMAT_R24G8_TYPELESS;
1045+
texDesc.SampleDesc.Count = 1;
1046+
texDesc.SampleDesc.Quality = 0;
1047+
texDesc.Usage = D3D_USAGE_DEFAULT;
1048+
texDesc.BindFlags = D3D_BIND_DEPTH_STENCIL | D3D_BIND_SHADER_RESOURCE | D3D_BIND_RENDER_TARGET;
1049+
texDesc.CPUAccessFlags = 0;
1050+
texDesc.MiscFlags = 0;
1051+
1052+
//Create DSV
1053+
D3D_DEPTH_STENCIL_VIEW_DESC dsvDesc;
1054+
#if defined(USE_DX11) //dirty hack so it doesnt crash DX10
1055+
dsvDesc.Flags = 0;
1056+
#endif
1057+
dsvDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1058+
dsvDesc.ViewDimension = D3D_DSV_DIMENSION_TEXTURE2D;
1059+
dsvDesc.Texture2D.MipSlice = 0;
10561060

1057-
pDepthStencil->Release();
1061+
R_CHK(pDevice->CreateTexture2D(&texDesc, NULL, &pBaseTEXZB));
1062+
R_CHK(pDevice->CreateDepthStencilView(pBaseTEXZB, &dsvDesc, &pBaseZB));
10581063
}
10591064
#endif

src/Layers/xrRenderPC_R4/r4_rendertarget.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ CRenderTarget::CRenderTarget()
419419
u32 w = Device.dwWidth, h = Device.dwHeight;
420420
rt_Position.create(r2_RT_P, w, h, D3DFMT_A16B16G16R16F, SampleCount);
421421

422+
rt_tempzb.create("$user$temp_zb", w, h, D3DFMT_D24S8);
423+
422424
if (RImplementation.o.dx10_msaa)
423425
rt_MSAADepth.create(r2_RT_MSAAdepth, w, h, D3DFMT_D24S8, SampleCount);
424426

src/Layers/xrRenderPC_R4/r4_rendertarget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ class CRenderTarget : public IRender_Target
154154
ref_rt rt_ssfx_accum;
155155
ref_rt rt_ssfx_hud;
156156

157+
ref_rt rt_tempzb;
158+
157159
ref_shader s_ssfx_dumb;
158160

159161
// Igor: for async screenshots

0 commit comments

Comments
 (0)