diff options
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_context.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/spirv/emit_context.cpp | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp index 770067d98..ea1c8a3be 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/emit_context.cpp | |||
| @@ -30,8 +30,11 @@ EmitContext::EmitContext(IR::Program& program) : Sirit::Module(0x00010000) { | |||
| 30 | DefineCommonTypes(program.info); | 30 | DefineCommonTypes(program.info); |
| 31 | DefineCommonConstants(); | 31 | DefineCommonConstants(); |
| 32 | DefineSpecialVariables(program.info); | 32 | DefineSpecialVariables(program.info); |
| 33 | DefineConstantBuffers(program.info); | 33 | |
| 34 | DefineStorageBuffers(program.info); | 34 | u32 binding{}; |
| 35 | DefineConstantBuffers(program.info, binding); | ||
| 36 | DefineStorageBuffers(program.info, binding); | ||
| 37 | |||
| 35 | DefineLabels(program); | 38 | DefineLabels(program); |
| 36 | } | 39 | } |
| 37 | 40 | ||
| @@ -58,6 +61,12 @@ void EmitContext::DefineCommonTypes(const Info& info) { | |||
| 58 | 61 | ||
| 59 | U1 = Name(TypeBool(), "u1"); | 62 | U1 = Name(TypeBool(), "u1"); |
| 60 | 63 | ||
| 64 | // TODO: Conditionally define these | ||
| 65 | AddCapability(spv::Capability::Int16); | ||
| 66 | AddCapability(spv::Capability::Int64); | ||
| 67 | U16 = Name(TypeInt(16, false), "u16"); | ||
| 68 | U64 = Name(TypeInt(64, false), "u64"); | ||
| 69 | |||
| 61 | F32.Define(*this, TypeFloat(32), "f32"); | 70 | F32.Define(*this, TypeFloat(32), "f32"); |
| 62 | U32.Define(*this, TypeInt(32, false), "u32"); | 71 | U32.Define(*this, TypeInt(32, false), "u32"); |
| 63 | 72 | ||
| @@ -95,12 +104,12 @@ void EmitContext::DefineSpecialVariables(const Info& info) { | |||
| 95 | } | 104 | } |
| 96 | } | 105 | } |
| 97 | 106 | ||
| 98 | void EmitContext::DefineConstantBuffers(const Info& info) { | 107 | void EmitContext::DefineConstantBuffers(const Info& info, u32& binding) { |
| 99 | if (info.constant_buffer_descriptors.empty()) { | 108 | if (info.constant_buffer_descriptors.empty()) { |
| 100 | return; | 109 | return; |
| 101 | } | 110 | } |
| 102 | const Id array_type{TypeArray(U32[1], Constant(U32[1], 4096))}; | 111 | const Id array_type{TypeArray(U32[1], Constant(U32[1], 4096))}; |
| 103 | Decorate(array_type, spv::Decoration::ArrayStride, 16U); | 112 | Decorate(array_type, spv::Decoration::ArrayStride, 4U); |
| 104 | 113 | ||
| 105 | const Id struct_type{TypeStruct(array_type)}; | 114 | const Id struct_type{TypeStruct(array_type)}; |
| 106 | Name(struct_type, "cbuf_block"); | 115 | Name(struct_type, "cbuf_block"); |
| @@ -111,18 +120,19 @@ void EmitContext::DefineConstantBuffers(const Info& info) { | |||
| 111 | const Id uniform_type{TypePointer(spv::StorageClass::Uniform, struct_type)}; | 120 | const Id uniform_type{TypePointer(spv::StorageClass::Uniform, struct_type)}; |
| 112 | uniform_u32 = TypePointer(spv::StorageClass::Uniform, U32[1]); | 121 | uniform_u32 = TypePointer(spv::StorageClass::Uniform, U32[1]); |
| 113 | 122 | ||
| 114 | u32 binding{}; | 123 | u32 index{}; |
| 115 | for (const Info::ConstantBufferDescriptor& desc : info.constant_buffer_descriptors) { | 124 | for (const Info::ConstantBufferDescriptor& desc : info.constant_buffer_descriptors) { |
| 116 | const Id id{AddGlobalVariable(uniform_type, spv::StorageClass::Uniform)}; | 125 | const Id id{AddGlobalVariable(uniform_type, spv::StorageClass::Uniform)}; |
| 117 | Decorate(id, spv::Decoration::Binding, binding); | 126 | Decorate(id, spv::Decoration::Binding, binding); |
| 118 | Decorate(id, spv::Decoration::DescriptorSet, 0U); | 127 | Decorate(id, spv::Decoration::DescriptorSet, 0U); |
| 119 | Name(id, fmt::format("c{}", desc.index)); | 128 | Name(id, fmt::format("c{}", desc.index)); |
| 120 | std::fill_n(cbufs.data() + desc.index, desc.count, id); | 129 | std::fill_n(cbufs.data() + desc.index, desc.count, id); |
| 130 | index += desc.count; | ||
| 121 | binding += desc.count; | 131 | binding += desc.count; |
| 122 | } | 132 | } |
| 123 | } | 133 | } |
| 124 | 134 | ||
| 125 | void EmitContext::DefineStorageBuffers(const Info& info) { | 135 | void EmitContext::DefineStorageBuffers(const Info& info, u32& binding) { |
| 126 | if (info.storage_buffers_descriptors.empty()) { | 136 | if (info.storage_buffers_descriptors.empty()) { |
| 127 | return; | 137 | return; |
| 128 | } | 138 | } |
| @@ -140,13 +150,14 @@ void EmitContext::DefineStorageBuffers(const Info& info) { | |||
| 140 | const Id storage_type{TypePointer(spv::StorageClass::StorageBuffer, struct_type)}; | 150 | const Id storage_type{TypePointer(spv::StorageClass::StorageBuffer, struct_type)}; |
| 141 | storage_u32 = TypePointer(spv::StorageClass::StorageBuffer, U32[1]); | 151 | storage_u32 = TypePointer(spv::StorageClass::StorageBuffer, U32[1]); |
| 142 | 152 | ||
| 143 | u32 binding{}; | 153 | u32 index{}; |
| 144 | for (const Info::StorageBufferDescriptor& desc : info.storage_buffers_descriptors) { | 154 | for (const Info::StorageBufferDescriptor& desc : info.storage_buffers_descriptors) { |
| 145 | const Id id{AddGlobalVariable(storage_type, spv::StorageClass::StorageBuffer)}; | 155 | const Id id{AddGlobalVariable(storage_type, spv::StorageClass::StorageBuffer)}; |
| 146 | Decorate(id, spv::Decoration::Binding, binding); | 156 | Decorate(id, spv::Decoration::Binding, binding); |
| 147 | Decorate(id, spv::Decoration::DescriptorSet, 0U); | 157 | Decorate(id, spv::Decoration::DescriptorSet, 0U); |
| 148 | Name(id, fmt::format("ssbo{}", binding)); | 158 | Name(id, fmt::format("ssbo{}", index)); |
| 149 | std::fill_n(ssbos.data() + binding, desc.count, id); | 159 | std::fill_n(ssbos.data() + index, desc.count, id); |
| 160 | index += desc.count; | ||
| 150 | binding += desc.count; | 161 | binding += desc.count; |
| 151 | } | 162 | } |
| 152 | } | 163 | } |