aboutsummaryrefslogtreecommitdiff
path: root/contrib/dxc_2025_07_14/inc/hlsl/vk/opcode_selector.h
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-12-02 16:39:36 -0800
committer3gg <3gg@shellblade.net>2025-12-02 16:39:36 -0800
commit6c8ae19be66cee247980a48e736a4e05d14de179 (patch)
treed860767907bf0cbe17ec66422e11bea700cf56d9 /contrib/dxc_2025_07_14/inc/hlsl/vk/opcode_selector.h
parent8f594c8ebd11f0e5f8a0c6369c3fe7383d250cbe (diff)
Immediate-mode renderer, triangle demo, shader compilation in cmake, Agility SDKHEADmain
Diffstat (limited to 'contrib/dxc_2025_07_14/inc/hlsl/vk/opcode_selector.h')
-rw-r--r--contrib/dxc_2025_07_14/inc/hlsl/vk/opcode_selector.h227
1 files changed, 227 insertions, 0 deletions
diff --git a/contrib/dxc_2025_07_14/inc/hlsl/vk/opcode_selector.h b/contrib/dxc_2025_07_14/inc/hlsl/vk/opcode_selector.h
new file mode 100644
index 0000000..bc8672c
--- /dev/null
+++ b/contrib/dxc_2025_07_14/inc/hlsl/vk/opcode_selector.h
@@ -0,0 +1,227 @@
1// Copyright (c) 2024 Google LLC
2//
3// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
7#ifndef _HLSL_VK_KHR_OPCODE_SELECTOR_H_
8#define _HLSL_VK_KHR_OPCODE_SELECTOR_H_
9
10#define DECLARE_UNARY_OP(name, opcode) \
11 template <typename ResultType> \
12 [[vk::ext_instruction(opcode)]] ResultType __builtin_spv_##name( \
13 ResultType a)
14
15DECLARE_UNARY_OP(CopyObject, 83);
16DECLARE_UNARY_OP(SNegate, 126);
17DECLARE_UNARY_OP(FNegate, 127);
18
19#define DECLARE_CONVERSION_OP(name, opcode) \
20 template <typename ResultType, typename OperandType> \
21 [[vk::ext_instruction(opcode)]] ResultType __builtin_spv_##name( \
22 OperandType a)
23
24DECLARE_CONVERSION_OP(ConvertFtoU, 109);
25DECLARE_CONVERSION_OP(ConvertFtoS, 110);
26DECLARE_CONVERSION_OP(ConvertSToF, 111);
27DECLARE_CONVERSION_OP(ConvertUToF, 112);
28DECLARE_CONVERSION_OP(UConvert, 113);
29DECLARE_CONVERSION_OP(SConvert, 114);
30DECLARE_CONVERSION_OP(FConvert, 115);
31DECLARE_CONVERSION_OP(Bitcast, 124);
32
33#undef DECLARY_UNARY_OP
34
35#define DECLARE_BINOP(name, opcode) \
36 template <typename ResultType> \
37 [[vk::ext_instruction(opcode)]] ResultType __builtin_spv_##name( \
38 ResultType a, ResultType b)
39
40DECLARE_BINOP(IAdd, 128);
41DECLARE_BINOP(FAdd, 129);
42DECLARE_BINOP(ISub, 130);
43DECLARE_BINOP(FSub, 131);
44DECLARE_BINOP(IMul, 132);
45DECLARE_BINOP(FMul, 133);
46DECLARE_BINOP(UDiv, 134);
47DECLARE_BINOP(SDiv, 135);
48DECLARE_BINOP(FDiv, 136);
49
50#undef DECLARE_BINOP
51namespace vk {
52namespace util {
53
54template <class ComponentType> class ArithmeticSelector;
55
56#define ARITHMETIC_SELECTOR(BaseType, OpNegate, OpAdd, OpSub, OpMul, OpDiv, \
57 SIGNED_INTEGER_TYPE) \
58 template <> class ArithmeticSelector<BaseType> { \
59 template <class T> static T Negate(T a) { return OpNegate(a); } \
60 template <class T> static T Add(T a, T b) { return OpAdd(a, b); } \
61 template <class T> static T Sub(T a, T b) { return OpSub(a, b); } \
62 template <class T> static T Mul(T a, T b) { return OpMul(a, b); } \
63 template <class T> static T Div(T a, T b) { return OpDiv(a, b); } \
64 };
65
66ARITHMETIC_SELECTOR(half, __builtin_spv_FNegate, __builtin_spv_FAdd,
67 __builtin_spv_FSub, __builtin_spv_FMul, __builtin_spv_FDiv,
68 false);
69ARITHMETIC_SELECTOR(float, __builtin_spv_FNegate, __builtin_spv_FAdd,
70 __builtin_spv_FSub, __builtin_spv_FMul, __builtin_spv_FDiv,
71 false);
72ARITHMETIC_SELECTOR(double, __builtin_spv_FNegate, __builtin_spv_FAdd,
73 __builtin_spv_FSub, __builtin_spv_FMul, __builtin_spv_FDiv,
74 false);
75
76#if __HLSL_ENABLE_16_BIT
77ARITHMETIC_SELECTOR(int16_t, __builtin_spv_SNegate, __builtin_spv_IAdd,
78 __builtin_spv_ISub, __builtin_spv_IMul, __builtin_spv_SDiv,
79 true);
80ARITHMETIC_SELECTOR(uint16_t, __builtin_spv_SNegate, __builtin_spv_IAdd,
81 __builtin_spv_ISub, __builtin_spv_IMul, __builtin_spv_UDiv,
82 false);
83#endif // __HLSL_ENABLE_16_BIT
84
85ARITHMETIC_SELECTOR(int32_t, __builtin_spv_SNegate, __builtin_spv_IAdd,
86 __builtin_spv_ISub, __builtin_spv_IMul, __builtin_spv_SDiv,
87 true);
88ARITHMETIC_SELECTOR(int64_t, __builtin_spv_SNegate, __builtin_spv_IAdd,
89 __builtin_spv_ISub, __builtin_spv_IMul, __builtin_spv_SDiv,
90 true);
91ARITHMETIC_SELECTOR(uint32_t, __builtin_spv_SNegate, __builtin_spv_IAdd,
92 __builtin_spv_ISub, __builtin_spv_IMul, __builtin_spv_UDiv,
93 false);
94ARITHMETIC_SELECTOR(uint64_t, __builtin_spv_SNegate, __builtin_spv_IAdd,
95 __builtin_spv_ISub, __builtin_spv_IMul, __builtin_spv_UDiv,
96 false);
97
98// The conversion selector is will be used to convert one type to another
99// using the SPIR-V conversion instructions. See
100// https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_conversion_instructions.
101// SourceType and TargetType must be integer or floating point scalar type.
102
103// ConversionSelector::Convert converts an object of type S to an object of type
104// T. S must be SourceType, a vector of SourceType, or a cooperative matrix of
105// SourceType. T must be TargetType, a vector of TargetType, or a cooperative
106// matrix of TargetType. T must have the same number of components as S. T is a
107// cooperative matrix if and only if S is a cooperative matrix.
108template <class SourceType, class TargetType> class ConversionSelector;
109
110#define CONVERSION_SELECTOR(SourceType, TargetType, OpConvert) \
111 template <> class ConversionSelector<SourceType, TargetType> { \
112 template <class T, class S> static T Convert(S a) { \
113 return OpConvert<T>(a); \
114 } \
115 };
116
117#if __HLSL_ENABLE_16_BIT
118CONVERSION_SELECTOR(uint16_t, uint16_t, __builtin_spv_CopyObject);
119CONVERSION_SELECTOR(uint16_t, int16_t, __builtin_spv_Bitcast);
120CONVERSION_SELECTOR(uint16_t, uint32_t, __builtin_spv_UConvert);
121CONVERSION_SELECTOR(uint16_t, int32_t, __builtin_spv_SConvert);
122CONVERSION_SELECTOR(uint16_t, uint64_t, __builtin_spv_UConvert);
123CONVERSION_SELECTOR(uint16_t, int64_t, __builtin_spv_SConvert);
124CONVERSION_SELECTOR(uint16_t, half, __builtin_spv_ConvertUToF);
125CONVERSION_SELECTOR(uint16_t, float, __builtin_spv_ConvertUToF);
126CONVERSION_SELECTOR(uint16_t, double, __builtin_spv_ConvertUToF);
127
128CONVERSION_SELECTOR(int16_t, uint16_t, __builtin_spv_Bitcast);
129CONVERSION_SELECTOR(int16_t, int16_t, __builtin_spv_CopyObject);
130CONVERSION_SELECTOR(int16_t, uint32_t, __builtin_spv_UConvert);
131CONVERSION_SELECTOR(int16_t, int32_t, __builtin_spv_SConvert);
132CONVERSION_SELECTOR(int16_t, uint64_t, __builtin_spv_UConvert);
133CONVERSION_SELECTOR(int16_t, int64_t, __builtin_spv_SConvert);
134CONVERSION_SELECTOR(int16_t, half, __builtin_spv_ConvertSToF);
135CONVERSION_SELECTOR(int16_t, float, __builtin_spv_ConvertSToF);
136CONVERSION_SELECTOR(int16_t, double, __builtin_spv_ConvertSToF);
137
138CONVERSION_SELECTOR(uint32_t, uint16_t, __builtin_spv_UConvert);
139CONVERSION_SELECTOR(uint32_t, int16_t, __builtin_spv_SConvert);
140
141CONVERSION_SELECTOR(int32_t, uint16_t, __builtin_spv_UConvert);
142CONVERSION_SELECTOR(int32_t, int16_t, __builtin_spv_SConvert);
143
144CONVERSION_SELECTOR(uint64_t, uint16_t, __builtin_spv_UConvert);
145CONVERSION_SELECTOR(uint64_t, int16_t, __builtin_spv_SConvert);
146
147CONVERSION_SELECTOR(int64_t, uint16_t, __builtin_spv_UConvert);
148CONVERSION_SELECTOR(int64_t, int16_t, __builtin_spv_SConvert);
149
150CONVERSION_SELECTOR(half, uint16_t, __builtin_spv_ConvertFtoU);
151CONVERSION_SELECTOR(half, int16_t, __builtin_spv_ConvertFtoS);
152
153CONVERSION_SELECTOR(float, uint16_t, __builtin_spv_ConvertFtoU);
154CONVERSION_SELECTOR(float, int16_t, __builtin_spv_ConvertFtoS);
155
156CONVERSION_SELECTOR(double, uint16_t, __builtin_spv_ConvertFtoU);
157CONVERSION_SELECTOR(double, int16_t, __builtin_spv_ConvertFtoS);
158#endif
159
160CONVERSION_SELECTOR(uint32_t, uint32_t, __builtin_spv_CopyObject);
161CONVERSION_SELECTOR(uint32_t, int32_t, __builtin_spv_Bitcast);
162CONVERSION_SELECTOR(uint32_t, uint64_t, __builtin_spv_UConvert);
163CONVERSION_SELECTOR(uint32_t, int64_t, __builtin_spv_SConvert);
164CONVERSION_SELECTOR(uint32_t, half, __builtin_spv_ConvertUToF);
165CONVERSION_SELECTOR(uint32_t, float, __builtin_spv_ConvertUToF);
166CONVERSION_SELECTOR(uint32_t, double, __builtin_spv_ConvertUToF);
167
168CONVERSION_SELECTOR(int32_t, uint32_t, __builtin_spv_Bitcast);
169CONVERSION_SELECTOR(int32_t, int32_t, __builtin_spv_CopyObject);
170CONVERSION_SELECTOR(int32_t, uint64_t, __builtin_spv_UConvert);
171CONVERSION_SELECTOR(int32_t, int64_t, __builtin_spv_SConvert);
172CONVERSION_SELECTOR(int32_t, half, __builtin_spv_ConvertSToF);
173CONVERSION_SELECTOR(int32_t, float, __builtin_spv_ConvertSToF);
174CONVERSION_SELECTOR(int32_t, double, __builtin_spv_ConvertSToF);
175
176CONVERSION_SELECTOR(uint64_t, uint32_t, __builtin_spv_UConvert);
177CONVERSION_SELECTOR(uint64_t, int32_t, __builtin_spv_SConvert);
178CONVERSION_SELECTOR(uint64_t, uint64_t, __builtin_spv_Bitcast);
179CONVERSION_SELECTOR(uint64_t, int64_t, __builtin_spv_CopyObject);
180CONVERSION_SELECTOR(uint64_t, half, __builtin_spv_ConvertUToF);
181CONVERSION_SELECTOR(uint64_t, float, __builtin_spv_ConvertUToF);
182CONVERSION_SELECTOR(uint64_t, double, __builtin_spv_ConvertUToF);
183
184CONVERSION_SELECTOR(int64_t, uint32_t, __builtin_spv_UConvert);
185CONVERSION_SELECTOR(int64_t, int32_t, __builtin_spv_SConvert);
186CONVERSION_SELECTOR(int64_t, uint64_t, __builtin_spv_Bitcast);
187CONVERSION_SELECTOR(int64_t, int64_t, __builtin_spv_CopyObject);
188CONVERSION_SELECTOR(int64_t, half, __builtin_spv_ConvertSToF);
189CONVERSION_SELECTOR(int64_t, float, __builtin_spv_ConvertSToF);
190CONVERSION_SELECTOR(int64_t, double, __builtin_spv_ConvertSToF);
191
192CONVERSION_SELECTOR(half, uint32_t, __builtin_spv_ConvertFtoU);
193CONVERSION_SELECTOR(half, int32_t, __builtin_spv_ConvertFtoS);
194CONVERSION_SELECTOR(half, uint64_t, __builtin_spv_ConvertFtoU);
195CONVERSION_SELECTOR(half, int64_t, __builtin_spv_ConvertFtoS);
196CONVERSION_SELECTOR(half, half, __builtin_spv_CopyObject);
197#if __HLSL_ENABLE_16_BIT
198CONVERSION_SELECTOR(half, float, __builtin_spv_FConvert);
199#else
200CONVERSION_SELECTOR(half, float, __builtin_spv_CopyObject);
201#endif
202
203CONVERSION_SELECTOR(half, double, __builtin_spv_FConvert);
204
205CONVERSION_SELECTOR(float, uint32_t, __builtin_spv_ConvertFtoU);
206CONVERSION_SELECTOR(float, int32_t, __builtin_spv_ConvertFtoS);
207CONVERSION_SELECTOR(float, uint64_t, __builtin_spv_ConvertFtoU);
208CONVERSION_SELECTOR(float, int64_t, __builtin_spv_ConvertFtoS);
209#if __HLSL_ENABLE_16_BIT
210CONVERSION_SELECTOR(float, half, __builtin_spv_FConvert);
211#else
212CONVERSION_SELECTOR(float, half, __builtin_spv_CopyObject);
213#endif
214CONVERSION_SELECTOR(float, float, __builtin_spv_CopyObject);
215CONVERSION_SELECTOR(float, double, __builtin_spv_FConvert);
216
217CONVERSION_SELECTOR(double, uint32_t, __builtin_spv_ConvertFtoU);
218CONVERSION_SELECTOR(double, int32_t, __builtin_spv_ConvertFtoS);
219CONVERSION_SELECTOR(double, uint64_t, __builtin_spv_ConvertFtoU);
220CONVERSION_SELECTOR(double, int64_t, __builtin_spv_ConvertFtoS);
221CONVERSION_SELECTOR(double, half, __builtin_spv_FConvert);
222CONVERSION_SELECTOR(double, float, __builtin_spv_FConvert);
223CONVERSION_SELECTOR(double, double, __builtin_spv_CopyObject);
224}; // namespace util
225} // namespace vk
226
227#endif // _HLSL_VK_KHR_OPCODE_SELECTOR_H_