summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/spirv/emit_context.cpp
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-04-06 02:56:15 -0300
committerGravatar ameerj2021-07-22 21:51:26 -0400
commit1f3eb601acdcdfa4c119cffbf36b5792147b893f (patch)
tree1a8dcc5e4ce11e9090dd6d7a8b4e8aaa130ff67b /src/shader_recompiler/backend/spirv/emit_context.cpp
parentshader: Address feedback (diff)
downloadyuzu-1f3eb601acdcdfa4c119cffbf36b5792147b893f.tar.gz
yuzu-1f3eb601acdcdfa4c119cffbf36b5792147b893f.tar.xz
yuzu-1f3eb601acdcdfa4c119cffbf36b5792147b893f.zip
shader: Implement texture buffers
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_context.cpp')
-rw-r--r--src/shader_recompiler/backend/spirv/emit_context.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp
index 2d39ea373..d01633628 100644
--- a/src/shader_recompiler/backend/spirv/emit_context.cpp
+++ b/src/shader_recompiler/backend/spirv/emit_context.cpp
@@ -46,6 +46,8 @@ Id ImageType(EmitContext& ctx, const TextureDescriptor& desc) {
46 return ctx.TypeImage(type, spv::Dim::Cube, true, false, false, 1, format); 46 return ctx.TypeImage(type, spv::Dim::Cube, true, false, false, 1, format);
47 case TextureType::ShadowArrayCube: 47 case TextureType::ShadowArrayCube:
48 return ctx.TypeImage(type, spv::Dim::Cube, true, true, false, 1, format); 48 return ctx.TypeImage(type, spv::Dim::Cube, true, true, false, 1, format);
49 case TextureType::Buffer:
50 break;
49 } 51 }
50 throw InvalidArgument("Invalid texture type {}", desc.type); 52 throw InvalidArgument("Invalid texture type {}", desc.type);
51} 53}
@@ -129,6 +131,7 @@ EmitContext::EmitContext(const Profile& profile_, IR::Program& program, u32& bin
129 DefineConstantBuffers(program.info, binding); 131 DefineConstantBuffers(program.info, binding);
130 DefineStorageBuffers(program.info, binding); 132 DefineStorageBuffers(program.info, binding);
131 DefineTextures(program.info, binding); 133 DefineTextures(program.info, binding);
134 DefineTextureBuffers(program.info, binding);
132 DefineAttributeMemAccess(program.info); 135 DefineAttributeMemAccess(program.info);
133 DefineLabels(program); 136 DefineLabels(program);
134} 137}
@@ -541,6 +544,32 @@ void EmitContext::DefineTextures(const Info& info, u32& binding) {
541 } 544 }
542} 545}
543 546
547void EmitContext::DefineTextureBuffers(const Info& info, u32& binding) {
548 if (info.texture_buffer_descriptors.empty()) {
549 return;
550 }
551 const spv::ImageFormat format{spv::ImageFormat::Unknown};
552 image_buffer_type = TypeImage(F32[1], spv::Dim::Buffer, 0U, false, false, 1, format);
553 sampled_texture_buffer_type = TypeSampledImage(image_buffer_type);
554
555 const Id type{TypePointer(spv::StorageClass::UniformConstant, sampled_texture_buffer_type)};
556 texture_buffers.reserve(info.texture_buffer_descriptors.size());
557 for (const TextureBufferDescriptor& desc : info.texture_buffer_descriptors) {
558 if (desc.count != 1) {
559 throw NotImplementedException("Array of texture buffers");
560 }
561 const Id id{AddGlobalVariable(type, spv::StorageClass::UniformConstant)};
562 Decorate(id, spv::Decoration::Binding, binding);
563 Decorate(id, spv::Decoration::DescriptorSet, 0U);
564 Name(id, fmt::format("texbuf{}_{:02x}", desc.cbuf_index, desc.cbuf_offset));
565 texture_buffers.insert(texture_buffers.end(), desc.count, id);
566 if (profile.supported_spirv >= 0x00010400) {
567 interfaces.push_back(id);
568 }
569 binding += desc.count;
570 }
571}
572
544void EmitContext::DefineLabels(IR::Program& program) { 573void EmitContext::DefineLabels(IR::Program& program) {
545 for (IR::Block* const block : program.blocks) { 574 for (IR::Block* const block : program.blocks) {
546 block->SetDefinition(OpLabel()); 575 block->SetDefinition(OpLabel());