diff options
| author | 2021-04-03 01:48:39 +0200 | |
|---|---|---|
| committer | 2021-07-22 21:51:26 -0400 | |
| commit | baec84247fe815199595d9e8077b71f3b5c8317e (patch) | |
| tree | 84195625ffb43922ba87b25296057bdeb9f22a2c /src/shader_recompiler/backend | |
| parent | shader: Implement SR_LaneId (diff) | |
| download | yuzu-baec84247fe815199595d9e8077b71f3b5c8317e.tar.gz yuzu-baec84247fe815199595d9e8077b71f3b5c8317e.tar.xz yuzu-baec84247fe815199595d9e8077b71f3b5c8317e.zip | |
shader: Address Feedback
Diffstat (limited to 'src/shader_recompiler/backend')
6 files changed, 26 insertions, 71 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp index 794cd4ed8..32f679f2a 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/emit_context.cpp | |||
| @@ -510,7 +510,8 @@ void EmitContext::DefineOutputs(const Info& info) { | |||
| 510 | const Id type{TypeArray(F32[1], Constant(U32[1], 8U))}; | 510 | const Id type{TypeArray(F32[1], Constant(U32[1], 8U))}; |
| 511 | clip_distances = DefineOutput(*this, type, spv::BuiltIn::ClipDistance); | 511 | clip_distances = DefineOutput(*this, type, spv::BuiltIn::ClipDistance); |
| 512 | } | 512 | } |
| 513 | if (info.stores_viewport_index && !ignore_viewport_layer) { | 513 | if (info.stores_viewport_index && |
| 514 | (profile.support_viewport_index_layer_non_geometry || stage == Shader::Stage::Geometry)) { | ||
| 514 | if (stage == Stage::Fragment) { | 515 | if (stage == Stage::Fragment) { |
| 515 | throw NotImplementedException("Storing ViewportIndex in Fragment stage"); | 516 | throw NotImplementedException("Storing ViewportIndex in Fragment stage"); |
| 516 | } | 517 | } |
diff --git a/src/shader_recompiler/backend/spirv/emit_context.h b/src/shader_recompiler/backend/spirv/emit_context.h index 1573c2560..f4715a709 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.h +++ b/src/shader_recompiler/backend/spirv/emit_context.h | |||
| @@ -134,8 +134,6 @@ public: | |||
| 134 | 134 | ||
| 135 | std::vector<Id> interfaces; | 135 | std::vector<Id> interfaces; |
| 136 | 136 | ||
| 137 | bool ignore_viewport_layer{}; | ||
| 138 | |||
| 139 | private: | 137 | private: |
| 140 | void DefineCommonTypes(const Info& info); | 138 | void DefineCommonTypes(const Info& info); |
| 141 | void DefineCommonConstants(); | 139 | void DefineCommonConstants(); |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv.cpp b/src/shader_recompiler/backend/spirv/emit_spirv.cpp index cc6b98f7e..191380db0 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv.cpp | |||
| @@ -228,11 +228,9 @@ void SetupCapabilities(const Profile& profile, const Info& info, EmitContext& ct | |||
| 228 | if (info.stores_viewport_index) { | 228 | if (info.stores_viewport_index) { |
| 229 | ctx.AddCapability(spv::Capability::MultiViewport); | 229 | ctx.AddCapability(spv::Capability::MultiViewport); |
| 230 | if (profile.support_viewport_index_layer_non_geometry && | 230 | if (profile.support_viewport_index_layer_non_geometry && |
| 231 | ctx.stage == Shader::Stage::VertexB) { | 231 | ctx.stage != Shader::Stage::Geometry) { |
| 232 | ctx.AddExtension("SPV_EXT_shader_viewport_index_layer"); | 232 | ctx.AddExtension("SPV_EXT_shader_viewport_index_layer"); |
| 233 | ctx.AddCapability(spv::Capability::ShaderViewportIndexLayerEXT); | 233 | ctx.AddCapability(spv::Capability::ShaderViewportIndexLayerEXT); |
| 234 | } else { | ||
| 235 | ctx.ignore_viewport_layer = true; | ||
| 236 | } | 234 | } |
| 237 | } | 235 | } |
| 238 | if (!profile.support_vertex_instance_id && (info.loads_instance_id || info.loads_vertex_id)) { | 236 | if (!profile.support_vertex_instance_id && (info.loads_instance_id || info.loads_vertex_id)) { |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv.h b/src/shader_recompiler/backend/spirv/emit_spirv.h index 17a452e0e..5d0f16b3a 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv.h +++ b/src/shader_recompiler/backend/spirv/emit_spirv.h | |||
| @@ -28,7 +28,9 @@ void EmitSelectionMerge(EmitContext& ctx, Id merge_label); | |||
| 28 | void EmitReturn(EmitContext& ctx); | 28 | void EmitReturn(EmitContext& ctx); |
| 29 | void EmitUnreachable(EmitContext& ctx); | 29 | void EmitUnreachable(EmitContext& ctx); |
| 30 | void EmitDemoteToHelperInvocation(EmitContext& ctx, Id continue_label); | 30 | void EmitDemoteToHelperInvocation(EmitContext& ctx, Id continue_label); |
| 31 | void EmitMemoryBarrier(EmitContext& ctx, IR::Inst* inst); | 31 | void EmitMemoryBarrierWorkgroupLevel(EmitContext& ctx); |
| 32 | void EmitMemoryBarrierDeviceLevel(EmitContext& ctx); | ||
| 33 | void EmitMemoryBarrierSystemLevel(EmitContext& ctx); | ||
| 32 | void EmitPrologue(EmitContext& ctx); | 34 | void EmitPrologue(EmitContext& ctx); |
| 33 | void EmitEpilogue(EmitContext& ctx); | 35 | void EmitEpilogue(EmitContext& ctx); |
| 34 | void EmitGetRegister(EmitContext& ctx); | 36 | void EmitGetRegister(EmitContext& ctx); |
| @@ -60,14 +62,6 @@ void EmitSetZFlag(EmitContext& ctx); | |||
| 60 | void EmitSetSFlag(EmitContext& ctx); | 62 | void EmitSetSFlag(EmitContext& ctx); |
| 61 | void EmitSetCFlag(EmitContext& ctx); | 63 | void EmitSetCFlag(EmitContext& ctx); |
| 62 | void EmitSetOFlag(EmitContext& ctx); | 64 | void EmitSetOFlag(EmitContext& ctx); |
| 63 | void EmitGetFCSMFlag(EmitContext& ctx); | ||
| 64 | void EmitGetTAFlag(EmitContext& ctx); | ||
| 65 | void EmitGetTRFlag(EmitContext& ctx); | ||
| 66 | void EmitGetMXFlag(EmitContext& ctx); | ||
| 67 | void EmitSetFCSMFlag(EmitContext& ctx); | ||
| 68 | void EmitSetTAFlag(EmitContext& ctx); | ||
| 69 | void EmitSetTRFlag(EmitContext& ctx); | ||
| 70 | void EmitSetMXFlag(EmitContext& ctx); | ||
| 71 | Id EmitWorkgroupId(EmitContext& ctx); | 65 | Id EmitWorkgroupId(EmitContext& ctx); |
| 72 | Id EmitLocalInvocationId(EmitContext& ctx); | 66 | Id EmitLocalInvocationId(EmitContext& ctx); |
| 73 | Id EmitLoadLocal(EmitContext& ctx, Id word_offset); | 67 | Id EmitLoadLocal(EmitContext& ctx, Id word_offset); |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_barriers.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_barriers.cpp index 413ac25a0..18f512319 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_barriers.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_barriers.cpp | |||
| @@ -7,34 +7,27 @@ | |||
| 7 | 7 | ||
| 8 | namespace Shader::Backend::SPIRV { | 8 | namespace Shader::Backend::SPIRV { |
| 9 | namespace { | 9 | namespace { |
| 10 | spv::Scope MemoryScopeToSpirVScope(IR::MemoryScope scope) { | 10 | void EmitMemoryBarrierImpl(EmitContext& ctx, spv::Scope scope) { |
| 11 | switch (scope) { | ||
| 12 | case IR::MemoryScope::Warp: | ||
| 13 | return spv::Scope::Subgroup; | ||
| 14 | case IR::MemoryScope::Workgroup: | ||
| 15 | return spv::Scope::Workgroup; | ||
| 16 | case IR::MemoryScope::Device: | ||
| 17 | return spv::Scope::Device; | ||
| 18 | case IR::MemoryScope::System: | ||
| 19 | return spv::Scope::CrossDevice; | ||
| 20 | case IR::MemoryScope::DontCare: | ||
| 21 | return spv::Scope::Invocation; | ||
| 22 | default: | ||
| 23 | throw NotImplementedException("Unknown memory scope!"); | ||
| 24 | } | ||
| 25 | } | ||
| 26 | |||
| 27 | } // namespace | ||
| 28 | |||
| 29 | void EmitMemoryBarrier(EmitContext& ctx, IR::Inst* inst) { | ||
| 30 | const auto info{inst->Flags<IR::BarrierInstInfo>()}; | ||
| 31 | const auto semantics = | 11 | const auto semantics = |
| 32 | spv::MemorySemanticsMask::AcquireRelease | spv::MemorySemanticsMask::UniformMemory | | 12 | spv::MemorySemanticsMask::AcquireRelease | spv::MemorySemanticsMask::UniformMemory | |
| 33 | spv::MemorySemanticsMask::WorkgroupMemory | spv::MemorySemanticsMask::AtomicCounterMemory | | 13 | spv::MemorySemanticsMask::WorkgroupMemory | spv::MemorySemanticsMask::AtomicCounterMemory | |
| 34 | spv::MemorySemanticsMask::ImageMemory; | 14 | spv::MemorySemanticsMask::ImageMemory; |
| 35 | const auto scope = MemoryScopeToSpirVScope(info.scope); | ||
| 36 | ctx.OpMemoryBarrier(ctx.Constant(ctx.U32[1], static_cast<u32>(scope)), | 15 | ctx.OpMemoryBarrier(ctx.Constant(ctx.U32[1], static_cast<u32>(scope)), |
| 37 | ctx.Constant(ctx.U32[1], static_cast<u32>(semantics))); | 16 | ctx.Constant(ctx.U32[1], static_cast<u32>(semantics))); |
| 38 | } | 17 | } |
| 39 | 18 | ||
| 19 | } // Anonymous namespace | ||
| 20 | |||
| 21 | void EmitMemoryBarrierWorkgroupLevel(EmitContext& ctx) { | ||
| 22 | EmitMemoryBarrierImpl(ctx, spv::Scope::Workgroup); | ||
| 23 | } | ||
| 24 | |||
| 25 | void EmitMemoryBarrierDeviceLevel(EmitContext& ctx) { | ||
| 26 | EmitMemoryBarrierImpl(ctx, spv::Scope::Device); | ||
| 27 | } | ||
| 28 | |||
| 29 | void EmitMemoryBarrierSystemLevel(EmitContext& ctx) { | ||
| 30 | EmitMemoryBarrierImpl(ctx, spv::Scope::CrossDevice); | ||
| 31 | } | ||
| 32 | |||
| 40 | } // namespace Shader::Backend::SPIRV | 33 | } // namespace Shader::Backend::SPIRV |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp index f13c0ee72..caab9aa12 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp | |||
| @@ -58,7 +58,10 @@ std::optional<Id> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) { | |||
| 58 | return ctx.OpAccessChain(ctx.output_f32, ctx.clip_distances, clip_num); | 58 | return ctx.OpAccessChain(ctx.output_f32, ctx.clip_distances, clip_num); |
| 59 | } | 59 | } |
| 60 | case IR::Attribute::ViewportIndex: | 60 | case IR::Attribute::ViewportIndex: |
| 61 | return ctx.ignore_viewport_layer ? std::nullopt : std::optional<Id>{ctx.viewport_index}; | 61 | return (ctx.profile.support_viewport_index_layer_non_geometry || |
| 62 | ctx.stage == Shader::Stage::Geometry) | ||
| 63 | ? std::optional<Id>{ctx.viewport_index} | ||
| 64 | : std::nullopt; | ||
| 62 | default: | 65 | default: |
| 63 | throw NotImplementedException("Read attribute {}", attr); | 66 | throw NotImplementedException("Read attribute {}", attr); |
| 64 | } | 67 | } |
| @@ -206,7 +209,7 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr) { | |||
| 206 | } | 209 | } |
| 207 | 210 | ||
| 208 | void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, Id value) { | 211 | void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, Id value) { |
| 209 | auto output = OutputAttrPointer(ctx, attr); | 212 | const std::optional<Id> output{OutputAttrPointer(ctx, attr)}; |
| 210 | if (!output) { | 213 | if (!output) { |
| 211 | return; | 214 | return; |
| 212 | } | 215 | } |
| @@ -263,38 +266,6 @@ void EmitSetOFlag(EmitContext&) { | |||
| 263 | throw NotImplementedException("SPIR-V Instruction"); | 266 | throw NotImplementedException("SPIR-V Instruction"); |
| 264 | } | 267 | } |
| 265 | 268 | ||
| 266 | void EmitGetFCSMFlag(EmitContext&) { | ||
| 267 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 268 | } | ||
| 269 | |||
| 270 | void EmitGetTAFlag(EmitContext&) { | ||
| 271 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 272 | } | ||
| 273 | |||
| 274 | void EmitGetTRFlag(EmitContext&) { | ||
| 275 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 276 | } | ||
| 277 | |||
| 278 | void EmitGetMXFlag(EmitContext&) { | ||
| 279 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 280 | } | ||
| 281 | |||
| 282 | void EmitSetFCSMFlag(EmitContext&) { | ||
| 283 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 284 | } | ||
| 285 | |||
| 286 | void EmitSetTAFlag(EmitContext&) { | ||
| 287 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 288 | } | ||
| 289 | |||
| 290 | void EmitSetTRFlag(EmitContext&) { | ||
| 291 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 292 | } | ||
| 293 | |||
| 294 | void EmitSetMXFlag(EmitContext&) { | ||
| 295 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 296 | } | ||
| 297 | |||
| 298 | Id EmitWorkgroupId(EmitContext& ctx) { | 269 | Id EmitWorkgroupId(EmitContext& ctx) { |
| 299 | return ctx.OpLoad(ctx.U32[3], ctx.workgroup_id); | 270 | return ctx.OpLoad(ctx.U32[3], ctx.workgroup_id); |
| 300 | } | 271 | } |