Skip to content

Commit 9caf185

Browse files
author
devsh
committed
start some bakward compatibility SPIR-V capability macros
1 parent 4e87727 commit 9caf185

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed

include/nbl/builtin/hlsl/bda/__ref.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace hlsl
1313
namespace bda
1414
{
1515
template<typename T>
16-
using __spv_ptr_t = spirv::pointer_t<spv::StorageClassPhysicalStorageBuffer,T>;
16+
using __spv_ptr_t __NBL_CAPABILITY_PhysicalStorageBufferAddresses = spirv::pointer_t<spv::StorageClassPhysicalStorageBuffer,T>;
1717

1818
template<typename T>
1919
struct __ptr;

include/nbl/builtin/hlsl/spirv_intrinsics/core.hlsl

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,40 @@ namespace nbl
1717
namespace hlsl
1818
{
1919
#ifdef __HLSL_VERSION
20+
21+
22+
#if __SPIRV_MAJOR_VERSION__>1 || (__SPIRV_MAJOR_VERSION__==1 && __SPIRV_MINOR_VERSION__>=5)
23+
24+
#define __NBL_SPIRV_SUPERSET_1_5__
25+
26+
#define __NBL_CAPABILITY_VulkanMemoryModel [[vk::ext_capability(spv::CapabilityVulkanMemoryModel)]]
27+
#define __NBL_CAPABILITY_ShaderNonUniform [[vk::ext_capability(spv::CapabilityShaderNonUniform)]]
28+
#define __NBL_CAPABILITY_PhysicalStorageBufferAddresses [[vk::ext_capability(spv::CapabilityPhysicalStorageBufferAddresses)]]
29+
// TODO: some poor soul needs to study rest of https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_capability
30+
#define __NBL_CAPABILITY_ShaderLayer [[vk::ext_capability(spv::CapabilityShaderLayer)]]
31+
#define __NBL_CAPABILITY_ShaderViewportIndex [[vk::ext_capability(spv::CapabilityShaderViewportIndex)]]
32+
33+
#else
34+
35+
#define __NBL_CAPABILITY_VulkanMemoryModel [[vk::ext_capability(spv::CapabilityVulkanMemoryModel)]] [[vk::ext_extension("SPV_KHR_vulkan_memory_model")]]
36+
#define __NBL_CAPABILITY_ShaderNonUniform [[vk::ext_capability(spv::CapabilityShaderNonUniform)]] [[vk::ext_extension("SPV_EXT_descriptor_indexing")]]
37+
#define __NBL_CAPABILITY_PhysicalStorageBufferAddresses [[vk::ext_capability(spv::CapabilityPhysicalStorageBufferAddresses)]] [[vk::ext_extension("SPV_KHR_physical_storage_buffer")]]
38+
39+
#endif
40+
41+
42+
#if __SPIRV_MAJOR_VERSION__>1 || (__SPIRV_MAJOR_VERSION__==1 && __SPIRV_MINOR_VERSION__>=6)
43+
44+
#define __NBL_SPIRV_SUPERSET_1_6__
45+
46+
// 1.6 core caps
47+
48+
#else
49+
50+
// 1.6 core caps and their old extensions
51+
52+
#endif
53+
2054
namespace spirv
2155
{
2256
//! General
@@ -171,7 +205,7 @@ enable_if_t<is_spirv_type_v<Ptr_T>, T> atomicCompareExchange(Ptr_T ptr, uint32_t
171205

172206

173207
template<typename T, uint32_t alignment>
174-
[[vk::ext_capability(spv::CapabilityPhysicalStorageBufferAddresses)]]
208+
__NBL_CAPABILITY_PhysicalStorageBufferAddresses
175209
[[vk::ext_instruction(spv::OpLoad)]]
176210
T load(pointer_t<spv::StorageClassPhysicalStorageBuffer,T> pointer, [[vk::ext_literal]] uint32_t __aligned = /*Aligned*/0x00000002, [[vk::ext_literal]] uint32_t __alignment = alignment);
177211

@@ -180,7 +214,7 @@ template<typename T, typename P>
180214
enable_if_t<is_spirv_type_v<P>,T> load(P pointer);
181215

182216
template<typename T, uint32_t alignment>
183-
[[vk::ext_capability(spv::CapabilityPhysicalStorageBufferAddresses)]]
217+
__NBL_CAPABILITY_PhysicalStorageBufferAddresses
184218
[[vk::ext_instruction(spv::OpStore)]]
185219
void store(pointer_t<spv::StorageClassPhysicalStorageBuffer,T> pointer, T obj, [[vk::ext_literal]] uint32_t __aligned = /*Aligned*/0x00000002, [[vk::ext_literal]] uint32_t __alignment = alignment);
186220

@@ -205,12 +239,12 @@ template<typename T, typename U>
205239
enable_if_t<is_spirv_type_v<T> && is_spirv_type_v<U>, T> bitcast(U);
206240

207241
template<typename T>
208-
[[vk::ext_capability(spv::CapabilityPhysicalStorageBufferAddresses)]]
242+
__NBL_CAPABILITY_PhysicalStorageBufferAddresses
209243
[[vk::ext_instruction(spv::OpBitcast)]]
210244
uint64_t bitcast(pointer_t<spv::StorageClassPhysicalStorageBuffer,T>);
211245

212246
template<typename T>
213-
[[vk::ext_capability(spv::CapabilityPhysicalStorageBufferAddresses)]]
247+
__NBL_CAPABILITY_PhysicalStorageBufferAddresses
214248
[[vk::ext_instruction(spv::OpBitcast)]]
215249
pointer_t<spv::StorageClassPhysicalStorageBuffer,T> bitcast(uint64_t);
216250

@@ -269,8 +303,7 @@ enable_if_t<is_vector_v<BooleanVector>&& is_same_v<typename vector_traits<Boolea
269303
}
270304

271305
#endif
272-
}
273306
}
274-
307+
}
275308
#endif
276309
#endif

include/nbl/builtin/hlsl/spirv_intrinsics/subgroup_arithmetic.hlsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// For all WaveMultiPrefix* ops, an example can be found here https://github.com/microsoft/DirectXShaderCompiler/blob/4e5440e1ee1f30d1164f90445611328293de08fa/tools/clang/test/HLSLFileCheck/hlsl/intrinsics/wave/prefix/sm_6_5_wave.hlsl
88
// However, we prefer to implement them with SPIRV intrinsics to avoid DXC changes in the compiler's emitted code
99

10+
11+
#include "nbl/builtin/hlsl/spirv_intrinsics/core.hlsl"
12+
1013
namespace nbl
1114
{
1215
namespace hlsl

include/nbl/builtin/hlsl/spirv_intrinsics/subgroup_vote.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#define _NBL_BUILTIN_HLSL_SPIRV_INTRINSICS_SUBGROUP_VOTE_INCLUDED_
66

77

8-
#include "nbl/builtin/hlsl/spirv_intrinsics/basic.hlsl"
8+
#include "nbl/builtin/hlsl/spirv_intrinsics/subgroup_basic.hlsl"
99

1010

1111
namespace nbl

0 commit comments

Comments
 (0)