Skip to content

Commit 1350835

Browse files
committed
improvements
1 parent 27294ab commit 1350835

9 files changed

Lines changed: 55 additions & 33 deletions

File tree

sources/HAL/HAL.CommandList.ixx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ export{
349349
return read_buffer(view.resource.get(), view.desc.offset + offset * sizeof(HAL::StructuredBufferView<T>::UnderlyingType), count * sizeof(HAL::StructuredBufferView<T>::UnderlyingType),
350350
[f](std::span<std::byte> memory)
351351
{
352-
uint read = uint(memory.size());
352+
uint read = uint(memory.size())/sizeof(HAL::StructuredBufferView<T>::UnderlyingType);
353353
auto data = reinterpret_cast<T*>(memory.data());
354354

355355

@@ -604,7 +604,17 @@ export{
604604
void dispatch_graph(ResourceAddress addr);
605605
void set_program(StateObject* id, ResourceAddress buffer, uint size, bool init);
606606

607+
template <class PSO>
608+
void set_program(ResourceAddress buffer, bool init)
609+
{
607610

611+
auto work_pso = get_base().device.get_engine_pso_holder().GetPSO<PSO>();
612+
613+
set_program(work_pso.get(),
614+
buffer,
615+
uint(work_pso->buffer_size),
616+
init);
617+
}
608618

609619
void build_ras(const HAL::RaytracingBuildDescStructure& build_desc, const HAL::RaytracingBuildDescBottomInputs& bottom);
610620
void build_ras(const HAL::RaytracingBuildDescStructure& build_desc, const HAL::RaytracingBuildDescTopInputs& top);

sources/HAL/HAL.ResourceViews.ixx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ export
409409

410410
uint get_data_offset_in_bytes(uint offset = 0) const
411411
{
412-
return offset + offset * sizeof(UnderlyingType);
412+
return this->offset + offset * sizeof(UnderlyingType);
413413
}
414414

415415

sources/RenderSystem/FrameGraph/FrameGraph.Base.ixx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,8 @@ public:
603603
void begin(Graph* graph,Pass* pass, HAL::FrameResources::ptr& frame);
604604
void end();
605605
void execute();
606+
607+
HAL::StructuredBufferView<DispatchArguments>& get_indirect_dispatch_args();
606608
};
607609

608610

@@ -777,9 +779,13 @@ public:
777779

778780

779781
class Graph: public UniversalContext, public VariableContext, public SlotContext
780-
{
782+
{
781783
public:
782784

785+
// One persistent indirect-dispatch argument buffer per command list type.
786+
// X is overwritten each frame via copy_buffer; Y and Z are initialized once to 1.
787+
enum_array<HAL::CommandListType, HAL::StructuredBufferView<DispatchArguments>> indirect_dispatch_args;
788+
783789
Events::Event<const Graph&> on_compile;
784790

785791
Variable<bool> optimize = { true, "optimize", this };

sources/RenderSystem/FrameGraph/FrameGraph.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,9 +1769,24 @@ namespace FrameGraph
17691769
slot_setters[id](setter);
17701770
}
17711771

1772+
HAL::StructuredBufferView<DispatchArguments>& FrameContext::get_indirect_dispatch_args()
1773+
{
1774+
return graph->indirect_dispatch_args[pass->get_type()];
1775+
}
1776+
17721777
Graph::Graph() : VariableContext(L"Graph")
17731778
{
17741779
builder.graph = this;
1780+
1781+
auto& device = RenderSystem::get().device();
1782+
for (auto& buf : indirect_dispatch_args)
1783+
buf = HAL::StructuredBufferView<DispatchArguments>(device, 1);
1784+
1785+
DispatchArguments init{ 0, 1, 1 };
1786+
auto upload = device.get_upload_list();
1787+
for (auto& buf : indirect_dispatch_args)
1788+
upload->get_copy().update(buf, 0, std::span{ &init, 1 });
1789+
upload->execute_and_wait();
17751790
}
17761791

17771792
void Graph::set_pipeline(Pipelines::PipelineBase* p) { current_pipeline = p; }

sources/RenderSystem/FrameGraph/PassDefaults.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ bool PassDefault<Passes::RTXPass>::setup(
9494
}
9595
else
9696
{
97-
builder.create(data.EmulTileBuffer, { 256u * 256u, true }, ResourceFlags::UnorderedAccess);
98-
builder.create(data.EmulDispatchArgs, { 1u, false }, ResourceFlags::UnorderedAccess);
97+
// counter_pad(8) + tile_data(256*256 * sizeof(TileRecord))
98+
constexpr uint64_t TILE_SECTION = 8u + 256u * 256u * sizeof(Table::TileRecord); // 524296
99+
builder.create(data.WorkGraphBuffer, { TILE_SECTION }, ResourceFlags::UnorderedAccess);
99100
}
100101

101102
return true;
@@ -156,12 +157,8 @@ void PassDefault<Passes::RTXPass>::render(
156157
if (RenderSystem::get().device().get_properties().work_graph)
157158
{
158159
auto& backingBuffer = data.WorkGraphBuffer->resource;
159-
auto work_pso = RenderSystem::get().device().get_engine_pso_holder().GetPSO<PSOS::WorkGR>();
160-
161-
compute.set_program(work_pso.get(),
162-
backingBuffer->get_resource_address(),
163-
uint(work_pso->buffer_size),
164-
data.WorkGraphBuffer.is_new());
160+
161+
compute.set_program<PSOS::WorkGR>(backingBuffer->get_resource_address(), data.WorkGraphBuffer.is_new());
165162

166163
auto ep = create_entry(compute);
167164
for (auto i = 0; i < res.DispatchCount; i++)
@@ -177,23 +174,24 @@ void PassDefault<Passes::RTXPass>::render(
177174
}
178175
else
179176
{
180-
auto& tile_buf = *data.EmulTileBuffer;
181-
auto& disp_args = *data.EmulDispatchArgs;
177+
// tile_buf: view into WorkGraphBuffer (stays UAV throughout).
178+
// disp_args: separate resource — exec_indirect transitions it to INDIRECT_ARGUMENT
179+
// independently, leaving WorkGraphBuffer in UAV for the Shadows_Node shader.
180+
constexpr uint64_t TILE_SECTION = 8u + 256u * 256u * sizeof(Table::TileRecord); // 524296
182181

183-
if (data.EmulDispatchArgs.is_new())
184-
{
185-
DispatchArguments init_args{ 0, 1, 1 };
186-
context.get_list()->get_copy().update(disp_args, 0, std::span{ &init_args, 1 });
187-
}
182+
auto tile_buf = data.WorkGraphBuffer->resource->create_view<HAL::StructuredBufferView<Table::TileRecord>>(
183+
*context.frame,
184+
HAL::StructuredBufferViewDesc{ 0, TILE_SECTION, counterType::SELF });
185+
auto& disp_args = context.get_indirect_dispatch_args();
188186

189187
// WaveCount[0] is always 64 (fixed wave size). Split YZ into chunks of 16
190188
// so each chunk has at most 64*16*64 = 65536 threads = 65536 tiles.
191189
constexpr int MAX_YZ_CHUNK = 16;
192190

193191
for (auto i = 0; i < res.DispatchCount; i++)
194192
{
195-
auto& e = res.Dispatch[i];
196-
int total_yz = e.WaveCount[1] * e.WaveCount[2];
193+
auto& e = res.Dispatch[i];
194+
int total_yz = e.WaveCount[1] * e.WaveCount[2];
197195

198196
for (int yz_base = 0; yz_base < total_yz; yz_base += MAX_YZ_CHUNK)
199197
{
@@ -208,7 +206,7 @@ void PassDefault<Passes::RTXPass>::render(
208206
classifyEmul.GetShadows_Node() = tile_buf.appendStructuredBuffer;
209207

210208
Slots::WorkGR_Shadows_NodeEmulation shadowsEmul;
211-
shadowsEmul.GetInput() = tile_buf.consumeStructuredBuffer;
209+
shadowsEmul.GetInput() = tile_buf.consumeStructuredBuffer;
212210

213211
compute.set_pipeline<PSOS::WorkGR_ClassifyPixels_Node>();
214212
compute.set(classifyEmul);
@@ -222,9 +220,9 @@ void PassDefault<Passes::RTXPass>::render(
222220
compute.set(shadowsEmul);
223221
compute.exec_indirect(disp_args, 1);
224222

225-
/* context.get_list()->get_copy().read_counter(tile_buf, [](uint remaining) {
223+
context.get_list()->get_copy().read_counter(tile_buf, [](uint remaining) {
226224
ASSERT(remaining == 0);
227-
});*/
225+
});
228226
}
229227
}
230228
}

sources/RenderSystem/FrameGraph/autogen/pass/RTXPass.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@ class RTXPass : public PassNodeBase
2424

2525
Handlers::ByteAdressBuffer H(WorkGraphBuffer);
2626

27-
Handlers::StructuredBuffer<Table::TileRecord> H(EmulTileBuffer);
28-
29-
30-
Handlers::StructuredBuffer<DispatchArguments> H(EmulDispatchArgs);
31-
32-
static inline const wchar_t* const resource_names[] = { L"GBuffer_Albedo", L"GBuffer_Normals", L"GBuffer_Depth", L"GBuffer_Specular", L"GBuffer_Speed", L"GBuffer_DepthMips", L"GBuffer_Quality", L"GBuffer_TempColor", L"GBuffer_NormalsPrev", L"GBuffer_SpecularPrev", L"GBuffer_DepthPrev", L"GBuffer_HiZ", L"GBuffer_HiZ_UAV", L"RTXDebug", L"WorkGraphBuffer", L"EmulTileBuffer", L"EmulDispatchArgs",
27+
static inline const wchar_t* const resource_names[] = { L"GBuffer_Albedo", L"GBuffer_Normals", L"GBuffer_Depth", L"GBuffer_Specular", L"GBuffer_Speed", L"GBuffer_DepthMips", L"GBuffer_Quality", L"GBuffer_TempColor", L"GBuffer_NormalsPrev", L"GBuffer_SpecularPrev", L"GBuffer_DepthPrev", L"GBuffer_HiZ", L"GBuffer_HiZ_UAV", L"RTXDebug", L"WorkGraphBuffer",
3328
};
3429
static constexpr uint32_t resource_count = std::size(resource_names);
3530
};

sources/RenderSystem/GUI/Elements/StatGraph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ namespace GUI
266266
auto tex = std::make_shared<HAL::Texture>(device,
267267
HAL::ResourceDesc::Tex2D(
268268
HAL::Format::R8G8B8A8_UNORM,
269-
{(UINT)tex_size.x, (UINT)tex_size.y}, 1, 0,
269+
{(UINT)tex_size.x, (UINT)tex_size.y}, 1, 1,
270270
HAL::ResFlags::ShaderResource | HAL::ResFlags::UnorderedAccess | HAL::ResFlags::RenderTarget));
271271
tex->resource->set_name("stat_graph::output");
272272
gpu->output_view = tex->texture_2d();

sources/SIGParser/sigs/raytracing.sig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,4 @@ PassNode RTXPass
186186
GBuffer gbuffer;
187187
Texture RTXDebug;
188188
ByteAdressBuffer WorkGraphBuffer;
189-
StructuredBuffer<TileRecord> EmulTileBuffer;
190-
StructuredBuffer<DispatchArguments> EmulDispatchArgs;
191189
}

workdir/shaders/workgraph_test.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ NODE_ClassifyPixels_Node(
2727
else
2828
{
2929

30-
// params.GetOutputTexture()[uint2(v.pixel_pos)] = 0.3;
30+
params.GetOutputTexture()[uint2(v.pixel_pos)] = 0.3;
3131
WG_SET_RECORD(tileRecord, tileXY, uint2(v.pixel_pos));
3232
}
3333

0 commit comments

Comments
 (0)