mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-21 03:16:54 +02:00
recompiler: handle non valid descriptors
This commit is contained in:
@@ -28,6 +28,10 @@ bool NullImageDescriptor(const DescriptorValue& descriptor) {
|
|||||||
return descriptor.dwords[0] == 0 && (descriptor.dwords[1] & 0xffu) == 0;
|
return descriptor.dwords[0] == 0 && (descriptor.dwords[1] & 0xffu) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ValidImageDescriptor(const DescriptorValue& descriptor) {
|
||||||
|
return ((descriptor.dwords[3] >> 28u) & 0x8u) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t DescriptorImageSwizzle(const DescriptorValue& descriptor) {
|
uint32_t DescriptorImageSwizzle(const DescriptorValue& descriptor) {
|
||||||
return descriptor.dwords[3] & 0xfffu;
|
return descriptor.dwords[3] & 0xfffu;
|
||||||
}
|
}
|
||||||
@@ -223,6 +227,11 @@ bool MaterializeResources(const Program& program, const SrtRuntime& runtime,
|
|||||||
cursor += program.info.buffers.size();
|
cursor += program.info.buffers.size();
|
||||||
next.images.assign(cursor, cursor + program.info.images.size());
|
next.images.assign(cursor, cursor + program.info.images.size());
|
||||||
cursor += program.info.images.size();
|
cursor += program.info.images.size();
|
||||||
|
for (auto& descriptor: next.images) {
|
||||||
|
if (!ValidImageDescriptor(descriptor)) {
|
||||||
|
descriptor.dwords.fill(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
next.samplers.assign(cursor, cursor + program.info.samplers.size());
|
next.samplers.assign(cursor, cursor + program.info.samplers.size());
|
||||||
cursor += program.info.samplers.size();
|
cursor += program.info.samplers.size();
|
||||||
for (const auto& address: program.info.addresses) {
|
for (const auto& address: program.info.addresses) {
|
||||||
|
|||||||
@@ -913,6 +913,8 @@ void TestMaterializationSharesReadConstEvaluation() {
|
|||||||
for (uint32_t i = 0; i < memory.words.size(); i++) {
|
for (uint32_t i = 0; i < memory.words.size(); i++) {
|
||||||
memory.words[i] = 0x100 + i;
|
memory.words[i] = 0x100 + i;
|
||||||
}
|
}
|
||||||
|
memory.words[3] |=
|
||||||
|
Prospero::GpuEnumValue(Prospero::ImageType::kColor2D) << 28u;
|
||||||
std::array<uint32_t, 32> user_data{};
|
std::array<uint32_t, 32> user_data{};
|
||||||
user_data[16] = static_cast<uint32_t>(memory.base);
|
user_data[16] = static_cast<uint32_t>(memory.base);
|
||||||
user_data[17] = static_cast<uint32_t>(memory.base >> 32u);
|
user_data[17] = static_cast<uint32_t>(memory.base >> 32u);
|
||||||
@@ -938,6 +940,60 @@ void TestMaterializationSharesReadConstEvaluation() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestInvalidImagesMaterializeAsNull() {
|
||||||
|
Program sampled;
|
||||||
|
sampled.stage = ShaderType::Pixel;
|
||||||
|
sampled.user_data_count = 8;
|
||||||
|
sampled.blocks.resize(1);
|
||||||
|
sampled.blocks[0].instructions = {
|
||||||
|
ImageUse(0x40, Opcode::ImageLoad, ResourceKind::Image,
|
||||||
|
Decoder::ImageDimension::Dim2D)};
|
||||||
|
Prepare(&sampled);
|
||||||
|
Check(sampled.info.images.size() == 1 && sampled.info.samplers.empty(),
|
||||||
|
"sampled-image normalization test has unexpected resource topology");
|
||||||
|
|
||||||
|
constexpr std::array<uint32_t, 8> stale = {
|
||||||
|
0x00000004, 0x00000004, 0xc0061060, 0x06000514,
|
||||||
|
0x20010000, 0xa4580290, 0x00000004, 0x00000001};
|
||||||
|
std::string error;
|
||||||
|
for (uint32_t type = 0; type < 8; type++) {
|
||||||
|
auto descriptor = stale;
|
||||||
|
descriptor[3] = (descriptor[3] & 0x0fffffffu) | (type << 28u);
|
||||||
|
ResourceSnapshot snapshot;
|
||||||
|
Check(MaterializeResources(sampled, {descriptor}, &snapshot, &error) &&
|
||||||
|
snapshot.images.size() == 1 &&
|
||||||
|
std::all_of(snapshot.images[0].dwords.begin(),
|
||||||
|
snapshot.images[0].dwords.end(),
|
||||||
|
[](uint32_t word) { return word == 0; }) &&
|
||||||
|
ValidateResourceSpecialization(sampled, snapshot, &error),
|
||||||
|
error.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto valid = stale;
|
||||||
|
valid[3] = (valid[3] & 0x0fffffffu) |
|
||||||
|
(Prospero::GpuEnumValue(Prospero::ImageType::kColor2D) << 28u);
|
||||||
|
ResourceSnapshot valid_snapshot;
|
||||||
|
Check(MaterializeResources(sampled, {valid}, &valid_snapshot, &error) &&
|
||||||
|
std::equal(valid.begin(), valid.end(),
|
||||||
|
valid_snapshot.images[0].dwords.begin()),
|
||||||
|
"valid sampled image descriptor was normalized");
|
||||||
|
|
||||||
|
Program storage;
|
||||||
|
storage.stage = ShaderType::Compute;
|
||||||
|
storage.user_data_count = 8;
|
||||||
|
storage.blocks.resize(1);
|
||||||
|
storage.blocks[0].instructions = {
|
||||||
|
ImageUse(0x40, Opcode::ImageStore, ResourceKind::StorageImage,
|
||||||
|
Decoder::ImageDimension::Dim2D)};
|
||||||
|
Prepare(&storage);
|
||||||
|
ResourceSnapshot storage_snapshot;
|
||||||
|
Check(MaterializeResources(storage, {stale}, &storage_snapshot, &error) &&
|
||||||
|
std::all_of(storage_snapshot.images[0].dwords.begin(),
|
||||||
|
storage_snapshot.images[0].dwords.end(),
|
||||||
|
[](uint32_t word) { return word == 0; }),
|
||||||
|
"invalid storage image descriptor was not normalized to null");
|
||||||
|
}
|
||||||
|
|
||||||
void TestMaterializationFailureIsTransactional() {
|
void TestMaterializationFailureIsTransactional() {
|
||||||
Program program;
|
Program program;
|
||||||
program.blocks.resize(1);
|
program.blocks.resize(1);
|
||||||
@@ -1756,6 +1812,7 @@ int main() {
|
|||||||
RUN(TestSrtPatchingHandlesCfgProducers);
|
RUN(TestSrtPatchingHandlesCfgProducers);
|
||||||
RUN(TestSrtPatchPlanValidation);
|
RUN(TestSrtPatchPlanValidation);
|
||||||
RUN(TestMaterializationSharesReadConstEvaluation);
|
RUN(TestMaterializationSharesReadConstEvaluation);
|
||||||
|
RUN(TestInvalidImagesMaterializeAsNull);
|
||||||
RUN(TestMaterializationFailureIsTransactional);
|
RUN(TestMaterializationFailureIsTransactional);
|
||||||
RUN(TestResourceSpecializationIsTypedAndTransactional);
|
RUN(TestResourceSpecializationIsTypedAndTransactional);
|
||||||
RUN(TestRuntimeSpecializationCoversBakedBufferAndAddressFields);
|
RUN(TestRuntimeSpecializationCoversBakedBufferAndAddressFields);
|
||||||
|
|||||||
Reference in New Issue
Block a user