diff options
| author | 2021-03-24 01:33:45 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:24 -0400 | |
| commit | 68a9505d8a1d00c6ba2739bc0af3069cf87b9b84 (patch) | |
| tree | b9a78497cd8af1d73a7eda34cd0df08b3dc324e6 /src/shader_recompiler/backend/spirv/emit_context.cpp | |
| parent | shader: Fix use-after-free bug in object_pool (diff) | |
| download | yuzu-68a9505d8a1d00c6ba2739bc0af3069cf87b9b84.tar.gz yuzu-68a9505d8a1d00c6ba2739bc0af3069cf87b9b84.tar.xz yuzu-68a9505d8a1d00c6ba2739bc0af3069cf87b9b84.zip | |
shader: Implement NDC [-1, 1], attribute types and default varying initialization
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_context.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/spirv/emit_context.cpp | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp index 36f130781..ea46af244 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/emit_context.cpp | |||
| @@ -67,6 +67,18 @@ Id DefineInput(EmitContext& ctx, Id type, std::optional<spv::BuiltIn> builtin = | |||
| 67 | Id DefineOutput(EmitContext& ctx, Id type, std::optional<spv::BuiltIn> builtin = std::nullopt) { | 67 | Id DefineOutput(EmitContext& ctx, Id type, std::optional<spv::BuiltIn> builtin = std::nullopt) { |
| 68 | return DefineVariable(ctx, type, builtin, spv::StorageClass::Output); | 68 | return DefineVariable(ctx, type, builtin, spv::StorageClass::Output); |
| 69 | } | 69 | } |
| 70 | |||
| 71 | Id GetAttributeType(EmitContext& ctx, AttributeType type) { | ||
| 72 | switch (type) { | ||
| 73 | case AttributeType::Float: | ||
| 74 | return ctx.F32[4]; | ||
| 75 | case AttributeType::SignedInt: | ||
| 76 | return ctx.TypeVector(ctx.TypeInt(32, true), 4); | ||
| 77 | case AttributeType::UnsignedInt: | ||
| 78 | return ctx.U32[4]; | ||
| 79 | } | ||
| 80 | throw InvalidArgument("Invalid attribute type {}", type); | ||
| 81 | } | ||
| 70 | } // Anonymous namespace | 82 | } // Anonymous namespace |
| 71 | 83 | ||
| 72 | void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) { | 84 | void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) { |
| @@ -82,11 +94,11 @@ void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_vie | |||
| 82 | } | 94 | } |
| 83 | 95 | ||
| 84 | EmitContext::EmitContext(const Profile& profile_, IR::Program& program, u32& binding) | 96 | EmitContext::EmitContext(const Profile& profile_, IR::Program& program, u32& binding) |
| 85 | : Sirit::Module(0x00010000), profile{profile_} { | 97 | : Sirit::Module(0x00010000), profile{profile_}, stage{program.stage} { |
| 86 | AddCapability(spv::Capability::Shader); | 98 | AddCapability(spv::Capability::Shader); |
| 87 | DefineCommonTypes(program.info); | 99 | DefineCommonTypes(program.info); |
| 88 | DefineCommonConstants(); | 100 | DefineCommonConstants(); |
| 89 | DefineInterfaces(program.info, program.stage); | 101 | DefineInterfaces(program.info); |
| 90 | DefineConstantBuffers(program.info, binding); | 102 | DefineConstantBuffers(program.info, binding); |
| 91 | DefineStorageBuffers(program.info, binding); | 103 | DefineStorageBuffers(program.info, binding); |
| 92 | DefineTextures(program.info, binding); | 104 | DefineTextures(program.info, binding); |
| @@ -130,6 +142,9 @@ void EmitContext::DefineCommonTypes(const Info& info) { | |||
| 130 | U32.Define(*this, TypeInt(32, false), "u32"); | 142 | U32.Define(*this, TypeInt(32, false), "u32"); |
| 131 | 143 | ||
| 132 | input_f32 = Name(TypePointer(spv::StorageClass::Input, F32[1]), "input_f32"); | 144 | input_f32 = Name(TypePointer(spv::StorageClass::Input, F32[1]), "input_f32"); |
| 145 | input_u32 = Name(TypePointer(spv::StorageClass::Input, U32[1]), "input_u32"); | ||
| 146 | input_s32 = Name(TypePointer(spv::StorageClass::Input, TypeInt(32, true)), "input_s32"); | ||
| 147 | |||
| 133 | output_f32 = Name(TypePointer(spv::StorageClass::Output, F32[1]), "output_f32"); | 148 | output_f32 = Name(TypePointer(spv::StorageClass::Output, F32[1]), "output_f32"); |
| 134 | 149 | ||
| 135 | if (info.uses_int8) { | 150 | if (info.uses_int8) { |
| @@ -162,9 +177,9 @@ void EmitContext::DefineCommonConstants() { | |||
| 162 | u32_zero_value = Constant(U32[1], 0U); | 177 | u32_zero_value = Constant(U32[1], 0U); |
| 163 | } | 178 | } |
| 164 | 179 | ||
| 165 | void EmitContext::DefineInterfaces(const Info& info, Stage stage) { | 180 | void EmitContext::DefineInterfaces(const Info& info) { |
| 166 | DefineInputs(info, stage); | 181 | DefineInputs(info); |
| 167 | DefineOutputs(info, stage); | 182 | DefineOutputs(info); |
| 168 | } | 183 | } |
| 169 | 184 | ||
| 170 | void EmitContext::DefineConstantBuffers(const Info& info, u32& binding) { | 185 | void EmitContext::DefineConstantBuffers(const Info& info, u32& binding) { |
| @@ -252,7 +267,7 @@ void EmitContext::DefineLabels(IR::Program& program) { | |||
| 252 | } | 267 | } |
| 253 | } | 268 | } |
| 254 | 269 | ||
| 255 | void EmitContext::DefineInputs(const Info& info, Stage stage) { | 270 | void EmitContext::DefineInputs(const Info& info) { |
| 256 | if (info.uses_workgroup_id) { | 271 | if (info.uses_workgroup_id) { |
| 257 | workgroup_id = DefineInput(*this, U32[3], spv::BuiltIn::WorkgroupId); | 272 | workgroup_id = DefineInput(*this, U32[3], spv::BuiltIn::WorkgroupId); |
| 258 | } | 273 | } |
| @@ -288,8 +303,8 @@ void EmitContext::DefineInputs(const Info& info, Stage stage) { | |||
| 288 | if (!info.loads_generics[index]) { | 303 | if (!info.loads_generics[index]) { |
| 289 | continue; | 304 | continue; |
| 290 | } | 305 | } |
| 291 | // FIXME: Declare size from input | 306 | const Id type{GetAttributeType(*this, profile.generic_input_types[index])}; |
| 292 | const Id id{DefineInput(*this, F32[4])}; | 307 | const Id id{DefineInput(*this, type)}; |
| 293 | Decorate(id, spv::Decoration::Location, static_cast<u32>(index)); | 308 | Decorate(id, spv::Decoration::Location, static_cast<u32>(index)); |
| 294 | Name(id, fmt::format("in_attr{}", index)); | 309 | Name(id, fmt::format("in_attr{}", index)); |
| 295 | input_generics[index] = id; | 310 | input_generics[index] = id; |
| @@ -323,8 +338,8 @@ void EmitContext::DefineConstantBuffers(const Info& info, Id UniformDefinitions: | |||
| 323 | } | 338 | } |
| 324 | } | 339 | } |
| 325 | 340 | ||
| 326 | void EmitContext::DefineOutputs(const Info& info, Stage stage) { | 341 | void EmitContext::DefineOutputs(const Info& info) { |
| 327 | if (info.stores_position) { | 342 | if (info.stores_position || stage == Stage::VertexB) { |
| 328 | output_position = DefineOutput(*this, F32[4], spv::BuiltIn::Position); | 343 | output_position = DefineOutput(*this, F32[4], spv::BuiltIn::Position); |
| 329 | } | 344 | } |
| 330 | for (size_t i = 0; i < info.stores_generics.size(); ++i) { | 345 | for (size_t i = 0; i < info.stores_generics.size(); ++i) { |