Skip to content

Commit 5481e4e

Browse files
authored
Merge pull request #262 from Devsh-Graphics-Programming/unroll
Precompile and cache EX31 path tracer variants
2 parents 46826a5 + 9c6dff4 commit 5481e4e

38 files changed

Lines changed: 2610 additions & 539 deletions

31_HLSLPathTracer/CMakeLists.txt

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
include(common RESULT_VARIABLE RES)
2-
3-
if(NOT RES)
4-
message(FATAL_ERROR "common.cmake not found. Should be in {repo_root}/cmake directory")
5-
endif()
1+
include(common)
2+
include("${CMAKE_CURRENT_SOURCE_DIR}/pt.cmake")
3+
include("${CMAKE_CURRENT_SOURCE_DIR}/pt.variant_ids.cmake")
64

75
if(NBL_BUILD_IMGUI)
6+
# EX31 keeps triangle polygon-method variants as separate precompiled entrypoints.
7+
# This keeps polygon-method choice compile-time and avoids runtime shader switching on this axis.
8+
# On AMD Ryzen 5 5600G with Radeon Graphics (6C/12T),
9+
# a Visual Studio Debug x64 full rebuild of the SPIR-V project completed in about 19.789 s.
10+
set(PT_CACHE_ROOT "pipeline/cache" CACHE STRING
11+
"Relative cache root written to path_tracer.runtime.json in the common bin directory. The runtime resolves this path relative to the JSON file location. Empty disables the generated dev-mode JSON and falls back to --pipeline-cache-dir or LocalAppData."
12+
)
13+
if(IS_ABSOLUTE "${PT_CACHE_ROOT}")
14+
message(FATAL_ERROR "PT_CACHE_ROOT must stay relative because the runtime resolves it against path_tracer.runtime.json")
15+
endif()
16+
817
set(NBL_INCLUDE_SERACH_DIRECTORIES
918
"${CMAKE_CURRENT_SOURCE_DIR}/include"
1019
)
@@ -16,25 +25,71 @@ if(NBL_BUILD_IMGUI)
1625
)
1726

