[dxbc] Do not emit depth compare for unsupported image types

Fixes invalid SPIR-V.
This commit is contained in:
Philip Rebohle 2024-03-07 16:10:50 +01:00
parent 707ad6f328
commit 69a52b3da0
1 changed files with 113 additions and 98 deletions

View File

@ -3881,33 +3881,38 @@ namespace dxvk {
if (imageOperands.sparse) if (imageOperands.sparse)
resultTypeId = getSparseResultTypeId(texelTypeId); resultTypeId = getSparseResultTypeId(texelTypeId);
switch (ins.op) { if (sampledImageId) {
// Simple image gather operation switch (ins.op) {
case DxbcOpcode::Gather4: // Simple image gather operation
case DxbcOpcode::Gather4S: case DxbcOpcode::Gather4:
case DxbcOpcode::Gather4Po: case DxbcOpcode::Gather4S:
case DxbcOpcode::Gather4PoS: { case DxbcOpcode::Gather4Po:
resultId = m_module.opImageGather( case DxbcOpcode::Gather4PoS: {
resultTypeId, sampledImageId, coord.id, resultId = m_module.opImageGather(
m_module.consti32(samplerReg.swizzle[0]), resultTypeId, sampledImageId, coord.id,
imageOperands); m_module.consti32(samplerReg.swizzle[0]),
} break; imageOperands);
} break;
// Depth-compare operation // Depth-compare operation
case DxbcOpcode::Gather4C: case DxbcOpcode::Gather4C:
case DxbcOpcode::Gather4CS: case DxbcOpcode::Gather4CS:
case DxbcOpcode::Gather4PoC: case DxbcOpcode::Gather4PoC:
case DxbcOpcode::Gather4PoCS: { case DxbcOpcode::Gather4PoCS: {
resultId = m_module.opImageDrefGather( resultId = m_module.opImageDrefGather(
resultTypeId, sampledImageId, coord.id, resultTypeId, sampledImageId, coord.id,
referenceValue.id, imageOperands); referenceValue.id, imageOperands);
} break; } break;
default: default:
Logger::warn(str::format( Logger::warn(str::format(
"DxbcCompiler: Unhandled instruction: ", "DxbcCompiler: Unhandled instruction: ",
ins.op)); ins.op));
return; return;
}
} else {
Logger::warn(str::format("DxbcCompiler: ", ins.op, ": Unsupported image type"));
resultId = m_module.constNull(resultTypeId);
} }
// If necessary, deal with the sparse result // If necessary, deal with the sparse result
@ -4035,73 +4040,78 @@ namespace dxvk {
if (imageOperands.sparse) if (imageOperands.sparse)
resultTypeId = getSparseResultTypeId(texelTypeId); resultTypeId = getSparseResultTypeId(texelTypeId);
switch (ins.op) { if (sampledImageId) {
// Simple image sample operation switch (ins.op) {
case DxbcOpcode::Sample: // Simple image sample operation
case DxbcOpcode::SampleClampS: { case DxbcOpcode::Sample:
resultId = m_module.opImageSampleImplicitLod( case DxbcOpcode::SampleClampS: {
resultTypeId, sampledImageId, coord.id, resultId = m_module.opImageSampleImplicitLod(
imageOperands); resultTypeId, sampledImageId, coord.id,
} break; imageOperands);
} break;
// Depth-compare operation // Depth-compare operation
case DxbcOpcode::SampleC: case DxbcOpcode::SampleC:
case DxbcOpcode::SampleCClampS: { case DxbcOpcode::SampleCClampS: {
resultId = m_module.opImageSampleDrefImplicitLod( resultId = m_module.opImageSampleDrefImplicitLod(
resultTypeId, sampledImageId, coord.id, resultTypeId, sampledImageId, coord.id,
referenceValue.id, imageOperands); referenceValue.id, imageOperands);
} break; } break;
// Depth-compare operation on mip level zero // Depth-compare operation on mip level zero
case DxbcOpcode::SampleClz: case DxbcOpcode::SampleClz:
case DxbcOpcode::SampleClzS: { case DxbcOpcode::SampleClzS: {
imageOperands.flags |= spv::ImageOperandsLodMask; imageOperands.flags |= spv::ImageOperandsLodMask;
imageOperands.sLod = m_module.constf32(0.0f); imageOperands.sLod = m_module.constf32(0.0f);
resultId = m_module.opImageSampleDrefExplicitLod( resultId = m_module.opImageSampleDrefExplicitLod(
resultTypeId, sampledImageId, coord.id, resultTypeId, sampledImageId, coord.id,
referenceValue.id, imageOperands); referenceValue.id, imageOperands);
} break; } break;
// Sample operation with explicit gradients // Sample operation with explicit gradients
case DxbcOpcode::SampleD: case DxbcOpcode::SampleD:
case DxbcOpcode::SampleDClampS: { case DxbcOpcode::SampleDClampS: {
imageOperands.flags |= spv::ImageOperandsGradMask; imageOperands.flags |= spv::ImageOperandsGradMask;
imageOperands.sGradX = explicitGradientX.id; imageOperands.sGradX = explicitGradientX.id;
imageOperands.sGradY = explicitGradientY.id; imageOperands.sGradY = explicitGradientY.id;
resultId = m_module.opImageSampleExplicitLod( resultId = m_module.opImageSampleExplicitLod(
resultTypeId, sampledImageId, coord.id, resultTypeId, sampledImageId, coord.id,
imageOperands); imageOperands);
} break; } break;
// Sample operation with explicit LOD // Sample operation with explicit LOD
case DxbcOpcode::SampleL: case DxbcOpcode::SampleL:
case DxbcOpcode::SampleLS: { case DxbcOpcode::SampleLS: {
imageOperands.flags |= spv::ImageOperandsLodMask; imageOperands.flags |= spv::ImageOperandsLodMask;
imageOperands.sLod = lod.id; imageOperands.sLod = lod.id;
resultId = m_module.opImageSampleExplicitLod( resultId = m_module.opImageSampleExplicitLod(
resultTypeId, sampledImageId, coord.id, resultTypeId, sampledImageId, coord.id,
imageOperands); imageOperands);
} break; } break;
// Sample operation with LOD bias // Sample operation with LOD bias
case DxbcOpcode::SampleB: case DxbcOpcode::SampleB:
case DxbcOpcode::SampleBClampS: { case DxbcOpcode::SampleBClampS: {
imageOperands.flags |= spv::ImageOperandsBiasMask; imageOperands.flags |= spv::ImageOperandsBiasMask;
imageOperands.sLodBias = lod.id; imageOperands.sLodBias = lod.id;
resultId = m_module.opImageSampleImplicitLod( resultId = m_module.opImageSampleImplicitLod(
resultTypeId, sampledImageId, coord.id, resultTypeId, sampledImageId, coord.id,
imageOperands); imageOperands);
} break; } break;
default: default:
Logger::warn(str::format( Logger::warn(str::format(
"DxbcCompiler: Unhandled instruction: ", "DxbcCompiler: Unhandled instruction: ",
ins.op)); ins.op));
return; return;
}
} else {
Logger::warn(str::format("DxbcCompiler: ", ins.op, ": Unsupported image type"));
resultId = m_module.constNull(resultTypeId);
} }
DxbcRegisterValue result; DxbcRegisterValue result;
@ -5147,9 +5157,14 @@ namespace dxvk {
const DxbcShaderResource& textureResource, const DxbcShaderResource& textureResource,
const DxbcSampler& samplerResource, const DxbcSampler& samplerResource,
bool isDepthCompare) { bool isDepthCompare) {
const uint32_t sampledImageType = isDepthCompare uint32_t baseId = isDepthCompare
? m_module.defSampledImageType(textureResource.depthTypeId) ? textureResource.depthTypeId
: m_module.defSampledImageType(textureResource.colorTypeId); : textureResource.colorTypeId;
if (!baseId)
return 0;
uint32_t sampledImageType = m_module.defSampledImageType(baseId);
return m_module.opSampledImage(sampledImageType, return m_module.opSampledImage(sampledImageType,
m_module.opLoad(textureResource.imageTypeId, textureResource.varId), m_module.opLoad(textureResource.imageTypeId, textureResource.varId),