mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
fix(shader): distinguish descriptor resources by register
This commit is contained in:
@@ -23,6 +23,8 @@ struct GuestSamplerResource {
|
||||
float maxLod;
|
||||
float lodBias;
|
||||
VkBorderColor borderColor;
|
||||
bool compareEnable = false;
|
||||
VkCompareOp compareOp = VK_COMPARE_OP_NEVER;
|
||||
};
|
||||
|
||||
GuestSamplerResource DecodeSamplerResource(std::span<const std::uint32_t> words);
|
||||
|
||||
@@ -67,7 +67,6 @@ GuestSamplerResource DecodeSamplerResource(std::span<const std::uint32_t> words)
|
||||
const auto lodBiasSec = (words[2] >> 14u) & 0x3fu;
|
||||
const auto xyMagFilter = (words[2] >> 20u) & 0x3u;
|
||||
const auto xyMinFilter = (words[2] >> 22u) & 0x3u;
|
||||
const auto zFilter = (words[2] >> 24u) & 0x3u;
|
||||
const auto mipFilter = (words[2] >> 26u) & 0x3u;
|
||||
const auto pointPreclamp = ((words[2] >> 28u) & 0x1u) != 0;
|
||||
const auto anisoOverride = ((words[2] >> 29u) & 0x1u) != 0;
|
||||
@@ -75,7 +74,6 @@ GuestSamplerResource DecodeSamplerResource(std::span<const std::uint32_t> words)
|
||||
|
||||
const auto borderColorType = (words[3] >> 30u) & 0x3u;
|
||||
|
||||
Require(depthCompareFunc == 0, "guest sampler descriptor uses depth comparison which is not implemented");
|
||||
Require(!forceUnormCoords, "guest sampler descriptor uses unnormalized coordinates which are not implemented");
|
||||
Require(anisoThreshold == 0, "guest sampler descriptor uses an anisotropy threshold override which is not implemented");
|
||||
Require(!forceSrgb, "guest sampler descriptor forces sRGB decoding which is not implemented");
|
||||
@@ -89,7 +87,6 @@ GuestSamplerResource DecodeSamplerResource(std::span<const std::uint32_t> words)
|
||||
Require(!pointPreclamp, "guest sampler descriptor uses point preclamping which is not implemented");
|
||||
Require(!anisoOverride, "guest sampler descriptor uses an anisotropy override which is not implemented");
|
||||
Require(!blendZeroPrt, "guest sampler descriptor uses PRT blend-zero which is not implemented");
|
||||
Require(zFilter == xyMinFilter, "guest sampler descriptor uses a Z filter that differs from the minification filter");
|
||||
Require(mipFilter <= 2u, "guest sampler descriptor uses an unknown mip filter " + std::to_string(mipFilter));
|
||||
|
||||
const auto aniso = isAnisoFilter(xyMagFilter) || isAnisoFilter(xyMinFilter);
|
||||
@@ -129,6 +126,8 @@ GuestSamplerResource DecodeSamplerResource(std::span<const std::uint32_t> words)
|
||||
result.maxLod = maxLod;
|
||||
result.lodBias = toSignedLodBias(lodBiasRaw);
|
||||
result.borderColor = border;
|
||||
const std::array compareOps{VK_COMPARE_OP_NEVER, VK_COMPARE_OP_LESS, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_ALWAYS};
|
||||
result.compareOp = compareOps.at(depthCompareFunc);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace AgcDriver::Graphics {
|
||||
info.mipLodBias = descriptor.lodBias;
|
||||
info.anisotropyEnable = descriptor.anisotropyEnable ? VK_TRUE : VK_FALSE;
|
||||
info.maxAnisotropy = descriptor.maxAnisotropy;
|
||||
info.compareEnable = VK_FALSE;
|
||||
info.compareOp = VK_COMPARE_OP_NEVER;
|
||||
info.compareEnable = descriptor.compareEnable ? VK_TRUE : VK_FALSE;
|
||||
info.compareOp = descriptor.compareOp;
|
||||
info.minLod = descriptor.minLod;
|
||||
info.maxLod = descriptor.maxLod;
|
||||
info.borderColor = descriptor.borderColor;
|
||||
|
||||
@@ -222,9 +222,11 @@ void ShaderResources::addImageBinding(const ShaderRecompiler::DescriptorBinding&
|
||||
} else {
|
||||
Require(elementWords == 4, "guest sampler descriptor must contain 4 dwords");
|
||||
Require(binding.count <= context.limits.maxPerStageDescriptorSamplers, "shader sampler descriptors exceed per-stage limits");
|
||||
Require(binding.samplerDepthCompare.size() == binding.count, "guest sampler binding is missing depth comparison metadata");
|
||||
for (std::uint32_t element = 0; element < binding.count; ++element) {
|
||||
const auto words = std::span<const std::uint32_t>(binding.guestDescriptor).subspan(static_cast<std::size_t>(element) * elementWords, elementWords);
|
||||
const auto resource = DecodeSamplerResource(words);
|
||||
auto resource = DecodeSamplerResource(words);
|
||||
resource.compareEnable = binding.samplerDepthCompare.at(element);
|
||||
samplers.push_back(std::make_unique<Sampler>(context, resource));
|
||||
item.imageAllocations.push_back(samplers.size() - 1);
|
||||
}
|
||||
|
||||
@@ -120,17 +120,30 @@ void RunGuestSamplerResourceTests() {
|
||||
badLod.maxLodRaw = 50;
|
||||
rejectFields(badLod, "minimum LOD past its maximum LOD");
|
||||
|
||||
Fields badZFilter = base;
|
||||
badZFilter.zFilter = 0;
|
||||
rejectFields(badZFilter, "differs from the minification filter");
|
||||
const std::array<std::uint32_t, 4> capturedSampler{0u, 0x00fff000u, 0x09000000u, 0u};
|
||||
const auto captured = DecodeSamplerResource(capturedSampler);
|
||||
Require(captured.magFilter == VK_FILTER_NEAREST && captured.minFilter == VK_FILTER_NEAREST, "captured 2D sampler filters decoded incorrectly");
|
||||
Require(captured.mipmapMode == VK_SAMPLER_MIPMAP_MODE_LINEAR && nearlyEqual(captured.maxLod, 4095.0f / 256.0f), "captured 2D sampler mip settings decoded incorrectly");
|
||||
Require(captured.addressModeU == VK_SAMPLER_ADDRESS_MODE_REPEAT && captured.addressModeV == VK_SAMPLER_ADDRESS_MODE_REPEAT, "captured 2D sampler address modes decoded incorrectly");
|
||||
for (std::uint32_t zFilter = 0; zFilter < 4; ++zFilter) {
|
||||
Fields twoDimensional = base;
|
||||
twoDimensional.zFilter = zFilter;
|
||||
const auto decoded = DecodeSamplerResource(pack(twoDimensional));
|
||||
Require(decoded.magFilter == VK_FILTER_LINEAR && decoded.minFilter == VK_FILTER_LINEAR, "Z filter changed 2D filtering");
|
||||
}
|
||||
|
||||
Fields badMipFilter = base;
|
||||
badMipFilter.mipFilter = 3;
|
||||
rejectFields(badMipFilter, "unknown mip filter");
|
||||
|
||||
Fields badDepthCompare = base;
|
||||
badDepthCompare.depthCompareFunc = 1;
|
||||
rejectFields(badDepthCompare, "depth comparison");
|
||||
const std::array compareOps{VK_COMPARE_OP_NEVER, VK_COMPARE_OP_LESS, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_ALWAYS};
|
||||
for (std::uint32_t function = 0; function < compareOps.size(); ++function) {
|
||||
Fields comparison = base;
|
||||
comparison.depthCompareFunc = function;
|
||||
const auto decoded = DecodeSamplerResource(pack(comparison));
|
||||
Require(decoded.compareOp == compareOps.at(function), "sampler depth comparison function decoded incorrectly");
|
||||
Require(!decoded.compareEnable, "sampler descriptor enabled comparison without shader metadata");
|
||||
}
|
||||
|
||||
Fields badUnorm = base;
|
||||
badUnorm.forceUnormCoords = true;
|
||||
|
||||
@@ -36,11 +36,39 @@ void verifyResult(const ShaderRecompiler::RecompileResult& first, const ShaderRe
|
||||
}
|
||||
}
|
||||
|
||||
void verifyRegisterSources() {
|
||||
using namespace ShaderRecompiler;
|
||||
IrResourcePlan plan;
|
||||
IrValue samplerRegister(IrOpcode::Void, IrType::ScalarReg, 0);
|
||||
IrValue bufferRegister(IrOpcode::Void, IrType::ScalarReg, 1);
|
||||
IrValue sameSamplerRegister(IrOpcode::Void, IrType::ScalarReg, 2);
|
||||
samplerRegister.SetRegister({RegisterBank::Scalar, 8});
|
||||
bufferRegister.SetRegister({RegisterBank::Scalar, 12});
|
||||
sameSamplerRegister.SetRegister({RegisterBank::Scalar, 8});
|
||||
IrValue samplerRead(IrOpcode::GetUserData, IrType::U32, 3);
|
||||
IrValue bufferRead(IrOpcode::GetUserData, IrType::U32, 4);
|
||||
IrValue sameSamplerRead(IrOpcode::GetUserData, IrType::U32, 5);
|
||||
samplerRead.AddArgument(&samplerRegister);
|
||||
bufferRead.AddArgument(&bufferRegister);
|
||||
sameSamplerRead.AddArgument(&sameSamplerRegister);
|
||||
require(!EquivalentValue(plan, &samplerRead, &bufferRead), "sampler SGPRs were merged with buffer SGPRs");
|
||||
require(EquivalentValue(plan, &samplerRead, &sameSamplerRead), "identical user data reads were not recognized");
|
||||
sameSamplerRegister.SetRegister({RegisterBank::UserData, 8});
|
||||
require(!EquivalentValue(plan, &samplerRead, &sameSamplerRead), "different register banks were merged");
|
||||
IrValue firstVector(IrOpcode::Void, IrType::VectorReg, 6);
|
||||
IrValue secondVector(IrOpcode::Void, IrType::VectorReg, 7);
|
||||
firstVector.SetRegister({RegisterBank::Vector, 0});
|
||||
secondVector.SetRegister({RegisterBank::Vector, 1});
|
||||
require(!EquivalentValue(plan, &firstVector, &secondVector), "different vector registers were merged");
|
||||
require(!EquivalentValue(plan, &samplerRegister, &firstVector), "different register types were merged");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
using namespace ShaderRecompiler;
|
||||
verifyRegisterSources();
|
||||
const std::vector<std::uint32_t> minimalSpirv{
|
||||
0x07230203u, 0x00010000u, 0u, 5u, 0u,
|
||||
0x00020011u, 1u,
|
||||
|
||||
@@ -85,6 +85,9 @@ bool equivalentValueImpl(const IrResourcePlan& program, const IrValue* left, con
|
||||
if (left->HasImmediate() || right->HasImmediate() || left->Type() != right->Type()) {
|
||||
return false;
|
||||
}
|
||||
if (left->Type() == IrType::ScalarReg || left->Type() == IrType::VectorReg) {
|
||||
return left->Register() == right->Register();
|
||||
}
|
||||
if (left->Opcode() != right->Opcode() || left->ArgumentCount() != right->ArgumentCount()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -203,6 +203,15 @@ void DescriptorBindingBuilder::Populate(BindingAllocationResult& allocation, con
|
||||
break;
|
||||
case DescriptorRole::GuestSamplers:
|
||||
physical.guestDescriptor = GuestSamplersDescriptor(logical.resources, snapshot);
|
||||
for (std::size_t element = 0; element < logical.resources.size(); ++element) {
|
||||
const auto& sampler = program.Info().samplers.at(logical.resources[element]);
|
||||
physical.samplerDepthCompare.push_back(sampler.depthCompare);
|
||||
if (sampler.forcePointFiltering) {
|
||||
auto& filter = physical.guestDescriptor.at(element * 4u + 2u);
|
||||
const bool mipmapped = ((filter >> 26u) & 3u) != 0u;
|
||||
filter = (filter & ~(0xffu << 20u)) | (1u << 24u) | (mipmapped ? 1u << 26u : 0u);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DescriptorRole::FlattenedSrt:
|
||||
if (snapshot.flattenedSrt.empty()) {
|
||||
|
||||
@@ -238,6 +238,7 @@ struct DescriptorBinding {
|
||||
std::vector<std::uint32_t> guestDescriptor;
|
||||
bool readOnly = false;
|
||||
std::optional<DescriptorImageShape> imageShape;
|
||||
std::vector<bool> samplerDepthCompare;
|
||||
};
|
||||
|
||||
struct VertexAttribute {
|
||||
|
||||
Reference in New Issue
Block a user