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/move_special_register.cpp
frontend/maxwell/translate/impl/not_implemented.cpp frontend/maxwell/translate/impl/not_implemented.cpp
frontend/maxwell/translate/impl/output_geometry.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_predicate.cpp
frontend/maxwell/translate/impl/predicate_set_register.cpp frontend/maxwell/translate/impl/predicate_set_register.cpp
frontend/maxwell/translate/impl/select_source_with_predicate.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) { if (info.uses_invocation_id) {
invocation_id = DefineInput(*this, U32[1], false, spv::BuiltIn::InvocationId); 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) { if (info.uses_is_helper_invocation) {
is_helper_invocation = DefineInput(*this, U1, false, spv::BuiltIn::HelperInvocation); is_helper_invocation = DefineInput(*this, U1, false, spv::BuiltIn::HelperInvocation);
} }

View file

@ -149,6 +149,7 @@ public:
Id workgroup_id{}; Id workgroup_id{};
Id local_invocation_id{}; Id local_invocation_id{};
Id invocation_id{}; Id invocation_id{};
Id sample_id{};
Id is_helper_invocation{}; Id is_helper_invocation{};
Id subgroup_local_invocation_id{}; Id subgroup_local_invocation_id{};
Id subgroup_mask_eq{}; 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) { if (info.uses_typeless_image_writes) {
ctx.AddCapability(spv::Capability::StorageImageWriteWithoutFormat); ctx.AddCapability(spv::Capability::StorageImageWriteWithoutFormat);
} }
if (info.uses_sample_id) {
ctx.AddCapability(spv::Capability::SampleRateShading);
}
if (!ctx.profile.xfb_varyings.empty()) { if (!ctx.profile.xfb_varyings.empty()) {
ctx.AddCapability(spv::Capability::TransformFeedback); ctx.AddCapability(spv::Capability::TransformFeedback);
} }

View file

@ -70,6 +70,7 @@ void EmitSetOFlag(EmitContext& ctx);
Id EmitWorkgroupId(EmitContext& ctx); Id EmitWorkgroupId(EmitContext& ctx);
Id EmitLocalInvocationId(EmitContext& ctx); Id EmitLocalInvocationId(EmitContext& ctx);
Id EmitInvocationId(EmitContext& ctx); Id EmitInvocationId(EmitContext& ctx);
Id EmitSampleId(EmitContext& ctx);
Id EmitIsHelperInvocation(EmitContext& ctx); Id EmitIsHelperInvocation(EmitContext& ctx);
Id EmitLoadLocal(EmitContext& ctx, Id word_offset); Id EmitLoadLocal(EmitContext& ctx, Id word_offset);
void EmitWriteLocal(EmitContext& ctx, Id word_offset, Id value); 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); 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) { Id EmitIsHelperInvocation(EmitContext& ctx) {
return ctx.OpLoad(ctx.U1, ctx.is_helper_invocation); return ctx.OpLoad(ctx.U1, ctx.is_helper_invocation);
} }

View file

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

View file

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

View file

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

View file

@ -181,10 +181,6 @@ void TranslatorVisitor::PEXIT(u64) {
ThrowNotImplemented(Opcode::PEXIT); ThrowNotImplemented(Opcode::PEXIT);
} }
void TranslatorVisitor::PIXLD(u64) {
ThrowNotImplemented(Opcode::PIXLD);
}
void TranslatorVisitor::PLONGJMP(u64) { void TranslatorVisitor::PLONGJMP(u64) {
ThrowNotImplemented(Opcode::PLONGJMP); 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: case IR::Opcode::InvocationId:
info.uses_invocation_id = true; info.uses_invocation_id = true;
break; break;
case IR::Opcode::SampleId:
info.uses_sample_id = true;
break;
case IR::Opcode::IsHelperInvocation: case IR::Opcode::IsHelperInvocation:
info.uses_is_helper_invocation = true; info.uses_is_helper_invocation = true;
break; break;

View file

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

View file

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