diff options
| author | 2021-11-16 18:52:11 -0800 | |
|---|---|---|
| committer | 2021-11-16 18:52:11 -0800 | |
| commit | 71313509f75aeafe425e531824d1faa9e7c0a40b (patch) | |
| tree | cb1df371d288677fcede6a3409eb079e0d278163 /src/shader_recompiler/backend/spirv/emit_context.cpp | |
| parent | Merge pull request #7347 from lioncash/catch (diff) | |
| parent | TextureCache: Fix Automatic Anisotropic. (diff) | |
| download | yuzu-71313509f75aeafe425e531824d1faa9e7c0a40b.tar.gz yuzu-71313509f75aeafe425e531824d1faa9e7c0a40b.tar.xz yuzu-71313509f75aeafe425e531824d1faa9e7c0a40b.zip | |
Merge pull request #7219 from FernandoS27/aristotles-right-testicle
Project A.R.T. Advanced Rendering Techniques
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_context.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/spirv/emit_context.cpp | 86 |
1 files changed, 80 insertions, 6 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp index 3c84e6466..723455462 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/emit_context.cpp | |||
| @@ -7,11 +7,14 @@ | |||
| 7 | #include <climits> | 7 | #include <climits> |
| 8 | #include <string_view> | 8 | #include <string_view> |
| 9 | 9 | ||
| 10 | #include <boost/container/static_vector.hpp> | ||
| 11 | |||
| 10 | #include <fmt/format.h> | 12 | #include <fmt/format.h> |
| 11 | 13 | ||
| 12 | #include "common/common_types.h" | 14 | #include "common/common_types.h" |
| 13 | #include "common/div_ceil.h" | 15 | #include "common/div_ceil.h" |
| 14 | #include "shader_recompiler/backend/spirv/emit_context.h" | 16 | #include "shader_recompiler/backend/spirv/emit_context.h" |
| 17 | #include "shader_recompiler/backend/spirv/emit_spirv.h" | ||
| 15 | 18 | ||
| 16 | namespace Shader::Backend::SPIRV { | 19 | namespace Shader::Backend::SPIRV { |
| 17 | namespace { | 20 | namespace { |
| @@ -474,8 +477,9 @@ void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_vie | |||
| 474 | 477 | ||
| 475 | EmitContext::EmitContext(const Profile& profile_, const RuntimeInfo& runtime_info_, | 478 | EmitContext::EmitContext(const Profile& profile_, const RuntimeInfo& runtime_info_, |
| 476 | IR::Program& program, Bindings& bindings) | 479 | IR::Program& program, Bindings& bindings) |
| 477 | : Sirit::Module(profile_.supported_spirv), profile{profile_}, | 480 | : Sirit::Module(profile_.supported_spirv), profile{profile_}, runtime_info{runtime_info_}, |
| 478 | runtime_info{runtime_info_}, stage{program.stage} { | 481 | stage{program.stage}, texture_rescaling_index{bindings.texture_scaling_index}, |
| 482 | image_rescaling_index{bindings.image_scaling_index} { | ||
| 479 | const bool is_unified{profile.unified_descriptor_binding}; | 483 | const bool is_unified{profile.unified_descriptor_binding}; |
| 480 | u32& uniform_binding{is_unified ? bindings.unified : bindings.uniform_buffer}; | 484 | u32& uniform_binding{is_unified ? bindings.unified : bindings.uniform_buffer}; |
| 481 | u32& storage_binding{is_unified ? bindings.unified : bindings.storage_buffer}; | 485 | u32& storage_binding{is_unified ? bindings.unified : bindings.storage_buffer}; |
| @@ -492,10 +496,11 @@ EmitContext::EmitContext(const Profile& profile_, const RuntimeInfo& runtime_inf | |||
| 492 | DefineStorageBuffers(program.info, storage_binding); | 496 | DefineStorageBuffers(program.info, storage_binding); |
| 493 | DefineTextureBuffers(program.info, texture_binding); | 497 | DefineTextureBuffers(program.info, texture_binding); |
| 494 | DefineImageBuffers(program.info, image_binding); | 498 | DefineImageBuffers(program.info, image_binding); |
| 495 | DefineTextures(program.info, texture_binding); | 499 | DefineTextures(program.info, texture_binding, bindings.texture_scaling_index); |
| 496 | DefineImages(program.info, image_binding); | 500 | DefineImages(program.info, image_binding, bindings.image_scaling_index); |
| 497 | DefineAttributeMemAccess(program.info); | 501 | DefineAttributeMemAccess(program.info); |
| 498 | DefineGlobalMemoryFunctions(program.info); | 502 | DefineGlobalMemoryFunctions(program.info); |
| 503 | DefineRescalingInput(program.info); | ||
| 499 | } | 504 | } |
| 500 | 505 | ||
| 501 | EmitContext::~EmitContext() = default; | 506 | EmitContext::~EmitContext() = default; |
| @@ -996,6 +1001,73 @@ void EmitContext::DefineGlobalMemoryFunctions(const Info& info) { | |||
| 996 | define(&StorageDefinitions::U32x4, storage_types.U32x4, U32[4], sizeof(u32[4])); | 1001 | define(&StorageDefinitions::U32x4, storage_types.U32x4, U32[4], sizeof(u32[4])); |
| 997 | } | 1002 | } |
| 998 | 1003 | ||
| 1004 | void EmitContext::DefineRescalingInput(const Info& info) { | ||
| 1005 | if (!info.uses_rescaling_uniform) { | ||
| 1006 | return; | ||
| 1007 | } | ||
| 1008 | if (profile.unified_descriptor_binding) { | ||
| 1009 | DefineRescalingInputPushConstant(); | ||
| 1010 | } else { | ||
| 1011 | DefineRescalingInputUniformConstant(); | ||
| 1012 | } | ||
| 1013 | } | ||
| 1014 | |||
| 1015 | void EmitContext::DefineRescalingInputPushConstant() { | ||
| 1016 | boost::container::static_vector<Id, 3> members{}; | ||
| 1017 | u32 member_index{0}; | ||
| 1018 | |||
| 1019 | rescaling_textures_type = TypeArray(U32[1], Const(4u)); | ||
| 1020 | Decorate(rescaling_textures_type, spv::Decoration::ArrayStride, 4u); | ||
| 1021 | members.push_back(rescaling_textures_type); | ||
| 1022 | rescaling_textures_member_index = member_index++; | ||
| 1023 | |||
| 1024 | rescaling_images_type = TypeArray(U32[1], Const(NUM_IMAGE_SCALING_WORDS)); | ||
| 1025 | Decorate(rescaling_images_type, spv::Decoration::ArrayStride, 4u); | ||
| 1026 | members.push_back(rescaling_images_type); | ||
| 1027 | rescaling_images_member_index = member_index++; | ||
| 1028 | |||
| 1029 | if (stage != Stage::Compute) { | ||
| 1030 | members.push_back(F32[1]); | ||
| 1031 | rescaling_downfactor_member_index = member_index++; | ||
| 1032 | } | ||
| 1033 | const Id push_constant_struct{TypeStruct(std::span(members.data(), members.size()))}; | ||
| 1034 | Decorate(push_constant_struct, spv::Decoration::Block); | ||
| 1035 | Name(push_constant_struct, "ResolutionInfo"); | ||
| 1036 | |||
| 1037 | MemberDecorate(push_constant_struct, rescaling_textures_member_index, spv::Decoration::Offset, | ||
| 1038 | static_cast<u32>(offsetof(RescalingLayout, rescaling_textures))); | ||
| 1039 | MemberName(push_constant_struct, rescaling_textures_member_index, "rescaling_textures"); | ||
| 1040 | |||
| 1041 | MemberDecorate(push_constant_struct, rescaling_images_member_index, spv::Decoration::Offset, | ||
| 1042 | static_cast<u32>(offsetof(RescalingLayout, rescaling_images))); | ||
| 1043 | MemberName(push_constant_struct, rescaling_images_member_index, "rescaling_images"); | ||
| 1044 | |||
| 1045 | if (stage != Stage::Compute) { | ||
| 1046 | MemberDecorate(push_constant_struct, rescaling_downfactor_member_index, | ||
| 1047 | spv::Decoration::Offset, | ||
| 1048 | static_cast<u32>(offsetof(RescalingLayout, down_factor))); | ||
| 1049 | MemberName(push_constant_struct, rescaling_downfactor_member_index, "down_factor"); | ||
| 1050 | } | ||
| 1051 | const Id pointer_type{TypePointer(spv::StorageClass::PushConstant, push_constant_struct)}; | ||
| 1052 | rescaling_push_constants = AddGlobalVariable(pointer_type, spv::StorageClass::PushConstant); | ||
| 1053 | Name(rescaling_push_constants, "rescaling_push_constants"); | ||
| 1054 | |||
| 1055 | if (profile.supported_spirv >= 0x00010400) { | ||
| 1056 | interfaces.push_back(rescaling_push_constants); | ||
| 1057 | } | ||
| 1058 | } | ||
| 1059 | |||
| 1060 | void EmitContext::DefineRescalingInputUniformConstant() { | ||
| 1061 | const Id pointer_type{TypePointer(spv::StorageClass::UniformConstant, F32[4])}; | ||
| 1062 | rescaling_uniform_constant = | ||
| 1063 | AddGlobalVariable(pointer_type, spv::StorageClass::UniformConstant); | ||
| 1064 | Decorate(rescaling_uniform_constant, spv::Decoration::Location, 0u); | ||
| 1065 | |||
| 1066 | if (profile.supported_spirv >= 0x00010400) { | ||
| 1067 | interfaces.push_back(rescaling_uniform_constant); | ||
| 1068 | } | ||
| 1069 | } | ||
| 1070 | |||
| 999 | void EmitContext::DefineConstantBuffers(const Info& info, u32& binding) { | 1071 | void EmitContext::DefineConstantBuffers(const Info& info, u32& binding) { |
| 1000 | if (info.constant_buffer_descriptors.empty()) { | 1072 | if (info.constant_buffer_descriptors.empty()) { |
| 1001 | return; | 1073 | return; |
| @@ -1184,7 +1256,7 @@ void EmitContext::DefineImageBuffers(const Info& info, u32& binding) { | |||
| 1184 | } | 1256 | } |
| 1185 | } | 1257 | } |
| 1186 | 1258 | ||
| 1187 | void EmitContext::DefineTextures(const Info& info, u32& binding) { | 1259 | void EmitContext::DefineTextures(const Info& info, u32& binding, u32& scaling_index) { |
| 1188 | textures.reserve(info.texture_descriptors.size()); | 1260 | textures.reserve(info.texture_descriptors.size()); |
| 1189 | for (const TextureDescriptor& desc : info.texture_descriptors) { | 1261 | for (const TextureDescriptor& desc : info.texture_descriptors) { |
| 1190 | const Id image_type{ImageType(*this, desc)}; | 1262 | const Id image_type{ImageType(*this, desc)}; |
| @@ -1206,13 +1278,14 @@ void EmitContext::DefineTextures(const Info& info, u32& binding) { | |||
| 1206 | interfaces.push_back(id); | 1278 | interfaces.push_back(id); |
| 1207 | } | 1279 | } |
| 1208 | ++binding; | 1280 | ++binding; |
| 1281 | ++scaling_index; | ||
| 1209 | } | 1282 | } |
| 1210 | if (info.uses_atomic_image_u32) { | 1283 | if (info.uses_atomic_image_u32) { |
| 1211 | image_u32 = TypePointer(spv::StorageClass::Image, U32[1]); | 1284 | image_u32 = TypePointer(spv::StorageClass::Image, U32[1]); |
| 1212 | } | 1285 | } |
| 1213 | } | 1286 | } |
| 1214 | 1287 | ||
| 1215 | void EmitContext::DefineImages(const Info& info, u32& binding) { | 1288 | void EmitContext::DefineImages(const Info& info, u32& binding, u32& scaling_index) { |
| 1216 | images.reserve(info.image_descriptors.size()); | 1289 | images.reserve(info.image_descriptors.size()); |
| 1217 | for (const ImageDescriptor& desc : info.image_descriptors) { | 1290 | for (const ImageDescriptor& desc : info.image_descriptors) { |
| 1218 | if (desc.count != 1) { | 1291 | if (desc.count != 1) { |
| @@ -1233,6 +1306,7 @@ void EmitContext::DefineImages(const Info& info, u32& binding) { | |||
| 1233 | interfaces.push_back(id); | 1306 | interfaces.push_back(id); |
| 1234 | } | 1307 | } |
| 1235 | ++binding; | 1308 | ++binding; |
| 1309 | ++scaling_index; | ||
| 1236 | } | 1310 | } |
| 1237 | } | 1311 | } |
| 1238 | 1312 | ||