From 33949281128a39663ac975de4685c2807cb5ac1c Mon Sep 17 00:00:00 2001 From: JoseEmilio-ARM <33630720+JoseEmilio-ARM@users.noreply.github.com> Date: Thu, 7 Apr 2022 15:35:38 +0100 Subject: [PATCH 1/2] Update scene.frag Ray Query example: shader optimization Calling rayQueryProceedEXT in a loop can prevent certain shader optimizations. By setting the TerminateOnFirstHit and SkipAABB flags, there is no scenario where rayQueryProceedEXT will return true, hence the loop can be removed. This way the implementation has a guarantee that the traversal can be completed without returning control to the shader, which improves performance. --- data/shaders/glsl/rayquery/scene.frag | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data/shaders/glsl/rayquery/scene.frag b/data/shaders/glsl/rayquery/scene.frag index edbd3617..059fc4d3 100644 --- a/data/shaders/glsl/rayquery/scene.frag +++ b/data/shaders/glsl/rayquery/scene.frag @@ -25,10 +25,10 @@ void main() outFragColor = vec4(diffuse, 1.0); rayQueryEXT rayQuery; - rayQueryInitializeEXT(rayQuery, topLevelAS, gl_RayFlagsTerminateOnFirstHitEXT, 0xFF, inWorldPos, 0.01, L, 1000.0); + rayQueryInitializeEXT(rayQuery, topLevelAS, gl_RayFlagsTerminateOnFirstHitEXT | gl_RayFlagsSkipAABBEXT, 0xFF, inWorldPos, 0.01, L, 1000.0); - // Start the ray traversal, rayQueryProceedEXT returns false if the traversal is complete - while (rayQueryProceedEXT(rayQuery)) { } + // Traverse the acceleration structure and store information about the first intersection (if any) + rayQueryProceedEXT(rayQuery); // If the intersection has hit a triangle, the fragment is shadowed if (rayQueryGetIntersectionTypeEXT(rayQuery, true) == gl_RayQueryCommittedIntersectionTriangleEXT ) { From fc5ef968ccd3cb4892f073914d051e9e542f0a7f Mon Sep 17 00:00:00 2001 From: jonnxie Date: Mon, 18 Apr 2022 16:54:21 +0800 Subject: [PATCH 2/2] Fixed potential memory leak bug. --- base/VulkanglTFModel.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/base/VulkanglTFModel.cpp b/base/VulkanglTFModel.cpp index c9c9a626..4cd0799c 100644 --- a/base/VulkanglTFModel.cpp +++ b/base/VulkanglTFModel.cpp @@ -273,6 +273,10 @@ void vkglTF::Texture::fromglTfImage(tinygltf::Image &gltfimage, std::string path vkCmdPipelineBarrier(blitCmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1, &imageMemoryBarrier); } + if (deleteBuffer) { + delete[] buffer; + } + device->flushCommandBuffer(blitCmd, copyQueue, true); } else {