diff options
| author | 2021-10-16 00:30:43 -0400 | |
|---|---|---|
| committer | 2021-11-16 22:11:31 +0100 | |
| commit | 618de4e7871898f165c028293becd235ce3ccb09 (patch) | |
| tree | a41f25c847177f4f5d8c6ce8da5651f71f7418a5 /src/shader_recompiler/backend | |
| parent | Texture Cahe: Fix downscaling on SMO. (diff) | |
| download | yuzu-618de4e7871898f165c028293becd235ce3ccb09.tar.gz yuzu-618de4e7871898f165c028293becd235ce3ccb09.tar.xz yuzu-618de4e7871898f165c028293becd235ce3ccb09.zip | |
vulkan: Fix rescaling push constant usage
Diffstat (limited to 'src/shader_recompiler/backend')
4 files changed, 36 insertions, 34 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp index 8646fe989..723455462 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/emit_context.cpp | |||
| @@ -1006,47 +1006,47 @@ void EmitContext::DefineRescalingInput(const Info& info) { | |||
| 1006 | return; | 1006 | return; |
| 1007 | } | 1007 | } |
| 1008 | if (profile.unified_descriptor_binding) { | 1008 | if (profile.unified_descriptor_binding) { |
| 1009 | DefineRescalingInputPushConstant(info); | 1009 | DefineRescalingInputPushConstant(); |
| 1010 | } else { | 1010 | } else { |
| 1011 | DefineRescalingInputUniformConstant(); | 1011 | DefineRescalingInputUniformConstant(); |
| 1012 | } | 1012 | } |
| 1013 | } | 1013 | } |
| 1014 | 1014 | ||
| 1015 | void EmitContext::DefineRescalingInputPushConstant(const Info& info) { | 1015 | void EmitContext::DefineRescalingInputPushConstant() { |
| 1016 | boost::container::static_vector<Id, 3> members{F32[1]}; | 1016 | boost::container::static_vector<Id, 3> members{}; |
| 1017 | u32 member_index{0}; | 1017 | u32 member_index{0}; |
| 1018 | if (!info.texture_descriptors.empty()) { | 1018 | |
| 1019 | rescaling_textures_type = TypeArray(U32[1], Const(4u)); | 1019 | rescaling_textures_type = TypeArray(U32[1], Const(4u)); |
| 1020 | Decorate(rescaling_textures_type, spv::Decoration::ArrayStride, 4u); | 1020 | Decorate(rescaling_textures_type, spv::Decoration::ArrayStride, 4u); |
| 1021 | members.push_back(rescaling_textures_type); | 1021 | members.push_back(rescaling_textures_type); |
| 1022 | rescaling_textures_member_index = ++member_index; | 1022 | rescaling_textures_member_index = member_index++; |
| 1023 | } | 1023 | |
| 1024 | if (!info.image_descriptors.empty()) { | 1024 | rescaling_images_type = TypeArray(U32[1], Const(NUM_IMAGE_SCALING_WORDS)); |
| 1025 | rescaling_images_type = TypeArray(U32[1], Const(NUM_IMAGE_SCALING_WORDS)); | 1025 | Decorate(rescaling_images_type, spv::Decoration::ArrayStride, 4u); |
| 1026 | if (rescaling_textures_type.value != rescaling_images_type.value) { | 1026 | members.push_back(rescaling_images_type); |
| 1027 | Decorate(rescaling_images_type, spv::Decoration::ArrayStride, 4u); | 1027 | rescaling_images_member_index = member_index++; |
| 1028 | } | 1028 | |
| 1029 | members.push_back(rescaling_images_type); | 1029 | if (stage != Stage::Compute) { |
| 1030 | rescaling_images_member_index = ++member_index; | 1030 | members.push_back(F32[1]); |
| 1031 | rescaling_downfactor_member_index = member_index++; | ||
| 1031 | } | 1032 | } |
| 1032 | const Id push_constant_struct{TypeStruct(std::span(members.data(), members.size()))}; | 1033 | const Id push_constant_struct{TypeStruct(std::span(members.data(), members.size()))}; |
| 1033 | Decorate(push_constant_struct, spv::Decoration::Block); | 1034 | Decorate(push_constant_struct, spv::Decoration::Block); |
| 1034 | Name(push_constant_struct, "ResolutionInfo"); | 1035 | Name(push_constant_struct, "ResolutionInfo"); |
| 1035 | 1036 | ||
| 1036 | MemberDecorate(push_constant_struct, 0u, spv::Decoration::Offset, 0u); | 1037 | MemberDecorate(push_constant_struct, rescaling_textures_member_index, spv::Decoration::Offset, |
| 1037 | MemberName(push_constant_struct, 0u, "down_factor"); | 1038 | static_cast<u32>(offsetof(RescalingLayout, rescaling_textures))); |
| 1039 | MemberName(push_constant_struct, rescaling_textures_member_index, "rescaling_textures"); | ||
| 1038 | 1040 | ||
| 1039 | const u32 offset_bias = stage == Stage::Compute ? sizeof(u32) : 0; | 1041 | MemberDecorate(push_constant_struct, rescaling_images_member_index, spv::Decoration::Offset, |
| 1040 | if (!info.texture_descriptors.empty()) { | 1042 | static_cast<u32>(offsetof(RescalingLayout, rescaling_images))); |
| 1041 | MemberDecorate( | 1043 | MemberName(push_constant_struct, rescaling_images_member_index, "rescaling_images"); |
| 1042 | push_constant_struct, rescaling_textures_member_index, spv::Decoration::Offset, | 1044 | |
| 1043 | static_cast<u32>(offsetof(RescalingLayout, rescaling_textures) - offset_bias)); | 1045 | if (stage != Stage::Compute) { |
| 1044 | MemberName(push_constant_struct, rescaling_textures_member_index, "rescaling_textures"); | 1046 | MemberDecorate(push_constant_struct, rescaling_downfactor_member_index, |
| 1045 | } | 1047 | spv::Decoration::Offset, |
| 1046 | if (!info.image_descriptors.empty()) { | 1048 | static_cast<u32>(offsetof(RescalingLayout, down_factor))); |
| 1047 | MemberDecorate(push_constant_struct, rescaling_images_member_index, spv::Decoration::Offset, | 1049 | MemberName(push_constant_struct, rescaling_downfactor_member_index, "down_factor"); |
| 1048 | static_cast<u32>(offsetof(RescalingLayout, rescaling_images) - offset_bias)); | ||
| 1049 | MemberName(push_constant_struct, rescaling_images_member_index, "rescaling_images"); | ||
| 1050 | } | 1050 | } |
| 1051 | const Id pointer_type{TypePointer(spv::StorageClass::PushConstant, push_constant_struct)}; | 1051 | const Id pointer_type{TypePointer(spv::StorageClass::PushConstant, push_constant_struct)}; |
| 1052 | rescaling_push_constants = AddGlobalVariable(pointer_type, spv::StorageClass::PushConstant); | 1052 | rescaling_push_constants = AddGlobalVariable(pointer_type, spv::StorageClass::PushConstant); |
diff --git a/src/shader_recompiler/backend/spirv/emit_context.h b/src/shader_recompiler/backend/spirv/emit_context.h index b67704baa..63f8185d9 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.h +++ b/src/shader_recompiler/backend/spirv/emit_context.h | |||
| @@ -244,6 +244,7 @@ public: | |||
| 244 | Id rescaling_images_type{}; | 244 | Id rescaling_images_type{}; |
| 245 | u32 rescaling_textures_member_index{}; | 245 | u32 rescaling_textures_member_index{}; |
| 246 | u32 rescaling_images_member_index{}; | 246 | u32 rescaling_images_member_index{}; |
| 247 | u32 rescaling_downfactor_member_index{}; | ||
| 247 | u32 texture_rescaling_index{}; | 248 | u32 texture_rescaling_index{}; |
| 248 | u32 image_rescaling_index{}; | 249 | u32 image_rescaling_index{}; |
| 249 | 250 | ||
| @@ -324,7 +325,7 @@ private: | |||
| 324 | void DefineAttributeMemAccess(const Info& info); | 325 | void DefineAttributeMemAccess(const Info& info); |
| 325 | void DefineGlobalMemoryFunctions(const Info& info); | 326 | void DefineGlobalMemoryFunctions(const Info& info); |
| 326 | void DefineRescalingInput(const Info& info); | 327 | void DefineRescalingInput(const Info& info); |
| 327 | void DefineRescalingInputPushConstant(const Info& info); | 328 | void DefineRescalingInputPushConstant(); |
| 328 | void DefineRescalingInputUniformConstant(); | 329 | void DefineRescalingInputUniformConstant(); |
| 329 | 330 | ||
| 330 | void DefineInputs(const IR::Program& program); | 331 | void DefineInputs(const IR::Program& program); |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv.h b/src/shader_recompiler/backend/spirv/emit_spirv.h index cf59f2572..4b25534ce 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv.h +++ b/src/shader_recompiler/backend/spirv/emit_spirv.h | |||
| @@ -22,11 +22,12 @@ constexpr u32 NUM_TEXTURE_AND_IMAGE_SCALING_WORDS = | |||
| 22 | NUM_TEXTURE_SCALING_WORDS + NUM_IMAGE_SCALING_WORDS; | 22 | NUM_TEXTURE_SCALING_WORDS + NUM_IMAGE_SCALING_WORDS; |
| 23 | 23 | ||
| 24 | struct RescalingLayout { | 24 | struct RescalingLayout { |
| 25 | u32 down_factor; | ||
| 26 | alignas(16) std::array<u32, NUM_TEXTURE_SCALING_WORDS> rescaling_textures; | 25 | alignas(16) std::array<u32, NUM_TEXTURE_SCALING_WORDS> rescaling_textures; |
| 27 | alignas(16) std::array<u32, NUM_IMAGE_SCALING_WORDS> rescaling_images; | 26 | alignas(16) std::array<u32, NUM_IMAGE_SCALING_WORDS> rescaling_images; |
| 27 | alignas(16) u32 down_factor; | ||
| 28 | }; | 28 | }; |
| 29 | constexpr u32 RESCALING_PUSH_CONSTANT_WORDS_OFFSET = offsetof(RescalingLayout, rescaling_textures); | 29 | constexpr u32 RESCALING_LAYOUT_WORDS_OFFSET = offsetof(RescalingLayout, rescaling_textures); |
| 30 | constexpr u32 RESCALING_LAYOUT_DOWN_FACTOR_OFFSET = offsetof(RescalingLayout, down_factor); | ||
| 30 | 31 | ||
| 31 | [[nodiscard]] std::vector<u32> EmitSPIRV(const Profile& profile, const RuntimeInfo& runtime_info, | 32 | [[nodiscard]] std::vector<u32> EmitSPIRV(const Profile& profile, const RuntimeInfo& runtime_info, |
| 32 | IR::Program& program, Bindings& bindings); | 33 | IR::Program& program, Bindings& bindings); |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp index c0db7452f..bac683ae1 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp | |||
| @@ -529,8 +529,8 @@ Id EmitYDirection(EmitContext& ctx) { | |||
| 529 | Id EmitResolutionDownFactor(EmitContext& ctx) { | 529 | Id EmitResolutionDownFactor(EmitContext& ctx) { |
| 530 | if (ctx.profile.unified_descriptor_binding) { | 530 | if (ctx.profile.unified_descriptor_binding) { |
| 531 | const Id pointer_type{ctx.TypePointer(spv::StorageClass::PushConstant, ctx.F32[1])}; | 531 | const Id pointer_type{ctx.TypePointer(spv::StorageClass::PushConstant, ctx.F32[1])}; |
| 532 | const Id pointer{ | 532 | const Id index{ctx.Const(ctx.rescaling_downfactor_member_index)}; |
| 533 | ctx.OpAccessChain(pointer_type, ctx.rescaling_push_constants, ctx.u32_zero_value)}; | 533 | const Id pointer{ctx.OpAccessChain(pointer_type, ctx.rescaling_push_constants, index)}; |
| 534 | return ctx.OpLoad(ctx.F32[1], pointer); | 534 | return ctx.OpLoad(ctx.F32[1], pointer); |
| 535 | } else { | 535 | } else { |
| 536 | const Id composite{ctx.OpLoad(ctx.F32[4], ctx.rescaling_uniform_constant)}; | 536 | const Id composite{ctx.OpLoad(ctx.F32[4], ctx.rescaling_uniform_constant)}; |