diff options
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_spirv_special.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/spirv/emit_spirv_special.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_special.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_special.cpp new file mode 100644 index 000000000..70ae7b51e --- /dev/null +++ b/src/shader_recompiler/backend/spirv/emit_spirv_special.cpp | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "shader_recompiler/backend/spirv/emit_spirv.h" | ||
| 6 | |||
| 7 | namespace Shader::Backend::SPIRV { | ||
| 8 | |||
| 9 | void EmitPrologue(EmitContext& ctx) { | ||
| 10 | if (ctx.stage == Stage::VertexB) { | ||
| 11 | const Id zero{ctx.Constant(ctx.F32[1], 0.0f)}; | ||
| 12 | const Id one{ctx.Constant(ctx.F32[1], 1.0f)}; | ||
| 13 | const Id null_vector{ctx.ConstantComposite(ctx.F32[4], zero, zero, zero, zero)}; | ||
| 14 | ctx.OpStore(ctx.output_position, ctx.ConstantComposite(ctx.F32[4], zero, zero, zero, one)); | ||
| 15 | for (const Id generic_id : ctx.output_generics) { | ||
| 16 | if (Sirit::ValidId(generic_id)) { | ||
| 17 | ctx.OpStore(generic_id, null_vector); | ||
| 18 | } | ||
| 19 | } | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | void EmitEpilogue(EmitContext& ctx) { | ||
| 24 | if (ctx.profile.convert_depth_mode) { | ||
| 25 | const Id type{ctx.F32[1]}; | ||
| 26 | const Id position{ctx.OpLoad(ctx.F32[4], ctx.output_position)}; | ||
| 27 | const Id z{ctx.OpCompositeExtract(type, position, 2u)}; | ||
| 28 | const Id w{ctx.OpCompositeExtract(type, position, 3u)}; | ||
| 29 | const Id screen_depth{ctx.OpFMul(type, ctx.OpFAdd(type, z, w), ctx.Constant(type, 0.5f))}; | ||
| 30 | const Id vector{ctx.OpCompositeInsert(ctx.F32[4], screen_depth, position, 2u)}; | ||
| 31 | ctx.OpStore(ctx.output_position, vector); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | } // namespace Shader::Backend::SPIRV | ||