yuzu-emu
/
yuzu-mainline
Archived
1
0
Fork 0

shader: Implement PIXLD.MY_INDEX

This commit is contained in:
ReinUsesLisp 2021-04-16 17:22:59 -03:00 committed by ameerj
parent f3473c5143
commit 95815a3883
14 changed files with 71 additions and 5 deletions

View File

@ -137,6 +137,7 @@ add_library(shader_recompiler STATIC
frontend/maxwell/translate/impl/move_special_register.cpp
frontend/maxwell/translate/impl/not_implemented.cpp
frontend/maxwell/translate/impl/output_geometry.cpp
frontend/maxwell/translate/impl/pixel_load.cpp
frontend/maxwell/translate/impl/predicate_set_predicate.cpp
frontend/maxwell/translate/impl/predicate_set_register.cpp
frontend/maxwell/translate/impl/select_source_with_predicate.cpp

View File

@ -998,6 +998,9 @@ void EmitContext::DefineInputs(const Info& info) {
if (info.uses_invocation_id) {
invocation_id = DefineInput(*this, U32[1], false, spv::BuiltIn::InvocationId);
}
if (info.uses_sample_id) {
sample_id = DefineInput(*this, U32[1], false, spv::BuiltIn::SampleId);
}
if (info.uses_is_helper_invocation) {
is_helper_invocation = DefineInput(*this, U1, false, spv::BuiltIn::HelperInvocation);
}

View File

@ -149,6 +149,7 @@ public:
Id workgroup_id{};
Id local_invocation_id{};
Id invocation_id{};
Id sample_id{};
Id is_helper_invocation{};
Id subgroup_local_invocation_id{};
Id subgroup_mask_eq{};

View File

@ -335,6 +335,9 @@ void SetupCapabilities(const Profile& profile, const Info& info, EmitContext& ct
if (info.uses_typeless_image_writes) {
ctx.AddCapability(spv::Capability::StorageImageWriteWithoutFormat);
}
if (info.uses_sample_id) {
ctx.AddCapability(spv::Capability::SampleRateShading);
}
if (!ctx.profile.xfb_varyings.empty()) {
ctx.AddCapability(spv::Capability::TransformFeedback);
}

View File

@ -70,6 +70,7 @@ void EmitSetOFlag(EmitContext& ctx);
Id EmitWorkgroupId(EmitContext& ctx);
Id EmitLocalInvocationId(EmitContext& ctx);
Id EmitInvocationId(EmitContext& ctx);
Id EmitSampleId(EmitContext& ctx);
Id EmitIsHelperInvocation(EmitContext& ctx);
Id EmitLoadLocal(EmitContext& ctx, Id word_offset);
void EmitWriteLocal(EmitContext& ctx, Id word_offset, Id value);

View File

@ -391,6 +391,10 @@ Id EmitInvocationId(EmitContext& ctx) {
return ctx.OpLoad(ctx.U32[1], ctx.invocation_id);
}
Id EmitSampleId(EmitContext& ctx) {
return ctx.OpLoad(ctx.U32[1], ctx.sample_id);
}
Id EmitIsHelperInvocation(EmitContext& ctx) {
return ctx.OpLoad(ctx.U1, ctx.is_helper_invocation);
}

View File

@ -375,6 +375,10 @@ U32 IREmitter::InvocationId() {
return Inst<U32>(Opcode::InvocationId);
}
U32 IREmitter::SampleId() {
return Inst<U32>(Opcode::SampleId);
}
U1 IREmitter::IsHelperInvocation() {
return Inst<U1>(Opcode::IsHelperInvocation);
}

View File

@ -99,6 +99,7 @@ public:
[[nodiscard]] U32 LocalInvocationIdZ();
[[nodiscard]] U32 InvocationId();
[[nodiscard]] U32 SampleId();
[[nodiscard]] U1 IsHelperInvocation();
[[nodiscard]] U32 LaneId();

View File

@ -63,6 +63,7 @@ OPCODE(SetOFlag, Void, U1,
OPCODE(WorkgroupId, U32x3, )
OPCODE(LocalInvocationId, U32x3, )
OPCODE(InvocationId, U32, )
OPCODE(SampleId, U32, )
OPCODE(IsHelperInvocation, U1, )
// Undefined

View File

@ -181,10 +181,6 @@ void TranslatorVisitor::PEXIT(u64) {
ThrowNotImplemented(Opcode::PEXIT);
}
void TranslatorVisitor::PIXLD(u64) {
ThrowNotImplemented(Opcode::PIXLD);
}
void TranslatorVisitor::PLONGJMP(u64) {
ThrowNotImplemented(Opcode::PLONGJMP);
}

View File

@ -0,0 +1,46 @@
// Copyright 2021 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "common/bit_field.h"
#include "common/common_types.h"
#include "shader_recompiler/frontend/maxwell/translate/impl/impl.h"
namespace Shader::Maxwell {
namespace {
enum class Mode : u64 {
Default,
CovMask,
Covered,
Offset,
CentroidOffset,
MyIndex,
};
} // Anonymous namespace
void TranslatorVisitor::PIXLD(u64 insn) {
union {
u64 raw;
BitField<31, 3, Mode> mode;
BitField<0, 8, IR::Reg> dest_reg;
BitField<8, 8, IR::Reg> addr_reg;
BitField<20, 8, s64> addr_offset;
BitField<45, 3, IR::Pred> dest_pred;
} const pixld{insn};
if (pixld.dest_pred != IR::Pred::PT) {
throw NotImplementedException("Destination predicate");
}
if (pixld.addr_reg != IR::Reg::RZ || pixld.addr_offset != 0) {
throw NotImplementedException("Non-zero source register");
}
switch (pixld.mode) {
case Mode::MyIndex:
X(pixld.dest_reg, ir.SampleId());
break;
default:
throw NotImplementedException("Mode {}", pixld.mode.Value());
}
}
} // namespace Shader::Maxwell

View File

@ -415,6 +415,9 @@ void VisitUsages(Info& info, IR::Inst& inst) {
case IR::Opcode::InvocationId:
info.uses_invocation_id = true;
break;
case IR::Opcode::SampleId:
info.uses_sample_id = true;
break;
case IR::Opcode::IsHelperInvocation:
info.uses_is_helper_invocation = true;
break;

View File

@ -102,6 +102,7 @@ struct Info {
bool uses_workgroup_id{};
bool uses_local_invocation_id{};
bool uses_invocation_id{};
bool uses_sample_id{};
bool uses_is_helper_invocation{};
bool uses_subgroup_invocation_id{};
std::array<bool, 30> uses_patches{};

View File

@ -218,7 +218,7 @@ Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR
.independentBlend = true,
.geometryShader = true,
.tessellationShader = true,
.sampleRateShading = false,
.sampleRateShading = true,
.dualSrcBlend = false,
.logicOp = false,
.multiDrawIndirect = false,
@ -677,6 +677,7 @@ void Device::CheckSuitability(bool requires_swapchain) const {
std::make_pair(features.fillModeNonSolid, "fillModeNonSolid"),
std::make_pair(features.geometryShader, "geometryShader"),
std::make_pair(features.tessellationShader, "tessellationShader"),
std::make_pair(features.sampleRateShading, "sampleRateShading"),
std::make_pair(features.occlusionQueryPrecise, "occlusionQueryPrecise"),
std::make_pair(features.fragmentStoresAndAtomics, "fragmentStoresAndAtomics"),
std::make_pair(features.shaderImageGatherExtended, "shaderImageGatherExtended"),