summaryrefslogtreecommitdiffstats
path: root/src/shader_recompiler/backend/spirv
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2022-11-04 06:21:58 +0100
committerGitHub <noreply@github.com>2022-11-04 06:21:58 +0100
commit38e4382f532d606afbd3969990a9ca3bac70e557 (patch)
treeb9af6ed0a26285f4b0dcd5c21028601004267607 /src/shader_recompiler/backend/spirv
parentMerge pull request #9135 from liamwhite/service-thread-event (diff)
parentMerge branch 'master' into mipmap (diff)
downloadyuzu-38e4382f532d606afbd3969990a9ca3bac70e557.tar
yuzu-38e4382f532d606afbd3969990a9ca3bac70e557.tar.gz
yuzu-38e4382f532d606afbd3969990a9ca3bac70e557.tar.bz2
yuzu-38e4382f532d606afbd3969990a9ca3bac70e557.tar.lz
yuzu-38e4382f532d606afbd3969990a9ca3bac70e557.tar.xz
yuzu-38e4382f532d606afbd3969990a9ca3bac70e557.tar.zst
yuzu-38e4382f532d606afbd3969990a9ca3bac70e557.zip
Diffstat (limited to 'src/shader_recompiler/backend/spirv')
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv.h4
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp12
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv_instructions.h1
-rw-r--r--src/shader_recompiler/backend/spirv/spirv_emit_context.cpp31
-rw-r--r--src/shader_recompiler/backend/spirv/spirv_emit_context.h4
5 files changed, 51 insertions, 1 deletions
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 {
alignas(16) std::array<u32, NUM_IMAGE_SCALING_WORDS> rescaling_images;
u32 down_factor;
};
+struct RenderAreaLayout {
+ std::array<f32, 4> render_area;
+};
constexpr u32 RESCALING_LAYOUT_WORDS_OFFSET = offsetof(RescalingLayout, rescaling_textures);
constexpr u32 RESCALING_LAYOUT_DOWN_FACTOR_OFFSET = offsetof(RescalingLayout, down_factor);
+constexpr u32 RENDERAREA_LAYOUT_OFFSET = offsetof(RenderAreaLayout, render_area);
[[nodiscard]] std::vector<u32> EmitSPIRV(const Profile& profile, const RuntimeInfo& runtime_info,
IR::Program& program, Bindings& bindings);
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..a4751b42d 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) {
case IR::Attribute::TessellationEvaluationPointV:
return ctx.OpLoad(ctx.F32[1],
ctx.OpAccessChain(ctx.input_f32, ctx.tess_coord, ctx.Const(1U)));
-
default:
throw NotImplementedException("Read attribute {}", attr);
}
@@ -537,6 +536,17 @@ Id EmitResolutionDownFactor(EmitContext& ctx) {
}
}
+Id EmitRenderArea(EmitContext& ctx) {
+ if (ctx.profile.unified_descriptor_binding) {
+ const Id pointer_type{ctx.TypePointer(spv::StorageClass::PushConstant, ctx.F32[4])};
+ const Id index{ctx.Const(ctx.render_are_member_index)};
+ const Id pointer{ctx.OpAccessChain(pointer_type, ctx.render_area_push_constant, index)};
+ return ctx.OpLoad(ctx.F32[4], pointer);
+ } else {
+ throw NotImplementedException("SPIR-V Instruction");
+ }
+}
+
Id EmitLoadLocal(EmitContext& ctx, Id word_offset) {
const Id pointer{ctx.OpAccessChain(ctx.private_u32, ctx.local_memory, word_offset)};
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..86dd3c4f3 100644
--- a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h
+++ b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h
@@ -76,6 +76,7 @@ Id EmitSampleId(EmitContext& ctx);
Id EmitIsHelperInvocation(EmitContext& ctx);
Id EmitYDirection(EmitContext& ctx);
Id EmitResolutionDownFactor(EmitContext& ctx);
+Id EmitRenderArea(EmitContext& ctx);
Id EmitLoadLocal(EmitContext& ctx, Id word_offset);
void EmitWriteLocal(EmitContext& ctx, Id word_offset, Id value);
Id EmitUndefU1(EmitContext& ctx);
diff --git a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp
index aecc4c612..c26ad8f93 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
DefineAttributeMemAccess(program.info);
DefineGlobalMemoryFunctions(program.info);
DefineRescalingInput(program.info);
+ DefineRenderArea(program.info);
}
EmitContext::~EmitContext() = default;
@@ -982,6 +983,36 @@ void EmitContext::DefineRescalingInputUniformConstant() {
}
}
+void EmitContext::DefineRenderArea(const Info& info) {
+ if (!info.uses_render_area) {
+ return;
+ }
+
+ if (profile.unified_descriptor_binding) {
+ boost::container::static_vector<Id, 1> members{};
+ u32 member_index{0};
+
+ members.push_back(F32[4]);
+ render_are_member_index = member_index++;
+
+ const Id push_constant_struct{TypeStruct(std::span(members.data(), members.size()))};
+ Decorate(push_constant_struct, spv::Decoration::Block);
+ Name(push_constant_struct, "RenderAreaInfo");
+
+ MemberDecorate(push_constant_struct, render_are_member_index, spv::Decoration::Offset, 0);
+ MemberName(push_constant_struct, render_are_member_index, "render_area");
+
+ const Id pointer_type{TypePointer(spv::StorageClass::PushConstant, push_constant_struct)};
+ render_area_push_constant =
+ AddGlobalVariable(pointer_type, spv::StorageClass::PushConstant);
+ Name(render_area_push_constant, "render_area_push_constants");
+
+ if (profile.supported_spirv >= 0x00010400) {
+ interfaces.push_back(render_area_push_constant);
+ }
+ }
+}
+
void EmitContext::DefineConstantBuffers(const Info& info, u32& binding) {
if (info.constant_buffer_descriptors.empty()) {
return;
diff --git a/src/shader_recompiler/backend/spirv/spirv_emit_context.h b/src/shader_recompiler/backend/spirv/spirv_emit_context.h
index bc25b8b84..c86e50911 100644
--- a/src/shader_recompiler/backend/spirv/spirv_emit_context.h
+++ b/src/shader_recompiler/backend/spirv/spirv_emit_context.h
@@ -243,6 +243,9 @@ public:
u32 texture_rescaling_index{};
u32 image_rescaling_index{};
+ Id render_area_push_constant{};
+ u32 render_are_member_index{};
+
Id local_memory{};
Id shared_memory_u8{};
@@ -318,6 +321,7 @@ private:
void DefineRescalingInput(const Info& info);
void DefineRescalingInputPushConstant();
void DefineRescalingInputUniformConstant();
+ void DefineRenderArea(const Info& info);
void DefineInputs(const IR::Program& program);
void DefineOutputs(const IR::Program& program);