MCPcopy Create free account
hub / github.com/DiligentGraphics/DiligentFX / Execute

Method Execute

Hydrogent/src/Tasks/HnReadRprimIdTask.cpp:74–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74void HnReadRprimIdTask::Execute(pxr::HdTaskContext* TaskCtx)
75{
76 m_MeshIndex = InvalidMeshIndex;
77
78 if (!m_Params.IsEnabled)
79 return;
80
81 if (m_RenderIndex == nullptr)
82 {
83 UNEXPECTED("Render index is null. This likely indicates that Prepare() has not been called.");
84 return;
85 }
86 if (m_MeshIdReadBackQueue == nullptr)
87 {
88 UNEXPECTED("Mesh ID readback queue is null.");
89 return;
90 }
91
92 // Render target Bprims are initialized by the HnSetupRenderingTask.
93
94 ITextureView* pMeshIdRTV = GetRenderBufferTarget(*m_RenderIndex, TaskCtx, HnRenderResourceTokens->meshIdTarget);
95 if (pMeshIdRTV == nullptr)
96 {
97 UNEXPECTED("Mesh Id RTV is not set in the task context");
98 return;
99 }
100
101 auto* const pMeshIdTexture = pMeshIdRTV->GetTexture();
102 const auto& MeshIdRTVDesc = pMeshIdTexture->GetDesc();
103 if (m_Params.LocationX >= MeshIdRTVDesc.GetWidth() ||
104 m_Params.LocationY >= MeshIdRTVDesc.GetHeight())
105 {
106 return;
107 }
108
109 HnRenderDelegate* RenderDelegate = static_cast<HnRenderDelegate*>(m_RenderIndex->GetRenderDelegate());
110 IRenderDevice* pDevice = RenderDelegate->GetDevice();
111 IDeviceContext* pCtx = RenderDelegate->GetDeviceContext();
112
113 ScopedDebugGroup DebugGroup{pCtx, "Read RPrim Id"};
114
115 while (auto pStagingTex = m_MeshIdReadBackQueue->GetFirstCompleted())
116 {
117 {
118 // We waited for the fence, so the texture data should be available.
119 // However, mapping the texture on AMD with the MAP_FLAG_DO_NOT_WAIT flag
120 // still returns null.
121 MAP_FLAGS MapFlags = pDevice->GetDeviceInfo().Type == RENDER_DEVICE_TYPE_D3D11 ?
122 MAP_FLAG_NONE :
123 MAP_FLAG_DO_NOT_WAIT;
124
125 MappedTextureSubresource MappedData;
126 pCtx->MapTextureSubresource(pStagingTex, 0, 0, MAP_READ, MapFlags, nullptr, MappedData);
127 if (MappedData.pData != nullptr)
128 {
129 float fMeshIndex = *static_cast<const float*>(MappedData.pData);
130 m_MeshIndex = fMeshIndex >= 0.f ? static_cast<Uint32>(fMeshIndex) : 0u;
131 pCtx->UnmapTextureSubresource(pStagingTex, 0, 0);

Callers

nothing calls this directly

Calls 4

GetWidthMethod · 0.80
GetHeightMethod · 0.80
GetDeviceContextMethod · 0.80
GetDeviceMethod · 0.45

Tested by

no test coverage detected