Skip to content

Commit 05f8a2f

Browse files
Remove need to specify image formats for ray tracing storage images (#1452)
* Remove need to specify image formats for ray tracing storage images * Remove need to specify image formats for ray tracing storage images for HLSL shaders * Fix code format and copyright
1 parent 71b2cb5 commit 05f8a2f

18 files changed

Lines changed: 59 additions & 12 deletions

File tree

samples/extensions/ray_tracing_basic/ray_tracing_basic.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ void RaytracingBasic::request_gpu_features(vkb::core::PhysicalDeviceC &gpu)
7171
REQUEST_REQUIRED_FEATURE(gpu, VkPhysicalDeviceRayTracingPipelineFeaturesKHR, rayTracingPipeline);
7272

7373
REQUEST_REQUIRED_FEATURE(gpu, VkPhysicalDeviceAccelerationStructureFeaturesKHR, accelerationStructure);
74+
75+
// Using this removes the need to explicitly force an image format inside the shader
76+
if (gpu.get_features().shaderStorageImageReadWithoutFormat && gpu.get_features().shaderStorageImageWriteWithoutFormat)
77+
{
78+
gpu.get_mutable_requested_features().shaderStorageImageReadWithoutFormat = VK_TRUE;
79+
gpu.get_mutable_requested_features().shaderStorageImageWriteWithoutFormat = VK_TRUE;
80+
}
81+
else
82+
{
83+
throw std::runtime_error("Requested required feature shaderStorageImageReadWithoutFormat or shaderStorageImageWriteWithoutFormat is not supported");
84+
}
7485
}
7586

7687
/*

samples/extensions/ray_tracing_extended/ray_tracing_extended.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ void RaytracingExtended::request_gpu_features(vkb::core::PhysicalDeviceC &gpu)
149149
{
150150
gpu.get_mutable_requested_features().samplerAnisotropy = true;
151151
}
152+
153+
// Using this removes the need to explicitly force an image format inside the shader
154+
if (gpu.get_features().shaderStorageImageReadWithoutFormat && gpu.get_features().shaderStorageImageWriteWithoutFormat)
155+
{
156+
gpu.get_mutable_requested_features().shaderStorageImageReadWithoutFormat = VK_TRUE;
157+
gpu.get_mutable_requested_features().shaderStorageImageWriteWithoutFormat = VK_TRUE;
158+
}
159+
else
160+
{
161+
throw std::runtime_error("Requested required feature shaderStorageImageReadWithoutFormat or shaderStorageImageWriteWithoutFormat is not supported");
162+
}
152163
}
153164

154165
/*

samples/extensions/ray_tracing_position_fetch/ray_tracing_position_fetch.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ void RayTracingPositionFetch::request_gpu_features(vkb::core::PhysicalDeviceC &g
6969

7070
// Sample sepcific feature
7171
REQUEST_REQUIRED_FEATURE(gpu, VkPhysicalDeviceRayTracingPositionFetchFeaturesKHR, rayTracingPositionFetch);
72+
73+
// Using this removes the need to explicitly force an image format inside the shader
74+
if (gpu.get_features().shaderStorageImageReadWithoutFormat && gpu.get_features().shaderStorageImageWriteWithoutFormat)
75+
{
76+
gpu.get_mutable_requested_features().shaderStorageImageReadWithoutFormat = VK_TRUE;
77+
gpu.get_mutable_requested_features().shaderStorageImageWriteWithoutFormat = VK_TRUE;
78+
}
79+
else
80+
{
81+
throw std::runtime_error("Requested required feature shaderStorageImageReadWithoutFormat or shaderStorageImageWriteWithoutFormat is not supported");
82+
}
7283
}
7384

7485
/*

samples/extensions/ray_tracing_reflection/ray_tracing_reflection.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,17 @@ void RaytracingReflection::request_gpu_features(vkb::core::PhysicalDeviceC &gpu)
143143
{
144144
throw std::runtime_error("Requested required feature <VkPhysicalDeviceFeatures::shaderInt64> is not supported");
145145
}
146+
147+
// Using this removes the need to explicitly force an image format inside the shader
148+
if (gpu.get_features().shaderStorageImageReadWithoutFormat && gpu.get_features().shaderStorageImageWriteWithoutFormat)
149+
{
150+
gpu.get_mutable_requested_features().shaderStorageImageReadWithoutFormat = VK_TRUE;
151+
gpu.get_mutable_requested_features().shaderStorageImageWriteWithoutFormat = VK_TRUE;
152+
}
153+
else
154+
{
155+
throw std::runtime_error("Requested required feature shaderStorageImageReadWithoutFormat or shaderStorageImageWriteWithoutFormat is not supported");
156+
}
146157
}
147158

148159
/*

shaders/ray_tracing_basic/glsl/raygen.rgen

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019-2024, Sascha Willems
1+
/* Copyright (c) 2019-2025, Sascha Willems
22
*
33
* SPDX-License-Identifier: Apache-2.0
44
*
@@ -19,7 +19,7 @@
1919
#extension GL_EXT_ray_tracing : enable
2020

2121
layout(binding = 0, set = 0) uniform accelerationStructureEXT topLevelAS;
22-
layout(binding = 1, set = 0, rgba8) uniform image2D image;
22+
layout(binding = 1, set = 0) uniform writeonly image2D image;
2323
layout(binding = 2, set = 0) uniform CameraProperties
2424
{
2525
mat4 viewInverse;
20 Bytes
Binary file not shown.

shaders/ray_tracing_basic/hlsl/raygen.rgen.hlsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2024, Sascha Willems
1+
/* Copyright (c) 2024-2025, Sascha Willems
22
*
33
* SPDX-License-Identifier: Apache-2.0
44
*
@@ -16,6 +16,7 @@
1616
*/
1717

1818
RaytracingAccelerationStructure rs : register(t0);
19+
[[vk::image_format("unknown")]]
1920
RWTexture2D<float4> image : register(u1);
2021

2122
struct CameraProperties
8 Bytes
Binary file not shown.

shaders/ray_tracing_extended/glsl/raygen.rgen

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2021-2024 Holochip Corporation
1+
/* Copyright (c) 2021-2025 Holochip Corporation
22
*
33
* SPDX-License-Identifier: Apache-2.0
44
*
@@ -26,7 +26,7 @@
2626
#define RENDER_AO 6
2727

2828
layout(binding = 0, set = 0) uniform accelerationStructureEXT topLevelAS;
29-
layout(binding = 1, set = 0, rgba8) uniform image2D image;
29+
layout(binding = 1, set = 0) uniform writeonly image2D image;
3030
layout(binding = 2, set = 0) uniform CameraProperties
3131
{
3232
mat4 viewInverse;
20 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)