Skip to content

Commit

Permalink
Inject TLAS declarations into fragment shaders if kTLAS[] is used
Browse files Browse the repository at this point in the history
  • Loading branch information
corporateshark committed Sep 21, 2024
1 parent b2c9ba1 commit 27f58a9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lvk/vulkan/VulkanClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5219,6 +5219,7 @@ lvk::ShaderModuleState lvk::VulkanContext::createShaderModuleFromGLSL(ShaderStag
)";
}
if (vkStage == VK_SHADER_STAGE_FRAGMENT_BIT) {
const bool bInjectTLAS = strstr(source, "kTLAS[") != nullptr;
// Note how nonuniformEXT() should be used:
// https://github.com/KhronosGroup/Vulkan-Samples/blob/main/shaders/descriptor_indexing/nonuniform-quads.frag#L33-L39
sourcePatched += R"(
Expand All @@ -5228,7 +5229,16 @@ lvk::ShaderModuleState lvk::VulkanContext::createShaderModuleFromGLSL(ShaderStag
#extension GL_EXT_nonuniform_qualifier : require
#extension GL_EXT_samplerless_texture_functions : require
#extension GL_EXT_shader_explicit_arithmetic_types_float16 : require
)";
if (bInjectTLAS) {
sourcePatched += R"(
#extension GL_EXT_buffer_reference : require
#extension GL_EXT_ray_query : require
layout(set = 0, binding = 4) uniform accelerationStructureEXT kTLAS[];
)";
}
sourcePatched += R"(
layout (set = 0, binding = 0) uniform texture2D kTextures2D[];
layout (set = 1, binding = 0) uniform texture3D kTextures3D[];
layout (set = 2, binding = 0) uniform textureCube kTexturesCube[];
Expand Down

0 comments on commit 27f58a9

Please sign in to comment.