From 256de5085d09996721395d078353d5ecef78a7e6 Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Sun, 7 Dec 2025 14:39:42 +0100 Subject: [PATCH 1/3] Remove need to specify image formats for ray tracing storage images --- .../ray_tracing_basic/ray_tracing_basic.cpp | 11 +++++++++++ .../ray_tracing_extended.cpp | 11 +++++++++++ .../ray_tracing_position_fetch.cpp | 11 +++++++++++ .../ray_tracing_reflection.cpp | 11 +++++++++++ shaders/ray_tracing_basic/glsl/raygen.rgen | 4 ++-- .../ray_tracing_basic/glsl/raygen.rgen.spv | Bin 2900 -> 2920 bytes shaders/ray_tracing_extended/glsl/raygen.rgen | 4 ++-- .../ray_tracing_extended/glsl/raygen.rgen.spv | Bin 12376 -> 12396 bytes .../glsl/raygen.rgen | 4 ++-- .../glsl/raygen.rgen.spv | Bin 2900 -> 2920 bytes shaders/ray_tracing_reflection/raygen.rgen | 4 ++-- .../ray_tracing_reflection/raygen.rgen.spv | Bin 4096 -> 4116 bytes 12 files changed, 52 insertions(+), 8 deletions(-) diff --git a/samples/extensions/ray_tracing_basic/ray_tracing_basic.cpp b/samples/extensions/ray_tracing_basic/ray_tracing_basic.cpp index ab66c0481f..0d22c929a0 100644 --- a/samples/extensions/ray_tracing_basic/ray_tracing_basic.cpp +++ b/samples/extensions/ray_tracing_basic/ray_tracing_basic.cpp @@ -71,6 +71,17 @@ void RaytracingBasic::request_gpu_features(vkb::core::PhysicalDeviceC &gpu) REQUEST_REQUIRED_FEATURE(gpu, VkPhysicalDeviceRayTracingPipelineFeaturesKHR, rayTracingPipeline); REQUEST_REQUIRED_FEATURE(gpu, VkPhysicalDeviceAccelerationStructureFeaturesKHR, accelerationStructure); + + // Using this removes the need to explicitly force an image format inside the shader + if (gpu.get_features().shaderStorageImageReadWithoutFormat && gpu.get_features().shaderStorageImageWriteWithoutFormat) + { + gpu.get_mutable_requested_features().shaderStorageImageReadWithoutFormat = VK_TRUE; + gpu.get_mutable_requested_features().shaderStorageImageWriteWithoutFormat = VK_TRUE; + } + else + { + throw std::runtime_error("Requested required feature shaderStorageImageReadWithoutFormat or shaderStorageImageWriteWithoutFormat is not supported"); + } } /* diff --git a/samples/extensions/ray_tracing_extended/ray_tracing_extended.cpp b/samples/extensions/ray_tracing_extended/ray_tracing_extended.cpp index ef8afdb626..f5ca7cc716 100644 --- a/samples/extensions/ray_tracing_extended/ray_tracing_extended.cpp +++ b/samples/extensions/ray_tracing_extended/ray_tracing_extended.cpp @@ -149,6 +149,17 @@ void RaytracingExtended::request_gpu_features(vkb::core::PhysicalDeviceC &gpu) { gpu.get_mutable_requested_features().samplerAnisotropy = true; } + + // Using this removes the need to explicitly force an image format inside the shader + if (gpu.get_features().shaderStorageImageReadWithoutFormat && gpu.get_features().shaderStorageImageWriteWithoutFormat) + { + gpu.get_mutable_requested_features().shaderStorageImageReadWithoutFormat = VK_TRUE; + gpu.get_mutable_requested_features().shaderStorageImageWriteWithoutFormat = VK_TRUE; + } + else + { + throw std::runtime_error("Requested required feature shaderStorageImageReadWithoutFormat or shaderStorageImageWriteWithoutFormat is not supported"); + } } /* diff --git a/samples/extensions/ray_tracing_position_fetch/ray_tracing_position_fetch.cpp b/samples/extensions/ray_tracing_position_fetch/ray_tracing_position_fetch.cpp index 8d326e6327..c91d982896 100644 --- a/samples/extensions/ray_tracing_position_fetch/ray_tracing_position_fetch.cpp +++ b/samples/extensions/ray_tracing_position_fetch/ray_tracing_position_fetch.cpp @@ -69,6 +69,17 @@ void RayTracingPositionFetch::request_gpu_features(vkb::core::PhysicalDeviceC &g // Sample sepcific feature REQUEST_REQUIRED_FEATURE(gpu, VkPhysicalDeviceRayTracingPositionFetchFeaturesKHR, rayTracingPositionFetch); + + // Using this removes the need to explicitly force an image format inside the shader + if (gpu.get_features().shaderStorageImageReadWithoutFormat && gpu.get_features().shaderStorageImageWriteWithoutFormat) + { + gpu.get_mutable_requested_features().shaderStorageImageReadWithoutFormat = VK_TRUE; + gpu.get_mutable_requested_features().shaderStorageImageWriteWithoutFormat = VK_TRUE; + } + else + { + throw std::runtime_error("Requested required feature shaderStorageImageReadWithoutFormat or shaderStorageImageWriteWithoutFormat is not supported"); + } } /* diff --git a/samples/extensions/ray_tracing_reflection/ray_tracing_reflection.cpp b/samples/extensions/ray_tracing_reflection/ray_tracing_reflection.cpp index 31a6ded930..b08493053a 100644 --- a/samples/extensions/ray_tracing_reflection/ray_tracing_reflection.cpp +++ b/samples/extensions/ray_tracing_reflection/ray_tracing_reflection.cpp @@ -143,6 +143,17 @@ void RaytracingReflection::request_gpu_features(vkb::core::PhysicalDeviceC &gpu) { throw std::runtime_error("Requested required feature is not supported"); } + + // Using this removes the need to explicitly force an image format inside the shader + if (gpu.get_features().shaderStorageImageReadWithoutFormat && gpu.get_features().shaderStorageImageWriteWithoutFormat) + { + gpu.get_mutable_requested_features().shaderStorageImageReadWithoutFormat = VK_TRUE; + gpu.get_mutable_requested_features().shaderStorageImageWriteWithoutFormat = VK_TRUE; + } + else + { + throw std::runtime_error("Requested required feature shaderStorageImageReadWithoutFormat or shaderStorageImageWriteWithoutFormat is not supported"); + } } /* diff --git a/shaders/ray_tracing_basic/glsl/raygen.rgen b/shaders/ray_tracing_basic/glsl/raygen.rgen index 1f0cda6949..158b5dd7ad 100644 --- a/shaders/ray_tracing_basic/glsl/raygen.rgen +++ b/shaders/ray_tracing_basic/glsl/raygen.rgen @@ -1,4 +1,4 @@ -/* Copyright (c) 2019-2024, Sascha Willems +/* Copyright (c) 2019-2025, Sascha Willems * * SPDX-License-Identifier: Apache-2.0 * @@ -19,7 +19,7 @@ #extension GL_EXT_ray_tracing : enable layout(binding = 0, set = 0) uniform accelerationStructureEXT topLevelAS; -layout(binding = 1, set = 0, rgba8) uniform image2D image; +layout(binding = 1, set = 0) uniform writeonly image2D image; layout(binding = 2, set = 0) uniform CameraProperties { mat4 viewInverse; diff --git a/shaders/ray_tracing_basic/glsl/raygen.rgen.spv b/shaders/ray_tracing_basic/glsl/raygen.rgen.spv index cec392359bea5d85fcdf76a32090b06468aba4f9..ef00f85e1d087989fc42a37411f737f827139a40 100644 GIT binary patch delta 32 ocmca2_Cjoe1f#`9K~ZLQW`=kM1_sH^ip+Cj3=EQ+4>I>NGcs%rWM9t#0E(IjFaQ7m delta 22 ecmbQD(4a6uVxz)3=FPX5yO Date: Sun, 7 Dec 2025 14:50:00 +0100 Subject: [PATCH 2/3] Remove need to specify image formats for ray tracing storage images for HLSL shaders --- .../ray_tracing_basic/hlsl/raygen.rgen.hlsl | 3 ++- .../ray_tracing_basic/hlsl/raygen.rgen.spv | Bin 2396 -> 2404 bytes .../hlsl/raygen.rgen.hlsl | 3 ++- .../ray_tracing_extended/hlsl/raygen.rgen.spv | Bin 8104 -> 8112 bytes .../hlsl/raygen.rgen.hlsl | 3 ++- .../hlsl/raygen.rgen.spv | Bin 2388 -> 2396 bytes 6 files changed, 6 insertions(+), 3 deletions(-) diff --git a/shaders/ray_tracing_basic/hlsl/raygen.rgen.hlsl b/shaders/ray_tracing_basic/hlsl/raygen.rgen.hlsl index 8e0f6bc318..99db5dcb12 100644 --- a/shaders/ray_tracing_basic/hlsl/raygen.rgen.hlsl +++ b/shaders/ray_tracing_basic/hlsl/raygen.rgen.hlsl @@ -1,4 +1,4 @@ -/* Copyright (c) 2024, Sascha Willems +/* Copyright (c) 2024-2025, Sascha Willems * * SPDX-License-Identifier: Apache-2.0 * @@ -16,6 +16,7 @@ */ RaytracingAccelerationStructure rs : register(t0); +[[vk::image_format("unknown")]] RWTexture2D image : register(u1); struct CameraProperties diff --git a/shaders/ray_tracing_basic/hlsl/raygen.rgen.spv b/shaders/ray_tracing_basic/hlsl/raygen.rgen.spv index 23f7b86d4019039f04029d84e466c4b604dc37fe..afb3b90fbee24de62410f944615278e211bab149 100644 GIT binary patch delta 19 acmca3^h9Wa1f#`9!EhEvhRvBQpIHDv@CEw- delta 17 YcmaDNbVq1{#72bx7DmR+g)E<006De=(*OVf diff --git a/shaders/ray_tracing_extended/hlsl/raygen.rgen.hlsl b/shaders/ray_tracing_extended/hlsl/raygen.rgen.hlsl index 1165e54628..0765dbf01a 100644 --- a/shaders/ray_tracing_extended/hlsl/raygen.rgen.hlsl +++ b/shaders/ray_tracing_extended/hlsl/raygen.rgen.hlsl @@ -1,4 +1,4 @@ -/* Copyright (c) 2024, Sascha Willems +/* Copyright (c) 2024-2025, Sascha Willems * * SPDX-License-Identifier: Apache-2.0 * @@ -24,6 +24,7 @@ #define RENDER_AO 6 RaytracingAccelerationStructure rs : register(t0); +[[vk::image_format("unknown")]] RWTexture2D image : register(u1); struct CameraProperties diff --git a/shaders/ray_tracing_extended/hlsl/raygen.rgen.spv b/shaders/ray_tracing_extended/hlsl/raygen.rgen.spv index b5891f040437f0694c748e4589bfc57755a6f2bb..b72f044a667b883d3565442b911639f225d2dcae 100644 GIT binary patch delta 19 acmZ2szrlWj1f#`9L1Q*XhRv>Q$&vs((FHC5 delta 17 YcmdmBzruck#6|@jHb%zHzHG^o05!7(1^@s6 diff --git a/shaders/ray_tracing_position_fetch/hlsl/raygen.rgen.hlsl b/shaders/ray_tracing_position_fetch/hlsl/raygen.rgen.hlsl index 51be3f2f0f..9922dcf572 100644 --- a/shaders/ray_tracing_position_fetch/hlsl/raygen.rgen.hlsl +++ b/shaders/ray_tracing_position_fetch/hlsl/raygen.rgen.hlsl @@ -1,4 +1,4 @@ -/* Copyright (c) 2024, Sascha Willems +/* Copyright (c) 2024-2025, Sascha Willems * * SPDX-License-Identifier: Apache-2.0 * @@ -16,6 +16,7 @@ */ RaytracingAccelerationStructure rs : register(t0); +[[vk::image_format("unknown")]] RWTexture2D image : register(u1); struct CameraProperties diff --git a/shaders/ray_tracing_position_fetch/hlsl/raygen.rgen.spv b/shaders/ray_tracing_position_fetch/hlsl/raygen.rgen.spv index 5535f2ed86ea22bf27dbdbb4477e3addd88fa49d..6b1d9c5df4f412db19d52f126c630c9c17185d8f 100644 GIT binary patch delta 19 acmca2bVq1{1f#`9L4OuThRumApIHDuXa(B< delta 17 Ycmca3bVX=_#6|@V7DmR+nJk}K060zsvj6}9 From 41c1c2a2d9c18417f3d96a7be353a86efa10d41e Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Sun, 7 Dec 2025 14:56:59 +0100 Subject: [PATCH 3/3] Fix code format and copyright --- samples/extensions/ray_tracing_basic/ray_tracing_basic.cpp | 2 +- .../extensions/ray_tracing_extended/ray_tracing_extended.cpp | 2 +- shaders/ray_tracing_reflection/raygen.rgen | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/extensions/ray_tracing_basic/ray_tracing_basic.cpp b/samples/extensions/ray_tracing_basic/ray_tracing_basic.cpp index 0d22c929a0..cbcee9f424 100644 --- a/samples/extensions/ray_tracing_basic/ray_tracing_basic.cpp +++ b/samples/extensions/ray_tracing_basic/ray_tracing_basic.cpp @@ -71,7 +71,7 @@ void RaytracingBasic::request_gpu_features(vkb::core::PhysicalDeviceC &gpu) REQUEST_REQUIRED_FEATURE(gpu, VkPhysicalDeviceRayTracingPipelineFeaturesKHR, rayTracingPipeline); REQUEST_REQUIRED_FEATURE(gpu, VkPhysicalDeviceAccelerationStructureFeaturesKHR, accelerationStructure); - + // Using this removes the need to explicitly force an image format inside the shader if (gpu.get_features().shaderStorageImageReadWithoutFormat && gpu.get_features().shaderStorageImageWriteWithoutFormat) { diff --git a/samples/extensions/ray_tracing_extended/ray_tracing_extended.cpp b/samples/extensions/ray_tracing_extended/ray_tracing_extended.cpp index f5ca7cc716..fcd8cd7940 100644 --- a/samples/extensions/ray_tracing_extended/ray_tracing_extended.cpp +++ b/samples/extensions/ray_tracing_extended/ray_tracing_extended.cpp @@ -153,7 +153,7 @@ void RaytracingExtended::request_gpu_features(vkb::core::PhysicalDeviceC &gpu) // Using this removes the need to explicitly force an image format inside the shader if (gpu.get_features().shaderStorageImageReadWithoutFormat && gpu.get_features().shaderStorageImageWriteWithoutFormat) { - gpu.get_mutable_requested_features().shaderStorageImageReadWithoutFormat = VK_TRUE; + gpu.get_mutable_requested_features().shaderStorageImageReadWithoutFormat = VK_TRUE; gpu.get_mutable_requested_features().shaderStorageImageWriteWithoutFormat = VK_TRUE; } else diff --git a/shaders/ray_tracing_reflection/raygen.rgen b/shaders/ray_tracing_reflection/raygen.rgen index 6aa654abeb..7711255ea9 100644 --- a/shaders/ray_tracing_reflection/raygen.rgen +++ b/shaders/ray_tracing_reflection/raygen.rgen @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * SPDX-FileCopyrightText: Copyright (c) 2014-2021 NVIDIA CORPORATION + * SPDX-FileCopyrightText: Copyright (c) 2014-2025 NVIDIA CORPORATION * SPDX-License-Identifier: Apache-2.0 */