From 3fa2b146346f94832290a1deb9935c129040b854 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Tue, 23 Jul 2019 12:23:41 +0200 Subject: [PATCH] Run format_all.sh. --- spirv_cross_parsed_ir.cpp | 2 +- spirv_glsl.cpp | 18 +++++++++------ spirv_glsl.hpp | 10 ++++---- spirv_msl.cpp | 48 +++++++++++++++++++++------------------ spirv_msl.hpp | 9 +++++--- 5 files changed, 49 insertions(+), 38 deletions(-) diff --git a/spirv_cross_parsed_ir.cpp b/spirv_cross_parsed_ir.cpp index c4f7247c..a5c87f45 100644 --- a/spirv_cross_parsed_ir.cpp +++ b/spirv_cross_parsed_ir.cpp @@ -775,7 +775,7 @@ ParsedIR::LoopLock::~LoopLock() } ParsedIR::LoopLock::LoopLock(uint32_t *lock_) - : lock(lock_) + : lock(lock_) { if (lock) (*lock)++; diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index ca13192d..e7ceb721 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -920,7 +920,8 @@ string CompilerGLSL::layout_for_member(const SPIRType &type, uint32_t index) // SPIRVCrossDecorationPacked is set by layout_for_variable earlier to mark that we need to emit offset qualifiers. // This is only done selectively in GLSL as needed. - if (has_extended_decoration(type.self, SPIRVCrossDecorationExplicitOffset) && dec.decoration_flags.get(DecorationOffset)) + if (has_extended_decoration(type.self, SPIRVCrossDecorationExplicitOffset) && + dec.decoration_flags.get(DecorationOffset)) attr.push_back(join("offset = ", dec.offset)); if (attr.empty()) @@ -2516,7 +2517,7 @@ void CompilerGLSL::emit_resources() if (!options.vulkan_semantics && c.specialization) { c.specialization_constant_macro_name = - constant_value_macro_name(get_decoration(c.self, DecorationSpecId)); + constant_value_macro_name(get_decoration(c.self, DecorationSpecId)); } emit_constant(c); emitted = true; @@ -3008,7 +3009,8 @@ string CompilerGLSL::to_expression(uint32_t id, bool register_expression_read) // when consuming an access chain expression. uint32_t physical_type_id = get_extended_decoration(id, SPIRVCrossDecorationPhysicalTypeID); bool is_packed = has_extended_decoration(id, SPIRVCrossDecorationPhysicalTypePacked); - return convert_row_major_matrix(e.expression, get(e.expression_type), physical_type_id, is_packed); + return convert_row_major_matrix(e.expression, get(e.expression_type), physical_type_id, + is_packed); } else { @@ -8330,9 +8332,11 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction) string expr; if (opcode == OpMatrixTimesVector) - expr = join(to_enclosed_unpacked_expression(ops[3]), " * ", enclose_expression(to_unpacked_row_major_matrix_expression(ops[2]))); + expr = join(to_enclosed_unpacked_expression(ops[3]), " * ", + enclose_expression(to_unpacked_row_major_matrix_expression(ops[2]))); else - expr = join(enclose_expression(to_unpacked_row_major_matrix_expression(ops[3])), " * ", to_enclosed_unpacked_expression(ops[2])); + expr = join(enclose_expression(to_unpacked_row_major_matrix_expression(ops[3])), " * ", + to_enclosed_unpacked_expression(ops[2])); bool forward = should_forward(ops[2]) && should_forward(ops[3]); emit_op(ops[0], ops[1], expr, forward); @@ -9998,8 +10002,8 @@ bool CompilerGLSL::member_is_packed_physical_type(const SPIRType &type, uint32_t // row_major matrix result of the expression to a column_major matrix. // Base implementation uses the standard library transpose() function. // Subclasses may override to use a different function. -string CompilerGLSL::convert_row_major_matrix(string exp_str, const SPIRType &exp_type, - uint32_t /* physical_type_id */, bool /*is_packed*/) +string CompilerGLSL::convert_row_major_matrix(string exp_str, const SPIRType &exp_type, uint32_t /* physical_type_id */, + bool /*is_packed*/) { strip_enclosed_expression(exp_str); if (!is_matrix(exp_type)) diff --git a/spirv_glsl.hpp b/spirv_glsl.hpp index a7152346..ef6cc37e 100644 --- a/spirv_glsl.hpp +++ b/spirv_glsl.hpp @@ -268,8 +268,7 @@ protected: virtual void emit_buffer_block(const SPIRVariable &type); virtual void emit_push_constant_block(const SPIRVariable &var); virtual void emit_uniform(const SPIRVariable &var); - virtual std::string unpack_expression_type(std::string expr_str, const SPIRType &type, - uint32_t physical_type_id, + virtual std::string unpack_expression_type(std::string expr_str, const SPIRType &type, uint32_t physical_type_id, bool packed_type, bool row_major); StringStream<> buffer; @@ -350,9 +349,10 @@ protected: virtual bool is_non_native_row_major_matrix(uint32_t id); virtual bool member_is_non_native_row_major_matrix(const SPIRType &type, uint32_t index); - bool member_is_remapped_physical_type(const SPIRType& type, uint32_t index) const; - bool member_is_packed_physical_type(const SPIRType& type, uint32_t index) const; - virtual std::string convert_row_major_matrix(std::string exp_str, const SPIRType &exp_type, uint32_t physical_type_id, bool is_packed); + bool member_is_remapped_physical_type(const SPIRType &type, uint32_t index) const; + bool member_is_packed_physical_type(const SPIRType &type, uint32_t index) const; + virtual std::string convert_row_major_matrix(std::string exp_str, const SPIRType &exp_type, + uint32_t physical_type_id, bool is_packed); std::unordered_set local_variable_names; std::unordered_set resource_names; diff --git a/spirv_msl.cpp b/spirv_msl.cpp index c0890df2..481cd063 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -2466,8 +2466,10 @@ void CompilerMSL::mark_scalar_layout_structs(const SPIRType &type) { if (has_extended_decoration(struct_type->self, SPIRVCrossDecorationPaddingTarget)) { - if (array_stride != get_extended_decoration(struct_type->self, SPIRVCrossDecorationPaddingTarget)) - SPIRV_CROSS_THROW("A struct is used with different array strides. Cannot express this in MSL."); + if (array_stride != + get_extended_decoration(struct_type->self, SPIRVCrossDecorationPaddingTarget)) + SPIRV_CROSS_THROW( + "A struct is used with different array strides. Cannot express this in MSL."); } else set_extended_decoration(struct_type->self, SPIRVCrossDecorationPaddingTarget, array_stride); @@ -2650,7 +2652,8 @@ void CompilerMSL::ensure_member_packing_rules_msl(SPIRType &ib_type, uint32_t in // Remove packed_ for vectors of size 1, 2 and 4. if (has_extended_decoration(ib_type.self, SPIRVCrossDecorationPhysicalTypePacked)) - SPIRV_CROSS_THROW("Unable to remove packed decoration as entire struct must be fully packed. Do not mix scalar and std140 layout rules."); + SPIRV_CROSS_THROW("Unable to remove packed decoration as entire struct must be fully packed. Do not mix " + "scalar and std140 layout rules."); else unset_extended_member_decoration(ib_type.self, index, SPIRVCrossDecorationPhysicalTypePacked); } @@ -2680,7 +2683,8 @@ void CompilerMSL::ensure_member_packing_rules_msl(SPIRType &ib_type, uint32_t in // Remove packed_ for vectors of size 1, 2 and 4. if (has_extended_decoration(ib_type.self, SPIRVCrossDecorationPhysicalTypePacked)) - SPIRV_CROSS_THROW("Unable to remove packed decoration as entire struct must be fully packed. Do not mix scalar and std140 layout rules."); + SPIRV_CROSS_THROW("Unable to remove packed decoration as entire struct must be fully packed. Do not mix " + "scalar and std140 layout rules."); else unset_extended_member_decoration(ib_type.self, index, SPIRVCrossDecorationPhysicalTypePacked); } @@ -2710,7 +2714,8 @@ void CompilerMSL::emit_store_statement(uint32_t lhs_expression, uint32_t rhs_exp if (is_matrix(type) && lhs_e && lhs_e->need_transpose) { if (!rhs_e) - SPIRV_CROSS_THROW("Need to transpose right-side expression of a store to row-major matrix, but it is not a SPIRExpression."); + SPIRV_CROSS_THROW("Need to transpose right-side expression of a store to row-major matrix, but it is " + "not a SPIRExpression."); lhs_e->need_transpose = false; if (rhs_e && rhs_e->need_transpose) @@ -2718,7 +2723,8 @@ void CompilerMSL::emit_store_statement(uint32_t lhs_expression, uint32_t rhs_exp // Direct copy, but might need to unpack RHS. // Skip the transpose, as we will transpose when writing to LHS and transpose(transpose(T)) == T. rhs_e->need_transpose = false; - statement(to_expression(lhs_expression), " = ", to_unpacked_row_major_matrix_expression(rhs_expression), ";"); + statement(to_expression(lhs_expression), " = ", to_unpacked_row_major_matrix_expression(rhs_expression), + ";"); rhs_e->need_transpose = true; } else @@ -2760,8 +2766,7 @@ void CompilerMSL::emit_store_statement(uint32_t lhs_expression, uint32_t rhs_exp // This is mostly to deal with std140 padded matrices or vectors. uint32_t physical_type_id = - lhs_remapped_type ? get_extended_decoration(lhs_expression, SPIRVCrossDecorationPhysicalTypeID) : - type.self; + lhs_remapped_type ? get_extended_decoration(lhs_expression, SPIRVCrossDecorationPhysicalTypeID) : type.self; auto &physical_type = get(physical_type_id); @@ -2801,8 +2806,8 @@ void CompilerMSL::emit_store_statement(uint32_t lhs_expression, uint32_t rhs_exp // If RHS is also transposed, we can just copy row by row. for (uint32_t i = 0; i < type.vecsize; i++) { - statement(to_enclosed_expression(lhs_expression), - "[", i, "]", store_swiz, " = ", to_unpacked_row_major_matrix_expression(rhs_expression), "[", i, "];"); + statement(to_enclosed_expression(lhs_expression), "[", i, "]", store_swiz, " = ", + to_unpacked_row_major_matrix_expression(rhs_expression), "[", i, "];"); } } else @@ -2824,8 +2829,7 @@ void CompilerMSL::emit_store_statement(uint32_t lhs_expression, uint32_t rhs_exp } rhs_row += ")"; - statement(to_enclosed_expression(lhs_expression), - "[", i, "]", store_swiz, " = ", rhs_row, ";"); + statement(to_enclosed_expression(lhs_expression), "[", i, "]", store_swiz, " = ", rhs_row, ";"); } } @@ -2858,8 +2862,7 @@ void CompilerMSL::emit_store_statement(uint32_t lhs_expression, uint32_t rhs_exp } rhs_row += ")"; - statement(to_enclosed_expression(lhs_expression), - "[", i, "]", store_swiz, " = ", rhs_row, ";"); + statement(to_enclosed_expression(lhs_expression), "[", i, "]", store_swiz, " = ", rhs_row, ";"); } } else @@ -2867,8 +2870,8 @@ void CompilerMSL::emit_store_statement(uint32_t lhs_expression, uint32_t rhs_exp // Copy column-by-column. for (uint32_t i = 0; i < type.columns; i++) { - statement(to_enclosed_expression(lhs_expression), - "[", i, "]", store_swiz, " = ", to_enclosed_unpacked_expression(rhs_expression), "[", i, "];"); + statement(to_enclosed_expression(lhs_expression), "[", i, "]", store_swiz, " = ", + to_enclosed_unpacked_expression(rhs_expression), "[", i, "];"); } } } @@ -3660,7 +3663,8 @@ void CompilerMSL::emit_specialization_constants_and_structs() // This makes the struct alignment as small as physically possible. // When we actually align the struct later, we can insert padding as necessary to make the packed members behave like normally aligned types. ir.for_each_typed_id([&](uint32_t type_id, const SPIRType &type) { - if (type.basetype == SPIRType::Struct && has_extended_decoration(type_id, SPIRVCrossDecorationBufferBlockRepacked)) + if (type.basetype == SPIRType::Struct && + has_extended_decoration(type_id, SPIRVCrossDecorationBufferBlockRepacked)) mark_scalar_layout_structs(type); }); @@ -5993,8 +5997,8 @@ bool CompilerMSL::member_is_non_native_row_major_matrix(const SPIRType &type, ui return has_member_decoration(type.self, index, DecorationRowMajor); } -string CompilerMSL::convert_row_major_matrix(string exp_str, const SPIRType &exp_type, - uint32_t physical_type_id, bool is_packed) +string CompilerMSL::convert_row_major_matrix(string exp_str, const SPIRType &exp_type, uint32_t physical_type_id, + bool is_packed) { if (!is_matrix(exp_type)) { @@ -8886,8 +8890,7 @@ const SPIRType &CompilerMSL::get_physical_member_type(const SPIRType &type, uint return get(type.member_types[index]); } -uint32_t CompilerMSL::get_declared_type_array_stride_msl(const SPIRType &type, - bool is_packed, bool row_major) const +uint32_t CompilerMSL::get_declared_type_array_stride_msl(const SPIRType &type, bool is_packed, bool row_major) const { // Array stride in MSL is always size * array_size. sizeof(float3) == 16, // unlike GLSL and HLSL where array stride would be 16 and size 12. @@ -8939,7 +8942,8 @@ uint32_t CompilerMSL::get_declared_struct_member_matrix_stride_msl(const SPIRTyp has_member_decoration(type.self, index, DecorationRowMajor)); } -uint32_t CompilerMSL::get_declared_struct_size_msl(const SPIRType &struct_type, bool ignore_alignment, bool ignore_padding) const +uint32_t CompilerMSL::get_declared_struct_size_msl(const SPIRType &struct_type, bool ignore_alignment, + bool ignore_padding) const { // If we have a target size, that is the declared size as well. if (!ignore_padding && has_extended_decoration(struct_type.self, SPIRVCrossDecorationPaddingTarget)) diff --git a/spirv_msl.hpp b/spirv_msl.hpp index 0fc9dd69..14e49e2e 100644 --- a/spirv_msl.hpp +++ b/spirv_msl.hpp @@ -430,7 +430,8 @@ protected: uint32_t grad_y, uint32_t lod, uint32_t coffset, uint32_t offset, uint32_t bias, uint32_t comp, uint32_t sample, uint32_t minlod, bool *p_forward) override; std::string to_initializer_expression(const SPIRVariable &var) override; - std::string unpack_expression_type(std::string expr_str, const SPIRType &type, uint32_t physical_type_id, bool is_packed, bool row_major) override; + std::string unpack_expression_type(std::string expr_str, const SPIRType &type, uint32_t physical_type_id, + bool is_packed, bool row_major) override; std::string bitcast_glsl_op(const SPIRType &result_type, const SPIRType &argument_type) override; bool skip_argument(uint32_t id) const override; @@ -442,7 +443,8 @@ protected: bool is_patch_block(const SPIRType &type); bool is_non_native_row_major_matrix(uint32_t id) override; bool member_is_non_native_row_major_matrix(const SPIRType &type, uint32_t index) override; - std::string convert_row_major_matrix(std::string exp_str, const SPIRType &exp_type, uint32_t physical_type_id, bool is_packed) override; + std::string convert_row_major_matrix(std::string exp_str, const SPIRType &exp_type, uint32_t physical_type_id, + bool is_packed) override; void preprocess_op_codes(); void localize_global_variables(); @@ -521,7 +523,8 @@ protected: const SPIRType &get_physical_member_type(const SPIRType &struct_type, uint32_t index) const; - uint32_t get_declared_struct_size_msl(const SPIRType &struct_type, bool ignore_alignment = false, bool ignore_padding = false) const; + uint32_t get_declared_struct_size_msl(const SPIRType &struct_type, bool ignore_alignment = false, + bool ignore_padding = false) const; std::string to_component_argument(uint32_t id); void align_struct(SPIRType &ib_type, std::unordered_set &aligned_structs);