blob: 54a49dafa258d61bc50db1d145440c1b671de9a4 [file] [log] [blame]
Robert Konrad45270f62016-08-14 16:21:43 +02001/*
Hans-Kristian Arntzen47044822021-01-14 16:07:49 +01002 * Copyright 2016-2021 Robert Konrad
Jon Leechf2a65542021-05-08 01:47:48 -07003 * SPDX-License-Identifier: Apache-2.0 OR MIT
Robert Konrad4358b2f2017-01-27 16:45:43 +01004 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
Robert Konrad45270f62016-08-14 16:21:43 +020017
Hans-Kristian Arntzencf1e9e02020-11-25 15:22:08 +010018/*
19 * At your option, you may choose to accept this material under either:
20 * 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
21 * 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
Hans-Kristian Arntzencf1e9e02020-11-25 15:22:08 +010022 */
23
Robert Konrad45270f62016-08-14 16:21:43 +020024#ifndef SPIRV_HLSL_HPP
25#define SPIRV_HLSL_HPP
26
27#include "spirv_glsl.hpp"
28#include <utility>
Robert Konrad45270f62016-08-14 16:21:43 +020029
Hans-Kristian Arntzen9b92e682019-03-29 10:29:44 +010030namespace SPIRV_CROSS_NAMESPACE
Robert Konrad45270f62016-08-14 16:21:43 +020031{
Hans-Kristian Arntzen4f88f972017-11-13 09:46:45 +010032// Interface which remaps vertex inputs to a fixed semantic name to make linking easier.
33struct HLSLVertexAttributeRemap
Amer Koleci7216d132017-11-06 20:10:04 +010034{
Hans-Kristian Arntzen4f88f972017-11-13 09:46:45 +010035 uint32_t location;
Amer Koleci7216d132017-11-06 20:10:04 +010036 std::string semantic;
Amer Koleci7216d132017-11-06 20:10:04 +010037};
msiglreithd096f5c2017-11-27 16:00:56 +010038// Specifying a root constant (d3d12) or push constant range (vulkan).
39//
40// `start` and `end` denotes the range of the root constant in bytes.
41// Both values need to be multiple of 4.
42struct RootConstants
43{
44 uint32_t start;
45 uint32_t end;
46
47 uint32_t binding;
48 uint32_t space;
49};
Amer Koleci7216d132017-11-06 20:10:04 +010050
Hans-Kristian Arntzenb9e5fe02019-11-11 11:01:35 +010051// For finer control, decorations may be removed from specific resources instead with unset_decoration().
52enum HLSLBindingFlagBits
53{
Hans-Kristian Arntzencc153f82020-01-09 11:18:14 +010054 HLSL_BINDING_AUTO_NONE_BIT = 0,
55
Hans-Kristian Arntzenb9e5fe02019-11-11 11:01:35 +010056 // Push constant (root constant) resources will be declared as CBVs (b-space) without a register() declaration.
57 // A register will be automatically assigned by the D3D compiler, but must therefore be reflected in D3D-land.
58 // Push constants do not normally have a DecorationBinding set, but if they do, this can be used to ignore it.
59 HLSL_BINDING_AUTO_PUSH_CONSTANT_BIT = 1 << 0,
60
61 // cbuffer resources will be declared as CBVs (b-space) without a register() declaration.
62 // A register will be automatically assigned, but must be reflected in D3D-land.
63 HLSL_BINDING_AUTO_CBV_BIT = 1 << 1,
64
65 // All SRVs (t-space) will be declared without a register() declaration.
66 HLSL_BINDING_AUTO_SRV_BIT = 1 << 2,
67
68 // All UAVs (u-space) will be declared without a register() declaration.
69 HLSL_BINDING_AUTO_UAV_BIT = 1 << 3,
70
71 // All samplers (s-space) will be declared without a register() declaration.
72 HLSL_BINDING_AUTO_SAMPLER_BIT = 1 << 4,
73
74 // No resources will be declared with register().
75 HLSL_BINDING_AUTO_ALL = 0x7fffffff
76};
77using HLSLBindingFlags = uint32_t;
78
Hans-Kristian Arntzencc153f82020-01-09 11:18:14 +010079// By matching stage, desc_set and binding for a SPIR-V resource,
80// register bindings are set based on whether the HLSL resource is a
81// CBV, UAV, SRV or Sampler. A single binding in SPIR-V might contain multiple
82// resource types, e.g. COMBINED_IMAGE_SAMPLER, and SRV/Sampler bindings will be used respectively.
83// On SM 5.0 and lower, register_space is ignored.
84//
85// To remap a push constant block which does not have any desc_set/binding associated with it,
86// use ResourceBindingPushConstant{DescriptorSet,Binding} as values for desc_set/binding.
87// For deeper control of push constants, set_root_constant_layouts() can be used instead.
88struct HLSLResourceBinding
89{
90 spv::ExecutionModel stage = spv::ExecutionModelMax;
91 uint32_t desc_set = 0;
92 uint32_t binding = 0;
93
94 struct Binding
95 {
96 uint32_t register_space = 0;
97 uint32_t register_binding = 0;
98 } cbv, uav, srv, sampler;
99};
100
Robert Konrade9cd04e2016-08-14 22:02:38 +0200101class CompilerHLSL : public CompilerGLSL
102{
103public:
Robert Konradf3740a02016-08-18 00:51:12 +0200104 struct Options
105 {
106 uint32_t shader_model = 30; // TODO: map ps_4_0_level_9_0,... somehow
Hans-Kristian Arntzen17d88ca2017-05-04 10:10:30 +0200107
108 // Allows the PointSize builtin, and ignores it, as PointSize is not supported in HLSL.
Hans-Kristian Arntzen2b4c3db2017-05-04 10:32:43 +0200109 bool point_size_compat = false;
Hans-Kristian Arntzenf6d08e62018-02-23 15:56:25 +0100110
111 // Allows the PointCoord builtin, returns float2(0.5, 0.5), as PointCoord is not supported in HLSL.
112 bool point_coord_compat = false;
Hans-Kristian Arntzena2a44d92019-01-11 10:32:14 +0100113
114 // If true, the backend will assume that VertexIndex and InstanceIndex will need to apply
115 // a base offset, and you will need to fill in a cbuffer with offsets.
116 // Set to false if you know you will never use base instance or base vertex
117 // functionality as it might remove an internal cbuffer.
118 bool support_nonzero_base_vertex_base_instance = false;
Hans-Kristian Arntzenc27e1ef2020-03-04 16:32:52 +0100119
120 // Forces a storage buffer to always be declared as UAV, even if the readonly decoration is used.
121 // By default, a readonly storage buffer will be declared as ByteAddressBuffer (SRV) instead.
Bryan Bernhart32bead82020-05-28 10:21:41 -0700122 // Alternatively, use set_hlsl_force_storage_buffer_as_uav to specify individually.
Hans-Kristian Arntzenc27e1ef2020-03-04 16:32:52 +0100123 bool force_storage_buffer_as_uav = false;
Hans-Kristian Arntzen28bf9052020-04-03 11:21:41 +0200124
125 // Forces any storage image type marked as NonWritable to be considered an SRV instead.
126 // For this to work with function call parameters, NonWritable must be considered to be part of the type system
127 // so that NonWritable image arguments are also translated to Texture rather than RWTexture.
128 bool nonwritable_uav_texture_as_srv = false;
Hans-Kristian Arntzen2d520062020-06-04 11:35:21 +0200129
130 // Enables native 16-bit types. Needs SM 6.2.
131 // Uses half/int16_t/uint16_t instead of min16* types.
132 // Also adds support for 16-bit load-store from (RW)ByteAddressBuffer.
133 bool enable_16bit_types = false;
Hans-Kristian Arntzenb3344172020-11-03 11:18:32 +0100134
135 // If matrices are used as IO variables, flatten the attribute declaration to use
136 // TEXCOORD{N,N+1,N+2,...} rather than TEXCOORDN_{0,1,2,3}.
137 // If add_vertex_attribute_remap is used and this feature is used,
138 // the semantic name will be queried once per active location.
139 bool flatten_matrix_vertex_input_semantics = false;
Robert Konradf3740a02016-08-18 00:51:12 +0200140 };
141
Hans-Kristian Arntzen3fe57d32019-04-09 12:46:23 +0200142 explicit CompilerHLSL(std::vector<uint32_t> spirv_)
Hans-Kristian Arntzena489ba72019-04-02 11:19:03 +0200143 : CompilerGLSL(std::move(spirv_))
Robert Konrad45270f62016-08-14 16:21:43 +0200144 {
Robert Konrade9cd04e2016-08-14 22:02:38 +0200145 }
Robert Konradf3740a02016-08-18 00:51:12 +0200146
Hans-Kristian Arntzen5bcf02f2018-10-05 11:30:57 +0200147 CompilerHLSL(const uint32_t *ir_, size_t size)
148 : CompilerGLSL(ir_, size)
149 {
150 }
151
152 explicit CompilerHLSL(const ParsedIR &ir_)
153 : CompilerGLSL(ir_)
154 {
155 }
156
157 explicit CompilerHLSL(ParsedIR &&ir_)
158 : CompilerGLSL(std::move(ir_))
Hans-Kristian Arntzen9bad4772017-04-01 16:08:19 +0200159 {
160 }
161
Hans-Kristian Arntzena803e5a2018-03-09 15:25:25 +0100162 const Options &get_hlsl_options() const
163 {
164 return hlsl_options;
165 }
166
Hans-Kristian Arntzena803e5a2018-03-09 15:25:25 +0100167 void set_hlsl_options(const Options &opts)
168 {
169 hlsl_options = opts;
Robert Konradf3740a02016-08-18 00:51:12 +0200170 }
171
msiglreithd096f5c2017-11-27 16:00:56 +0100172 // Optionally specify a custom root constant layout.
173 //
174 // Push constants ranges will be split up according to the
175 // layout specified.
Hans-Kristian Arntzen3fe57d32019-04-09 12:46:23 +0200176 void set_root_constant_layouts(std::vector<RootConstants> layout);
msiglreithd096f5c2017-11-27 16:00:56 +0100177
Hans-Kristian Arntzen4f88f972017-11-13 09:46:45 +0100178 // Compiles and remaps vertex attributes at specific locations to a fixed semantic.
179 // The default is TEXCOORD# where # denotes location.
180 // Matrices are unrolled to vectors with notation ${SEMANTIC}_#, where # denotes row.
181 // $SEMANTIC is either TEXCOORD# or a semantic name specified here.
Hans-Kristian Arntzen9bbdccd2019-02-12 11:11:29 +0100182 void add_vertex_attribute_remap(const HLSLVertexAttributeRemap &vertex_attributes);
Robert Konrade9cd04e2016-08-14 22:02:38 +0200183 std::string compile() override;
Robert Konrad45270f62016-08-14 16:21:43 +0200184
Hans-Kristian Arntzen18e88332018-02-05 10:27:42 +0100185 // This is a special HLSL workaround for the NumWorkGroups builtin.
186 // This does not exist in HLSL, so the calling application must create a dummy cbuffer in
187 // which the application will store this builtin.
188 // The cbuffer layout will be:
189 // cbuffer SPIRV_Cross_NumWorkgroups : register(b#, space#) { uint3 SPIRV_Cross_NumWorkgroups_count; };
190 // This must be called before compile().
191 // The function returns 0 if NumWorkGroups builtin is not statically used in the shader from the current entry point.
192 // If non-zero, this returns the variable ID of a cbuffer which corresponds to
193 // the cbuffer declared above. By default, no binding or descriptor set decoration is set,
194 // so the calling application should declare explicit bindings on this ID before calling compile().
Hans-Kristian Arntzen333980a2019-09-05 12:43:40 +0200195 VariableID remap_num_workgroups_builtin();
Hans-Kristian Arntzen18e88332018-02-05 10:27:42 +0100196
Hans-Kristian Arntzenb9e5fe02019-11-11 11:01:35 +0100197 // Controls how resource bindings are declared in the output HLSL.
198 void set_resource_binding_flags(HLSLBindingFlags flags);
199
Hans-Kristian Arntzencc153f82020-01-09 11:18:14 +0100200 // resource is a resource binding to indicate the HLSL CBV, SRV, UAV or sampler binding
201 // to use for a particular SPIR-V description set
202 // and binding. If resource bindings are provided,
203 // is_hlsl_resource_binding_used() will return true after calling ::compile() if
204 // the set/binding combination was used by the HLSL code.
205 void add_hlsl_resource_binding(const HLSLResourceBinding &resource);
206 bool is_hlsl_resource_binding_used(spv::ExecutionModel model, uint32_t set, uint32_t binding) const;
207
Bryan Bernhart17bccc92020-05-27 13:08:15 -0700208 // Controls which storage buffer bindings will be forced to be declared as UAVs.
Bryan Bernhart32bead82020-05-28 10:21:41 -0700209 void set_hlsl_force_storage_buffer_as_uav(uint32_t desc_set, uint32_t binding);
Bryan Bernhart17bccc92020-05-27 13:08:15 -0700210
Robert Konrade9cd04e2016-08-14 22:02:38 +0200211private:
Bill Hollingsb41e1482017-05-29 20:45:05 -0400212 std::string type_to_glsl(const SPIRType &type, uint32_t id = 0) override;
Hans-Kristian Arntzene0447322018-07-04 14:25:10 +0200213 std::string image_type_hlsl(const SPIRType &type, uint32_t id);
214 std::string image_type_hlsl_modern(const SPIRType &type, uint32_t id);
215 std::string image_type_hlsl_legacy(const SPIRType &type, uint32_t id);
Hans-Kristian Arntzene8e58842018-03-12 13:09:25 +0100216 void emit_function_prototype(SPIRFunction &func, const Bitset &return_flags) override;
Robert Konrade9cd04e2016-08-14 22:02:38 +0200217 void emit_hlsl_entry_point();
218 void emit_header() override;
219 void emit_resources();
Hans-Kristian Arntzene81c1b12020-02-08 13:39:50 +0100220 void declare_undefined_values() override;
Robert Konrade9cd04e2016-08-14 22:02:38 +0200221 void emit_interface_block_globally(const SPIRVariable &type);
Hans-Kristian Arntzend6b29ab2021-06-28 14:24:29 +0200222 void emit_interface_block_in_struct(const SPIRVariable &var, std::unordered_set<uint32_t> &active_locations);
223 void emit_interface_block_member_in_struct(const SPIRVariable &var, uint32_t member_index,
224 uint32_t location,
225 std::unordered_set<uint32_t> &active_locations);
Hans-Kristian Arntzenbdea1a42017-03-06 16:50:15 +0100226 void emit_builtin_inputs_in_struct();
227 void emit_builtin_outputs_in_struct();
Hans-Kristian Arntzen275974e2020-06-04 15:50:28 +0200228 void emit_texture_op(const Instruction &i, bool sparse) override;
Robert Konradda5f99b2016-08-14 23:54:51 +0200229 void emit_instruction(const Instruction &instruction) override;
Robert Konrad40e5d1e2017-01-23 14:49:32 +0100230 void emit_glsl_op(uint32_t result_type, uint32_t result_id, uint32_t op, const uint32_t *args,
231 uint32_t count) override;
Robert Konrad99469f02017-01-24 09:17:43 +0100232 void emit_buffer_block(const SPIRVariable &type) override;
233 void emit_push_constant_block(const SPIRVariable &var) override;
Robert Konradc3268c92017-01-24 09:23:22 +0100234 void emit_uniform(const SPIRVariable &var) override;
Hans-Kristian Arntzen100e9d32017-04-25 10:44:55 +0200235 void emit_modern_uniform(const SPIRVariable &var);
236 void emit_legacy_uniform(const SPIRVariable &var);
Hans-Kristian Arntzend92de002019-01-10 09:49:33 +0100237 void emit_specialization_constants_and_structs();
Hans-Kristian Arntzen5d9df6a2018-02-02 10:10:17 +0100238 void emit_composite_constants();
Hans-Kristian Arntzenbdfa97a2017-08-03 13:02:59 +0200239 void emit_fixup() override;
Hans-Kristian Arntzen5e9b53e2017-12-06 11:01:32 +0100240 std::string builtin_to_glsl(spv::BuiltIn builtin, spv::StorageClass storage) override;
Hans-Kristian Arntzen439fa9f2017-03-07 16:18:43 +0100241 std::string layout_for_member(const SPIRType &type, uint32_t index) override;
Hans-Kristian Arntzene8e58842018-03-12 13:09:25 +0100242 std::string to_interpolation_qualifiers(const Bitset &flags) override;
Robert Konrada7e2a692017-03-24 14:13:59 +0100243 std::string bitcast_glsl_op(const SPIRType &result_type, const SPIRType &argument_type) override;
Hans-Kristian Arntzen5e5d1c22020-04-21 23:27:33 +0200244 bool emit_complex_bitcast(uint32_t result_type, uint32_t id, uint32_t op0) override;
Chip Davis39dce882019-08-02 15:11:19 -0500245 std::string to_func_call_arg(const SPIRFunction::Parameter &arg, uint32_t id) override;
Hans-Kristian Arntzen686ac682017-05-07 13:22:16 +0200246 std::string to_sampler_expression(uint32_t id);
Hans-Kristian Arntzen620da7b2017-06-17 10:15:32 +0200247 std::string to_resource_binding(const SPIRVariable &var);
248 std::string to_resource_binding_sampler(const SPIRVariable &var);
Hans-Kristian Arntzencc153f82020-01-09 11:18:14 +0100249 std::string to_resource_register(HLSLBindingFlagBits flag, char space, uint32_t binding, uint32_t set);
Hans-Kristian Arntzen9a304fe2021-01-04 11:16:58 +0100250 std::string to_initializer_expression(const SPIRVariable &var) override;
Hans-Kristian Arntzen947f7012017-05-07 13:28:08 +0200251 void emit_sampled_image_op(uint32_t result_type, uint32_t result_id, uint32_t image_id, uint32_t samp_id) override;
Hans-Kristian Arntzen7d7f4b32017-08-10 17:12:48 +0200252 void emit_access_chain(const Instruction &instruction);
253 void emit_load(const Instruction &instruction);
Hans-Kristian Arntzenca9398c2020-01-08 13:05:56 +0100254 void read_access_chain(std::string *expr, const std::string &lhs, const SPIRAccessChain &chain);
255 void read_access_chain_struct(const std::string &lhs, const SPIRAccessChain &chain);
256 void read_access_chain_array(const std::string &lhs, const SPIRAccessChain &chain);
Hans-Kristian Arntzen151ff1e2020-01-08 14:17:28 +0100257 void write_access_chain(const SPIRAccessChain &chain, uint32_t value, const SmallVector<uint32_t> &composite_chain);
Hans-Kristian Arntzenc2565252020-01-08 14:27:34 +0100258 void write_access_chain_struct(const SPIRAccessChain &chain, uint32_t value,
259 const SmallVector<uint32_t> &composite_chain);
260 void write_access_chain_array(const SPIRAccessChain &chain, uint32_t value,
261 const SmallVector<uint32_t> &composite_chain);
Hans-Kristian Arntzen151ff1e2020-01-08 14:17:28 +0100262 std::string write_access_chain_value(uint32_t value, const SmallVector<uint32_t> &composite_chain, bool enclose);
Hans-Kristian Arntzen7d7f4b32017-08-10 17:12:48 +0200263 void emit_store(const Instruction &instruction);
Hans-Kristian Arntzen044d3c82017-10-20 14:56:37 +0200264 void emit_atomic(const uint32_t *ops, uint32_t length, spv::Op op);
Hans-Kristian Arntzenc2664292018-04-11 15:02:02 +0200265 void emit_subgroup_op(const Instruction &i) override;
Hans-Kristian Arntzen33c61d22018-06-25 10:33:13 +0200266 void emit_block_hints(const SPIRBlock &block) override;
Robert Konradf3740a02016-08-18 00:51:12 +0200267
msiglreithd096f5c2017-11-27 16:00:56 +0100268 void emit_struct_member(const SPIRType &type, uint32_t member_type_id, uint32_t index, const std::string &qualifier,
269 uint32_t base_offset = 0) override;
Hans-Kristian Arntzenf0200bb2017-10-10 13:15:49 +0200270
Hans-Kristian Arntzenbcf23032017-02-24 11:15:34 +0100271 const char *to_storage_qualifiers_glsl(const SPIRVariable &var) override;
Pascal Muetschardaced6052018-05-04 14:53:32 -0700272 void replace_illegal_names() override;
Hans-Kristian Arntzenbcf23032017-02-24 11:15:34 +0100273
Bryan Bernhart32bead82020-05-28 10:21:41 -0700274 bool is_hlsl_force_storage_buffer_as_uav(ID id) const;
Bryan Bernhart17bccc92020-05-27 13:08:15 -0700275
Hans-Kristian Arntzena803e5a2018-03-09 15:25:25 +0100276 Options hlsl_options;
Hans-Kristian Arntzen041f1032019-07-03 12:24:58 +0200277
278 // TODO: Refactor this to be more similar to MSL, maybe have some common system in place?
Robert Konrad1a48d7d2016-08-18 12:54:22 +0200279 bool requires_op_fmod = false;
Hans-Kristian Arntzen6c7c6802017-11-27 14:24:30 +0100280 bool requires_fp16_packing = false;
Asuka55dfbea2020-04-17 22:46:06 +0800281 bool requires_uint2_packing = false;
Hans-Kristian Arntzen47d94ff2018-03-07 10:21:25 +0100282 bool requires_explicit_fp16_packing = false;
Hans-Kristian Arntzen719ba632017-11-27 14:44:21 +0100283 bool requires_unorm8_packing = false;
284 bool requires_snorm8_packing = false;
Hans-Kristian Arntzen656af7e2017-11-27 15:03:40 +0100285 bool requires_unorm16_packing = false;
286 bool requires_snorm16_packing = false;
Hans-Kristian Arntzen48f3fa42017-11-29 11:33:44 +0100287 bool requires_bitfield_insert = false;
288 bool requires_bitfield_extract = false;
Hans-Kristian Arntzenb380a212018-02-23 16:36:12 +0100289 bool requires_inverse_2x2 = false;
290 bool requires_inverse_3x3 = false;
291 bool requires_inverse_4x4 = false;
Hans-Kristian Arntzen041f1032019-07-03 12:24:58 +0200292 bool requires_scalar_reflect = false;
293 bool requires_scalar_refract = false;
Hans-Kristian Arntzenc7eda1b2019-07-17 11:24:31 +0200294 bool requires_scalar_faceforward = false;
Hans-Kristian Arntzenf3a362b2020-05-19 13:39:48 +0200295
296 struct TextureSizeVariants
297 {
298 // MSVC 2013 workaround.
299 TextureSizeVariants()
300 {
301 srv = 0;
302 for (auto &unorm : uav)
303 for (auto &u : unorm)
304 u = 0;
305 }
306 uint64_t srv;
307 uint64_t uav[3][4];
308 } required_texture_size_variants;
309
310 void require_texture_query_variant(uint32_t var_id);
Hans-Kristian Arntzend573a952020-07-01 11:42:58 +0200311 void emit_texture_size_variants(uint64_t variant_mask, const char *vecsize_qualifier, bool uav,
312 const char *type_qualifier);
Hans-Kristian Arntzen9aa42a82017-09-20 10:31:05 +0200313
314 enum TextureQueryVariantDim
315 {
316 Query1D = 0,
317 Query1DArray,
318 Query2D,
319 Query2DArray,
320 Query3D,
321 QueryBuffer,
322 QueryCube,
323 QueryCubeArray,
324 Query2DMS,
325 Query2DMSArray,
326 QueryDimCount
327 };
328
329 enum TextureQueryVariantType
330 {
331 QueryTypeFloat = 0,
332 QueryTypeInt = 16,
333 QueryTypeUInt = 32,
334 QueryTypeCount = 3
335 };
Hans-Kristian Arntzenbdea1a42017-03-06 16:50:15 +0100336
Asuka55dfbea2020-04-17 22:46:06 +0800337 enum BitcastType
338 {
339 TypeNormal,
340 TypePackUint2x32,
341 TypeUnpackUint64
342 };
343
344 BitcastType get_bitcast_type(uint32_t result_type, uint32_t op0);
345
Hans-Kristian Arntzenbdea1a42017-03-06 16:50:15 +0100346 void emit_builtin_variables();
347 bool require_output = false;
348 bool require_input = false;
Hans-Kristian Arntzena489ba72019-04-02 11:19:03 +0200349 SmallVector<HLSLVertexAttributeRemap> remap_vertex_attributes;
Hans-Kristian Arntzen61c31c62017-03-07 13:27:04 +0100350
351 uint32_t type_to_consumed_locations(const SPIRType &type) const;
Hans-Kristian Arntzen439fa9f2017-03-07 16:18:43 +0100352
Ashley Harriscc2d2902019-04-12 13:54:58 +0930353 std::string to_semantic(uint32_t location, spv::ExecutionModel em, spv::StorageClass sc);
Hans-Kristian Arntzen18e88332018-02-05 10:27:42 +0100354
355 uint32_t num_workgroups_builtin = 0;
Hans-Kristian Arntzenb9e5fe02019-11-11 11:01:35 +0100356 HLSLBindingFlags resource_binding_flags = 0;
msiglreithd096f5c2017-11-27 16:00:56 +0100357
358 // Custom root constant layout, which should be emitted
359 // when translating push constant ranges.
Hans-Kristian Arntzen3fe57d32019-04-09 12:46:23 +0200360 std::vector<RootConstants> root_constants_layout;
Hans-Kristian Arntzen647ddae2019-05-13 14:58:27 +0200361
362 void validate_shader_model();
Hans-Kristian Arntzenca9398c2020-01-08 13:05:56 +0100363
364 std::string get_unique_identifier();
365 uint32_t unique_identifier_count = 0;
Hans-Kristian Arntzencc153f82020-01-09 11:18:14 +0100366
367 std::unordered_map<StageSetBinding, std::pair<HLSLResourceBinding, bool>, InternalHasher> resource_bindings;
368 void remap_hlsl_resource_binding(HLSLBindingFlagBits type, uint32_t &desc_set, uint32_t &binding);
Bryan Bernhart17bccc92020-05-27 13:08:15 -0700369
Bryan Bernhart32bead82020-05-28 10:21:41 -0700370 std::unordered_set<SetBindingPair, InternalHasher> force_uav_buffer_bindings;
Tomek Ponitkaba58f782020-07-23 19:09:43 +0200371
372 // Returns true for BuiltInSampleMask because gl_SampleMask[] is an array in SPIR-V, but SV_Coverage is a scalar in HLSL.
373 bool builtin_translates_to_nonarray(spv::BuiltIn builtin) const override;
Hans-Kristian Arntzen8216e872021-06-28 11:10:55 +0200374
375 std::vector<TypeID> composite_selection_workaround_types;
Robert Konrade9cd04e2016-08-14 22:02:38 +0200376};
Hans-Kristian Arntzena489ba72019-04-02 11:19:03 +0200377} // namespace SPIRV_CROSS_NAMESPACE
Robert Konrad45270f62016-08-14 16:21:43 +0200378
379#endif