diff options
Diffstat (limited to 'src/shader_recompiler/backend')
15 files changed, 131 insertions, 2 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm.cpp b/src/shader_recompiler/backend/glasm/emit_glasm.cpp index 01f9abc71..3b0176bf6 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm.cpp | |||
| @@ -450,6 +450,9 @@ std::string EmitGLASM(const Profile& profile, const RuntimeInfo& runtime_info, I | |||
| 450 | if (program.info.uses_rescaling_uniform) { | 450 | if (program.info.uses_rescaling_uniform) { |
| 451 | header += "PARAM scaling[1]={program.local[0..0]};"; | 451 | header += "PARAM scaling[1]={program.local[0..0]};"; |
| 452 | } | 452 | } |
| 453 | if (program.info.uses_render_area) { | ||
| 454 | header += "PARAM render_area[1]={program.local[1..1]};"; | ||
| 455 | } | ||
| 453 | header += "TEMP "; | 456 | header += "TEMP "; |
| 454 | for (size_t index = 0; index < ctx.reg_alloc.NumUsedRegisters(); ++index) { | 457 | for (size_t index = 0; index < ctx.reg_alloc.NumUsedRegisters(); ++index) { |
| 455 | header += fmt::format("R{},", index); | 458 | header += fmt::format("R{},", index); |
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_bitwise_conversion.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_bitwise_conversion.cpp index 2fc2a0ac6..5bfdecc09 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_bitwise_conversion.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_bitwise_conversion.cpp | |||
| @@ -43,6 +43,10 @@ void EmitBitCastU64F64(EmitContext&, IR::Inst& inst, const IR::Value& value) { | |||
| 43 | Alias(inst, value); | 43 | Alias(inst, value); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | void EmitBitCastS32F32(EmitContext&, IR::Inst& inst, const IR::Value& value) { | ||
| 47 | Alias(inst, value); | ||
| 48 | } | ||
| 49 | |||
| 46 | void EmitBitCastF16U16(EmitContext&, IR::Inst& inst, const IR::Value& value) { | 50 | void EmitBitCastF16U16(EmitContext&, IR::Inst& inst, const IR::Value& value) { |
| 47 | Alias(inst, value); | 51 | Alias(inst, value); |
| 48 | } | 52 | } |
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp index 7e8f37563..d6562c842 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp | |||
| @@ -379,6 +379,18 @@ void EmitInvocationId(EmitContext& ctx, IR::Inst& inst) { | |||
| 379 | ctx.Add("MOV.S {}.x,primitive_invocation.x;", inst); | 379 | ctx.Add("MOV.S {}.x,primitive_invocation.x;", inst); |
| 380 | } | 380 | } |
| 381 | 381 | ||
| 382 | void EmitInvocationInfo(EmitContext& ctx, IR::Inst& inst) { | ||
| 383 | switch (ctx.stage) { | ||
| 384 | case Stage::TessellationControl: | ||
| 385 | case Stage::TessellationEval: | ||
| 386 | ctx.Add("SHL.U {}.x,primitive.vertexcount,16;", inst); | ||
| 387 | break; | ||
| 388 | default: | ||
| 389 | LOG_WARNING(Shader, "(STUBBED) called"); | ||
| 390 | ctx.Add("MOV.S {}.x,0x00ff0000;", inst); | ||
| 391 | } | ||
| 392 | } | ||
| 393 | |||
| 382 | void EmitSampleId(EmitContext& ctx, IR::Inst& inst) { | 394 | void EmitSampleId(EmitContext& ctx, IR::Inst& inst) { |
| 383 | ctx.Add("MOV.S {}.x,fragment.sampleid.x;", inst); | 395 | ctx.Add("MOV.S {}.x,fragment.sampleid.x;", inst); |
| 384 | } | 396 | } |
| @@ -396,6 +408,10 @@ void EmitResolutionDownFactor(EmitContext& ctx, IR::Inst& inst) { | |||
| 396 | ctx.Add("MOV.F {}.x,scaling[0].z;", inst); | 408 | ctx.Add("MOV.F {}.x,scaling[0].z;", inst); |
| 397 | } | 409 | } |
| 398 | 410 | ||
| 411 | void EmitRenderArea(EmitContext& ctx, IR::Inst& inst) { | ||
| 412 | ctx.Add("MOV.F {},render_area[0];", inst); | ||
| 413 | } | ||
| 414 | |||
| 399 | void EmitLoadLocal(EmitContext& ctx, IR::Inst& inst, ScalarU32 word_offset) { | 415 | void EmitLoadLocal(EmitContext& ctx, IR::Inst& inst, ScalarU32 word_offset) { |
| 400 | ctx.Add("MOV.U {},lmem[{}].x;", inst, word_offset); | 416 | ctx.Add("MOV.U {},lmem[{}].x;", inst, word_offset); |
| 401 | } | 417 | } |
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h b/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h index 8b0ac3031..eaaf9ba39 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h +++ b/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h | |||
| @@ -69,10 +69,12 @@ void EmitSetOFlag(EmitContext& ctx); | |||
| 69 | void EmitWorkgroupId(EmitContext& ctx, IR::Inst& inst); | 69 | void EmitWorkgroupId(EmitContext& ctx, IR::Inst& inst); |
| 70 | void EmitLocalInvocationId(EmitContext& ctx, IR::Inst& inst); | 70 | void EmitLocalInvocationId(EmitContext& ctx, IR::Inst& inst); |
| 71 | void EmitInvocationId(EmitContext& ctx, IR::Inst& inst); | 71 | void EmitInvocationId(EmitContext& ctx, IR::Inst& inst); |
| 72 | void EmitInvocationInfo(EmitContext& ctx, IR::Inst& inst); | ||
| 72 | void EmitSampleId(EmitContext& ctx, IR::Inst& inst); | 73 | void EmitSampleId(EmitContext& ctx, IR::Inst& inst); |
| 73 | void EmitIsHelperInvocation(EmitContext& ctx, IR::Inst& inst); | 74 | void EmitIsHelperInvocation(EmitContext& ctx, IR::Inst& inst); |
| 74 | void EmitYDirection(EmitContext& ctx, IR::Inst& inst); | 75 | void EmitYDirection(EmitContext& ctx, IR::Inst& inst); |
| 75 | void EmitResolutionDownFactor(EmitContext& ctx, IR::Inst& inst); | 76 | void EmitResolutionDownFactor(EmitContext& ctx, IR::Inst& inst); |
| 77 | void EmitRenderArea(EmitContext& ctx, IR::Inst& inst); | ||
| 76 | void EmitLoadLocal(EmitContext& ctx, IR::Inst& inst, ScalarU32 word_offset); | 78 | void EmitLoadLocal(EmitContext& ctx, IR::Inst& inst, ScalarU32 word_offset); |
| 77 | void EmitWriteLocal(EmitContext& ctx, ScalarU32 word_offset, ScalarU32 value); | 79 | void EmitWriteLocal(EmitContext& ctx, ScalarU32 word_offset, ScalarU32 value); |
| 78 | void EmitUndefU1(EmitContext& ctx, IR::Inst& inst); | 80 | void EmitUndefU1(EmitContext& ctx, IR::Inst& inst); |
| @@ -195,6 +197,7 @@ void EmitSelectF64(EmitContext& ctx, ScalarS32 cond, Register true_value, Regist | |||
| 195 | void EmitBitCastU16F16(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 197 | void EmitBitCastU16F16(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
| 196 | void EmitBitCastU32F32(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 198 | void EmitBitCastU32F32(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
| 197 | void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 199 | void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
| 200 | void EmitBitCastS32F32(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | ||
| 198 | void EmitBitCastF16U16(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 201 | void EmitBitCastF16U16(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
| 199 | void EmitBitCastF32U32(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 202 | void EmitBitCastF32U32(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
| 200 | void EmitBitCastF64U64(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 203 | void EmitBitCastF64U64(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
diff --git a/src/shader_recompiler/backend/glasm/glasm_emit_context.cpp b/src/shader_recompiler/backend/glasm/glasm_emit_context.cpp index 89603c1c4..333a91cc5 100644 --- a/src/shader_recompiler/backend/glasm/glasm_emit_context.cpp +++ b/src/shader_recompiler/backend/glasm/glasm_emit_context.cpp | |||
| @@ -95,6 +95,10 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile | |||
| 95 | if (info.uses_invocation_id) { | 95 | if (info.uses_invocation_id) { |
| 96 | Add("ATTRIB primitive_invocation=primitive.invocation;"); | 96 | Add("ATTRIB primitive_invocation=primitive.invocation;"); |
| 97 | } | 97 | } |
| 98 | if (info.uses_invocation_info && | ||
| 99 | (stage == Stage::TessellationControl || stage == Stage::TessellationEval)) { | ||
| 100 | Add("ATTRIB primitive_vertexcount = primitive.vertexcount;"); | ||
| 101 | } | ||
| 98 | if (info.stores_tess_level_outer) { | 102 | if (info.stores_tess_level_outer) { |
| 99 | Add("OUTPUT result_patch_tessouter[]={{result.patch.tessouter[0..3]}};"); | 103 | Add("OUTPUT result_patch_tessouter[]={{result.patch.tessouter[0..3]}};"); |
| 100 | } | 104 | } |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp index 1be4a0f59..8e5e6cf1f 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp | |||
| @@ -48,6 +48,10 @@ void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value) | |||
| 48 | ctx.AddU64("{}=doubleBitsToUint64({});", inst, value); | 48 | ctx.AddU64("{}=doubleBitsToUint64({});", inst, value); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | void EmitBitCastS32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value) { | ||
| 52 | ctx.AddF32("{}=ftoi({});", inst, value); | ||
| 53 | } | ||
| 54 | |||
| 51 | void EmitBitCastF16U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst) { | 55 | void EmitBitCastF16U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst) { |
| 52 | NotImplemented(); | 56 | NotImplemented(); |
| 53 | } | 57 | } |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp index fad8d1e30..c1671c37b 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp | |||
| @@ -399,6 +399,18 @@ void EmitInvocationId(EmitContext& ctx, IR::Inst& inst) { | |||
| 399 | ctx.AddU32("{}=uint(gl_InvocationID);", inst); | 399 | ctx.AddU32("{}=uint(gl_InvocationID);", inst); |
| 400 | } | 400 | } |
| 401 | 401 | ||
| 402 | void EmitInvocationInfo(EmitContext& ctx, IR::Inst& inst) { | ||
| 403 | switch (ctx.stage) { | ||
| 404 | case Stage::TessellationControl: | ||
| 405 | case Stage::TessellationEval: | ||
| 406 | ctx.AddU32("{}=uint(gl_PatchVerticesIn)<<16;", inst); | ||
| 407 | break; | ||
| 408 | default: | ||
| 409 | LOG_WARNING(Shader, "(STUBBED) called"); | ||
| 410 | ctx.AddU32("{}=uint(0x00ff0000);", inst); | ||
| 411 | } | ||
| 412 | } | ||
| 413 | |||
| 402 | void EmitSampleId(EmitContext& ctx, IR::Inst& inst) { | 414 | void EmitSampleId(EmitContext& ctx, IR::Inst& inst) { |
| 403 | ctx.AddU32("{}=uint(gl_SampleID);", inst); | 415 | ctx.AddU32("{}=uint(gl_SampleID);", inst); |
| 404 | } | 416 | } |
| @@ -416,6 +428,10 @@ void EmitResolutionDownFactor(EmitContext& ctx, IR::Inst& inst) { | |||
| 416 | ctx.AddF32("{}=scaling.z;", inst); | 428 | ctx.AddF32("{}=scaling.z;", inst); |
| 417 | } | 429 | } |
| 418 | 430 | ||
| 431 | void EmitRenderArea(EmitContext& ctx, IR::Inst& inst) { | ||
| 432 | ctx.AddF32x4("{}=render_area;", inst); | ||
| 433 | } | ||
| 434 | |||
| 419 | void EmitLoadLocal(EmitContext& ctx, IR::Inst& inst, std::string_view word_offset) { | 435 | void EmitLoadLocal(EmitContext& ctx, IR::Inst& inst, std::string_view word_offset) { |
| 420 | ctx.AddU32("{}=lmem[{}];", inst, word_offset); | 436 | ctx.AddU32("{}=lmem[{}];", inst, word_offset); |
| 421 | } | 437 | } |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h index 639691ba6..4151c89de 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h +++ b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h | |||
| @@ -83,10 +83,12 @@ void EmitSetOFlag(EmitContext& ctx); | |||
| 83 | void EmitWorkgroupId(EmitContext& ctx, IR::Inst& inst); | 83 | void EmitWorkgroupId(EmitContext& ctx, IR::Inst& inst); |
| 84 | void EmitLocalInvocationId(EmitContext& ctx, IR::Inst& inst); | 84 | void EmitLocalInvocationId(EmitContext& ctx, IR::Inst& inst); |
| 85 | void EmitInvocationId(EmitContext& ctx, IR::Inst& inst); | 85 | void EmitInvocationId(EmitContext& ctx, IR::Inst& inst); |
| 86 | void EmitInvocationInfo(EmitContext& ctx, IR::Inst& inst); | ||
| 86 | void EmitSampleId(EmitContext& ctx, IR::Inst& inst); | 87 | void EmitSampleId(EmitContext& ctx, IR::Inst& inst); |
| 87 | void EmitIsHelperInvocation(EmitContext& ctx, IR::Inst& inst); | 88 | void EmitIsHelperInvocation(EmitContext& ctx, IR::Inst& inst); |
| 88 | void EmitYDirection(EmitContext& ctx, IR::Inst& inst); | 89 | void EmitYDirection(EmitContext& ctx, IR::Inst& inst); |
| 89 | void EmitResolutionDownFactor(EmitContext& ctx, IR::Inst& inst); | 90 | void EmitResolutionDownFactor(EmitContext& ctx, IR::Inst& inst); |
| 91 | void EmitRenderArea(EmitContext& ctx, IR::Inst& inst); | ||
| 90 | void EmitLoadLocal(EmitContext& ctx, IR::Inst& inst, std::string_view word_offset); | 92 | void EmitLoadLocal(EmitContext& ctx, IR::Inst& inst, std::string_view word_offset); |
| 91 | void EmitWriteLocal(EmitContext& ctx, std::string_view word_offset, std::string_view value); | 93 | void EmitWriteLocal(EmitContext& ctx, std::string_view word_offset, std::string_view value); |
| 92 | void EmitUndefU1(EmitContext& ctx, IR::Inst& inst); | 94 | void EmitUndefU1(EmitContext& ctx, IR::Inst& inst); |
| @@ -229,6 +231,7 @@ void EmitSelectF64(EmitContext& ctx, IR::Inst& inst, std::string_view cond, | |||
| 229 | void EmitBitCastU16F16(EmitContext& ctx, IR::Inst& inst); | 231 | void EmitBitCastU16F16(EmitContext& ctx, IR::Inst& inst); |
| 230 | void EmitBitCastU32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value); | 232 | void EmitBitCastU32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value); |
| 231 | void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value); | 233 | void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value); |
| 234 | void EmitBitCastS32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value); | ||
| 232 | void EmitBitCastF16U16(EmitContext& ctx, IR::Inst& inst); | 235 | void EmitBitCastF16U16(EmitContext& ctx, IR::Inst& inst); |
| 233 | void EmitBitCastF32U32(EmitContext& ctx, IR::Inst& inst, std::string_view value); | 236 | void EmitBitCastF32U32(EmitContext& ctx, IR::Inst& inst, std::string_view value); |
| 234 | void EmitBitCastF64U64(EmitContext& ctx, IR::Inst& inst, std::string_view value); | 237 | void EmitBitCastF64U64(EmitContext& ctx, IR::Inst& inst, std::string_view value); |
diff --git a/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp b/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp index c767a9dc3..5d01ec0cd 100644 --- a/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp | |||
| @@ -358,6 +358,9 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile | |||
| 358 | if (info.uses_rescaling_uniform) { | 358 | if (info.uses_rescaling_uniform) { |
| 359 | header += "layout(location=0) uniform vec4 scaling;"; | 359 | header += "layout(location=0) uniform vec4 scaling;"; |
| 360 | } | 360 | } |
| 361 | if (info.uses_render_area) { | ||
| 362 | header += "layout(location=1) uniform vec4 render_area;"; | ||
| 363 | } | ||
| 361 | DefineConstantBuffers(bindings); | 364 | DefineConstantBuffers(bindings); |
| 362 | DefineConstantBufferIndirect(); | 365 | DefineConstantBufferIndirect(); |
| 363 | DefineStorageBuffers(bindings); | 366 | DefineStorageBuffers(bindings); |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv.h b/src/shader_recompiler/backend/spirv/emit_spirv.h index 7567b6fc9..937881484 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv.h +++ b/src/shader_recompiler/backend/spirv/emit_spirv.h | |||
| @@ -23,8 +23,12 @@ struct RescalingLayout { | |||
| 23 | alignas(16) std::array<u32, NUM_IMAGE_SCALING_WORDS> rescaling_images; | 23 | alignas(16) std::array<u32, NUM_IMAGE_SCALING_WORDS> rescaling_images; |
| 24 | u32 down_factor; | 24 | u32 down_factor; |
| 25 | }; | 25 | }; |
| 26 | struct RenderAreaLayout { | ||
| 27 | std::array<f32, 4> render_area; | ||
| 28 | }; | ||
| 26 | constexpr u32 RESCALING_LAYOUT_WORDS_OFFSET = offsetof(RescalingLayout, rescaling_textures); | 29 | constexpr u32 RESCALING_LAYOUT_WORDS_OFFSET = offsetof(RescalingLayout, rescaling_textures); |
| 27 | constexpr u32 RESCALING_LAYOUT_DOWN_FACTOR_OFFSET = offsetof(RescalingLayout, down_factor); | 30 | constexpr u32 RESCALING_LAYOUT_DOWN_FACTOR_OFFSET = offsetof(RescalingLayout, down_factor); |
| 31 | constexpr u32 RENDERAREA_LAYOUT_OFFSET = offsetof(RenderAreaLayout, render_area); | ||
| 28 | 32 | ||
| 29 | [[nodiscard]] std::vector<u32> EmitSPIRV(const Profile& profile, const RuntimeInfo& runtime_info, | 33 | [[nodiscard]] std::vector<u32> EmitSPIRV(const Profile& profile, const RuntimeInfo& runtime_info, |
| 30 | IR::Program& program, Bindings& bindings); | 34 | IR::Program& program, Bindings& bindings); |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_bitwise_conversion.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_bitwise_conversion.cpp index c4ca28d11..50daacd95 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_bitwise_conversion.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_bitwise_conversion.cpp | |||
| @@ -18,6 +18,10 @@ void EmitBitCastU64F64(EmitContext&) { | |||
| 18 | throw NotImplementedException("SPIR-V Instruction"); | 18 | throw NotImplementedException("SPIR-V Instruction"); |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | void EmitBitCastS32F32(EmitContext&) { | ||
| 22 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 23 | } | ||
| 24 | |||
| 21 | void EmitBitCastF16U16(EmitContext&) { | 25 | void EmitBitCastF16U16(EmitContext&) { |
| 22 | throw NotImplementedException("SPIR-V Instruction"); | 26 | throw NotImplementedException("SPIR-V Instruction"); |
| 23 | } | 27 | } |
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 2c68aba39..5b3b5d1f3 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 | |||
| @@ -353,7 +353,6 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) { | |||
| 353 | case IR::Attribute::TessellationEvaluationPointV: | 353 | case IR::Attribute::TessellationEvaluationPointV: |
| 354 | return ctx.OpLoad(ctx.F32[1], | 354 | return ctx.OpLoad(ctx.F32[1], |
| 355 | ctx.OpAccessChain(ctx.input_f32, ctx.tess_coord, ctx.Const(1U))); | 355 | ctx.OpAccessChain(ctx.input_f32, ctx.tess_coord, ctx.Const(1U))); |
| 356 | |||
| 357 | default: | 356 | default: |
| 358 | throw NotImplementedException("Read attribute {}", attr); | 357 | throw NotImplementedException("Read attribute {}", attr); |
| 359 | } | 358 | } |
| @@ -513,6 +512,18 @@ Id EmitInvocationId(EmitContext& ctx) { | |||
| 513 | return ctx.OpLoad(ctx.U32[1], ctx.invocation_id); | 512 | return ctx.OpLoad(ctx.U32[1], ctx.invocation_id); |
| 514 | } | 513 | } |
| 515 | 514 | ||
| 515 | Id EmitInvocationInfo(EmitContext& ctx) { | ||
| 516 | switch (ctx.stage) { | ||
| 517 | case Stage::TessellationControl: | ||
| 518 | case Stage::TessellationEval: | ||
| 519 | return ctx.OpShiftLeftLogical(ctx.U32[1], ctx.OpLoad(ctx.U32[1], ctx.patch_vertices_in), | ||
| 520 | ctx.Const(16u)); | ||
| 521 | default: | ||
| 522 | LOG_WARNING(Shader, "(STUBBED) called"); | ||
| 523 | return ctx.Const(0x00ff0000u); | ||
| 524 | } | ||
| 525 | } | ||
| 526 | |||
| 516 | Id EmitSampleId(EmitContext& ctx) { | 527 | Id EmitSampleId(EmitContext& ctx) { |
| 517 | return ctx.OpLoad(ctx.U32[1], ctx.sample_id); | 528 | return ctx.OpLoad(ctx.U32[1], ctx.sample_id); |
| 518 | } | 529 | } |
| @@ -537,6 +548,17 @@ Id EmitResolutionDownFactor(EmitContext& ctx) { | |||
| 537 | } | 548 | } |
| 538 | } | 549 | } |
| 539 | 550 | ||
| 551 | Id EmitRenderArea(EmitContext& ctx) { | ||
| 552 | if (ctx.profile.unified_descriptor_binding) { | ||
| 553 | const Id pointer_type{ctx.TypePointer(spv::StorageClass::PushConstant, ctx.F32[4])}; | ||
| 554 | const Id index{ctx.Const(ctx.render_are_member_index)}; | ||
| 555 | const Id pointer{ctx.OpAccessChain(pointer_type, ctx.render_area_push_constant, index)}; | ||
| 556 | return ctx.OpLoad(ctx.F32[4], pointer); | ||
| 557 | } else { | ||
| 558 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 559 | } | ||
| 560 | } | ||
| 561 | |||
| 540 | Id EmitLoadLocal(EmitContext& ctx, Id word_offset) { | 562 | Id EmitLoadLocal(EmitContext& ctx, Id word_offset) { |
| 541 | const Id pointer{ctx.OpAccessChain(ctx.private_u32, ctx.local_memory, word_offset)}; | 563 | const Id pointer{ctx.OpAccessChain(ctx.private_u32, ctx.local_memory, word_offset)}; |
| 542 | return ctx.OpLoad(ctx.U32[1], pointer); | 564 | return ctx.OpLoad(ctx.U32[1], pointer); |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h index 984d072b4..e31cdc5e8 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h +++ b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h | |||
| @@ -72,10 +72,12 @@ void EmitSetOFlag(EmitContext& ctx); | |||
| 72 | Id EmitWorkgroupId(EmitContext& ctx); | 72 | Id EmitWorkgroupId(EmitContext& ctx); |
| 73 | Id EmitLocalInvocationId(EmitContext& ctx); | 73 | Id EmitLocalInvocationId(EmitContext& ctx); |
| 74 | Id EmitInvocationId(EmitContext& ctx); | 74 | Id EmitInvocationId(EmitContext& ctx); |
| 75 | Id EmitInvocationInfo(EmitContext& ctx); | ||
| 75 | Id EmitSampleId(EmitContext& ctx); | 76 | Id EmitSampleId(EmitContext& ctx); |
| 76 | Id EmitIsHelperInvocation(EmitContext& ctx); | 77 | Id EmitIsHelperInvocation(EmitContext& ctx); |
| 77 | Id EmitYDirection(EmitContext& ctx); | 78 | Id EmitYDirection(EmitContext& ctx); |
| 78 | Id EmitResolutionDownFactor(EmitContext& ctx); | 79 | Id EmitResolutionDownFactor(EmitContext& ctx); |
| 80 | Id EmitRenderArea(EmitContext& ctx); | ||
| 79 | Id EmitLoadLocal(EmitContext& ctx, Id word_offset); | 81 | Id EmitLoadLocal(EmitContext& ctx, Id word_offset); |
| 80 | void EmitWriteLocal(EmitContext& ctx, Id word_offset, Id value); | 82 | void EmitWriteLocal(EmitContext& ctx, Id word_offset, Id value); |
| 81 | Id EmitUndefU1(EmitContext& ctx); | 83 | Id EmitUndefU1(EmitContext& ctx); |
| @@ -177,7 +179,8 @@ Id EmitSelectF64(EmitContext& ctx, Id cond, Id true_value, Id false_value); | |||
| 177 | void EmitBitCastU16F16(EmitContext& ctx); | 179 | void EmitBitCastU16F16(EmitContext& ctx); |
| 178 | Id EmitBitCastU32F32(EmitContext& ctx, Id value); | 180 | Id EmitBitCastU32F32(EmitContext& ctx, Id value); |
| 179 | void EmitBitCastU64F64(EmitContext& ctx); | 181 | void EmitBitCastU64F64(EmitContext& ctx); |
| 180 | void EmitBitCastF16U16(EmitContext& ctx); | 182 | void EmitBitCastS32F32(EmitContext& ctx); |
| 183 | void EmitBitCastF16U16(EmitContext&); | ||
| 181 | Id EmitBitCastF32U32(EmitContext& ctx, Id value); | 184 | Id EmitBitCastF32U32(EmitContext& ctx, Id value); |
| 182 | void EmitBitCastF64U64(EmitContext& ctx); | 185 | void EmitBitCastF64U64(EmitContext& ctx); |
| 183 | Id EmitPackUint2x32(EmitContext& ctx, Id value); | 186 | Id EmitPackUint2x32(EmitContext& ctx, Id value); |
diff --git a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp index aecc4c612..0bfc2dd89 100644 --- a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp | |||
| @@ -473,6 +473,7 @@ EmitContext::EmitContext(const Profile& profile_, const RuntimeInfo& runtime_inf | |||
| 473 | DefineAttributeMemAccess(program.info); | 473 | DefineAttributeMemAccess(program.info); |
| 474 | DefineGlobalMemoryFunctions(program.info); | 474 | DefineGlobalMemoryFunctions(program.info); |
| 475 | DefineRescalingInput(program.info); | 475 | DefineRescalingInput(program.info); |
| 476 | DefineRenderArea(program.info); | ||
| 476 | } | 477 | } |
| 477 | 478 | ||
| 478 | EmitContext::~EmitContext() = default; | 479 | EmitContext::~EmitContext() = default; |
| @@ -982,6 +983,36 @@ void EmitContext::DefineRescalingInputUniformConstant() { | |||
| 982 | } | 983 | } |
| 983 | } | 984 | } |
| 984 | 985 | ||
| 986 | void EmitContext::DefineRenderArea(const Info& info) { | ||
| 987 | if (!info.uses_render_area) { | ||
| 988 | return; | ||
| 989 | } | ||
| 990 | |||
| 991 | if (profile.unified_descriptor_binding) { | ||
| 992 | boost::container::static_vector<Id, 1> members{}; | ||
| 993 | u32 member_index{0}; | ||
| 994 | |||
| 995 | members.push_back(F32[4]); | ||
| 996 | render_are_member_index = member_index++; | ||
| 997 | |||
| 998 | const Id push_constant_struct{TypeStruct(std::span(members.data(), members.size()))}; | ||
| 999 | Decorate(push_constant_struct, spv::Decoration::Block); | ||
| 1000 | Name(push_constant_struct, "RenderAreaInfo"); | ||
| 1001 | |||
| 1002 | MemberDecorate(push_constant_struct, render_are_member_index, spv::Decoration::Offset, 0); | ||
| 1003 | MemberName(push_constant_struct, render_are_member_index, "render_area"); | ||
| 1004 | |||
| 1005 | const Id pointer_type{TypePointer(spv::StorageClass::PushConstant, push_constant_struct)}; | ||
| 1006 | render_area_push_constant = | ||
| 1007 | AddGlobalVariable(pointer_type, spv::StorageClass::PushConstant); | ||
| 1008 | Name(render_area_push_constant, "render_area_push_constants"); | ||
| 1009 | |||
| 1010 | if (profile.supported_spirv >= 0x00010400) { | ||
| 1011 | interfaces.push_back(render_area_push_constant); | ||
| 1012 | } | ||
| 1013 | } | ||
| 1014 | } | ||
| 1015 | |||
| 985 | void EmitContext::DefineConstantBuffers(const Info& info, u32& binding) { | 1016 | void EmitContext::DefineConstantBuffers(const Info& info, u32& binding) { |
| 986 | if (info.constant_buffer_descriptors.empty()) { | 1017 | if (info.constant_buffer_descriptors.empty()) { |
| 987 | return; | 1018 | return; |
| @@ -1294,6 +1325,10 @@ void EmitContext::DefineInputs(const IR::Program& program) { | |||
| 1294 | if (info.uses_invocation_id) { | 1325 | if (info.uses_invocation_id) { |
| 1295 | invocation_id = DefineInput(*this, U32[1], false, spv::BuiltIn::InvocationId); | 1326 | invocation_id = DefineInput(*this, U32[1], false, spv::BuiltIn::InvocationId); |
| 1296 | } | 1327 | } |
| 1328 | if (info.uses_invocation_info && | ||
| 1329 | (stage == Shader::Stage::TessellationControl || stage == Shader::Stage::TessellationEval)) { | ||
| 1330 | patch_vertices_in = DefineInput(*this, U32[1], false, spv::BuiltIn::PatchVertices); | ||
| 1331 | } | ||
| 1297 | if (info.uses_sample_id) { | 1332 | if (info.uses_sample_id) { |
| 1298 | sample_id = DefineInput(*this, U32[1], false, spv::BuiltIn::SampleId); | 1333 | sample_id = DefineInput(*this, U32[1], false, spv::BuiltIn::SampleId); |
| 1299 | } | 1334 | } |
diff --git a/src/shader_recompiler/backend/spirv/spirv_emit_context.h b/src/shader_recompiler/backend/spirv/spirv_emit_context.h index bc25b8b84..dde45b4bc 100644 --- a/src/shader_recompiler/backend/spirv/spirv_emit_context.h +++ b/src/shader_recompiler/backend/spirv/spirv_emit_context.h | |||
| @@ -204,6 +204,7 @@ public: | |||
| 204 | Id workgroup_id{}; | 204 | Id workgroup_id{}; |
| 205 | Id local_invocation_id{}; | 205 | Id local_invocation_id{}; |
| 206 | Id invocation_id{}; | 206 | Id invocation_id{}; |
| 207 | Id patch_vertices_in{}; | ||
| 207 | Id sample_id{}; | 208 | Id sample_id{}; |
| 208 | Id is_helper_invocation{}; | 209 | Id is_helper_invocation{}; |
| 209 | Id subgroup_local_invocation_id{}; | 210 | Id subgroup_local_invocation_id{}; |
| @@ -243,6 +244,9 @@ public: | |||
| 243 | u32 texture_rescaling_index{}; | 244 | u32 texture_rescaling_index{}; |
| 244 | u32 image_rescaling_index{}; | 245 | u32 image_rescaling_index{}; |
| 245 | 246 | ||
| 247 | Id render_area_push_constant{}; | ||
| 248 | u32 render_are_member_index{}; | ||
| 249 | |||
| 246 | Id local_memory{}; | 250 | Id local_memory{}; |
| 247 | 251 | ||
| 248 | Id shared_memory_u8{}; | 252 | Id shared_memory_u8{}; |
| @@ -318,6 +322,7 @@ private: | |||
| 318 | void DefineRescalingInput(const Info& info); | 322 | void DefineRescalingInput(const Info& info); |
| 319 | void DefineRescalingInputPushConstant(); | 323 | void DefineRescalingInputPushConstant(); |
| 320 | void DefineRescalingInputUniformConstant(); | 324 | void DefineRescalingInputUniformConstant(); |
| 325 | void DefineRenderArea(const Info& info); | ||
| 321 | 326 | ||
| 322 | void DefineInputs(const IR::Program& program); | 327 | void DefineInputs(const IR::Program& program); |
| 323 | void DefineOutputs(const IR::Program& program); | 328 | void DefineOutputs(const IR::Program& program); |