diff options
Diffstat (limited to 'src/shader_recompiler/backend')
| -rw-r--r-- | src/shader_recompiler/backend/spirv/emit_context.cpp | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp index 8e625f8fb..0459c3925 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/emit_context.cpp | |||
| @@ -222,13 +222,39 @@ std::optional<AttrInfo> AttrTypes(EmitContext& ctx, u32 index) { | |||
| 222 | throw InvalidArgument("Invalid attribute type {}", type); | 222 | throw InvalidArgument("Invalid attribute type {}", type); |
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | std::string_view StageName(Stage stage) { | ||
| 226 | switch (stage) { | ||
| 227 | case Stage::VertexA: | ||
| 228 | return "vs_a"; | ||
| 229 | case Stage::VertexB: | ||
| 230 | return "vs"; | ||
| 231 | case Stage::TessellationControl: | ||
| 232 | return "tcs"; | ||
| 233 | case Stage::TessellationEval: | ||
| 234 | return "tes"; | ||
| 235 | case Stage::Geometry: | ||
| 236 | return "gs"; | ||
| 237 | case Stage::Fragment: | ||
| 238 | return "fs"; | ||
| 239 | case Stage::Compute: | ||
| 240 | return "cs"; | ||
| 241 | } | ||
| 242 | throw InvalidArgument("Invalid stage {}", stage); | ||
| 243 | } | ||
| 244 | |||
| 245 | template <typename... Args> | ||
| 246 | void Name(EmitContext& ctx, Id object, std::string_view format_str, Args&&... args) { | ||
| 247 | ctx.Name(object, | ||
| 248 | fmt::format(format_str, StageName(ctx.stage), std::forward<Args>(args)...).c_str()); | ||
| 249 | } | ||
| 250 | |||
| 225 | void DefineConstBuffers(EmitContext& ctx, const Info& info, Id UniformDefinitions::*member_type, | 251 | void DefineConstBuffers(EmitContext& ctx, const Info& info, Id UniformDefinitions::*member_type, |
| 226 | u32 binding, Id type, char type_char, u32 element_size) { | 252 | u32 binding, Id type, char type_char, u32 element_size) { |
| 227 | const Id array_type{ctx.TypeArray(type, ctx.Const(65536U / element_size))}; | 253 | const Id array_type{ctx.TypeArray(type, ctx.Const(65536U / element_size))}; |
| 228 | ctx.Decorate(array_type, spv::Decoration::ArrayStride, element_size); | 254 | ctx.Decorate(array_type, spv::Decoration::ArrayStride, element_size); |
| 229 | 255 | ||
| 230 | const Id struct_type{ctx.TypeStruct(array_type)}; | 256 | const Id struct_type{ctx.TypeStruct(array_type)}; |
| 231 | ctx.Name(struct_type, fmt::format("cbuf_block_{}{}", type_char, element_size * CHAR_BIT)); | 257 | Name(ctx, struct_type, "{}_cbuf_block_{}{}", ctx.stage, type_char, element_size * CHAR_BIT); |
| 232 | ctx.Decorate(struct_type, spv::Decoration::Block); | 258 | ctx.Decorate(struct_type, spv::Decoration::Block); |
| 233 | ctx.MemberName(struct_type, 0, "data"); | 259 | ctx.MemberName(struct_type, 0, "data"); |
| 234 | ctx.MemberDecorate(struct_type, 0, spv::Decoration::Offset, 0U); | 260 | ctx.MemberDecorate(struct_type, 0, spv::Decoration::Offset, 0U); |
| @@ -382,11 +408,13 @@ Id CasLoop(EmitContext& ctx, Operation operation, Id array_pointer, Id element_p | |||
| 382 | } | 408 | } |
| 383 | 409 | ||
| 384 | template <typename Desc> | 410 | template <typename Desc> |
| 385 | std::string NameOf(const Desc& desc, std::string_view prefix) { | 411 | std::string NameOf(Stage stage, const Desc& desc, std::string_view prefix) { |
| 386 | if (desc.count > 1) { | 412 | if (desc.count > 1) { |
| 387 | return fmt::format("{}{}_{:02x}x{}", prefix, desc.cbuf_index, desc.cbuf_offset, desc.count); | 413 | return fmt::format("{}_{}{}_{:02x}x{}", StageName(stage), prefix, desc.cbuf_index, |
| 414 | desc.cbuf_offset, desc.count); | ||
| 388 | } else { | 415 | } else { |
| 389 | return fmt::format("{}{}_{:02x}", prefix, desc.cbuf_index, desc.cbuf_offset); | 416 | return fmt::format("{}_{}{}_{:02x}", StageName(stage), prefix, desc.cbuf_index, |
| 417 | desc.cbuf_offset); | ||
| 390 | } | 418 | } |
| 391 | } | 419 | } |
| 392 | 420 | ||
| @@ -989,7 +1017,7 @@ void EmitContext::DefineTextureBuffers(const Info& info, u32& binding) { | |||
| 989 | const Id id{AddGlobalVariable(type, spv::StorageClass::UniformConstant)}; | 1017 | const Id id{AddGlobalVariable(type, spv::StorageClass::UniformConstant)}; |
| 990 | Decorate(id, spv::Decoration::Binding, binding); | 1018 | Decorate(id, spv::Decoration::Binding, binding); |
| 991 | Decorate(id, spv::Decoration::DescriptorSet, 0U); | 1019 | Decorate(id, spv::Decoration::DescriptorSet, 0U); |
| 992 | Name(id, NameOf(desc, "texbuf")); | 1020 | Name(id, NameOf(stage, desc, "texbuf")); |
| 993 | texture_buffers.push_back({ | 1021 | texture_buffers.push_back({ |
| 994 | .id = id, | 1022 | .id = id, |
| 995 | .count = desc.count, | 1023 | .count = desc.count, |
| @@ -1008,12 +1036,12 @@ void EmitContext::DefineImageBuffers(const Info& info, u32& binding) { | |||
| 1008 | throw NotImplementedException("Array of image buffers"); | 1036 | throw NotImplementedException("Array of image buffers"); |
| 1009 | } | 1037 | } |
| 1010 | const spv::ImageFormat format{GetImageFormat(desc.format)}; | 1038 | const spv::ImageFormat format{GetImageFormat(desc.format)}; |
| 1011 | const Id image_type{TypeImage(U32[4], spv::Dim::Buffer, false, false, false, 2, format)}; | 1039 | const Id image_type{TypeImage(U32[1], spv::Dim::Buffer, false, false, false, 2, format)}; |
| 1012 | const Id pointer_type{TypePointer(spv::StorageClass::UniformConstant, image_type)}; | 1040 | const Id pointer_type{TypePointer(spv::StorageClass::UniformConstant, image_type)}; |
| 1013 | const Id id{AddGlobalVariable(pointer_type, spv::StorageClass::UniformConstant)}; | 1041 | const Id id{AddGlobalVariable(pointer_type, spv::StorageClass::UniformConstant)}; |
| 1014 | Decorate(id, spv::Decoration::Binding, binding); | 1042 | Decorate(id, spv::Decoration::Binding, binding); |
| 1015 | Decorate(id, spv::Decoration::DescriptorSet, 0U); | 1043 | Decorate(id, spv::Decoration::DescriptorSet, 0U); |
| 1016 | Name(id, NameOf(desc, "imgbuf")); | 1044 | Name(id, NameOf(stage, desc, "imgbuf")); |
| 1017 | image_buffers.push_back({ | 1045 | image_buffers.push_back({ |
| 1018 | .id = id, | 1046 | .id = id, |
| 1019 | .image_type = image_type, | 1047 | .image_type = image_type, |
| @@ -1036,7 +1064,7 @@ void EmitContext::DefineTextures(const Info& info, u32& binding) { | |||
| 1036 | const Id id{AddGlobalVariable(desc_type, spv::StorageClass::UniformConstant)}; | 1064 | const Id id{AddGlobalVariable(desc_type, spv::StorageClass::UniformConstant)}; |
| 1037 | Decorate(id, spv::Decoration::Binding, binding); | 1065 | Decorate(id, spv::Decoration::Binding, binding); |
| 1038 | Decorate(id, spv::Decoration::DescriptorSet, 0U); | 1066 | Decorate(id, spv::Decoration::DescriptorSet, 0U); |
| 1039 | Name(id, NameOf(desc, "tex")); | 1067 | Name(id, NameOf(stage, desc, "tex")); |
| 1040 | textures.push_back({ | 1068 | textures.push_back({ |
| 1041 | .id = id, | 1069 | .id = id, |
| 1042 | .sampled_type = sampled_type, | 1070 | .sampled_type = sampled_type, |
| @@ -1062,7 +1090,7 @@ void EmitContext::DefineImages(const Info& info, u32& binding) { | |||
| 1062 | const Id id{AddGlobalVariable(pointer_type, spv::StorageClass::UniformConstant)}; | 1090 | const Id id{AddGlobalVariable(pointer_type, spv::StorageClass::UniformConstant)}; |
| 1063 | Decorate(id, spv::Decoration::Binding, binding); | 1091 | Decorate(id, spv::Decoration::Binding, binding); |
| 1064 | Decorate(id, spv::Decoration::DescriptorSet, 0U); | 1092 | Decorate(id, spv::Decoration::DescriptorSet, 0U); |
| 1065 | Name(id, NameOf(desc, "img")); | 1093 | Name(id, NameOf(stage, desc, "img")); |
| 1066 | images.push_back({ | 1094 | images.push_back({ |
| 1067 | .id = id, | 1095 | .id = id, |
| 1068 | .image_type = image_type, | 1096 | .image_type = image_type, |