Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/libs/prx/libSceAgcDriver/Graphics/include/Context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ inline void EndRenderPass(const Context& context, VkCommandBuffer commands) {
}

std::uint32_t ImageTableCapacity(const Context& context);
std::uint32_t StorageTableCapacity(const Context& context);
std::uint32_t SamplerTableCapacity(const Context& context);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,15 @@ class ShaderResources {
std::uint32_t set = 0;
std::size_t firstSampler = 0;
std::size_t samplerCount = 0;
bool sampled = false;
bool storage = false;
std::vector<std::size_t> elementTextures;
std::vector<std::pair<std::uint32_t, std::uint32_t>> samplerRejections;
};
std::vector<TableStage> tableStages;
std::array<std::size_t, 2> tableBindings{std::numeric_limits<std::size_t>::max(), std::numeric_limits<std::size_t>::max()};
std::array<std::uint32_t, 2> tableElements{};
std::array<std::size_t, 2> storageTableBindings{std::numeric_limits<std::size_t>::max(), std::numeric_limits<std::size_t>::max()};
TableStage& tableStage(const CompiledShader& shader);
static const ShaderRecompiler::DescriptorBinding* tableImages(std::span<const CompiledShader> shaders, ShaderRecompiler::ShaderStage stage);
std::uint32_t rejectTableElement(TableStage& table, std::span<const std::uint32_t> words, const std::string& message);
Expand Down
87 changes: 78 additions & 9 deletions core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,10 @@ Module Inspect(const CompiledShader& compiled, const State& state, const VkPhysi
Require(decoration.set && decoration.binding, "unbound shader resource");
const auto key = std::make_pair(*decoration.set, *decoration.binding);
const auto binding = std::find_if(shader.bindings.begin(), shader.bindings.end(), [&](const auto& item) { return item.descriptorSet == key.first && item.binding == key.second; });
Require(descriptors.insert(key).second || (binding != shader.bindings.end() && binding->role == ShaderRecompiler::DescriptorRole::ImageTable), "duplicate SPIR-V resource binding");
Require(descriptors.insert(key).second || (binding != shader.bindings.end() && (binding->role == ShaderRecompiler::DescriptorRole::ImageTable || binding->role == ShaderRecompiler::DescriptorRole::ImageStorageTable)), "duplicate SPIR-V resource binding");
Require(binding != shader.bindings.end(), "SPIR-V resource is absent from recompiler binding metadata");
Require(binding->kind == ShaderRecompiler::DescriptorKind::Sampler || binding->kind == ShaderRecompiler::DescriptorKind::SampledImage || binding->kind == ShaderRecompiler::DescriptorKind::StorageImage, "SPIR-V descriptor type disagrees with recompiler binding metadata");
if (binding->role == ShaderRecompiler::DescriptorRole::ImageTable || binding->role == ShaderRecompiler::DescriptorRole::SamplerTable) {
if (binding->role == ShaderRecompiler::DescriptorRole::ImageTable || binding->role == ShaderRecompiler::DescriptorRole::ImageStorageTable || binding->role == ShaderRecompiler::DescriptorRole::SamplerTable) {
Require(type.size() == 3 && (type[0] & 0xffffu) == spv::OpTypeRuntimeArray, "image table must be declared as a runtime descriptor array");
continue;
}
Expand Down
19 changes: 16 additions & 3 deletions core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1587,11 +1587,24 @@ void verifyImageTableRegistration() {
const std::vector<std::uint32_t> storeCode{0xf4080100u, 0xfa000000u, 0xf4080700u, 0xfa000030u, 0x7e200500u, 0x8f108510u, 0xf42c0502u, 0x20000000u, 0xf0200f08u, 0x00050200u, 0xbf810000u};
const auto store = CompileTable(TableRequest(storeCode, userData));
const auto& storePlan = *store.capture->plan;
require(storePlan.info.images.size() == 1u && storePlan.info.images[0].table == 0u && storePlan.info.images[0].tableOperation == TableOperation::Unsupported, "image table registration: a table T# feeding image_store was not an unsupported table operation");
require(storePlan.info.images.size() == 1u && storePlan.info.images[0].table == 0u && storePlan.info.images[0].tableOperation == TableOperation::Supported, "image table registration: a table T# feeding image_store was not a supported table operation");
const auto& storeMap = TableMap(*store.result);
const auto storeFault = storeMap[Abi::TableHeader(0) + Abi::TableFault];
require((storeFault & Abi::PoisonFlag) != 0u && store.result->imageTablePoison.at(storeFault & ~Abi::PoisonFlag).reason == static_cast<std::uint32_t>(Abi::PoisonReason::UnsupportedOperation) && store.result->imageTableFaults != 0u, "image table registration: the store's table does not fault on use");
require(TableBinding(*store.result, DescriptorRole::ImageTable) == nullptr || TableBinding(*store.result, DescriptorRole::ImageTable)->count == 0u, "image table registration: an unsupported table bound elements");
const auto* storeTable = TableBinding(*store.result, DescriptorRole::ImageStorageTable);
require((storeFault & Abi::PoisonFlag) == 0u && storeTable != nullptr && storeTable->count != 0u && std::all_of(storeTable->imageWritten.begin(), storeTable->imageWritten.end(), [](bool written) { return written; }), "image table registration: the store's table was not bound as written storage elements");
require(TableBinding(*store.result, DescriptorRole::ImageTable) == nullptr || TableBinding(*store.result, DescriptorRole::ImageTable)->count == 0u, "image table registration: a store-only table bound sampled elements");
const std::array<std::pair<std::uint32_t, const char*>, 3> unsupportedStores{{{0xf0240f08u, "image_store_mip"}, {0xf0280f08u, "image_store_pck"}, {0xf0440108u, "image_atomic_add"}}};
for (const auto& [instruction, name] : unsupportedStores) {
auto code = storeCode;
code[8] = instruction;
const auto unsupported = CompileTable(TableRequest(code, userData));
const auto& plan = *unsupported.capture->plan;
require(plan.info.images.size() == 1u && plan.info.images[0].table == 0u && (plan.info.images[0].tableOperation == TableOperation::Unsupported || plan.info.images[0].mipMode == ImageMipMode::DynamicStorage), (std::string("image table registration: a table T# feeding ") + name + " was not planned as an unsupported or dynamic-mip table store").c_str());
const auto fault = TableMap(*unsupported.result)[Abi::TableHeader(0) + Abi::TableFault];
require((fault & Abi::PoisonFlag) != 0u && unsupported.result->imageTablePoison.at(fault & ~Abi::PoisonFlag).reason == static_cast<std::uint32_t>(Abi::PoisonReason::UnsupportedOperation) && unsupported.result->imageTableFaults != 0u, (std::string("image table registration: the ") + name + " table does not fault on use").c_str());
const auto* storage = TableBinding(*unsupported.result, DescriptorRole::ImageStorageTable);
require(storage == nullptr || storage->count == 0u, (std::string("image table registration: the unsupported ") + name + " bound storage table elements").c_str());
}

const std::vector<std::uint32_t> compareCode{0xf4080100u, 0xfa000000u, 0xf4080200u, 0xfa000010u, 0xf4080700u, 0xfa000030u, 0x7e200500u, 0x8f108510u, 0xf42c0502u, 0x20000000u, 0xf0fc0108u, 0x00450000u, 0xe0700000u, 0x80070000u, 0xbf810000u};
auto compareRequest = TableRequest(compareCode, userData);
Expand Down
37 changes: 32 additions & 5 deletions core/libs/prx/libSceAgcDriver/tests/execution/ImageTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ alignas(256) constexpr std::array<std::uint32_t, 15> StoreTableCode{
0xf42c0802u, 0x24000000u, 0x360200bfu, 0x7e040280u, 0xf0208f08u, 0x00090401u, 0xbf810000u,
};

alignas(256) constexpr std::array<std::uint32_t, 16> StoreLaneTableCode{
0xf4080100u, 0xfa000000u, 0xf4080200u, 0xfa000010u, 0x8f108202u, 0xf4200444u, 0x20000000u, 0x9312b011u,
0xf42c0802u, 0x24000000u, 0x360200bfu, 0x7e040280u, 0x7e080301u, 0xf0208f08u, 0x00090401u, 0xbf810000u,
};

alignas(256) constexpr std::array<std::uint32_t, 17> StoreTableCutCode{
0xf4080100u, 0xfa000000u, 0xf4080200u, 0xfa000010u, 0x8f108202u, 0xf4200444u, 0x20000000u, 0x9312b011u,
0xf42c0802u, 0x24000000u, 0x360200bfu, 0x7e040280u, 0x7da400ffu, 0x00001000u, 0xf0208f08u, 0x00090401u,
Expand Down Expand Up @@ -368,7 +373,7 @@ Outcome Execute(AgcDriver::VulkanDevice& device, std::span<const std::uint32_t>
outcome.cacheable = AgcDriver::DriverDetail::CacheableResult(result);
outcome.imageTableReadRanges = result.imageTableReadRanges;
for (const auto& binding : result.bindings) {
if (binding.role == ShaderRecompiler::DescriptorRole::ImageTable) outcome.imageTableCount = binding.count;
if (binding.role == ShaderRecompiler::DescriptorRole::ImageTable || binding.role == ShaderRecompiler::DescriptorRole::ImageStorageTable) outcome.imageTableCount = binding.count;
if (binding.role == ShaderRecompiler::DescriptorRole::GuestSamplers) outcome.samplers = SamplerWords(binding.guestDescriptor);
if (binding.role == ShaderRecompiler::DescriptorRole::SamplerTable) outcome.samplerTable = SamplerWords(binding.guestDescriptor);
}
Expand Down Expand Up @@ -988,15 +993,37 @@ void RunModeTests(AgcDriver::VulkanDevice& device) {
}

void RunStoreTests(AgcDriver::VulkanDevice& device) {
struct Registration {
void* data;
Registration(void* data, std::size_t bytes) : data(data) { GuestAllocations::Mutation().Add(data, bytes, true, true, true); }
~Registration() { GuestAllocations::Mutation().Remove(data); }
} registeredUint(UintTexels.data(), sizeof(UintTexels)), registeredFloat(FloatTexels.data(), sizeof(FloatTexels)), registeredSint(SintTexels.data(), sizeof(SintTexels));
SetClassRecords();
const auto saved = UintTexels;
const auto savedUint = UintTexels;
const auto savedFloat = FloatTexels;
const auto savedSint = SintTexels;
const auto untouched = [&] { return UintTexels == savedUint && FloatTexels == savedFloat && SintTexels == savedSint; };
Keys = {};
Keys[0] = 1;
const auto cut = Run(device, StoreTableCutCode, 1, Lanes, 64);
AgcDriver::Graphics::StorageTexture::FlushAllPending("image table store test");
Require(!Faulted(cut), "image table store: a store with EXEC clear faulted:\n" + cut.log);
const auto stored = Run(device, StoreTableCode, 1, Lanes, 64);
Require(Faulted(stored) && stored.log.find("unsupported operation") != std::string::npos, "image table store: an image_store through a table did not fault as an unsupported operation:\n" + stored.log);
Require(UintTexels == saved, "image table store: an unsupported store reached the image");
Require(untouched(), "image table store: a store with EXEC clear reached an image");
const auto stored = Run(device, StoreLaneTableCode, 1, Lanes, 64);
AgcDriver::Graphics::StorageTexture::FlushAllPending("image table store test");
Require(!Faulted(stored), "image table store: a store through a table faulted:\n" + stored.log);
Require(stored.imageTableCount == 2u, "image table store: the storage table does not hold one element per distinct T# (" + std::to_string(stored.imageTableCount) + ")");
for (std::uint32_t x = 0; x < Width; ++x) Require(UintTexels[x] == x, "image table store: texel " + std::to_string(x) + " of the selected image is " + Hex(UintTexels[x]) + ", expected " + Hex(x));
Require(std::equal(UintTexels.begin() + Width, UintTexels.end(), savedUint.begin() + Width), "image table store: a store to row 0 reached another row");
Require(FloatTexels == savedFloat && SintTexels == savedSint, "image table store: a store through key 1 reached another entry's image");
UintTexels = savedUint;
const auto restored = Run(device, StoreTableCutCode, 1, Lanes, 64);
AgcDriver::Graphics::StorageTexture::FlushAllPending("image table store test");
Require(!Faulted(restored) && untouched(), "image table store: restoring the image failed:\n" + restored.log);
Keys[0] = 6;
const auto null = Run(device, StoreLaneTableCode, 1, Lanes, 64);
AgcDriver::Graphics::StorageTexture::FlushAllPending("image table store test");
Require(untouched(), "image table store: a store through a null entry reached an image:\n" + null.log);
}

void RunPointerTests(AgcDriver::VulkanDevice& device) {
Expand Down
3 changes: 3 additions & 0 deletions core/shader/recompiler/Optimization/src/BindingAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ BindingAllocationResult BindingAllocator::Allocate(IrProgram& program, const Bin
if (imageTables) {
addBinding(next, DescriptorBindingKind::ImageTable);
}
if (std::ranges::any_of(info.images, [](const ImageResource& image) { return image.table != NoTable && image.resourceClass == ImageResourceClass::Storage && image.tableOperation == TableOperation::Supported; })) {
addBinding(next, DescriptorBindingKind::ImageStorageTable);
}

if (next.ShaderDataDwords() != 0u && !next.UsesPushData()) {
addBinding(next, DescriptorBindingKind::ShaderData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ DescriptorKind PhysicalKindFor(DescriptorBindingKind kind) {
if (kind == DescriptorBindingKind::ImageTable) {
return DescriptorKind::SampledImage;
}
if (kind == DescriptorBindingKind::ImageStorageTable) {
return DescriptorKind::StorageImage;
}
const ImageResourceClass imageClass = ImageBindingResourceClass(kind);
if (imageClass == ImageResourceClass::Sampled) {
return DescriptorKind::SampledImage;
Expand Down Expand Up @@ -82,6 +85,9 @@ DescriptorRole RoleFor(DescriptorBindingKind kind) {
if (kind == DescriptorBindingKind::ImageTableMap) {
return DescriptorRole::ImageTableMap;
}
if (kind == DescriptorBindingKind::ImageStorageTable) {
return DescriptorRole::ImageStorageTable;
}
if (ImageBindingResourceClass(kind) != ImageResourceClass::None) {
return DescriptorRole::GuestImages;
}
Expand Down Expand Up @@ -494,7 +500,7 @@ DescriptorBindingPlan DescriptorBindingBuilder::Prepare(const IrBindingLayout& l
}
}
for (auto& binding : plan.bindings) {
if (binding.descriptor.role == DescriptorRole::ImageTable) binding.tableSamplerMasks = samplerMasks;
if (binding.descriptor.role == DescriptorRole::ImageTable || binding.descriptor.role == DescriptorRole::ImageStorageTable) binding.tableSamplerMasks = samplerMasks;
}
return plan;
}
Expand Down Expand Up @@ -563,6 +569,7 @@ void DescriptorBindingBuilder::Populate(BindingAllocationResult& allocation, con
}
break;
case DescriptorRole::ImageTable:
case DescriptorRole::ImageStorageTable:
if (tables == nullptr) fail("DescriptorBindingBuilder::Populate image table elements were not resolved");
physical.guestDescriptor.reserve(tables->elements.size() * 8u);
for (const auto& element : tables->elements) {
Expand All @@ -571,7 +578,7 @@ void DescriptorBindingBuilder::Populate(BindingAllocationResult& allocation, con
shape.dimension = element.dimension;
physical.imageShapes.push_back(ImageShapeForResource(shape));
physical.imageDepthCompare.push_back(element.depthCompare);
physical.imageWritten.push_back(false);
physical.imageWritten.push_back(ImageBindingResourceClass(element.kind) == ImageResourceClass::Storage);
physical.imageAtomic.push_back(false);
std::uint32_t samplers = 0;
for (std::uint32_t sampler = 0; sampler < entry.tableSamplerMasks.size(); ++sampler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,8 @@ void ResourceMaterializer::ApplyStaticInterface(IrProgram& program, bool nativeS
if (image.table == NoTable) continue;
tables = true;
const auto modes = RuntimeImageModes(image);
if (modes.empty() || modes.size() > ImageTableAbi::MaxModes) image.tableOperation = TableOperation::Unsupported;
const bool storage = image.resourceClass == ImageResourceClass::Storage;
if (modes.empty() || modes.size() > ImageTableAbi::MaxModes || (storage && image.mipMode == ImageMipMode::DynamicStorage)) image.tableOperation = TableOperation::Unsupported;
}
for (const auto& pair : resources.info.sampledPairs) {
if (pair.image >= images.size() || pair.sampler >= resources.info.samplers.size()) throw std::runtime_error("static sampled pair is out of range");
Expand Down
3 changes: 1 addition & 2 deletions core/shader/recompiler/Optimization/src/ResourceTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1358,8 +1358,7 @@ class Tracker {
continue;
}
image.table = next++;
const bool storage = image.resourceClass == ImageResourceClass::Storage || image.written || image.atomic;
if (storage || image.packed || image.byElements != 0u) {
if (image.atomic || image.packed || image.byElements != 0u) {
image.tableOperation = TableOperation::Unsupported;
}
}
Expand Down
3 changes: 2 additions & 1 deletion core/shader/recompiler/Recompiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ enum class DescriptorRole {
ShaderData,
ImageTable,
SamplerTable,
ImageTableMap
ImageTableMap,
ImageStorageTable
};

struct DescriptorBinding {
Expand Down
11 changes: 7 additions & 4 deletions core/shader/recompiler/RuntimeAbi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace ShaderRecompiler::RuntimeAbi {

inline constexpr std::uint32_t Version = 13u;
inline constexpr std::uint32_t Version = 14u;
inline constexpr std::uint32_t DescriptorSet = 0u;
inline constexpr std::uint32_t FragmentDescriptorSet = 1u;
inline constexpr std::uint32_t StageCount = 4u;
Expand All @@ -30,7 +30,8 @@ enum class Binding : std::uint32_t {
SamplerTable = 63u,
ImageTableMap = 64u,
Count = 65u,
ImageTable = 256u
ImageTable = 256u,
ImageStorageTable = 257u
};

enum class Stage : std::uint32_t { Main, Fragment, TessellationControl, TessellationEvaluation };
Expand Down Expand Up @@ -96,10 +97,12 @@ inline void RequireVersion(std::uint32_t version) {
if (version != Version) throw std::runtime_error("Shader runtime ABI: incompatible version");
}

inline constexpr std::uint32_t ImageTableBinding = StageCount * static_cast<std::uint32_t>(Binding::Count);
inline constexpr std::uint32_t ImageStorageTableBinding = StageCount * static_cast<std::uint32_t>(Binding::Count);
inline constexpr std::uint32_t ImageTableBinding = ImageStorageTableBinding + 1u;

inline std::uint32_t BindingNumber(Stage stage, Binding binding) {
if (binding == Binding::ImageTable) return ImageTableBinding;
if (binding == Binding::ImageStorageTable) return ImageStorageTableBinding;
const auto group = static_cast<std::uint32_t>(stage);
const auto index = static_cast<std::uint32_t>(binding);
const auto count = static_cast<std::uint32_t>(Binding::Count);
Expand All @@ -108,7 +111,7 @@ inline std::uint32_t BindingNumber(Stage stage, Binding binding) {
}

static_assert(FirstImageBinding + ImageBindingCount == static_cast<std::uint32_t>(Binding::Samplers));
static_assert(static_cast<std::uint32_t>(Binding::ImageTable) > static_cast<std::uint32_t>(Binding::Count) && ImageTableBinding == 260u);
static_assert(static_cast<std::uint32_t>(Binding::ImageTable) > static_cast<std::uint32_t>(Binding::Count) && ImageStorageTableBinding == 260u && ImageTableBinding == 261u);

}

Expand Down
Loading
Loading