| 179 | } |
| 180 | |
| 181 | void HnBeginFrameTask::PrepareRenderTargets(pxr::HdRenderIndex* RenderIndex, |
| 182 | pxr::HdTaskContext* TaskCtx, |
| 183 | ITextureView* pFinalColorRTV) |
| 184 | { |
| 185 | if (pFinalColorRTV == nullptr) |
| 186 | { |
| 187 | UNEXPECTED("Final color target RTV is null"); |
| 188 | return; |
| 189 | } |
| 190 | const auto& FinalTargetDesc = pFinalColorRTV->GetTexture()->GetDesc(); |
| 191 | |
| 192 | m_FrameBufferWidth = FinalTargetDesc.Width; |
| 193 | m_FrameBufferHeight = FinalTargetDesc.Height; |
| 194 | |
| 195 | auto UpdateBrim = [&](const pxr::SdfPath& Id, TEXTURE_FORMAT Format, const std::string& Name) -> ITextureView* { |
| 196 | if (Format == TEX_FORMAT_UNKNOWN) |
| 197 | return nullptr; |
| 198 | |
| 199 | IRenderDevice* const pDevice = static_cast<HnRenderDelegate*>(RenderIndex->GetRenderDelegate())->GetDevice(); |
| 200 | if (!pDevice->GetTextureFormatInfo(Format).Supported) |
| 201 | { |
| 202 | Format = GetFallbackTextureFormat(Format); |
| 203 | } |
| 204 | |
| 205 | VERIFY_EXPR(!Id.IsEmpty()); |
| 206 | |
| 207 | HnRenderBuffer* Renderbuffer = static_cast<HnRenderBuffer*>(RenderIndex->GetBprim(pxr::HdPrimTypeTokens->renderBuffer, Id)); |
| 208 | if (Renderbuffer == nullptr) |
| 209 | { |
| 210 | UNEXPECTED("Render buffer is not set at Id ", Id); |
| 211 | return nullptr; |
| 212 | } |
| 213 | |
| 214 | if (auto* pView = Renderbuffer->GetTarget()) |
| 215 | { |
| 216 | const auto& ViewDesc = pView->GetDesc(); |
| 217 | const auto& TargetDesc = pView->GetTexture()->GetDesc(); |
| 218 | if (TargetDesc.GetWidth() == FinalTargetDesc.GetWidth() && |
| 219 | TargetDesc.GetHeight() == FinalTargetDesc.GetHeight() && |
| 220 | ViewDesc.Format == Format) |
| 221 | return pView; |
| 222 | } |
| 223 | |
| 224 | const bool IsDepth = GetTextureFormatAttribs(Format).IsDepthStencil(); |
| 225 | |
| 226 | auto TargetDesc = FinalTargetDesc; |
| 227 | TargetDesc.Name = Name.c_str(); |
| 228 | TargetDesc.Format = Format; |
| 229 | TargetDesc.BindFlags = (IsDepth ? BIND_DEPTH_STENCIL : BIND_RENDER_TARGET) | BIND_SHADER_RESOURCE; |
| 230 | |
| 231 | RefCntAutoPtr<ITexture> pTarget; |
| 232 | pDevice->CreateTexture(TargetDesc, nullptr, &pTarget); |
| 233 | if (!pTarget) |
| 234 | { |
| 235 | UNEXPECTED("Failed to create ", Name, " texture"); |
| 236 | return nullptr; |
| 237 | } |
| 238 | LOG_INFO_MESSAGE("HnBeginFrameTask: created ", TargetDesc.GetWidth(), "x", TargetDesc.GetHeight(), " ", Name, " texture"); |