diff options
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_context.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/spirv/emit_context.cpp | 79 |
1 files changed, 48 insertions, 31 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp index 7f16cb0dc..8e625f8fb 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/emit_context.cpp | |||
| @@ -380,6 +380,24 @@ Id CasLoop(EmitContext& ctx, Operation operation, Id array_pointer, Id element_p | |||
| 380 | ctx.OpFunctionEnd(); | 380 | ctx.OpFunctionEnd(); |
| 381 | return func; | 381 | return func; |
| 382 | } | 382 | } |
| 383 | |||
| 384 | template <typename Desc> | ||
| 385 | std::string NameOf(const Desc& desc, std::string_view prefix) { | ||
| 386 | if (desc.count > 1) { | ||
| 387 | return fmt::format("{}{}_{:02x}x{}", prefix, desc.cbuf_index, desc.cbuf_offset, desc.count); | ||
| 388 | } else { | ||
| 389 | return fmt::format("{}{}_{:02x}", prefix, desc.cbuf_index, desc.cbuf_offset); | ||
| 390 | } | ||
| 391 | } | ||
| 392 | |||
| 393 | Id DescType(EmitContext& ctx, Id sampled_type, Id pointer_type, u32 count) { | ||
| 394 | if (count > 1) { | ||
| 395 | const Id array_type{ctx.TypeArray(sampled_type, ctx.Const(count))}; | ||
| 396 | return ctx.TypePointer(spv::StorageClass::UniformConstant, array_type); | ||
| 397 | } else { | ||
| 398 | return pointer_type; | ||
| 399 | } | ||
| 400 | } | ||
| 383 | } // Anonymous namespace | 401 | } // Anonymous namespace |
| 384 | 402 | ||
| 385 | void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) { | 403 | void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) { |
| @@ -971,12 +989,15 @@ void EmitContext::DefineTextureBuffers(const Info& info, u32& binding) { | |||
| 971 | const Id id{AddGlobalVariable(type, spv::StorageClass::UniformConstant)}; | 989 | const Id id{AddGlobalVariable(type, spv::StorageClass::UniformConstant)}; |
| 972 | Decorate(id, spv::Decoration::Binding, binding); | 990 | Decorate(id, spv::Decoration::Binding, binding); |
| 973 | Decorate(id, spv::Decoration::DescriptorSet, 0U); | 991 | Decorate(id, spv::Decoration::DescriptorSet, 0U); |
| 974 | Name(id, fmt::format("texbuf{}_{:02x}", desc.cbuf_index, desc.cbuf_offset)); | 992 | Name(id, NameOf(desc, "texbuf")); |
| 975 | texture_buffers.insert(texture_buffers.end(), desc.count, id); | 993 | texture_buffers.push_back({ |
| 994 | .id = id, | ||
| 995 | .count = desc.count, | ||
| 996 | }); | ||
| 976 | if (profile.supported_spirv >= 0x00010400) { | 997 | if (profile.supported_spirv >= 0x00010400) { |
| 977 | interfaces.push_back(id); | 998 | interfaces.push_back(id); |
| 978 | } | 999 | } |
| 979 | binding += desc.count; | 1000 | ++binding; |
| 980 | } | 1001 | } |
| 981 | } | 1002 | } |
| 982 | 1003 | ||
| @@ -992,44 +1013,41 @@ void EmitContext::DefineImageBuffers(const Info& info, u32& binding) { | |||
| 992 | const Id id{AddGlobalVariable(pointer_type, spv::StorageClass::UniformConstant)}; | 1013 | const Id id{AddGlobalVariable(pointer_type, spv::StorageClass::UniformConstant)}; |
| 993 | Decorate(id, spv::Decoration::Binding, binding); | 1014 | Decorate(id, spv::Decoration::Binding, binding); |
| 994 | Decorate(id, spv::Decoration::DescriptorSet, 0U); | 1015 | Decorate(id, spv::Decoration::DescriptorSet, 0U); |
| 995 | Name(id, fmt::format("imgbuf{}_{:02x}", desc.cbuf_index, desc.cbuf_offset)); | 1016 | Name(id, NameOf(desc, "imgbuf")); |
| 996 | const ImageBufferDefinition def{ | 1017 | image_buffers.push_back({ |
| 997 | .id = id, | 1018 | .id = id, |
| 998 | .image_type = image_type, | 1019 | .image_type = image_type, |
| 999 | }; | 1020 | .count = desc.count, |
| 1000 | image_buffers.insert(image_buffers.end(), desc.count, def); | 1021 | }); |
| 1001 | if (profile.supported_spirv >= 0x00010400) { | 1022 | if (profile.supported_spirv >= 0x00010400) { |
| 1002 | interfaces.push_back(id); | 1023 | interfaces.push_back(id); |
| 1003 | } | 1024 | } |
| 1004 | binding += desc.count; | 1025 | ++binding; |
| 1005 | } | 1026 | } |
| 1006 | } | 1027 | } |
| 1007 | 1028 | ||
| 1008 | void EmitContext::DefineTextures(const Info& info, u32& binding) { | 1029 | void EmitContext::DefineTextures(const Info& info, u32& binding) { |
| 1009 | textures.reserve(info.texture_descriptors.size()); | 1030 | textures.reserve(info.texture_descriptors.size()); |
| 1010 | for (const TextureDescriptor& desc : info.texture_descriptors) { | 1031 | for (const TextureDescriptor& desc : info.texture_descriptors) { |
| 1011 | if (desc.count != 1) { | ||
| 1012 | throw NotImplementedException("Array of textures"); | ||
| 1013 | } | ||
| 1014 | const Id image_type{ImageType(*this, desc)}; | 1032 | const Id image_type{ImageType(*this, desc)}; |
| 1015 | const Id sampled_type{TypeSampledImage(image_type)}; | 1033 | const Id sampled_type{TypeSampledImage(image_type)}; |
| 1016 | const Id pointer_type{TypePointer(spv::StorageClass::UniformConstant, sampled_type)}; | 1034 | const Id pointer_type{TypePointer(spv::StorageClass::UniformConstant, sampled_type)}; |
| 1017 | const Id id{AddGlobalVariable(pointer_type, spv::StorageClass::UniformConstant)}; | 1035 | const Id desc_type{DescType(*this, sampled_type, pointer_type, desc.count)}; |
| 1036 | const Id id{AddGlobalVariable(desc_type, spv::StorageClass::UniformConstant)}; | ||
| 1018 | Decorate(id, spv::Decoration::Binding, binding); | 1037 | Decorate(id, spv::Decoration::Binding, binding); |
| 1019 | Decorate(id, spv::Decoration::DescriptorSet, 0U); | 1038 | Decorate(id, spv::Decoration::DescriptorSet, 0U); |
| 1020 | Name(id, fmt::format("tex{}_{:02x}", desc.cbuf_index, desc.cbuf_offset)); | 1039 | Name(id, NameOf(desc, "tex")); |
| 1021 | for (u32 index = 0; index < desc.count; ++index) { | 1040 | textures.push_back({ |
| 1022 | // TODO: Pass count info | 1041 | .id = id, |
| 1023 | textures.push_back(TextureDefinition{ | 1042 | .sampled_type = sampled_type, |
| 1024 | .id{id}, | 1043 | .pointer_type = pointer_type, |
| 1025 | .sampled_type{sampled_type}, | 1044 | .image_type = image_type, |
| 1026 | .image_type{image_type}, | 1045 | .count = desc.count, |
| 1027 | }); | 1046 | }); |
| 1028 | } | ||
| 1029 | if (profile.supported_spirv >= 0x00010400) { | 1047 | if (profile.supported_spirv >= 0x00010400) { |
| 1030 | interfaces.push_back(id); | 1048 | interfaces.push_back(id); |
| 1031 | } | 1049 | } |
| 1032 | binding += desc.count; | 1050 | ++binding; |
| 1033 | } | 1051 | } |
| 1034 | } | 1052 | } |
| 1035 | 1053 | ||
| @@ -1037,24 +1055,23 @@ void EmitContext::DefineImages(const Info& info, u32& binding) { | |||
| 1037 | images.reserve(info.image_descriptors.size()); | 1055 | images.reserve(info.image_descriptors.size()); |
| 1038 | for (const ImageDescriptor& desc : info.image_descriptors) { | 1056 | for (const ImageDescriptor& desc : info.image_descriptors) { |
| 1039 | if (desc.count != 1) { | 1057 | if (desc.count != 1) { |
| 1040 | throw NotImplementedException("Array of textures"); | 1058 | throw NotImplementedException("Array of images"); |
| 1041 | } | 1059 | } |
| 1042 | const Id image_type{ImageType(*this, desc)}; | 1060 | const Id image_type{ImageType(*this, desc)}; |
| 1043 | const Id pointer_type{TypePointer(spv::StorageClass::UniformConstant, image_type)}; | 1061 | const Id pointer_type{TypePointer(spv::StorageClass::UniformConstant, image_type)}; |
| 1044 | const Id id{AddGlobalVariable(pointer_type, spv::StorageClass::UniformConstant)}; | 1062 | const Id id{AddGlobalVariable(pointer_type, spv::StorageClass::UniformConstant)}; |
| 1045 | Decorate(id, spv::Decoration::Binding, binding); | 1063 | Decorate(id, spv::Decoration::Binding, binding); |
| 1046 | Decorate(id, spv::Decoration::DescriptorSet, 0U); | 1064 | Decorate(id, spv::Decoration::DescriptorSet, 0U); |
| 1047 | Name(id, fmt::format("img{}_{:02x}", desc.cbuf_index, desc.cbuf_offset)); | 1065 | Name(id, NameOf(desc, "img")); |
| 1048 | for (u32 index = 0; index < desc.count; ++index) { | 1066 | images.push_back({ |
| 1049 | images.push_back(ImageDefinition{ | 1067 | .id = id, |
| 1050 | .id{id}, | 1068 | .image_type = image_type, |
| 1051 | .image_type{image_type}, | 1069 | .count = desc.count, |
| 1052 | }); | 1070 | }); |
| 1053 | } | ||
| 1054 | if (profile.supported_spirv >= 0x00010400) { | 1071 | if (profile.supported_spirv >= 0x00010400) { |
| 1055 | interfaces.push_back(id); | 1072 | interfaces.push_back(id); |
| 1056 | } | 1073 | } |
| 1057 | binding += desc.count; | 1074 | ++binding; |
| 1058 | } | 1075 | } |
| 1059 | } | 1076 | } |
| 1060 | 1077 | ||