SPV Capabilities: StorageImageExtendedFormats, StorageImageReadWithoutFormat, and StorageImageWriteWithoutFormat.

This commit is contained in:
John Kessenich
2016-02-15 11:57:00 -07:00
parent 5e80113939
commit 5d0fa9781b
4 changed files with 90 additions and 35 deletions

View File

@@ -90,6 +90,7 @@ public:
protected:
spv::Decoration TranslateInterpolationDecoration(const glslang::TQualifier& qualifier);
spv::BuiltIn TranslateBuiltInDecoration(glslang::TBuiltInVariable);
spv::ImageFormat TranslateImageFormat(const glslang::TType& type);
spv::Id createSpvVariable(const glslang::TIntermSymbol*);
spv::Id getSampledType(const glslang::TSampler&);
spv::Id convertGlslangToSpvType(const glslang::TType& type);
@@ -404,10 +405,48 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI
}
// Translate glslang image layout format to SPIR-V image format.
spv::ImageFormat TranslateImageFormat(const glslang::TType& type)
spv::ImageFormat TGlslangToSpvTraverser::TranslateImageFormat(const glslang::TType& type)
{
assert(type.getBasicType() == glslang::EbtSampler);
// Check for capabilities
switch (type.getQualifier().layoutFormat) {
case glslang::ElfRg32f:
case glslang::ElfRg16f:
case glslang::ElfR11fG11fB10f:
case glslang::ElfR16f:
case glslang::ElfRgba16:
case glslang::ElfRgb10A2:
case glslang::ElfRg16:
case glslang::ElfRg8:
case glslang::ElfR16:
case glslang::ElfR8:
case glslang::ElfRgba16Snorm:
case glslang::ElfRg16Snorm:
case glslang::ElfRg8Snorm:
case glslang::ElfR16Snorm:
case glslang::ElfR8Snorm:
case glslang::ElfRg32i:
case glslang::ElfRg16i:
case glslang::ElfRg8i:
case glslang::ElfR16i:
case glslang::ElfR8i:
case glslang::ElfRgb10a2ui:
case glslang::ElfRg32ui:
case glslang::ElfRg16ui:
case glslang::ElfRg8ui:
case glslang::ElfR16ui:
case glslang::ElfR8ui:
builder.addCapability(spv::CapabilityStorageImageExtendedFormats);
break;
default:
break;
}
// do the translation
switch (type.getQualifier().layoutFormat) {
case glslang::ElfNone: return spv::ImageFormatUnknown;
case glslang::ElfRgba32f: return spv::ImageFormatRgba32f;
@@ -2137,6 +2176,8 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO
operands.push_back(*opIt);
}
return builder.createOp(spv::OpImageRead, convertGlslangToSpvType(node->getType()), operands);
if (builder.getImageTypeFormat(builder.getImageType(operands.front())) == spv::ImageFormatUnknown)
builder.addCapability(spv::CapabilityStorageImageReadWithoutFormat);
} else if (node->getOp() == glslang::EOpImageStore) {
if (sampler.ms) {
operands.push_back(*(opIt + 1));
@@ -2145,6 +2186,8 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO
} else
operands.push_back(*opIt);
builder.createNoResultOp(spv::OpImageWrite, operands);
if (builder.getImageTypeFormat(builder.getImageType(operands.front())) == spv::ImageFormatUnknown)
builder.addCapability(spv::CapabilityStorageImageWriteWithoutFormat);
return spv::NoResult;
} else if (node->isSparseImage()) {
spv::MissingFunctionality("sparse image functions");
@@ -2894,10 +2937,6 @@ spv::Id TGlslangToSpvTraverser::createUnaryOperation(glslang::TOperator op, spv:
return createAtomicOperation(op, precision, typeId, operands, typeProxy);
}
case glslang::EOpImageLoad:
unaryOp = spv::OpImageRead;
break;
case glslang::EOpBitFieldReverse:
unaryOp = spv::OpBitReverse;
break;

View File

@@ -124,6 +124,7 @@ public:
Id getContainedTypeId(Id typeId) const;
Id getContainedTypeId(Id typeId, int) const;
StorageClass getTypeStorageClass(Id typeId) const { return module.getStorageClass(typeId); }
ImageFormat getImageTypeFormat(Id typeId) const { return (ImageFormat)module.getInstruction(typeId)->getImmediateOperand(6); }
bool isPointer(Id resultId) const { return isPointerType(getTypeId(resultId)); }
bool isScalar(Id resultId) const { return isScalarType(getTypeId(resultId)); }