On second thought, don't use a feature struct for the aux buffer.

This commit is contained in:
Chip Davis 2019-02-06 14:45:26 -06:00
parent ea74e453e3
commit f55253dc1b
2 changed files with 10 additions and 27 deletions

View File

@ -278,24 +278,16 @@ void CompilerMSL::build_implicit_builtins()
SPIRType struct_type; SPIRType struct_type;
struct_type.basetype = SPIRType::Struct; struct_type.basetype = SPIRType::Struct;
if (msl_options.aux_buffer_features.vertex_count)
struct_type.member_types.push_back(type_id); // Vertex count struct_type.member_types.push_back(type_id); // Vertex count
if (msl_options.aux_buffer_features.swizzle_const)
struct_type.member_types.push_back(type_arr_id); // Swizzle constants struct_type.member_types.push_back(type_arr_id); // Swizzle constants
auto &type = set<SPIRType>(struct_id, struct_type); auto &type = set<SPIRType>(struct_id, struct_type);
type.self = struct_id; type.self = struct_id;
set_decoration(struct_id, DecorationBlock); set_decoration(struct_id, DecorationBlock);
set_name(struct_id, "spvAux"); set_name(struct_id, "spvAux");
if (msl_options.aux_buffer_features.vertex_count)
{
set_member_name(struct_id, k_aux_mbr_idx_vertex_count, "vertexCount"); set_member_name(struct_id, k_aux_mbr_idx_vertex_count, "vertexCount");
set_member_decoration(struct_id, k_aux_mbr_idx_vertex_count, DecorationOffset, 0); set_member_decoration(struct_id, k_aux_mbr_idx_vertex_count, DecorationOffset, 0);
}
if (msl_options.aux_buffer_features.swizzle_const)
{
set_member_name(struct_id, k_aux_mbr_idx_swizzle_const, "swizzleConst"); set_member_name(struct_id, k_aux_mbr_idx_swizzle_const, "swizzleConst");
set_member_decoration(struct_id, k_aux_mbr_idx_swizzle_const, DecorationOffset, 4); set_member_decoration(struct_id, k_aux_mbr_idx_swizzle_const, DecorationOffset, 4);
}
SPIRType struct_type_ptr = struct_type; SPIRType struct_type_ptr = struct_type;
struct_type_ptr.pointer = true; struct_type_ptr.pointer = true;
@ -1522,8 +1514,6 @@ uint32_t CompilerMSL::add_interface_block(StorageClass storage)
// copying that to the output buffer, we'll declare the output variable // copying that to the output buffer, we'll declare the output variable
// as a reference to the final output element in the buffer. Then we can // as a reference to the final output element in the buffer. Then we can
// avoid the extra copy. // avoid the extra copy.
if (!msl_options.aux_buffer_features.vertex_count)
SPIRV_CROSS_THROW("Capturing vertex output to a buffer requires the vertexCount feature.");
entry_func.fixup_hooks_in.push_back([=]() { entry_func.fixup_hooks_in.push_back([=]() {
auto &aux_type = expression_type(aux_buffer_id); auto &aux_type = expression_type(aux_buffer_id);
statement("device ", to_name(ir.default_entry_point), "_", ib_var_ref, "& ", ib_var_ref, " = ", statement("device ", to_name(ir.default_entry_point), "_", ib_var_ref, "& ", ib_var_ref, " = ",
@ -4802,8 +4792,6 @@ void CompilerMSL::fix_up_shader_inputs_outputs()
{ {
if (msl_options.swizzle_texture_samples && has_sampled_images && is_sampled_image_type(type)) if (msl_options.swizzle_texture_samples && has_sampled_images && is_sampled_image_type(type))
{ {
if (!msl_options.aux_buffer_features.swizzle_const)
SPIRV_CROSS_THROW("Swizzling sampled values from images requires the swizzleConst feature.");
auto &entry_func = this->get<SPIRFunction>(ir.default_entry_point); auto &entry_func = this->get<SPIRFunction>(ir.default_entry_point);
entry_func.fixup_hooks_in.push_back([this, &var, var_id]() { entry_func.fixup_hooks_in.push_back([this, &var, var_id]() {
auto &aux_type = expression_type(aux_buffer_id); auto &aux_type = expression_type(aux_buffer_id);

View File

@ -147,6 +147,10 @@ static const uint32_t kPushConstDescSet = ~(0u);
// element to indicate the bindings for the push constants. // element to indicate the bindings for the push constants.
static const uint32_t kPushConstBinding = 0; static const uint32_t kPushConstBinding = 0;
// The current version of the aux buffer structure. It must be incremented any time a
// new field is added to the aux buffer.
#define SPIRV_CROSS_MSL_AUX_BUFFER_STRUCT_VERSION 2
// Decompiles SPIR-V to Metal Shading Language // Decompiles SPIR-V to Metal Shading Language
class CompilerMSL : public CompilerGLSL class CompilerMSL : public CompilerGLSL
{ {
@ -174,15 +178,6 @@ public:
// Add support to explicit pad out components. // Add support to explicit pad out components.
bool pad_fragment_output_components = false; bool pad_fragment_output_components = false;
// The current version of this structure. It must be incremented any time a
// new field is added to the aux buffer.
#define SPIRV_CROSS_MSL_AUX_BUFFER_STRUCT_VERSION 2
struct AuxBufferFeatures
{
bool vertex_count = true;
bool swizzle_const = true;
} aux_buffer_features;
bool is_ios() bool is_ios()
{ {
return platform == iOS; return platform == iOS;