Skip to content
2 changes: 1 addition & 1 deletion 3rdparty/SPIRV-Headers
Submodule SPIRV-Headers updated 36 files
+9 −9 .github/workflows/presubmit.yml
+19 −0 BUILD.bazel
+3 −1 CMakeLists.txt
+6 −1 CODE_OF_CONDUCT.md
+28 −0 CONTRIBUTING.md
+338 −99 LICENSES/CC-BY-4.0.txt
+1 −1 MODULE.bazel
+87 −3 README.md
+12 −30 REUSE.toml
+5 −0 SECURITY.md
+19 −7 include/spirv/spir-v.xml
+26 −0 include/spirv/unified1/ArmExperimentalMLOperations.h
+28 −0 include/spirv/unified1/NonSemanticGraphDebugInfo.h
+157 −0 include/spirv/unified1/NonSemanticShaderDebugInfo.h
+5 −1 include/spirv/unified1/NonSemanticShaderDebugInfo100.h
+25 −0 include/spirv/unified1/extinst.arm.experimental-ml-operations.grammar.json
+35 −0 include/spirv/unified1/extinst.nonsemantic.graph.debuginfo.grammar.json
+718 −0 include/spirv/unified1/extinst.nonsemantic.shader.debuginfo.grammar.json
+3,158 −0 include/spirv/unified1/org/khronos/spv/Spv.java
+107 −1 include/spirv/unified1/spirv.bf
+751 −89 include/spirv/unified1/spirv.core.grammar.json
+107 −1 include/spirv/unified1/spirv.cs
+239 −29 include/spirv/unified1/spirv.h
+239 −29 include/spirv/unified1/spirv.hpp
+239 −29 include/spirv/unified1/spirv.hpp11
+116 −11 include/spirv/unified1/spirv.json
+106 −1 include/spirv/unified1/spirv.lua
+105 −1 include/spirv/unified1/spirv.py
+107 −1 include/spirv/unified1/spv.d
+2 −0 tools/buildHeaders/bin/makeExtinstHeaders.py
+1 −1 tools/buildHeaders/bin/makeHeaders
+80 −6 tools/buildHeaders/header.cpp
+1 −0 tools/buildHeaders/header.h
+5 −3 tools/buildHeaders/jsonToSpirv.cpp
+2 −1 tools/buildHeaders/jsonToSpirv.h
+3 −0 tools/buildHeaders/main.cpp
2 changes: 1 addition & 1 deletion 3rdparty/SPIRV-Tools
Submodule SPIRV-Tools updated 400 files
35 changes: 25 additions & 10 deletions core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7077,14 +7077,13 @@ void verifyDescriptorPhis() {
const std::array<std::uint32_t, 4> pointWrap{0u, 0u, 0u, 0u};
const std::array<std::uint32_t, 4> linearMirror{0x49u, 0u, 0x00500000u, 0u};
std::array<std::uint32_t, 4> output{};
const auto outputAddress = static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(output.data()));
std::array<std::uint32_t, 32> srt{};
const auto first = imageDescriptor(textures[0]);
const auto second = imageDescriptor(textures[1]);
std::copy(first.begin(), first.end(), srt.begin());
std::copy(pointWrap.begin(), pointWrap.end(), srt.begin() + 8);
std::copy(linearMirror.begin(), linearMirror.end(), srt.begin() + 12);
const std::array<std::uint32_t, 4> outputV{static_cast<std::uint32_t>(outputAddress), static_cast<std::uint32_t>((outputAddress >> 32u) & 0xffffu), 16u, 0xfacu};
const auto outputV = TableV(output.data(), 0u, sizeof(output));
std::copy(outputV.begin(), outputV.end(), srt.begin() + 16);
srt[20] = 1u;
std::copy(second.begin(), second.end(), srt.begin() + 24);
Expand Down Expand Up @@ -10210,11 +10209,11 @@ void verifyComputedTexelOffsets() {
static Texture texture;
static std::array<std::uint32_t, 64> output{};
const auto textureBase = static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(texture.bytes.data()));
const auto outputBase = static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(output.data()));
const auto outputV = TableV(output.data(), 0u, 64u);
const std::array<std::uint32_t, 16> userData{
static_cast<std::uint32_t>(textureBase >> 8u), static_cast<std::uint32_t>((textureBase >> 40u) & 0xffu) | (Format8888UNorm << 20u) | (3u << 30u), 3u << 14u, 0xfacu | (Type2D << 28u), 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u,
static_cast<std::uint32_t>(outputBase), static_cast<std::uint32_t>((outputBase >> 32u) & 0xffffu), 64u, 0xfacu};
outputV[0], outputV[1], outputV[2], outputV[3]};
const auto program = [](std::uint32_t offsetSource, std::uint32_t literal) {
std::vector<std::uint32_t> code{0x7e020200u | offsetSource};
if (offsetSource == 0xffu) code.push_back(literal);
Expand Down Expand Up @@ -10476,16 +10475,18 @@ void verifySpecializedBufferAtomicBindings(bool finalAbiOnly = false) {
atomicElements += static_cast<std::size_t>(std::count(binding.bufferAtomic.begin(), binding.bufferAtomic.end(), true));
}
require(tables == 0, "specialized buffer atomic: a buffer_atomic_inc through a V# the program specializes binds the address tables");
require(faults == 1 && result.bdaAbiVersion == BdaAbi::Version, "specialized buffer atomic: the program has no fault buffer for its unaligned atomic");
require(faults <= 1u && result.bdaAbiVersion == (faults == 0u ? 0u : BdaAbi::Version), "specialized buffer atomic: final fault binding and BDA ABI disagree");
require(atomicElements == 1, "specialized buffer atomic: the V# element is not reported as atomic");
const auto words = result.spirv.Words();
std::uint32_t faultFunction = 0;
std::size_t faultCalls = 0;
std::size_t atomicWrites = 0;
bool physical = false;
bool int64 = false;
for (std::size_t cursor = 5; cursor < words.size();) {
const auto count = words[cursor] >> 16u;
const auto opcode = words[cursor] & 0xffffu;
if (opcode >= spv::OpAtomicStore && opcode <= spv::OpAtomicXor) ++atomicWrites;
require(count != 0 && count <= words.size() - cursor, "specialized buffer atomic: truncated SPIR-V instruction");
if (opcode == spv::OpCapability && words[cursor + 1] == spv::CapabilityPhysicalStorageBufferAddresses) physical = true;
if (opcode == spv::OpCapability && words[cursor + 1] == spv::CapabilityInt64) int64 = true;
Expand All @@ -10496,6 +10497,7 @@ void verifySpecializedBufferAtomicBindings(bool finalAbiOnly = false) {
}
require(!physical, "specialized buffer atomic: the module addresses physical storage without an address access");
require(int64, "specialized buffer atomic: the fault address is 64-bit and the module does not declare Int64");
require(atomicWrites != 0u, "specialized buffer atomic: the program has no atomic memory update");
require(faultCalls == 0, "specialized buffer atomic: a 32-bit atomic records an unaligned fault instead of acting on its dword");
const std::array<std::uint32_t, 1> shaderOnly{spv::CapabilityShader};
expectFailure([&] { static_cast<void>(compile(shaderOnly)); }, "buffer atomic fault addresses require shaderInt64", "specialized buffer atomic: the program compiled without shaderInt64");
Expand Down Expand Up @@ -10645,14 +10647,14 @@ void verifyUnnormalizedSamplers() {
static Texture texture;
static std::array<std::uint32_t, 64> output{};
const auto textureBase = static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(texture.bytes.data()));
const auto outputBase = static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(output.data()));
const auto outputV = TableV(output.data(), 0u, 64u);
const std::array<std::uint32_t, 4> unnormalized{0x00008092u, 0x00fff000u, 0x05500000u, 0u};
const std::array<std::uint32_t, 4> normalized{0x00000092u, 0x00fff000u, 0x05500000u, 0u};
const auto imageData = [&](const std::array<std::uint32_t, 4>& sampler, std::uint32_t type, std::uint32_t format, std::uint32_t depth) {
return std::array<std::uint32_t, 16>{
static_cast<std::uint32_t>(textureBase >> 8u), static_cast<std::uint32_t>((textureBase >> 40u) & 0xffu) | (format << 20u) | (3u << 30u), 3u << 14u, 0xfacu | (type << 28u), depth, 0u, 0u, 0u,
sampler[0], sampler[1], sampler[2], sampler[3],
static_cast<std::uint32_t>(outputBase), static_cast<std::uint32_t>((outputBase >> 32u) & 0xffffu), 64u, 0xfacu};
outputV[0], outputV[1], outputV[2], outputV[3]};
};
const auto userData = [&](const std::array<std::uint32_t, 4>& sampler) {
return imageData(sampler, Type2D, Format8888UNorm, 0u);
Expand Down Expand Up @@ -11128,9 +11130,9 @@ void verifyTwoLaneUniformValues() {
};
static GuestTables guest;
auto& output = guest.output;
const auto outputBase = static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(output.data()));
const auto outputV = TableV(output.data(), 0u, 64u);
auto& srt = guest.srt;
srt = {6u, 7u, 0u, 0u, static_cast<std::uint32_t>(outputBase), static_cast<std::uint32_t>((outputBase >> 32u) & 0xffffu), 64u, 0xfacu};
srt = {6u, 7u, 0u, 0u, outputV[0], outputV[1], outputV[2], outputV[3]};
const auto srtAddress = static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(srt.data()));
const std::array<std::uint32_t, 2> userData{static_cast<std::uint32_t>(srtAddress), static_cast<std::uint32_t>(srtAddress >> 32u)};
const std::array<std::uint32_t, 10> code{0xf4040080u, 0xfa000000u, 0xf4080200u, 0xfa000010u, 0xbf8cc07fu, 0x93040302u, 0x4a020004u, 0xe0700000u, 0x80020100u, 0xbf810000u};
Expand Down Expand Up @@ -12514,7 +12516,12 @@ class GcnImageModule {
if (op == spv::OpImageWrite) writes.push_back({words[cursor + 1], words[cursor + 2]});
if (op == spv::OpImageQuerySizeLod) querySize = words[cursor + 2];
if (op == spv::OpIEqual) comparisons.push_back({words[cursor + 3], words[cursor + 4]});
if (op == spv::OpCompositeExtract) extracted[words[cursor + 2]] = words[cursor + 3];
if (op == spv::OpCompositeExtract) {
extracted[words[cursor + 2]] = words[cursor + 3];
extractedComponents[words[cursor + 2]] = words[cursor + 4];
}
if (op == spv::OpStore) storedValues.push_back(words[cursor + 2]);
if (op == spv::OpBitcast || op == spv::OpCopyObject || op == spv::OpConvertUToF || op == spv::OpConvertFToU) depthSources[words[cursor + 2]] = words[cursor + 3];
if (op == spv::OpConstant && length == 4u) constants[words[cursor + 2]] = words[cursor + 3];
if (op == spv::OpBitcast || op == spv::OpFSub || op == spv::OpISub || op == spv::OpConvertUToF || op == spv::OpConvertFToU) sources[words[cursor + 2]] = words[cursor + 3];
for (std::size_t operand = 3; (op == spv::OpCompositeConstruct || op == spv::OpConstantComposite) && operand < length; ++operand) composites[words[cursor + 2]].push_back(words[cursor + operand]);
Expand Down Expand Up @@ -12558,6 +12565,11 @@ class GcnImageModule {
}

bool QueryReportsDepth() const {
if (std::ranges::any_of(storedValues, [&](std::uint32_t value) {
for (auto source = depthSources.find(value); source != depthSources.end(); source = depthSources.find(value)) value = source->second;
const auto extract = extracted.find(value);
return extract != extracted.end() && extract->second == querySize && extractedComponents.at(value) == 2u;
})) return true;
return std::ranges::any_of(composites, [&](const auto& composite) {
if (composite.second.size() != 4u) return false;
const auto extract = extracted.find(composite.second[2]);
Expand All @@ -12575,6 +12587,9 @@ class GcnImageModule {
std::map<std::uint32_t, std::uint32_t> constants;
std::map<std::uint32_t, std::uint32_t> sources;
std::map<std::uint32_t, std::uint32_t> extracted;
std::map<std::uint32_t, std::uint32_t> extractedComponents;
std::map<std::uint32_t, std::uint32_t> depthSources;
std::vector<std::uint32_t> storedValues;
std::map<std::uint32_t, std::vector<std::uint32_t>> composites;
std::vector<std::pair<std::uint32_t, std::uint32_t>> comparisons;
std::uint32_t querySize = 0u;
Expand Down
18 changes: 12 additions & 6 deletions core/libs/prx/libSceAgcDriver/tests/SpirvBranchTargets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,10 @@ void requireCrossRegionNan(bool conjunct, bool certified = false, bool unproved
block.AppendInstruction(&value);
return &value;
};
MemoryInfo lds;
lds.kind = ResourceKind::Lds;
program.Resources().memoryInfo.push_back(lds);
MemoryInfo output;
output.kind = ResourceKind::Buffer;
program.Resources().memoryInfo.push_back(output);
program.Info().buffers.emplace_back().written = true;
auto* zero = constant(0u);
auto* nan = constant(0x7fc12345u);
const auto isNan = [&](IrValue* value) {
Expand Down Expand Up @@ -273,18 +274,23 @@ void requireCrossRegionNan(bool conjunct, bool certified = false, bool unproved
auto* fourth = select(isNan(third));
auto& active = program.CreateValue(IrOpcode::Void, IrType::Bool);
active.SetImmediateBool(true);
emit(IrOpcode::WriteSharedU32, IrType::Void, {zero, fourth, &active});
auto* resource = emit(IrOpcode::GetBufferResource, IrType::BufferResource, {constant(0x1000u), zero, constant(4u), constant(0x31016facu)});
emit(IrOpcode::StoreBufferU32, IrType::Void, {resource, zero, zero, zero, fourth, &active});
ShaderComputeInputInfo compute;
compute.threadsNum[0] = 32;
compute.threadsNum[1] = 1;
compute.threadsNum[2] = 1;
compute.hostSubgroupSize = 32;
compute.waveSize = 32;
compute.ldsSizeDwords = 1;
ShaderStageInputInfo inputs;
inputs.compute = &compute;
CompiledBindingLayout bindings;
bindings.layout = program.Metadata().bindings;
auto& layout = program.Metadata().bindings;
layout.memoryOffsetCount = 1u;
layout.pushDataStartDword = 0u;
layout.descriptors = {{DescriptorBindingKind::Buffers, {0u}}};
bindings.layout = layout;
bindings.pushConstantSizeBytes = 4u;
SpirvTargetOptions target{};
target.vulkanVersion = 0x00403000u;
target.spirvVersion = 0x00010600u;
Expand Down
45 changes: 45 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/SpirvOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,50 @@ std::vector<std::uint32_t> swapByteOrder(std::vector<std::uint32_t> words) {
return words;
}

void testPushConstantInterface(bool optimizationEnabled) {
for (const auto version : {Spirv11, Spirv13, 0x00010400u, Spirv16}) {
const bool extendedInterface = version >= 0x00010400u;
spvtools::SpirvTools tools(extendedInterface ? SPV_ENV_VULKAN_1_3 : SPV_ENV_VULKAN_1_1);
const std::string source = std::string(R"(OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main")") + (extendedInterface ? " %push\n" : "\n") + R"(OpExecutionMode %main LocalSize 1 1 1
OpDecorate %block Block
OpMemberDecorate %block 0 Offset 0
%void = OpTypeVoid
%function = OpTypeFunction %void
%uint = OpTypeInt 32 0
%zero = OpConstant %uint 0
%block = OpTypeStruct %uint
%pointer = OpTypePointer PushConstant %block
%push = OpVariable %pointer PushConstant
%main = OpFunction %void None %function
%entry = OpLabel
%dead = OpIAdd %uint %zero %zero
OpReturn
OpFunctionEnd
)";
std::vector<std::uint32_t> words;
check(tools.Assemble(source, &words), "push constant fixture did not assemble");
if (words.empty()) continue;
words[1] = version;
check(tools.Validate(words), "push constant fixture is invalid");
for (const bool specialize : {false, true}) {
try {
const auto output = ShaderRecompiler::ValidateAndOptimizeSpirv(
words, extendedInterface ? Vulkan13 : Vulkan11, version, false, true, specialize);
check(tools.Validate(output), "push constant optimization produced invalid SPIR-V");
check(output[1] == version, "push constant optimization changed SPIR-V version");
check(opcodeCount(output, spv::OpVariable) == 1u, "optimizer removed the unused push constant interface");
check(opcodeCount(output, spv::OpTypeStruct) == 1u, "optimizer removed the push constant block type");
check(opcodeCount(output, spv::OpMemberDecorate) == 1u, "optimizer removed the push constant member offset");
check(opcodeCount(output, spv::OpIAdd) == (optimizationEnabled ? 0u : 1u), "push constant preservation changed dead arithmetic elimination");
} catch (const std::exception& error) {
check(false, std::string("push constant interface: ") + error.what());
}
}
}
}

void testNarrowConversions(bool optimizationEnabled) {
spvtools::SpirvTools validator(SPV_ENV_VULKAN_1_1);
for (const auto& type : Types) {
Expand Down Expand Up @@ -1037,6 +1081,7 @@ void testSpecializedPrivateCompositeTableLoad() {
int main() {
const char* mode = std::getenv("APS5_SPIRV_OPT");
const bool optimizationEnabled = mode == nullptr || std::string(mode) != "none";
testPushConstantInterface(optimizationEnabled);
testNarrowConversions(optimizationEnabled);
testLargeFunctionArray();
testSpecializedSelectionExitSpirv16();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ bool HardwareFlush = false;

std::size_t CompiledWords(AgcDriver::VulkanDevice& device, bool hardwareFlush, bool& declaresFlush) {
std::vector<std::uint32_t> userData(8, 0u);
const auto input = BufferDescriptor(Input.data(), static_cast<std::uint32_t>(Input.size() * 4u));
const auto output = BufferDescriptor(Output.data(), static_cast<std::uint32_t>(Output.size() * 4u));
std::copy(input.begin(), input.end(), userData.begin());
std::copy(output.begin(), output.end(), userData.begin() + 4);
const std::array<ShaderRecompiler::MemoryRegion, 1> memory{{{reinterpret_cast<std::uintptr_t>(Code.data()), std::as_bytes(std::span(Code))}}};
const ShaderRecompiler::ShaderComputeStageInfo compute{{Threads, 1, 1}, 0u, {false, false, false}, false, 1};
ShaderRecompiler::RecompileRequest request{
Expand Down
Loading
Loading