diff options
| author | 2021-04-18 20:47:31 -0400 | |
|---|---|---|
| committer | 2021-07-22 21:51:28 -0400 | |
| commit | 5b8afed87115c82cb48913fd47dfbfa347e4faa5 (patch) | |
| tree | 84eff714b71e1f3e5f1b9436e877327480144b0b /src/shader_recompiler/backend/spirv/emit_context.cpp | |
| parent | shader: Address feedback (diff) | |
| download | yuzu-5b8afed87115c82cb48913fd47dfbfa347e4faa5.tar.gz yuzu-5b8afed87115c82cb48913fd47dfbfa347e4faa5.tar.xz yuzu-5b8afed87115c82cb48913fd47dfbfa347e4faa5.zip | |
spirv: Replace Constant/ConstantComposite with Const helper
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_context.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/spirv/emit_context.cpp | 69 |
1 files changed, 34 insertions, 35 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp index b9e6d5655..214ef9c25 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/emit_context.cpp | |||
| @@ -131,13 +131,13 @@ Id DefineInput(EmitContext& ctx, Id type, bool per_invocation, | |||
| 131 | case Stage::TessellationControl: | 131 | case Stage::TessellationControl: |
| 132 | case Stage::TessellationEval: | 132 | case Stage::TessellationEval: |
| 133 | if (per_invocation) { | 133 | if (per_invocation) { |
| 134 | type = ctx.TypeArray(type, ctx.Constant(ctx.U32[1], 32u)); | 134 | type = ctx.TypeArray(type, ctx.Const(32u)); |
| 135 | } | 135 | } |
| 136 | break; | 136 | break; |
| 137 | case Stage::Geometry: | 137 | case Stage::Geometry: |
| 138 | if (per_invocation) { | 138 | if (per_invocation) { |
| 139 | const u32 num_vertices{NumVertices(ctx.profile.input_topology)}; | 139 | const u32 num_vertices{NumVertices(ctx.profile.input_topology)}; |
| 140 | type = ctx.TypeArray(type, ctx.Constant(ctx.U32[1], num_vertices)); | 140 | type = ctx.TypeArray(type, ctx.Const(num_vertices)); |
| 141 | } | 141 | } |
| 142 | break; | 142 | break; |
| 143 | default: | 143 | default: |
| @@ -149,7 +149,7 @@ Id DefineInput(EmitContext& ctx, Id type, bool per_invocation, | |||
| 149 | Id DefineOutput(EmitContext& ctx, Id type, std::optional<u32> invocations, | 149 | Id DefineOutput(EmitContext& ctx, Id type, std::optional<u32> invocations, |
| 150 | std::optional<spv::BuiltIn> builtin = std::nullopt) { | 150 | std::optional<spv::BuiltIn> builtin = std::nullopt) { |
| 151 | if (invocations && ctx.stage == Stage::TessellationControl) { | 151 | if (invocations && ctx.stage == Stage::TessellationControl) { |
| 152 | type = ctx.TypeArray(type, ctx.Constant(ctx.U32[1], *invocations)); | 152 | type = ctx.TypeArray(type, ctx.Const(*invocations)); |
| 153 | } | 153 | } |
| 154 | return DefineVariable(ctx, type, builtin, spv::StorageClass::Output); | 154 | return DefineVariable(ctx, type, builtin, spv::StorageClass::Output); |
| 155 | } | 155 | } |
| @@ -224,7 +224,7 @@ std::optional<AttrInfo> AttrTypes(EmitContext& ctx, u32 index) { | |||
| 224 | 224 | ||
| 225 | void DefineConstBuffers(EmitContext& ctx, const Info& info, Id UniformDefinitions::*member_type, | 225 | void DefineConstBuffers(EmitContext& ctx, const Info& info, Id UniformDefinitions::*member_type, |
| 226 | u32 binding, Id type, char type_char, u32 element_size) { | 226 | u32 binding, Id type, char type_char, u32 element_size) { |
| 227 | const Id array_type{ctx.TypeArray(type, ctx.Constant(ctx.U32[1], 65536U / element_size))}; | 227 | const Id array_type{ctx.TypeArray(type, ctx.Const(65536U / element_size))}; |
| 228 | ctx.Decorate(array_type, spv::Decoration::ArrayStride, element_size); | 228 | ctx.Decorate(array_type, spv::Decoration::ArrayStride, element_size); |
| 229 | 229 | ||
| 230 | const Id struct_type{ctx.TypeStruct(array_type)}; | 230 | const Id struct_type{ctx.TypeStruct(array_type)}; |
| @@ -328,7 +328,7 @@ Id CasLoop(EmitContext& ctx, Operation operation, Id array_pointer, Id element_p | |||
| 328 | const bool is_struct{!is_shared || ctx.profile.support_explicit_workgroup_layout}; | 328 | const bool is_struct{!is_shared || ctx.profile.support_explicit_workgroup_layout}; |
| 329 | const Id cas_func{CasFunction(ctx, operation, value_type)}; | 329 | const Id cas_func{CasFunction(ctx, operation, value_type)}; |
| 330 | const Id zero{ctx.u32_zero_value}; | 330 | const Id zero{ctx.u32_zero_value}; |
| 331 | const Id scope_id{ctx.Constant(ctx.U32[1], static_cast<u32>(scope))}; | 331 | const Id scope_id{ctx.Const(static_cast<u32>(scope))}; |
| 332 | 332 | ||
| 333 | const Id loop_header{ctx.OpLabel()}; | 333 | const Id loop_header{ctx.OpLabel()}; |
| 334 | const Id continue_block{ctx.OpLabel()}; | 334 | const Id continue_block{ctx.OpLabel()}; |
| @@ -428,11 +428,11 @@ Id EmitContext::Def(const IR::Value& value) { | |||
| 428 | case IR::Type::U1: | 428 | case IR::Type::U1: |
| 429 | return value.U1() ? true_value : false_value; | 429 | return value.U1() ? true_value : false_value; |
| 430 | case IR::Type::U32: | 430 | case IR::Type::U32: |
| 431 | return Constant(U32[1], value.U32()); | 431 | return Const(value.U32()); |
| 432 | case IR::Type::U64: | 432 | case IR::Type::U64: |
| 433 | return Constant(U64, value.U64()); | 433 | return Constant(U64, value.U64()); |
| 434 | case IR::Type::F32: | 434 | case IR::Type::F32: |
| 435 | return Constant(F32[1], value.F32()); | 435 | return Const(value.F32()); |
| 436 | case IR::Type::F64: | 436 | case IR::Type::F64: |
| 437 | return Constant(F64[1], value.F64()); | 437 | return Constant(F64[1], value.F64()); |
| 438 | case IR::Type::Label: | 438 | case IR::Type::Label: |
| @@ -486,8 +486,8 @@ void EmitContext::DefineCommonTypes(const Info& info) { | |||
| 486 | void EmitContext::DefineCommonConstants() { | 486 | void EmitContext::DefineCommonConstants() { |
| 487 | true_value = ConstantTrue(U1); | 487 | true_value = ConstantTrue(U1); |
| 488 | false_value = ConstantFalse(U1); | 488 | false_value = ConstantFalse(U1); |
| 489 | u32_zero_value = Constant(U32[1], 0U); | 489 | u32_zero_value = Const(0U); |
| 490 | f32_zero_value = Constant(F32[1], 0.0f); | 490 | f32_zero_value = Const(0.0f); |
| 491 | } | 491 | } |
| 492 | 492 | ||
| 493 | void EmitContext::DefineInterfaces(const IR::Program& program) { | 493 | void EmitContext::DefineInterfaces(const IR::Program& program) { |
| @@ -500,7 +500,7 @@ void EmitContext::DefineLocalMemory(const IR::Program& program) { | |||
| 500 | return; | 500 | return; |
| 501 | } | 501 | } |
| 502 | const u32 num_elements{Common::DivCeil(program.local_memory_size, 4U)}; | 502 | const u32 num_elements{Common::DivCeil(program.local_memory_size, 4U)}; |
| 503 | const Id type{TypeArray(U32[1], Constant(U32[1], num_elements))}; | 503 | const Id type{TypeArray(U32[1], Const(num_elements))}; |
| 504 | const Id pointer{TypePointer(spv::StorageClass::Private, type)}; | 504 | const Id pointer{TypePointer(spv::StorageClass::Private, type)}; |
| 505 | local_memory = AddGlobalVariable(pointer, spv::StorageClass::Private); | 505 | local_memory = AddGlobalVariable(pointer, spv::StorageClass::Private); |
| 506 | if (profile.supported_spirv >= 0x00010400) { | 506 | if (profile.supported_spirv >= 0x00010400) { |
| @@ -514,7 +514,7 @@ void EmitContext::DefineSharedMemory(const IR::Program& program) { | |||
| 514 | } | 514 | } |
| 515 | const auto make{[&](Id element_type, u32 element_size) { | 515 | const auto make{[&](Id element_type, u32 element_size) { |
| 516 | const u32 num_elements{Common::DivCeil(program.shared_memory_size, element_size)}; | 516 | const u32 num_elements{Common::DivCeil(program.shared_memory_size, element_size)}; |
| 517 | const Id array_type{TypeArray(element_type, Constant(U32[1], num_elements))}; | 517 | const Id array_type{TypeArray(element_type, Const(num_elements))}; |
| 518 | Decorate(array_type, spv::Decoration::ArrayStride, element_size); | 518 | Decorate(array_type, spv::Decoration::ArrayStride, element_size); |
| 519 | 519 | ||
| 520 | const Id struct_type{TypeStruct(array_type)}; | 520 | const Id struct_type{TypeStruct(array_type)}; |
| @@ -549,7 +549,7 @@ void EmitContext::DefineSharedMemory(const IR::Program& program) { | |||
| 549 | return; | 549 | return; |
| 550 | } | 550 | } |
| 551 | const u32 num_elements{Common::DivCeil(program.shared_memory_size, 4U)}; | 551 | const u32 num_elements{Common::DivCeil(program.shared_memory_size, 4U)}; |
| 552 | const Id type{TypeArray(U32[1], Constant(U32[1], num_elements))}; | 552 | const Id type{TypeArray(U32[1], Const(num_elements))}; |
| 553 | shared_memory_u32_type = TypePointer(spv::StorageClass::Workgroup, type); | 553 | shared_memory_u32_type = TypePointer(spv::StorageClass::Workgroup, type); |
| 554 | 554 | ||
| 555 | shared_u32 = TypePointer(spv::StorageClass::Workgroup, U32[1]); | 555 | shared_u32 = TypePointer(spv::StorageClass::Workgroup, U32[1]); |
| @@ -569,10 +569,10 @@ void EmitContext::DefineSharedMemory(const IR::Program& program) { | |||
| 569 | OpBranch(loop_header); | 569 | OpBranch(loop_header); |
| 570 | 570 | ||
| 571 | AddLabel(loop_header); | 571 | AddLabel(loop_header); |
| 572 | const Id word_offset{OpShiftRightArithmetic(U32[1], offset, Constant(U32[1], 2U))}; | 572 | const Id word_offset{OpShiftRightArithmetic(U32[1], offset, Const(2U))}; |
| 573 | const Id shift_offset{OpShiftLeftLogical(U32[1], offset, Constant(U32[1], 3U))}; | 573 | const Id shift_offset{OpShiftLeftLogical(U32[1], offset, Const(3U))}; |
| 574 | const Id bit_offset{OpBitwiseAnd(U32[1], shift_offset, Constant(U32[1], mask))}; | 574 | const Id bit_offset{OpBitwiseAnd(U32[1], shift_offset, Const(mask))}; |
| 575 | const Id count{Constant(U32[1], size)}; | 575 | const Id count{Const(size)}; |
| 576 | OpLoopMerge(merge_block, continue_block, spv::LoopControlMask::MaskNone); | 576 | OpLoopMerge(merge_block, continue_block, spv::LoopControlMask::MaskNone); |
| 577 | OpBranch(continue_block); | 577 | OpBranch(continue_block); |
| 578 | 578 | ||
| @@ -580,9 +580,8 @@ void EmitContext::DefineSharedMemory(const IR::Program& program) { | |||
| 580 | const Id word_pointer{OpAccessChain(shared_u32, shared_memory_u32, word_offset)}; | 580 | const Id word_pointer{OpAccessChain(shared_u32, shared_memory_u32, word_offset)}; |
| 581 | const Id old_value{OpLoad(U32[1], word_pointer)}; | 581 | const Id old_value{OpLoad(U32[1], word_pointer)}; |
| 582 | const Id new_value{OpBitFieldInsert(U32[1], old_value, insert_value, bit_offset, count)}; | 582 | const Id new_value{OpBitFieldInsert(U32[1], old_value, insert_value, bit_offset, count)}; |
| 583 | const Id atomic_res{OpAtomicCompareExchange(U32[1], word_pointer, Constant(U32[1], 1U), | 583 | const Id atomic_res{OpAtomicCompareExchange(U32[1], word_pointer, Const(1U), u32_zero_value, |
| 584 | u32_zero_value, u32_zero_value, new_value, | 584 | u32_zero_value, new_value, old_value)}; |
| 585 | old_value)}; | ||
| 586 | const Id success{OpIEqual(U1, atomic_res, old_value)}; | 585 | const Id success{OpIEqual(U1, atomic_res, old_value)}; |
| 587 | OpBranchConditional(success, merge_block, loop_header); | 586 | OpBranchConditional(success, merge_block, loop_header); |
| 588 | 587 | ||
| @@ -623,9 +622,9 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) { | |||
| 623 | const Id vertex{is_array ? OpFunctionParameter(U32[1]) : Id{}}; | 622 | const Id vertex{is_array ? OpFunctionParameter(U32[1]) : Id{}}; |
| 624 | 623 | ||
| 625 | AddLabel(); | 624 | AddLabel(); |
| 626 | const Id base_index{OpShiftRightArithmetic(U32[1], offset, Constant(U32[1], 2U))}; | 625 | const Id base_index{OpShiftRightArithmetic(U32[1], offset, Const(2U))}; |
| 627 | const Id masked_index{OpBitwiseAnd(U32[1], base_index, Constant(U32[1], 3U))}; | 626 | const Id masked_index{OpBitwiseAnd(U32[1], base_index, Const(3U))}; |
| 628 | const Id compare_index{OpShiftRightArithmetic(U32[1], base_index, Constant(U32[1], 2U))}; | 627 | const Id compare_index{OpShiftRightArithmetic(U32[1], base_index, Const(2U))}; |
| 629 | std::vector<Sirit::Literal> literals; | 628 | std::vector<Sirit::Literal> literals; |
| 630 | std::vector<Id> labels; | 629 | std::vector<Id> labels; |
| 631 | if (info.loads_position) { | 630 | if (info.loads_position) { |
| @@ -643,7 +642,7 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) { | |||
| 643 | OpSelectionMerge(end_block, spv::SelectionControlMask::MaskNone); | 642 | OpSelectionMerge(end_block, spv::SelectionControlMask::MaskNone); |
| 644 | OpSwitch(compare_index, default_label, literals, labels); | 643 | OpSwitch(compare_index, default_label, literals, labels); |
| 645 | AddLabel(default_label); | 644 | AddLabel(default_label); |
| 646 | OpReturnValue(Constant(F32[1], 0.0f)); | 645 | OpReturnValue(Const(0.0f)); |
| 647 | size_t label_index{0}; | 646 | size_t label_index{0}; |
| 648 | if (info.loads_position) { | 647 | if (info.loads_position) { |
| 649 | AddLabel(labels[label_index]); | 648 | AddLabel(labels[label_index]); |
| @@ -661,7 +660,7 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) { | |||
| 661 | AddLabel(labels[label_index]); | 660 | AddLabel(labels[label_index]); |
| 662 | const auto type{AttrTypes(*this, static_cast<u32>(i))}; | 661 | const auto type{AttrTypes(*this, static_cast<u32>(i))}; |
| 663 | if (!type) { | 662 | if (!type) { |
| 664 | OpReturnValue(Constant(F32[1], 0.0f)); | 663 | OpReturnValue(Const(0.0f)); |
| 665 | ++label_index; | 664 | ++label_index; |
| 666 | continue; | 665 | continue; |
| 667 | } | 666 | } |
| @@ -688,9 +687,9 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) { | |||
| 688 | const Id offset{OpFunctionParameter(U32[1])}; | 687 | const Id offset{OpFunctionParameter(U32[1])}; |
| 689 | const Id store_value{OpFunctionParameter(F32[1])}; | 688 | const Id store_value{OpFunctionParameter(F32[1])}; |
| 690 | AddLabel(); | 689 | AddLabel(); |
| 691 | const Id base_index{OpShiftRightArithmetic(U32[1], offset, Constant(U32[1], 2U))}; | 690 | const Id base_index{OpShiftRightArithmetic(U32[1], offset, Const(2U))}; |
| 692 | const Id masked_index{OpBitwiseAnd(U32[1], base_index, Constant(U32[1], 3U))}; | 691 | const Id masked_index{OpBitwiseAnd(U32[1], base_index, Const(3U))}; |
| 693 | const Id compare_index{OpShiftRightArithmetic(U32[1], base_index, Constant(U32[1], 2U))}; | 692 | const Id compare_index{OpShiftRightArithmetic(U32[1], base_index, Const(2U))}; |
| 694 | std::vector<Sirit::Literal> literals; | 693 | std::vector<Sirit::Literal> literals; |
| 695 | std::vector<Id> labels; | 694 | std::vector<Id> labels; |
| 696 | if (info.stores_position) { | 695 | if (info.stores_position) { |
| @@ -744,7 +743,7 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) { | |||
| 744 | OpReturn(); | 743 | OpReturn(); |
| 745 | ++label_index; | 744 | ++label_index; |
| 746 | AddLabel(labels[label_index]); | 745 | AddLabel(labels[label_index]); |
| 747 | const Id fixed_index{OpIAdd(U32[1], masked_index, Constant(U32[1], 4))}; | 746 | const Id fixed_index{OpIAdd(U32[1], masked_index, Const(4U))}; |
| 748 | const Id pointer2{OpAccessChain(output_f32, clip_distances, fixed_index)}; | 747 | const Id pointer2{OpAccessChain(output_f32, clip_distances, fixed_index)}; |
| 749 | OpStore(pointer2, store_value); | 748 | OpStore(pointer2, store_value); |
| 750 | OpReturn(); | 749 | OpReturn(); |
| @@ -1018,9 +1017,9 @@ void EmitContext::DefineInputs(const Info& info) { | |||
| 1018 | DefineInput(*this, U32[1], false, spv::BuiltIn::SubgroupLocalInvocationId); | 1017 | DefineInput(*this, U32[1], false, spv::BuiltIn::SubgroupLocalInvocationId); |
| 1019 | } | 1018 | } |
| 1020 | if (info.uses_fswzadd) { | 1019 | if (info.uses_fswzadd) { |
| 1021 | const Id f32_one{Constant(F32[1], 1.0f)}; | 1020 | const Id f32_one{Const(1.0f)}; |
| 1022 | const Id f32_minus_one{Constant(F32[1], -1.0f)}; | 1021 | const Id f32_minus_one{Const(-1.0f)}; |
| 1023 | const Id f32_zero{Constant(F32[1], 0.0f)}; | 1022 | const Id f32_zero{Const(0.0f)}; |
| 1024 | fswzadd_lut_a = ConstantComposite(F32[4], f32_minus_one, f32_one, f32_minus_one, f32_zero); | 1023 | fswzadd_lut_a = ConstantComposite(F32[4], f32_minus_one, f32_one, f32_minus_one, f32_zero); |
| 1025 | fswzadd_lut_b = | 1024 | fswzadd_lut_b = |
| 1026 | ConstantComposite(F32[4], f32_minus_one, f32_minus_one, f32_one, f32_minus_one); | 1025 | ConstantComposite(F32[4], f32_minus_one, f32_minus_one, f32_one, f32_minus_one); |
| @@ -1118,7 +1117,7 @@ void EmitContext::DefineOutputs(const IR::Program& program) { | |||
| 1118 | if (stage == Stage::Fragment) { | 1117 | if (stage == Stage::Fragment) { |
| 1119 | throw NotImplementedException("Storing ClipDistance in fragment stage"); | 1118 | throw NotImplementedException("Storing ClipDistance in fragment stage"); |
| 1120 | } | 1119 | } |
| 1121 | const Id type{TypeArray(F32[1], Constant(U32[1], 8U))}; | 1120 | const Id type{TypeArray(F32[1], Const(8U))}; |
| 1122 | clip_distances = DefineOutput(*this, type, invocations, spv::BuiltIn::ClipDistance); | 1121 | clip_distances = DefineOutput(*this, type, invocations, spv::BuiltIn::ClipDistance); |
| 1123 | } | 1122 | } |
| 1124 | if (info.stores_layer && | 1123 | if (info.stores_layer && |
| @@ -1136,7 +1135,7 @@ void EmitContext::DefineOutputs(const IR::Program& program) { | |||
| 1136 | viewport_index = DefineOutput(*this, U32[1], invocations, spv::BuiltIn::ViewportIndex); | 1135 | viewport_index = DefineOutput(*this, U32[1], invocations, spv::BuiltIn::ViewportIndex); |
| 1137 | } | 1136 | } |
| 1138 | if (info.stores_viewport_mask && profile.support_viewport_mask) { | 1137 | if (info.stores_viewport_mask && profile.support_viewport_mask) { |
| 1139 | viewport_mask = DefineOutput(*this, TypeArray(U32[1], Constant(U32[1], 1u)), std::nullopt); | 1138 | viewport_mask = DefineOutput(*this, TypeArray(U32[1], Const(1u)), std::nullopt); |
| 1140 | } | 1139 | } |
| 1141 | for (size_t index = 0; index < info.stores_generics.size(); ++index) { | 1140 | for (size_t index = 0; index < info.stores_generics.size(); ++index) { |
| 1142 | if (info.stores_generics[index]) { | 1141 | if (info.stores_generics[index]) { |
| @@ -1146,13 +1145,13 @@ void EmitContext::DefineOutputs(const IR::Program& program) { | |||
| 1146 | switch (stage) { | 1145 | switch (stage) { |
| 1147 | case Stage::TessellationControl: | 1146 | case Stage::TessellationControl: |
| 1148 | if (info.stores_tess_level_outer) { | 1147 | if (info.stores_tess_level_outer) { |
| 1149 | const Id type{TypeArray(F32[1], Constant(U32[1], 4))}; | 1148 | const Id type{TypeArray(F32[1], Const(4U))}; |
| 1150 | output_tess_level_outer = | 1149 | output_tess_level_outer = |
| 1151 | DefineOutput(*this, type, std::nullopt, spv::BuiltIn::TessLevelOuter); | 1150 | DefineOutput(*this, type, std::nullopt, spv::BuiltIn::TessLevelOuter); |
| 1152 | Decorate(output_tess_level_outer, spv::Decoration::Patch); | 1151 | Decorate(output_tess_level_outer, spv::Decoration::Patch); |
| 1153 | } | 1152 | } |
| 1154 | if (info.stores_tess_level_inner) { | 1153 | if (info.stores_tess_level_inner) { |
| 1155 | const Id type{TypeArray(F32[1], Constant(U32[1], 2))}; | 1154 | const Id type{TypeArray(F32[1], Const(2U))}; |
| 1156 | output_tess_level_inner = | 1155 | output_tess_level_inner = |
| 1157 | DefineOutput(*this, type, std::nullopt, spv::BuiltIn::TessLevelInner); | 1156 | DefineOutput(*this, type, std::nullopt, spv::BuiltIn::TessLevelInner); |
| 1158 | Decorate(output_tess_level_inner, spv::Decoration::Patch); | 1157 | Decorate(output_tess_level_inner, spv::Decoration::Patch); |