feat(shader): add fragmentShaderBarycentricEnabled flag to recompiler

This commit is contained in:
boykopovar 2026-09-22 21:35:45 +03:00
parent 4734f43c60
commit bb27de6fac
8 changed files with 9 additions and 2 deletions

View File

@ -607,7 +607,7 @@ void VulkanDevice::WaitPresented(std::uint64_t id) {
ShaderRecompiler::SpirvTarget VulkanDevice::Target() const {
const auto& limits = state->properties.limits;
ShaderRecompiler::SpirvTarget target{VK_API_VERSION_1_1, state->meshShader ? 0x00010400u : 0x00010300u, state->subgroup.subgroupSize, ShaderRecompiler::BdaAbi::Version, state->capabilities, state->spirvExtensions, {limits.maxComputeWorkGroupSize[0], limits.maxComputeWorkGroupSize[1], limits.maxComputeWorkGroupSize[2]}, limits.maxComputeWorkGroupInvocations, limits.maxComputeSharedMemorySize, {}, {}};
ShaderRecompiler::SpirvTarget target{VK_API_VERSION_1_1, state->meshShader ? 0x00010400u : 0x00010300u, state->subgroup.subgroupSize, ShaderRecompiler::BdaAbi::Version, state->capabilities, state->spirvExtensions, false, {limits.maxComputeWorkGroupSize[0], limits.maxComputeWorkGroupSize[1], limits.maxComputeWorkGroupSize[2]}, limits.maxComputeWorkGroupInvocations, limits.maxComputeSharedMemorySize, {}, {}};
if (state->meshShader) {
const auto& mesh = state->meshLimits;
target.mesh = ShaderRecompiler::MeshTargetLimits{{mesh.maxMeshWorkGroupSize[0], mesh.maxMeshWorkGroupSize[1], mesh.maxMeshWorkGroupSize[2]}, mesh.maxMeshWorkGroupInvocations, std::min(mesh.maxMeshSharedMemorySize, mesh.maxMeshPayloadAndSharedMemorySize), mesh.maxMeshOutputVertices, mesh.maxMeshOutputPrimitives, mesh.maxMeshOutputComponents, std::min(mesh.maxMeshOutputMemorySize, mesh.maxMeshPayloadAndOutputMemorySize), mesh.meshOutputPerVertexGranularity, mesh.meshOutputPerPrimitiveGranularity};

View File

@ -43,6 +43,7 @@ void RunBdaContractTests() {
request.target.bdaAbiVersion = BdaAbi::Version;
request.target.supportedCapabilities = capabilities;
request.target.supportedExtensions = extensions;
request.target.fragmentShaderBarycentricEnabled = false;
const RequestSerializer serializer;
const auto encoded = serializer.Serialize(request);
const auto decoded = serializer.Deserialize(encoded);

View File

@ -72,6 +72,7 @@ int main() {
request.target.vulkanVersion = 0x00401000u;
request.target.spirvVersion = 0x00010300u;
request.target.subgroupSize = 64;
request.target.fragmentShaderBarycentricEnabled = false;
request.layout.pushConstantSizeBytes = 128;
expectFailure([&] { static_cast<void>(Recompile(request)); }, "SrtWalker::EvaluateRuntimeSources", "missing snapshot unexpectedly read live memory");

View File

@ -525,6 +525,7 @@ void writeSpirvTarget(Writer& writer, const SpirvTarget& target) {
for (const std::string_view extension : target.supportedExtensions) {
writer.WriteString(extension);
}
writer.WriteBool(target.fragmentShaderBarycentricEnabled);
for (const std::uint32_t value : target.maxWorkgroupSize) {
writer.WriteU32(value);
}
@ -557,6 +558,7 @@ SpirvTarget readSpirvTarget(Reader& reader, DeserializedRequest& result) {
result.supportedExtensions.push_back(result.supportedExtensionStorage.back());
}
target.supportedExtensions = result.supportedExtensions;
target.fragmentShaderBarycentricEnabled = reader.ReadBool();
for (std::uint32_t& value : target.maxWorkgroupSize) {
value = reader.ReadU32();
}

View File

@ -72,6 +72,7 @@ IrProgram PrepareResourceProgram(const RecompileRequest& request) {
translateOptions.userDataBaseRegister = request.context.userDataBaseRegister;
translateOptions.userDataCount = static_cast<std::uint32_t>(request.context.userData.size());
translateOptions.embeddedFetch = nullptr;
translateOptions.fragmentShaderBarycentricEnabled = request.target.fragmentShaderBarycentricEnabled;
translateOptions.inputInfo = inputInfo;
constexpr InstructionTranslator translator;

View File

@ -126,6 +126,7 @@ struct SpirvTarget {
std::uint32_t bdaAbiVersion;
std::span<const std::uint32_t> supportedCapabilities;
std::span<const std::string_view> supportedExtensions;
bool fragmentShaderBarycentricEnabled;
std::array<std::uint32_t, 3> maxWorkgroupSize;
std::uint32_t maxWorkgroupInvocations;
std::uint32_t maxWorkgroupSharedMemoryBytes;

View File

@ -30,6 +30,7 @@ struct TranslateOptions {
std::uint32_t userDataCount = 64;
std::uint32_t scratchDwords = 0;
std::uint64_t shaderHash = 0;
bool fragmentShaderBarycentricEnabled = false;
ShaderStageInputInfo inputInfo;
const EmbeddedFetchPlan* embeddedFetch = nullptr;
};

View File

@ -297,7 +297,7 @@ void emitEntryPrologue(IrProgram& program, IrBlock& entryBlock, const TranslateO
entryIr.SetVectorReg(static_cast<VectorReg>(8), builtin(StageInputKind::PrimitiveId));
} else if (options.stage == ShaderStageKind::Pixel) {
const auto* ps = options.inputInfo.pixel;
if (ps->psPerspectiveCenterVgpr != std::numeric_limits<std::uint32_t>::max()) {
if (options.fragmentShaderBarycentricEnabled && ps->psPerspectiveCenterVgpr != std::numeric_limits<std::uint32_t>::max()) {
entryIr.SetVectorReg(static_cast<VectorReg>(ps->psPerspectiveCenterVgpr), builtin(StageInputKind::BaryCoordSmooth, 0u));
entryIr.SetVectorReg(static_cast<VectorReg>(ps->psPerspectiveCenterVgpr + 1u), builtin(StageInputKind::BaryCoordSmooth, 1u));
}