| 177 | } |
| 178 | |
| 179 | void HnProcessSelectionTask::PrepareSRBs(const HnFrameRenderTargets& Targets) |
| 180 | { |
| 181 | if (Targets.ClosestSelectedLocationRTV[0] == nullptr || Targets.ClosestSelectedLocationRTV[1] == nullptr || Targets.SelectionDepthDSV == nullptr) |
| 182 | { |
| 183 | UNEXPECTED("Closest selected location render targets are not initialized"); |
| 184 | return; |
| 185 | } |
| 186 | ITextureView* pSelectionDepthSRV = Targets.SelectionDepthDSV->GetTexture()->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE); |
| 187 | if (pSelectionDepthSRV == nullptr) |
| 188 | { |
| 189 | UNEXPECTED("Selection depth SRV is null"); |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | std::array<ITextureView*, 2> ClosestSelectedLocationSRVs = |
| 194 | { |
| 195 | Targets.ClosestSelectedLocationRTV[0]->GetTexture()->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE), |
| 196 | Targets.ClosestSelectedLocationRTV[1]->GetTexture()->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE), |
| 197 | }; |
| 198 | if (ClosestSelectedLocationSRVs[0] == nullptr || ClosestSelectedLocationSRVs[1] == nullptr) |
| 199 | { |
| 200 | UNEXPECTED("Closest selected location SRV is null"); |
| 201 | return; |
| 202 | } |
| 203 | |
| 204 | if (!m_InitTech.PSO || !m_UpdateTech.PSO) |
| 205 | { |
| 206 | UNEXPECTED("PSOs are not initialized"); |
| 207 | return; |
| 208 | } |
| 209 | |
| 210 | if (m_InitTech.PSO->GetStatus() != PIPELINE_STATE_STATUS_READY || |
| 211 | m_UpdateTech.PSO->GetStatus() != PIPELINE_STATE_STATUS_READY) |
| 212 | { |
| 213 | // Wait until PSOs are ready |
| 214 | return; |
| 215 | } |
| 216 | |
| 217 | if (m_InitTech.SRB && m_InitTech.Vars) |
| 218 | { |
| 219 | if (m_InitTech.Vars.SelectionDepth->Get() != pSelectionDepthSRV) |
| 220 | { |
| 221 | m_InitTech.SRB.Release(); |
| 222 | m_InitTech.Vars = {}; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | if (!m_InitTech.SRB) |
| 227 | { |
| 228 | m_InitTech.PSO->CreateShaderResourceBinding(&m_InitTech.SRB, true); |
| 229 | VERIFY_EXPR(m_InitTech.SRB); |
| 230 | m_InitTech.SRB->GetVariableByName(SHADER_TYPE_PIXEL, "cbConstants")->Set(m_ConstantsCB); |
| 231 | m_InitTech.Vars.SelectionDepth = m_InitTech.SRB->GetVariableByName(SHADER_TYPE_PIXEL, "g_SelectionDepth"); |
| 232 | VERIFY_EXPR(m_InitTech.Vars); |
| 233 | |
| 234 | if (m_InitTech.Vars.SelectionDepth != nullptr) |
| 235 | m_InitTech.Vars.SelectionDepth->Set(pSelectionDepthSRV); |
| 236 | } |