MSL: Factor creating a uint type into its own method.
This is so common for artificially created variables that it's worth it to create it once and save it for later use.
This commit is contained in:
parent
5e13f7fdf2
commit
884bc6df65
151
spirv_msl.cpp
151
spirv_msl.cpp
@ -308,24 +308,18 @@ void CompilerMSL::build_implicit_builtins()
|
||||
|
||||
if (!has_sample_id && need_sample_pos)
|
||||
{
|
||||
uint32_t offset = ir.increase_bound_by(3);
|
||||
uint32_t type_id = offset;
|
||||
uint32_t type_ptr_id = offset + 1;
|
||||
uint32_t var_id = offset + 2;
|
||||
uint32_t offset = ir.increase_bound_by(2);
|
||||
uint32_t type_ptr_id = offset;
|
||||
uint32_t var_id = offset + 1;
|
||||
|
||||
// Create gl_SampleID.
|
||||
SPIRType uint_type;
|
||||
uint_type.basetype = SPIRType::UInt;
|
||||
uint_type.width = 32;
|
||||
set<SPIRType>(type_id, uint_type);
|
||||
|
||||
SPIRType uint_type_ptr;
|
||||
uint_type_ptr = uint_type;
|
||||
uint_type_ptr = get_uint_type();
|
||||
uint_type_ptr.pointer = true;
|
||||
uint_type_ptr.parent_type = type_id;
|
||||
uint_type_ptr.parent_type = get_uint_type_id();
|
||||
uint_type_ptr.storage = StorageClassInput;
|
||||
auto &ptr_type = set<SPIRType>(type_ptr_id, uint_type_ptr);
|
||||
ptr_type.self = type_id;
|
||||
ptr_type.self = get_uint_type_id();
|
||||
|
||||
set<SPIRVariable>(var_id, type_ptr_id, StorageClassInput);
|
||||
set_decoration(var_id, DecorationBuiltIn, BuiltInSampleId);
|
||||
@ -336,22 +330,15 @@ void CompilerMSL::build_implicit_builtins()
|
||||
if ((need_vertex_params && (!has_vertex_idx || !has_base_vertex || !has_instance_idx || !has_base_instance)) ||
|
||||
(need_multiview && (!has_instance_idx || !has_view_idx)))
|
||||
{
|
||||
uint32_t offset = ir.increase_bound_by(2);
|
||||
uint32_t type_id = offset;
|
||||
uint32_t type_ptr_id = offset + 1;
|
||||
|
||||
SPIRType uint_type;
|
||||
uint_type.basetype = SPIRType::UInt;
|
||||
uint_type.width = 32;
|
||||
set<SPIRType>(type_id, uint_type);
|
||||
uint32_t type_ptr_id = ir.increase_bound_by(1);
|
||||
|
||||
SPIRType uint_type_ptr;
|
||||
uint_type_ptr = uint_type;
|
||||
uint_type_ptr = get_uint_type();
|
||||
uint_type_ptr.pointer = true;
|
||||
uint_type_ptr.parent_type = type_id;
|
||||
uint_type_ptr.parent_type = get_uint_type_id();
|
||||
uint_type_ptr.storage = StorageClassInput;
|
||||
auto &ptr_type = set<SPIRType>(type_ptr_id, uint_type_ptr);
|
||||
ptr_type.self = type_id;
|
||||
ptr_type.self = get_uint_type_id();
|
||||
|
||||
if (need_vertex_params && !has_vertex_idx)
|
||||
{
|
||||
@ -405,12 +392,12 @@ void CompilerMSL::build_implicit_builtins()
|
||||
// gl_Layer is an output in vertex-pipeline shaders.
|
||||
uint32_t type_ptr_out_id = ir.increase_bound_by(2);
|
||||
SPIRType uint_type_ptr_out;
|
||||
uint_type_ptr_out = uint_type;
|
||||
uint_type_ptr_out = get_uint_type();
|
||||
uint_type_ptr_out.pointer = true;
|
||||
uint_type_ptr_out.parent_type = type_id;
|
||||
uint_type_ptr_out.parent_type = get_uint_type_id();
|
||||
uint_type_ptr_out.storage = StorageClassOutput;
|
||||
auto &ptr_out_type = set<SPIRType>(type_ptr_out_id, uint_type_ptr_out);
|
||||
ptr_out_type.self = type_id;
|
||||
ptr_out_type.self = get_uint_type_id();
|
||||
uint32_t var_id = type_ptr_out_id + 1;
|
||||
set<SPIRVariable>(var_id, type_ptr_out_id, StorageClassOutput);
|
||||
set_decoration(var_id, DecorationBuiltIn, BuiltInLayer);
|
||||
@ -432,22 +419,15 @@ void CompilerMSL::build_implicit_builtins()
|
||||
|
||||
if (need_tesc_params && (!has_invocation_id || !has_primitive_id))
|
||||
{
|
||||
uint32_t offset = ir.increase_bound_by(2);
|
||||
uint32_t type_id = offset;
|
||||
uint32_t type_ptr_id = offset + 1;
|
||||
|
||||
SPIRType uint_type;
|
||||
uint_type.basetype = SPIRType::UInt;
|
||||
uint_type.width = 32;
|
||||
set<SPIRType>(type_id, uint_type);
|
||||
uint32_t type_ptr_id = ir.increase_bound_by(1);
|
||||
|
||||
SPIRType uint_type_ptr;
|
||||
uint_type_ptr = uint_type;
|
||||
uint_type_ptr = get_uint_type();
|
||||
uint_type_ptr.pointer = true;
|
||||
uint_type_ptr.parent_type = type_id;
|
||||
uint_type_ptr.parent_type = get_uint_type_id();
|
||||
uint_type_ptr.storage = StorageClassInput;
|
||||
auto &ptr_type = set<SPIRType>(type_ptr_id, uint_type_ptr);
|
||||
ptr_type.self = type_id;
|
||||
ptr_type.self = get_uint_type_id();
|
||||
|
||||
if (!has_invocation_id)
|
||||
{
|
||||
@ -474,24 +454,18 @@ void CompilerMSL::build_implicit_builtins()
|
||||
|
||||
if (!has_subgroup_invocation_id && (need_subgroup_mask || needs_subgroup_invocation_id))
|
||||
{
|
||||
uint32_t offset = ir.increase_bound_by(3);
|
||||
uint32_t type_id = offset;
|
||||
uint32_t type_ptr_id = offset + 1;
|
||||
uint32_t var_id = offset + 2;
|
||||
uint32_t offset = ir.increase_bound_by(2);
|
||||
uint32_t type_ptr_id = offset;
|
||||
uint32_t var_id = offset + 1;
|
||||
|
||||
// Create gl_SubgroupInvocationID.
|
||||
SPIRType uint_type;
|
||||
uint_type.basetype = SPIRType::UInt;
|
||||
uint_type.width = 32;
|
||||
set<SPIRType>(type_id, uint_type);
|
||||
|
||||
SPIRType uint_type_ptr;
|
||||
uint_type_ptr = uint_type;
|
||||
uint_type_ptr = get_uint_type();
|
||||
uint_type_ptr.pointer = true;
|
||||
uint_type_ptr.parent_type = type_id;
|
||||
uint_type_ptr.parent_type = get_uint_type_id();
|
||||
uint_type_ptr.storage = StorageClassInput;
|
||||
auto &ptr_type = set<SPIRType>(type_ptr_id, uint_type_ptr);
|
||||
ptr_type.self = type_id;
|
||||
ptr_type.self = get_uint_type_id();
|
||||
|
||||
set<SPIRVariable>(var_id, type_ptr_id, StorageClassInput);
|
||||
set_decoration(var_id, DecorationBuiltIn, BuiltInSubgroupLocalInvocationId);
|
||||
@ -501,24 +475,18 @@ void CompilerMSL::build_implicit_builtins()
|
||||
|
||||
if (!has_subgroup_size && need_subgroup_ge_mask)
|
||||
{
|
||||
uint32_t offset = ir.increase_bound_by(3);
|
||||
uint32_t type_id = offset;
|
||||
uint32_t type_ptr_id = offset + 1;
|
||||
uint32_t var_id = offset + 2;
|
||||
uint32_t offset = ir.increase_bound_by(2);
|
||||
uint32_t type_ptr_id = offset;
|
||||
uint32_t var_id = offset + 1;
|
||||
|
||||
// Create gl_SubgroupSize.
|
||||
SPIRType uint_type;
|
||||
uint_type.basetype = SPIRType::UInt;
|
||||
uint_type.width = 32;
|
||||
set<SPIRType>(type_id, uint_type);
|
||||
|
||||
SPIRType uint_type_ptr;
|
||||
uint_type_ptr = uint_type;
|
||||
uint_type_ptr = get_uint_type();
|
||||
uint_type_ptr.pointer = true;
|
||||
uint_type_ptr.parent_type = type_id;
|
||||
uint_type_ptr.parent_type = get_uint_type_id();
|
||||
uint_type_ptr.storage = StorageClassInput;
|
||||
auto &ptr_type = set<SPIRType>(type_ptr_id, uint_type_ptr);
|
||||
ptr_type.self = type_id;
|
||||
ptr_type.self = get_uint_type_id();
|
||||
|
||||
set<SPIRVariable>(var_id, type_ptr_id, StorageClassInput);
|
||||
set_decoration(var_id, DecorationBuiltIn, BuiltInSubgroupSize);
|
||||
@ -665,22 +633,16 @@ void CompilerMSL::mark_implicit_builtin(StorageClass storage, BuiltIn builtin, u
|
||||
|
||||
uint32_t CompilerMSL::build_constant_uint_array_pointer()
|
||||
{
|
||||
uint32_t offset = ir.increase_bound_by(4);
|
||||
uint32_t type_id = offset;
|
||||
uint32_t type_ptr_id = offset + 1;
|
||||
uint32_t type_ptr_ptr_id = offset + 2;
|
||||
uint32_t var_id = offset + 3;
|
||||
uint32_t offset = ir.increase_bound_by(3);
|
||||
uint32_t type_ptr_id = offset;
|
||||
uint32_t type_ptr_ptr_id = offset + 1;
|
||||
uint32_t var_id = offset + 2;
|
||||
|
||||
// Create a buffer to hold extra data, including the swizzle constants.
|
||||
SPIRType uint_type;
|
||||
uint_type.basetype = SPIRType::UInt;
|
||||
uint_type.width = 32;
|
||||
set<SPIRType>(type_id, uint_type);
|
||||
|
||||
SPIRType uint_type_pointer = uint_type;
|
||||
SPIRType uint_type_pointer = get_uint_type();
|
||||
uint_type_pointer.pointer = true;
|
||||
uint_type_pointer.pointer_depth = 1;
|
||||
uint_type_pointer.parent_type = type_id;
|
||||
uint_type_pointer.parent_type = get_uint_type_id();
|
||||
uint_type_pointer.storage = StorageClassUniform;
|
||||
set<SPIRType>(type_ptr_id, uint_type_pointer);
|
||||
set_decoration(type_ptr_id, DecorationArrayStride, 4);
|
||||
@ -744,6 +706,25 @@ std::string CompilerMSL::get_tess_factor_struct_name()
|
||||
return "MTLQuadTessellationFactorsHalf";
|
||||
}
|
||||
|
||||
SPIRType &CompilerMSL::get_uint_type()
|
||||
{
|
||||
return get<SPIRType>(get_uint_type_id());
|
||||
}
|
||||
|
||||
uint32_t CompilerMSL::get_uint_type_id()
|
||||
{
|
||||
if (uint_type_id != 0)
|
||||
return uint_type_id;
|
||||
|
||||
uint_type_id = ir.increase_bound_by(1);
|
||||
|
||||
SPIRType type;
|
||||
type.basetype = SPIRType::UInt;
|
||||
type.width = 32;
|
||||
set<SPIRType>(uint_type_id, type);
|
||||
return uint_type_id;
|
||||
}
|
||||
|
||||
void CompilerMSL::emit_entry_point_declarations()
|
||||
{
|
||||
// FIXME: Get test coverage here ...
|
||||
@ -5662,14 +5643,9 @@ bool CompilerMSL::emit_tessellation_access_chain(const uint32_t *ops, uint32_t l
|
||||
{
|
||||
AccessChainMeta meta;
|
||||
SmallVector<uint32_t> indices;
|
||||
uint32_t next_id = ir.increase_bound_by(2);
|
||||
uint32_t next_id = ir.increase_bound_by(1);
|
||||
|
||||
indices.reserve(length - 3 + 1);
|
||||
uint32_t type_id = next_id++;
|
||||
SPIRType new_uint_type;
|
||||
new_uint_type.basetype = SPIRType::UInt;
|
||||
new_uint_type.width = 32;
|
||||
set<SPIRType>(type_id, new_uint_type);
|
||||
|
||||
uint32_t first_non_array_index = ptr_is_chain ? 3 : 4;
|
||||
VariableID stage_var_id = var->storage == StorageClassInput ? stage_in_ptr_var_id : stage_out_ptr_var_id;
|
||||
@ -5732,7 +5708,7 @@ bool CompilerMSL::emit_tessellation_access_chain(const uint32_t *ops, uint32_t l
|
||||
else
|
||||
{
|
||||
// Access the appropriate member of gl_in/gl_out.
|
||||
set<SPIRConstant>(const_mbr_id, type_id, index, false);
|
||||
set<SPIRConstant>(const_mbr_id, get_uint_type_id(), index, false);
|
||||
indices.push_back(const_mbr_id);
|
||||
|
||||
// Append any straggling access chain indices.
|
||||
@ -5743,7 +5719,7 @@ bool CompilerMSL::emit_tessellation_access_chain(const uint32_t *ops, uint32_t l
|
||||
else
|
||||
{
|
||||
assert(index != uint32_t(-1));
|
||||
set<SPIRConstant>(const_mbr_id, type_id, index, false);
|
||||
set<SPIRConstant>(const_mbr_id, get_uint_type_id(), index, false);
|
||||
indices.push_back(const_mbr_id);
|
||||
|
||||
indices.insert(indices.end(), ops + 4, ops + length);
|
||||
@ -12871,20 +12847,13 @@ void CompilerMSL::analyze_argument_buffers()
|
||||
|
||||
if (uint_ptr_type_id == 0)
|
||||
{
|
||||
uint32_t offset = ir.increase_bound_by(2);
|
||||
uint32_t type_id = offset;
|
||||
uint_ptr_type_id = offset + 1;
|
||||
uint_ptr_type_id = ir.increase_bound_by(1);
|
||||
|
||||
// Create a buffer to hold extra data, including the swizzle constants.
|
||||
SPIRType uint_type;
|
||||
uint_type.basetype = SPIRType::UInt;
|
||||
uint_type.width = 32;
|
||||
set<SPIRType>(type_id, uint_type);
|
||||
|
||||
SPIRType uint_type_pointer = uint_type;
|
||||
SPIRType uint_type_pointer = get_uint_type();
|
||||
uint_type_pointer.pointer = true;
|
||||
uint_type_pointer.pointer_depth = 1;
|
||||
uint_type_pointer.parent_type = type_id;
|
||||
uint_type_pointer.parent_type = get_uint_type_id();
|
||||
uint_type_pointer.storage = StorageClassUniform;
|
||||
set<SPIRType>(uint_ptr_type_id, uint_type_pointer);
|
||||
set_decoration(uint_ptr_type_id, DecorationArrayStride, 4);
|
||||
|
@ -758,6 +758,8 @@ protected:
|
||||
SPIRType &get_patch_stage_in_struct_type();
|
||||
SPIRType &get_patch_stage_out_struct_type();
|
||||
std::string get_tess_factor_struct_name();
|
||||
SPIRType &get_uint_type();
|
||||
uint32_t get_uint_type_id();
|
||||
void emit_atomic_func_op(uint32_t result_type, uint32_t result_id, const char *op, uint32_t mem_order_1,
|
||||
uint32_t mem_order_2, bool has_mem_order_2, uint32_t op0, uint32_t op1 = 0,
|
||||
bool op1_is_pointer = false, bool op1_is_literal = false, uint32_t op2 = 0);
|
||||
@ -787,6 +789,7 @@ protected:
|
||||
uint32_t buffer_size_buffer_id = 0;
|
||||
uint32_t view_mask_buffer_id = 0;
|
||||
uint32_t dynamic_offsets_buffer_id = 0;
|
||||
uint32_t uint_type_id = 0;
|
||||
|
||||
void bitcast_to_builtin_store(uint32_t target_id, std::string &expr, const SPIRType &expr_type) override;
|
||||
void bitcast_from_builtin_load(uint32_t source_id, std::string &expr, const SPIRType &expr_type) override;
|
||||
|
Loading…
Reference in New Issue
Block a user