mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
fix(shader): relocate prepared push constants across graphics stages
This commit is contained in:
@@ -168,7 +168,13 @@ std::shared_ptr<const ShaderRecompiler::SourceHandle> SourceHandleFor(const Shad
|
||||
snapshot.prepared->entries.push_back({codeOffset, handle});
|
||||
return handle;
|
||||
}
|
||||
throw std::runtime_error("AGC driver: prepared shader artifact is missing for the requested static ABI");
|
||||
std::string layouts;
|
||||
for (const auto& entry : snapshot.prepared->entries) {
|
||||
if (entry.codeOffset != codeOffset || entry.handle == nullptr || entry.handle->artifact == nullptr) continue;
|
||||
const auto& layout = entry.handle->artifact->layout;
|
||||
layouts += " [" + std::to_string(layout.pushConstantOffsetBytes) + "," + std::to_string(layout.pushConstantSizeBytes) + "]";
|
||||
}
|
||||
throw std::runtime_error("AGC driver: prepared shader artifact is missing for the requested static ABI: address=" + std::to_string(request.shader.codeAddress) + " stage=" + std::to_string(static_cast<std::uint32_t>(request.shader.stage)) + " wave=" + std::to_string(request.context.waveSize) + " pushOffset=" + std::to_string(request.layout.pushConstantOffsetBytes) + " pushCapacity=" + std::to_string(request.layout.pushConstantSizeBytes) + " preparedLayouts=" + layouts);
|
||||
}
|
||||
|
||||
ShaderRecompiler::RectListShaders PreparedRectangle(const ShaderSnapshot& snapshot, std::uint64_t vertexId, std::uint64_t fragmentId) {
|
||||
@@ -190,7 +196,13 @@ ShaderRecompiler::PreparedShaderInvocation InvocationFor(const ShaderSnapshot& s
|
||||
invocationRequest.shader.code = ShaderRecompiler::GetPreparedCode(*entry.handle);
|
||||
if (auto invocation = ShaderRecompiler::PreparedShaderInvocation::TryCreate(invocationRequest, entry.handle)) return std::move(*invocation);
|
||||
}
|
||||
throw std::runtime_error("AGC driver: prepared shader artifact is missing for the requested static ABI");
|
||||
std::string layouts;
|
||||
for (const auto& entry : snapshot.prepared->entries) {
|
||||
if (entry.codeOffset != codeOffset || entry.handle == nullptr || entry.handle->artifact == nullptr) continue;
|
||||
const auto& layout = entry.handle->artifact->layout;
|
||||
layouts += " [" + std::to_string(layout.pushConstantOffsetBytes) + "," + std::to_string(layout.pushConstantSizeBytes) + "]";
|
||||
}
|
||||
throw std::runtime_error("AGC driver: prepared shader artifact is missing for the requested static ABI: address=" + std::to_string(request.shader.codeAddress) + " stage=" + std::to_string(static_cast<std::uint32_t>(request.shader.stage)) + " wave=" + std::to_string(request.context.waveSize) + " pushOffset=" + std::to_string(request.layout.pushConstantOffsetBytes) + " pushCapacity=" + std::to_string(request.layout.pushConstantSizeBytes) + " preparedLayouts=" + layouts);
|
||||
}
|
||||
namespace {
|
||||
|
||||
@@ -307,7 +319,7 @@ std::vector<PreparedShaders::Entry> PrepareRegistered(const ShaderSnapshot& snap
|
||||
request.context.compute->partialThreads = {1, 1, 1};
|
||||
append();
|
||||
} else if (pixel) {
|
||||
request.layout.pushConstantSizeBytes = ShaderRecompiler::MeshDrawPushOffsetBytes;
|
||||
request.layout.pushConstantSizeBytes = 0;
|
||||
append();
|
||||
}
|
||||
return entries;
|
||||
|
||||
@@ -20,6 +20,7 @@ inline constexpr std::uint32_t ImageBase = 1024u;
|
||||
inline constexpr std::uint32_t ImageWords = 5u;
|
||||
inline constexpr std::uint32_t VertexBase = 4096u;
|
||||
inline constexpr std::uint32_t VertexWords = 6u;
|
||||
inline constexpr std::uint32_t PushDataOffset = 8188u;
|
||||
inline constexpr std::uint32_t ExportBase = 8192u;
|
||||
inline constexpr std::uint32_t HeapCountBase = 8256u;
|
||||
inline constexpr std::uint32_t MipCountBase = 8320u;
|
||||
|
||||
@@ -515,6 +515,7 @@ RecompileResult materializeResult(const CompiledVariant& variant, const Recompil
|
||||
DescriptorBindingBuilder{}.Populate(bindings, variant.info.info, variant.info.stage, variant.info.userDataBase, snapshot, partialThreads(request), request.context.pixel ? std::span<const std::uint8_t>(request.context.pixel->targetExportMapping) : std::span<const std::uint8_t>{});
|
||||
result.bindings = std::move(bindings.bindings);
|
||||
result.specialization = std::move(bindings.specialization);
|
||||
if (variant.bindings.layout.UsesPushData()) result.specialization.push_back({PipelineSpecialization::PushDataOffset, request.layout.pushConstantOffsetBytes / 4u});
|
||||
result.pushConstants = std::move(bindings.pushConstants);
|
||||
result.vertexAttributes.reserve(result.vertexInputs.size());
|
||||
std::array<std::uint32_t, ShaderVertexStageInfo::MaxResources> vertexClasses{};
|
||||
@@ -695,6 +696,7 @@ std::uint64_t snapshotHash(const RecompileRequest& request, const ResourceSnapsh
|
||||
mix(snapshot.uniformFill.words);
|
||||
mix(snapshot.uniformFill.value);
|
||||
for (const auto threads : partialThreads(request)) mix(threads);
|
||||
mix(request.layout.pushConstantOffsetBytes);
|
||||
if (request.context.pixel) {
|
||||
for (const auto mapping : request.context.pixel->targetExportMapping) mix(mapping);
|
||||
}
|
||||
@@ -866,7 +868,14 @@ std::shared_ptr<const SourceHandle> PrepareShader(const RecompileRequest& reques
|
||||
}
|
||||
|
||||
bool MatchesPreparedShader(const RecompileRequest& request, const SourceHandle& handle) {
|
||||
if (handle.source == nullptr || handle.artifact == nullptr || !sameLayout(handle.artifact->layout, request.layout)) return false;
|
||||
if (handle.source == nullptr || handle.artifact == nullptr) return false;
|
||||
const auto& layout = request.layout;
|
||||
const auto& prepared = handle.artifact->bindings.layout;
|
||||
if (layout.descriptorSet != handle.artifact->layout.descriptorSet || layout.firstBinding != handle.artifact->layout.firstBinding) return false;
|
||||
if (layout.pushConstantOffsetBytes % 4u != 0u || layout.pushConstantSizeBytes % 4u != 0u || layout.pushConstantOffsetBytes > NativePushConstantSize || layout.pushConstantSizeBytes > NativePushConstantSize - layout.pushConstantOffsetBytes) return false;
|
||||
const auto words = prepared.ShaderDataDwords();
|
||||
const bool usesPush = prepared.runtimeImageCount == 0u && words != 0u && words <= layout.pushConstantSizeBytes / 4u;
|
||||
if (prepared.UsesPushData() != usesPush) return false;
|
||||
struct PreparedKeyStorage {};
|
||||
auto& key = HostThreadLocal<std::vector<std::uint64_t>, PreparedKeyStorage>();
|
||||
RecompileCacheKey::BuildInterface(request, key);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace ShaderRecompiler::RuntimeAbi {
|
||||
|
||||
inline constexpr std::uint32_t Version = 7u;
|
||||
inline constexpr std::uint32_t Version = 8u;
|
||||
inline constexpr std::uint32_t DescriptorSet = 0u;
|
||||
inline constexpr std::uint32_t StageCount = 4u;
|
||||
inline constexpr std::uint32_t PushConstantDwords = 32u;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "PipelineSpecialization.hpp"
|
||||
#include "SpirvBackend/SpirvMemory/SpirvBufferAccess.hpp"
|
||||
#include "SpirvBackend/SpirvEmitterHelpers.hpp"
|
||||
#include "SpirvBackend/SpirvMemory/SpirvTypes.hpp"
|
||||
@@ -36,7 +37,9 @@ std::uint32_t EmitShaderDataDwordLoad(SpirvEmitterState& state, std::uint32_t dw
|
||||
const auto pointer = state.module.AllocateId();
|
||||
const auto value = state.module.AllocateId();
|
||||
if (layout.UsesPushData()) {
|
||||
state.module.AddFunction(spv::OpAccessChain, TypePushConstantElementPointer(state), pointer, state.pushConstantVariable, ConstantU32(state, 0), ConstantU32(state, dwordIndex + layout.pushDataStartDword));
|
||||
const auto base = state.module.SpecializationConstant(TypeU32(state), PipelineSpecialization::PushDataOffset, layout.pushDataStartDword);
|
||||
const auto index = Binary(state, spv::OpIAdd, TypeU32(state), base, ConstantU32(state, dwordIndex));
|
||||
state.module.AddFunction(spv::OpAccessChain, TypePushConstantElementPointer(state), pointer, state.pushConstantVariable, ConstantU32(state, 0), index);
|
||||
} else if (state.shaderDataStorageVariable != 0) {
|
||||
state.module.AddFunction(spv::OpAccessChain, TypeStorageBufferElementPointer(state), pointer, state.shaderDataStorageVariable, ConstantU32(state, 0), ConstantU32(state, dwordIndex));
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user