Skip to content

Commit 616575d

Browse files
Bound Box Renderer: added RenderTargetMask parameter
1 parent 83bee54 commit 616575d

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

Components/interface/BoundBoxRenderer.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ class BoundBoxRenderer
5353
TEXTURE_FORMAT RTVFormats[DILIGENT_MAX_RENDER_TARGETS] = {TEX_FORMAT_RGBA8_UNORM_SRGB};
5454
TEXTURE_FORMAT DSVFormat = TEX_FORMAT_D32_FLOAT;
5555

56+
/// A bit mask that defines the render targets to render to.
57+
///
58+
/// \remarks If bit N is set, the N-th render target's color write mask will be set to
59+
/// COLOR_MASK_ALL. Otherwise, it will be set to COLOR_MASK_NONE.
60+
Uint32 RenderTargetMask = 0x1u;
61+
5662
const char* PSMainSource = nullptr;
5763

5864
/// Whether shader matrices are laid out in row-major order in GPU memory.
@@ -140,6 +146,7 @@ class BoundBoxRenderer
140146
const std::vector<TEXTURE_FORMAT> m_RTVFormats;
141147
const TEXTURE_FORMAT m_DSVFormat;
142148
const std::string m_PSMainSource;
149+
const Uint32 m_RenderTargetMask;
143150
const bool m_PackMatrixRowMajor;
144151
const bool m_AsyncShaders;
145152

Components/src/BoundBoxRenderer.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ BoundBoxRenderer::BoundBoxRenderer(const CreateInfo& CI) :
5656
m_RTVFormats{CI.RTVFormats, CI.RTVFormats + CI.NumRenderTargets},
5757
m_DSVFormat{CI.DSVFormat},
5858
m_PSMainSource{CI.PSMainSource != nullptr ? CI.PSMainSource : ""},
59+
m_RenderTargetMask{CI.RenderTargetMask},
5960
m_PackMatrixRowMajor{CI.PackMatrixRowMajor},
6061
m_AsyncShaders{CI.AsyncShaders}
6162
{
@@ -152,17 +153,26 @@ IPipelineState* BoundBoxRenderer::GetPSO(const PSOKey& Key)
152153
.AddShader(pPS)
153154
.SetPrimitiveTopology(PRIMITIVE_TOPOLOGY_LINE_LIST)
154155
.SetDepthFormat(m_DSVFormat);
155-
for (auto RTVFormat : m_RTVFormats)
156+
for (TEXTURE_FORMAT RTVFormat : m_RTVFormats)
156157
PsoCI.AddRenderTarget(RTVFormat);
157158

158159
PsoCI.PSODesc.ResourceLayout.DefaultVariableMergeStages = SHADER_TYPE_VS_PS;
159160
PsoCI.PSODesc.ResourceLayout.DefaultVariableType = SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE;
160161
PsoCI.GraphicsPipeline.DepthStencilDesc.DepthFunc = (Key.Flags & OPTION_FLAG_USE_REVERSE_DEPTH) != 0 ? COMPARISON_FUNC_GREATER_EQUAL : COMPARISON_FUNC_LESS_EQUAL;
161162
PsoCI.GraphicsPipeline.DepthStencilDesc.DepthWriteEnable = false;
163+
for (Uint32 i = 0; i < PsoCI.GraphicsPipeline.NumRenderTargets; ++i)
164+
{
165+
PsoCI.GraphicsPipeline.BlendDesc.RenderTargets[i].RenderTargetWriteMask = (m_RenderTargetMask & (1u << i)) != 0 ?
166+
COLOR_MASK_ALL :
167+
COLOR_MASK_NONE;
168+
}
169+
162170
if (m_AsyncShaders)
171+
{
163172
PsoCI.Flags |= PSO_CREATE_FLAG_ASYNCHRONOUS;
173+
}
164174

165-
auto PSO = Device.CreateGraphicsPipelineState(PsoCI);
175+
RefCntAutoPtr<IPipelineState> PSO = Device.CreateGraphicsPipelineState(PsoCI);
166176
if (!PSO)
167177
{
168178
UNEXPECTED("Failed to create bound box PSO");

Hydrogent/src/Tasks/HnRenderBoundBoxTask.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,15 @@ void HnRenderBoundBoxTask::Prepare(pxr::HdTaskContext* TaskCtx,
177177
BoundBoxRndrCI.pCameraAttribsCB = pRenderDelegate->GetFrameAttribsCB();
178178
BoundBoxRndrCI.NumRenderTargets = RenderPassState->GetNumRenderTargets();
179179
for (Uint32 rt = 0; rt < BoundBoxRndrCI.NumRenderTargets; ++rt)
180+
{
180181
BoundBoxRndrCI.RTVFormats[rt] = RenderPassState->GetRenderTargetFormat(rt);
182+
}
181183
BoundBoxRndrCI.DSVFormat = RenderPassState->GetDepthStencilFormat();
182184

183-
const std::string PSMain = GetBoundBoxPSMain(BoundBoxRndrCI.pDevice->GetDeviceInfo().IsGLDevice() ||
184-
BoundBoxRndrCI.pDevice->GetDeviceInfo().IsWebGPUDevice());
185+
BoundBoxRndrCI.RenderTargetMask = ((1u << HnFrameRenderTargets::GBUFFER_TARGET_SCENE_COLOR) |
186+
(1u << HnFrameRenderTargets::GBUFFER_TARGET_MOTION_VECTOR));
187+
188+
const std::string PSMain = GetBoundBoxPSMain(BoundBoxRndrCI.pDevice->GetDeviceInfo().IsGLDevice());
185189

186190
BoundBoxRndrCI.PSMainSource = PSMain.c_str();
187191

0 commit comments

Comments
 (0)