1827
nbl_create_executable_project("" "" "${NBL_INCLUDE_SERACH_DIRECTORIES}" "${NBL_LIBRARIES}" "${NBL_EXECUTABLE_PROJECT_CREATION_PCH_TARGET}")
28+
add_dependencies(${EXECUTABLE_NAME} argparse)
29+
target_include_directories(${EXECUTABLE_NAME} PUBLIC $<TARGET_PROPERTY:argparse,INTERFACE_INCLUDE_DIRECTORIES>)
30+
target_compile_definitions(${EXECUTABLE_NAME} PRIVATE PATH_TRACER_BUILD_CONFIG_NAME=\"$<CONFIG>\")
31+
if(NOT PT_CACHE_ROOT STREQUAL "")
32+
string(REPLACE "\\" "/" PT_CACHE_ROOT_JSON "${PT_CACHE_ROOT}")
33+
configure_file(
34+
"${CMAKE_CURRENT_SOURCE_DIR}/path_tracer.runtime.json.in"
35+
"${CMAKE_CURRENT_BINARY_DIR}/path_tracer.runtime.json"
36+
@ONLY
37+
)
38+
file(GENERATE
39+
OUTPUT "$<TARGET_FILE_DIR:${EXECUTABLE_NAME}>/path_tracer.runtime.json"
40+
INPUT "${CMAKE_CURRENT_BINARY_DIR}/path_tracer.runtime.json"
41+
)
42+
endif()
1943
20-
if(NBL_EMBED_BUILTIN_RESOURCES)
21-
set(_BR_TARGET_ ${EXECUTABLE_NAME}_builtinResourceData)
22-
set(RESOURCE_DIR "app_resources")
23-
24-
get_filename_component(_SEARCH_DIRECTORIES_ "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
25-
get_filename_component(_OUTPUT_DIRECTORY_SOURCE_ "${CMAKE_CURRENT_BINARY_DIR}/src" ABSOLUTE)
26-
get_filename_component(_OUTPUT_DIRECTORY_HEADER_ "${CMAKE_CURRENT_BINARY_DIR}/include" ABSOLUTE)
27-
28-
file(GLOB_RECURSE BUILTIN_RESOURCE_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DIR}/*")
44+
set(SM 6_8)
45+
set(OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/auto-gen")
46+
set(COMPILE_OPTIONS
47+
-I "${CMAKE_CURRENT_SOURCE_DIR}/include"
48+
-I "${CMAKE_CURRENT_SOURCE_DIR}/app_resources/hlsl"
49+
-isystem "${NBL_ROOT_PATH}/include" # workaround, the same thing like in IES I will address this issue later
50+
$<$<CONFIG:Debug>:-O1experimental>
51+
$<$<CONFIG:RelWithDebInfo>:-O1experimental>
52+
-T "lib_${SM}"
53+
-Wno-conversion
54+
-Wno-sign-conversion
55+
-Wno-float-conversion
56+
-Wno-shorten-64-to-32
57+
-Wno-shadow
58+
-Wno-literal-range
59+
)
2960
30-
foreach(RES_FILE ${BUILTIN_RESOURCE_FILES})
31-
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "${RES_FILE}")
32-
endforeach()
61+
# Keep the payload flat and explicit here. Once Nabla PR #988 lands, these per-rule compile axes should move to first-class packaged-variant support there.
62+
PT_APPEND_SPIRV_RULE(VAR JSON INPUT "app_resources/hlsl/spirv/pt.compute.sphere.proxy.hlsl" KEY "pt.compute.sphere" COMPILE_OPTIONS "-DPT_VARIANT_USE_RWMC=0" "-DPT_VARIANT_SCENE_KIND=${PT_SCENE_SPHERE}" "-DPT_VARIANT_ENTRYPOINT_KIND=${PT_ENTRYPOINT_COMBINED}")
63+
PT_APPEND_SPIRV_RULE(VAR JSON INPUT "app_resources/hlsl/spirv/pt.compute.sphere.rwmc.proxy.hlsl" KEY "pt.compute.sphere.rwmc" COMPILE_OPTIONS "-DPT_VARIANT_USE_RWMC=1" "-DPT_VARIANT_SCENE_KIND=${PT_SCENE_SPHERE}" "-DPT_VARIANT_ENTRYPOINT_KIND=${PT_ENTRYPOINT_COMBINED}")
64+
PT_APPEND_SPIRV_RULE(VAR JSON INPUT "app_resources/hlsl/spirv/pt.compute.triangle.linear.proxy.hlsl" KEY "pt.compute.triangle.linear" COMPILE_OPTIONS "-DPT_VARIANT_USE_RWMC=0" "-DPT_VARIANT_ENTRYPOINT_KIND=${PT_ENTRYPOINT_LINEAR}")
65+
PT_APPEND_SPIRV_RULE(VAR JSON INPUT "app_resources/hlsl/spirv/pt.compute.triangle.persistent.proxy.hlsl" KEY "pt.compute.triangle.persistent" COMPILE_OPTIONS "-DPT_VARIANT_USE_RWMC=0" "-DPT_VARIANT_ENTRYPOINT_KIND=${PT_ENTRYPOINT_PERSISTENT}")
66+
PT_APPEND_SPIRV_RULE(VAR JSON INPUT "app_resources/hlsl/spirv/pt.compute.triangle.rwmc.linear.proxy.hlsl" KEY "pt.compute.triangle.rwmc.linear" COMPILE_OPTIONS "-DPT_VARIANT_USE_RWMC=1" "-DPT_VARIANT_ENTRYPOINT_KIND=${PT_ENTRYPOINT_LINEAR}")
67+
PT_APPEND_SPIRV_RULE(VAR JSON INPUT "app_resources/hlsl/spirv/pt.compute.triangle.rwmc.persistent.proxy.hlsl" KEY "pt.compute.triangle.rwmc.persistent" COMPILE_OPTIONS "-DPT_VARIANT_USE_RWMC=1" "-DPT_VARIANT_ENTRYPOINT_KIND=${PT_ENTRYPOINT_PERSISTENT}")
68+
PT_APPEND_SPIRV_RULE(VAR JSON INPUT "app_resources/hlsl/spirv/pt.compute.rectangle.rwmc.linear.proxy.hlsl" KEY "pt.compute.rectangle.rwmc.linear" COMPILE_OPTIONS "-DPT_VARIANT_USE_RWMC=1" "-DPT_VARIANT_SCENE_KIND=${PT_SCENE_RECTANGLE}" "-DPT_VARIANT_ENTRYPOINT_KIND=${PT_ENTRYPOINT_LINEAR}")
69+
PT_APPEND_SPIRV_RULE(VAR JSON INPUT "app_resources/hlsl/spirv/pt.compute.rectangle.rwmc.persistent.proxy.hlsl" KEY "pt.compute.rectangle.rwmc.persistent" COMPILE_OPTIONS "-DPT_VARIANT_USE_RWMC=1" "-DPT_VARIANT_SCENE_KIND=${PT_SCENE_RECTANGLE}" "-DPT_VARIANT_ENTRYPOINT_KIND=${PT_ENTRYPOINT_PERSISTENT}")
70+
PT_APPEND_SPIRV_RULE(VAR JSON INPUT "app_resources/hlsl/spirv/pt.compute.rectangle.proxy.hlsl" KEY "pt.compute.rectangle" COMPILE_OPTIONS "-DPT_VARIANT_USE_RWMC=0" "-DPT_VARIANT_SCENE_KIND=${PT_SCENE_RECTANGLE}" "-DPT_VARIANT_ENTRYPOINT_KIND=${PT_ENTRYPOINT_COMBINED}")
71+
PT_APPEND_SPIRV_RULE(VAR JSON INPUT "app_resources/hlsl/resolve.comp.hlsl" KEY "pt.compute.resolve")
72+
PT_APPEND_SPIRV_RULE(VAR JSON INPUT "app_resources/hlsl/spirv/pt.misc.proxy.hlsl" KEY "pt.misc")
73+
PT_FINALIZE_JSON_PAYLOAD(INOUT JSON)
3374
34-
ADD_CUSTOM_BUILTIN_RESOURCES(${_BR_TARGET_} RESOURCES_TO_EMBED "${_SEARCH_DIRECTORIES_}" "${RESOURCE_DIR}" "nbl::this_example::builtin" "${_OUTPUT_DIRECTORY_HEADER_}" "${_OUTPUT_DIRECTORY_SOURCE_}")
75+
NBL_CREATE_NSC_COMPILE_RULES(
76+
TARGET ${EXECUTABLE_NAME}SPIRV
77+
LINK_TO ${EXECUTABLE_NAME}
78+
DEPENDS ${DEPENDS}
79+
BINARY_DIR ${OUTPUT_DIRECTORY}
80+
MOUNT_POINT_DEFINE NBL_THIS_EXAMPLE_BUILD_MOUNT_POINT
81+
COMMON_OPTIONS ${COMPILE_OPTIONS}
82+
OUTPUT_VAR KEYS
83+
INCLUDE nbl/this_example/builtin/build/spirv/keys.hpp
84+
NAMESPACE nbl::this_example::builtin::build
85+
INPUTS ${JSON}
86+
)
3587
36-
LINK_BUILTIN_RESOURCES_TO_TARGET(${EXECUTABLE_NAME} ${_BR_TARGET_})
37-
endif()
88+
NBL_CREATE_RESOURCE_ARCHIVE(
89+
NAMESPACE nbl::this_example::builtin::build
90+
TARGET ${EXECUTABLE_NAME}_builtinsBuild
91+
LINK_TO ${EXECUTABLE_NAME}
92+
BIND ${OUTPUT_DIRECTORY}
93+
BUILTINS ${KEYS}
94+
)
3895
endif()
39-
40-
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#ifndef PATH_TRACER_USE_RWMC
2+
#error PATH_TRACER_USE_RWMC must be defined before including compute.render.common.hlsl
3+
#endif
4+
5+
#ifndef PATH_TRACER_ENABLE_LINEAR
6+
#define PATH_TRACER_ENABLE_LINEAR 1
7+
#endif
8+
9+
#ifndef PATH_TRACER_ENABLE_PERSISTENT
10+
#define PATH_TRACER_ENABLE_PERSISTENT 1
11+
#endif
12+
13+
#if !PATH_TRACER_ENABLE_LINEAR && !PATH_TRACER_ENABLE_PERSISTENT
14+
#error At least one path tracer entrypoint mode must be enabled
15+
#endif
16+
17+
#include "nbl/builtin/hlsl/cpp_compat.hlsl"
18+
#include "nbl/builtin/hlsl/glsl_compat/core.hlsl"
19+
#include "nbl/builtin/hlsl/random/pcg.hlsl"
20+
#include "nbl/builtin/hlsl/random/xoroshiro.hlsl"
21+
#if PATH_TRACER_ENABLE_PERSISTENT
22+
#include "nbl/builtin/hlsl/morton.hlsl"
23+
#endif
24+
#include "nbl/builtin/hlsl/bxdf/reflection.hlsl"
25+
#include "nbl/builtin/hlsl/bxdf/transmission.hlsl"
26+
#include "nbl/builtin/hlsl/path_tracing/basic_ray_gen.hlsl"
27+
#include "nbl/builtin/hlsl/path_tracing/unidirectional.hlsl"
28+
#include "render_common.hlsl"
29+
30+
#if PATH_TRACER_USE_RWMC
31+
#include "nbl/builtin/hlsl/rwmc/CascadeAccumulator.hlsl"
32+
#include "render_rwmc_common.hlsl"
33+
#else
34+
#include "nbl/builtin/hlsl/path_tracing/default_accumulator.hlsl"
35+
#endif
36+
37+
#if PATH_TRACER_USE_RWMC
38+
[[vk::push_constant]] RenderRWMCPushConstants pc;
39+
#else
40+
[[vk::push_constant]] RenderPushConstants pc;
41+
#endif
42+
43+
[[vk::combinedImageSampler]] [[vk::binding(0, 0)]] Texture2D<float3> envMap;
44+
[[vk::combinedImageSampler]] [[vk::binding(0, 0)]] SamplerState envSampler;
45+
46+
[[vk::combinedImageSampler]] [[vk::binding(1, 0)]] Texture2D<uint2> scramblebuf;
47+
[[vk::combinedImageSampler]] [[vk::binding(1, 0)]] SamplerState scrambleSampler;
48+
49+
[[vk::image_format("rgba16f")]] [[vk::binding(2, 0)]] RWTexture2DArray<float32_t4> outImage;
50+
51+
#if PATH_TRACER_USE_RWMC
52+
[[vk::image_format("rgba16f")]] [[vk::binding(3, 0)]] RWTexture2DArray<float32_t4> cascade;
53+
#endif
54+
55+
#include "example_common.hlsl"
56+
#include "rand_gen.hlsl"
57+
#include "intersector.hlsl"
58+
#include "material_system.hlsl"
59+
#include "next_event_estimator.hlsl"
60+
61+
using namespace nbl;
62+
using namespace hlsl;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef PATH_TRACER_ENTRYPOINT_NAME
2+
#define PATH_TRACER_ENTRYPOINT_NAME main
3+
#endif
4+
5+
#ifndef PATH_TRACER_ENTRYPOINT_POLYGON_METHOD
6+
#define PATH_TRACER_ENTRYPOINT_POLYGON_METHOD pathtracer_variant_config::EntryPointPolygonMethod
7+
#endif
8+
9+
#if !PATH_TRACER_ENABLE_LINEAR
10+
#error Linear entrypoint requested while PATH_TRACER_ENABLE_LINEAR is disabled
11+
#endif
12+
13+
[numthreads(RenderWorkgroupSize, 1, 1)]
14+
[shader("compute")]
15+
void PATH_TRACER_ENTRYPOINT_NAME(uint32_t3 threadID : SV_DispatchThreadID)
16+
{
17+
pathtracer_render_variant::runLinear<PATH_TRACER_ENTRYPOINT_POLYGON_METHOD>(threadID);
18+
}
19+
20+
#undef PATH_TRACER_ENTRYPOINT_POLYGON_METHOD
21+
#undef PATH_TRACER_ENTRYPOINT_NAME
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef PATH_TRACER_ENTRYPOINT_NAME
2+
#define PATH_TRACER_ENTRYPOINT_NAME mainPersistent
3+
#endif
4+
5+
#ifndef PATH_TRACER_ENTRYPOINT_POLYGON_METHOD
6+
#define PATH_TRACER_ENTRYPOINT_POLYGON_METHOD pathtracer_variant_config::EntryPointPolygonMethod
7+
#endif
8+
9+
#if !PATH_TRACER_ENABLE_PERSISTENT
10+
#error Persistent entrypoint requested while PATH_TRACER_ENABLE_PERSISTENT is disabled
11+
#endif
12+
13+
[numthreads(RenderWorkgroupSize, 1, 1)]
14+
[shader("compute")]
15+
void PATH_TRACER_ENTRYPOINT_NAME(uint32_t3 threadID : SV_DispatchThreadID)
16+
{
17+
pathtracer_render_variant::runPersistent<PATH_TRACER_ENTRYPOINT_POLYGON_METHOD>();
18+
}
19+
20+
#undef PATH_TRACER_ENTRYPOINT_POLYGON_METHOD
21+
#undef PATH_TRACER_ENTRYPOINT_NAME
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#ifndef PATH_TRACER_USE_RWMC
2+
#error PATH_TRACER_USE_RWMC must be defined before including compute_render_scene_impl.hlsl
3+
#endif
4+
5+
namespace pathtracer_render_variant
6+
{
7+
using namespace nbl;
8+
using namespace hlsl;
9+
10+
using ray_dir_info_t = bxdf::ray_dir_info::SBasic<float>;
11+
using iso_interaction = PTIsotropicInteraction<ray_dir_info_t, spectral_t>;
12+
using aniso_interaction = PTAnisotropicInteraction<iso_interaction>;
13+
using sample_t = bxdf::SLightSample<ray_dir_info_t>;
14+
using iso_cache = bxdf::SIsotropicMicrofacetCache<float>;
15+
using aniso_cache = bxdf::SAnisotropicMicrofacetCache<iso_cache>;
16+
17+
using iso_config_t = PTIsoConfiguration<sample_t, iso_interaction, spectral_t>;
18+
using iso_microfacet_config_t = PTIsoMicrofacetConfiguration<sample_t, iso_interaction, iso_cache, spectral_t>;
19+
20+
using diffuse_bxdf_type = bxdf::reflection::SOrenNayar<iso_config_t>;
21+
using conductor_bxdf_type = bxdf::reflection::SGGXIsotropic<iso_microfacet_config_t>;
22+
using dielectric_bxdf_type = bxdf::transmission::SGGXDielectricIsotropic<iso_microfacet_config_t>;
23+
using iri_conductor_bxdf_type = bxdf::reflection::SIridescent<iso_microfacet_config_t>;
24+
using iri_dielectric_bxdf_type = bxdf::transmission::SIridescent<iso_microfacet_config_t>;
25+
26+
using payload_type = Payload<float>;
27+
using randgen_type = RandomUniformND<Xoroshiro64Star, 3>;
28+
using material_system_type = MaterialSystem<bxdfnode_type, diffuse_bxdf_type, conductor_bxdf_type, dielectric_bxdf_type, iri_conductor_bxdf_type, iri_dielectric_bxdf_type, scene_type>;
29+
30+
#if PATH_TRACER_USE_RWMC
31+
using accumulator_type = rwmc::CascadeAccumulator<rwmc::DefaultCascades<float32_t3, CascadeCount> >;
32+
#else
33+
using accumulator_type = path_tracing::DefaultAccumulator<float32_t3>;
34+
#endif
35+
36+
template<NEEPolygonMethod PPM>
37+
struct SVariantTypes
38+
{
39+
using ray_type = Ray<payload_type, PPM>;
40+
using raygen_type = path_tracing::BasicRayGenerator<ray_type>;
41+
using intersector_type = Intersector<ray_type, scene_type, aniso_interaction>;
42+
using nee_type = NextEventEstimator<scene_type, light_type, ray_type, sample_t, aniso_interaction, LIGHT_TYPE, PPM>;
43+
using pathtracer_type = path_tracing::Unidirectional<randgen_type, ray_type, intersector_type, material_system_type, nee_type, accumulator_type, scene_type>;
44+
};
45+
46+
RenderPushConstants getRenderPushConstants()
47+
{
48+
#if PATH_TRACER_USE_RWMC
49+
return ::pc.renderPushConstants;
50+
#else
51+
return ::pc;
52+
#endif
53+
}
54+
55+
template<NEEPolygonMethod PPM>
56+
void tracePixel(int32_t2 coords)
57+
{
58+
const RenderPushConstants renderPushConstants = getRenderPushConstants();
59+
using variant_types = SVariantTypes<PPM>;
60+
61+
uint32_t width, height, imageArraySize;
62+
::outImage.GetDimensions(width, height, imageArraySize);
63+
if (any(coords < int32_t2(0, 0)) || any(coords >= int32_t2(width, height)))
64+
return;
65+
66+
float32_t2 texCoord = float32_t2(coords) / float32_t2(width, height);
67+
texCoord.y = 1.0 - texCoord.y;
68+
69+
if (((renderPushConstants.depth - 1) >> MaxDepthLog2) > 0 || ((renderPushConstants.sampleCount - 1) >> MaxSamplesLog2) > 0)
70+
{
71+
::outImage[uint3(coords.x, coords.y, 0)] = float32_t4(1.0, 0.0, 0.0, 1.0);
72+
return;
73+
}
74+
75+
typename variant_types::pathtracer_type pathtracer;
76+
77+
uint2 scrambleDim;
78+
::scramblebuf.GetDimensions(scrambleDim.x, scrambleDim.y);
79+
const float32_t2 pixOffsetParam = float32_t2(1.0, 1.0) / float32_t2(scrambleDim);
80+
81+
float32_t4 NDC = float32_t4(texCoord * float32_t2(2.0, -2.0) + float32_t2(-1.0, 1.0), 0.0, 1.0);
82+
float32_t3 camPos;
83+
{
84+
float32_t4 tmp = mul(renderPushConstants.invMVP, NDC);
85+
camPos = tmp.xyz / tmp.w;
86+
NDC.z = 1.0;
87+
}
88+
89+
scene_type scene;
90+
scene.updateLight(renderPushConstants.generalPurposeLightMatrix);
91+
92+
typename variant_types::raygen_type rayGen;
93+
rayGen.pixOffsetParam = pixOffsetParam;
94+
rayGen.camPos = camPos;
95+
rayGen.NDC = NDC;
96+
rayGen.invMVP = renderPushConstants.invMVP;
97+
98+
pathtracer.scene = scene;
99+
pathtracer.randGen = randgen_type::create(::scramblebuf[coords].rg, renderPushConstants.pSampleSequence);
100+
pathtracer.nee.lights = lights;
101+
pathtracer.materialSystem.bxdfs = bxdfs;
102+
pathtracer.bxdfPdfThreshold = 0.0001;
103+
pathtracer.lumaContributionThreshold = hlsl::dot(colorspace::scRGBtoXYZ[1], colorspace::eotf::sRGB(hlsl::promote<spectral_t>(1.0 / 255.0)));
104+
pathtracer.spectralTypeToLumaCoeffs = colorspace::scRGBtoXYZ[1];
105+
106+
#if PATH_TRACER_USE_RWMC
107+
accumulator_type accumulator = accumulator_type::create(::pc.splattingParameters);
108+
#else
109+
accumulator_type accumulator = accumulator_type::create();
110+
#endif
111+
112+
for (int i = 0; i < renderPushConstants.sampleCount; ++i)
113+
{
114+
const float32_t3 uvw = pathtracer.randGen(0u, i);
115+
typename variant_types::ray_type ray = rayGen.generate(uvw);
116+
ray.initPayload();
117+
pathtracer.sampleMeasure(ray, i, renderPushConstants.depth, accumulator);
118+
}
119+
120+
#if PATH_TRACER_USE_RWMC
121+
for (uint32_t i = 0; i < CascadeCount; ++i)
122+
::cascade[uint3(coords.x, coords.y, i)] = float32_t4(accumulator.accumulation.data[i], 1.0f);
123+
#else
124+
::outImage[uint3(coords.x, coords.y, 0)] = float32_t4(accumulator.accumulation, 1.0);
125+
#endif
126+
}
127+
128+
#if PATH_TRACER_ENABLE_LINEAR
129+
template<NEEPolygonMethod PPM>
130+
void runLinear(uint32_t3 threadID)
131+
{
132+
uint32_t width, height, imageArraySize;
133+
::outImage.GetDimensions(width, height, imageArraySize);
134+
tracePixel<PPM>(int32_t2(threadID.x % width, threadID.x / width));
135+
}
136+
#endif
137+
138+
#if PATH_TRACER_ENABLE_PERSISTENT
139+
template<NEEPolygonMethod PPM>
140+
void runPersistent()
141+
{
142+
uint32_t width, height, imageArraySize;
143+
::outImage.GetDimensions(width, height, imageArraySize);
144+
const uint32_t numWorkgroupsX = width / RenderWorkgroupSizeSqrt;
145+
const uint32_t numWorkgroupsY = height / RenderWorkgroupSizeSqrt;
146+
147+
[loop]
148+
for (uint32_t wgBase = glsl::gl_WorkGroupID().x; wgBase < numWorkgroupsX * numWorkgroupsY; wgBase += glsl::gl_NumWorkGroups().x)
149+
{
150+
const int32_t2 wgCoords = int32_t2(wgBase % numWorkgroupsX, wgBase / numWorkgroupsX);
151+
morton::code<true, 32, 2> mc;
152+
mc.value = glsl::gl_LocalInvocationIndex().x;
153+
const int32_t2 localCoords = _static_cast<int32_t2>(mc);
154+
tracePixel<PPM>(wgCoords * int32_t2(RenderWorkgroupSizeSqrt, RenderWorkgroupSizeSqrt) + localCoords);
155+
}
156+
}
157+
#endif
158+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#define NBL_TEXTURES_BINDING_IX 0
2+
#define NBL_SAMPLER_STATES_BINDING_IX 1
3+
#define NBL_TEXTURES_SET_IX 0
4+
#define NBL_SAMPLER_STATES_SET_IX 0
5+
#define NBL_TEXTURES_COUNT 1
6+
#define NBL_SAMPLERS_COUNT 2
7+
8+
#include "nbl/ext/ImGui/builtin/hlsl/fragment.hlsl"
9+
#include "nbl/ext/ImGui/builtin/hlsl/vertex.hlsl"

0 commit comments

Comments
 (0)