| 174 | } |
| 175 | |
| 176 | void BoundBoxRenderer::Prepare(IDeviceContext* pContext, const RenderAttribs& Attribs) |
| 177 | { |
| 178 | m_pCurrentPSO = GetPSO({Attribs.ConvertOutputToSRGB, Attribs.ComputeMotionVectors}); |
| 179 | if (m_pCurrentPSO == nullptr) |
| 180 | { |
| 181 | UNEXPECTED("Failed to get PSO"); |
| 182 | return; |
| 183 | } |
| 184 | |
| 185 | if (m_pCurrentPSO->GetStatus() != PIPELINE_STATE_STATUS_READY) |
| 186 | return; |
| 187 | |
| 188 | if (!m_SRB) |
| 189 | { |
| 190 | m_pCurrentPSO->CreateShaderResourceBinding(&m_SRB, true); |
| 191 | m_SRB->GetVariableByName(SHADER_TYPE_VERTEX, "cbCameraAttribs")->Set(m_pCameraAttribsCB); |
| 192 | m_SRB->GetVariableByName(SHADER_TYPE_VERTEX, "cbBoundBoxAttribs")->Set(m_RenderAttribsCB); |
| 193 | } |
| 194 | |
| 195 | VERIFY_EXPR(Attribs.BoundBoxTransform != nullptr); |
| 196 | |
| 197 | if (m_ShaderAttribs) |
| 198 | { |
| 199 | const BoundBoxShaderAttribs ShaderAttribs{ |
| 200 | m_PackMatrixRowMajor ? *Attribs.BoundBoxTransform : Attribs.BoundBoxTransform->Transpose(), |
| 201 | Attribs.Color != nullptr ? *Attribs.Color : float4{1.0, 1.0, 1.0, 1.0}, |
| 202 | Attribs.PatternLength, |
| 203 | Attribs.PatternMask, |
| 204 | 0, |
| 205 | 0, |
| 206 | }; |
| 207 | if (std::memcmp(m_ShaderAttribs.get(), &ShaderAttribs, sizeof(ShaderAttribs)) != 0) |
| 208 | { |
| 209 | *m_ShaderAttribs = ShaderAttribs; |
| 210 | pContext->UpdateBuffer(m_RenderAttribsCB, 0, sizeof(BoundBoxShaderAttribs), m_ShaderAttribs.get(), RESOURCE_STATE_TRANSITION_MODE_TRANSITION); |
| 211 | StateTransitionDesc Barrier{m_RenderAttribsCB, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_CONSTANT_BUFFER, STATE_TRANSITION_FLAG_UPDATE_STATE}; |
| 212 | pContext->TransitionResourceStates(1, &Barrier); |
| 213 | } |
| 214 | } |
| 215 | else |
| 216 | { |
| 217 | MapHelper<BoundBoxShaderAttribs> BBAttribs{pContext, m_RenderAttribsCB, MAP_WRITE, MAP_FLAG_DISCARD}; |
| 218 | WriteShaderMatrix(&BBAttribs->Transform, *Attribs.BoundBoxTransform, !m_PackMatrixRowMajor); |
| 219 | BBAttribs->Color = Attribs.Color != nullptr ? *Attribs.Color : float4{1.0, 1.0, 1.0, 1.0}; |
| 220 | BBAttribs->PatternLength = Attribs.PatternLength; |
| 221 | BBAttribs->PatternMask = Attribs.PatternMask; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | void BoundBoxRenderer::Render(IDeviceContext* pContext) |
| 226 | { |
nothing calls this directly
no outgoing calls
no test coverage detected