Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions include/dxc/dxcapi.internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,14 @@ enum LEGAL_INTRINSIC_COMPTYPES {

#ifdef ENABLE_SPIRV_CODEGEN
LICOMPTYPE_VK_BUFFER_POINTER = 56,
LICOMPTYPE_VK_SAMPLED_TEXTURE2D = 57,
LICOMPTYPE_COUNT = 58
LICOMPTYPE_VK_SAMPLED_TEXTURE1D = 57,
LICOMPTYPE_VK_SAMPLED_TEXTURE1D_ARRAY = 58,
LICOMPTYPE_VK_SAMPLED_TEXTURE2D = 59,
LICOMPTYPE_VK_SAMPLED_TEXTURE2D_ARRAY = 60,
LICOMPTYPE_VK_SAMPLED_TEXTURE2DMS = 61,
LICOMPTYPE_VK_SAMPLED_TEXTURE2DMS_ARRAY = 62,
LICOMPTYPE_VK_SAMPLED_TEXTURE3D = 63,
LICOMPTYPE_COUNT = 64
#else
LICOMPTYPE_COUNT = 56
#endif
Expand Down
4 changes: 4 additions & 0 deletions tools/clang/include/clang/SPIRV/AstTypeProbe.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ bool isTexture(QualType);
/// Texture2DMSArray type.
bool isTextureMS(QualType);

/// \brief Returns true if the given type is an HLSL SampledTexture2DMS or
/// SampledTexture2DMSArray type.
bool isSampledTextureMS(QualType);

/// \brief Returns true if the given type is an HLSL SampledTexture type.
bool isSampledTexture(QualType);

Expand Down
2 changes: 0 additions & 2 deletions tools/clang/lib/AST/ASTContextHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1376,8 +1376,6 @@ CXXRecordDecl *hlsl::DeclareVkSampledTextureType(ASTContext &context,
DeclContext *declContext,
llvm::StringRef hlslTypeName,
QualType defaultParamType) {
// TODO(https://github.com/microsoft/DirectXShaderCompiler/issues/7979): Later
// generalize these to all SampledTexture types.
BuiltinTypeDeclBuilder Builder(declContext, hlslTypeName,
TagDecl::TagKind::TTK_Struct);

Expand Down
15 changes: 14 additions & 1 deletion tools/clang/lib/SPIRV/AstTypeProbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,11 @@ bool isSampledTexture(QualType type) {
const auto name = rt->getDecl()->getName();
// TODO(https://github.com/microsoft/DirectXShaderCompiler/issues/7979): Add
// other sampled texture types as needed.
if (name == "SampledTexture2D")

if (name == "SampledTexture1D" || name == "SampledTexture1DArray" ||
name == "SampledTexture2D" || name == "SampledTexture2DArray" ||
name == "SampledTexture2DMS" || name == "SampledTexture2DMSArray" ||
name == "SampledTexture3D")
return true;
}
return false;
Expand All @@ -946,6 +950,15 @@ bool isTextureMS(QualType type) {
return false;
}

bool isSampledTextureMS(QualType type) {
if (const auto *rt = type->getAs<RecordType>()) {
const auto name = rt->getDecl()->getName();
if (name == "SampledTexture2DMS" || name == "SampledTexture2DMSArray")
return true;
}
return false;
}

bool isSampler(QualType type) {
if (const auto *rt = type->getAs<RecordType>()) {
const auto name = rt->getDecl()->getName();
Expand Down
17 changes: 13 additions & 4 deletions tools/clang/lib/SPIRV/LowerTypeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,10 @@ const SpirvType *LowerTypeVisitor::lowerVkTypeInVkNamespace(
assert(visitedTypeStack.size() == visitedTypeStackSize);
return pointerType;
}
if (name == "SampledTexture2D") {
if (name == "SampledTexture1D" || name == "SampledTexture1DArray" ||
name == "SampledTexture2D" || name == "SampledTexture2DArray" ||
name == "SampledTexture2DMS" || name == "SampledTexture2DMSArray" ||
name == "SampledTexture3D") {
const auto sampledType = hlsl::GetHLSLResourceResultType(type);
auto loweredType = lowerType(getElementType(astContext, sampledType), rule,
/*isRowMajor*/ llvm::None, srcLoc);
Expand All @@ -860,10 +863,16 @@ const SpirvType *LowerTypeVisitor::lowerVkTypeInVkNamespace(
loweredType = spvContext.getUIntType(32);
}

const spv::Dim dimension =
name.count("1D") > 0
? spv::Dim::Dim1D
: (name.count("3D") > 0 ? spv::Dim::Dim3D : spv::Dim::Dim2D);
const bool isArray = name.count("Array") > 0;
const bool isMS = name.count("MS") > 0;

const auto *imageType = spvContext.getImageType(
loweredType, spv::Dim::Dim2D, ImageType::WithDepth::No,
false /* array */, false /* ms */, ImageType::WithSampler::Yes,
spv::ImageFormat::Unknown);
loweredType, dimension, ImageType::WithDepth::No, isArray, isMS,
ImageType::WithSampler::Yes, spv::ImageFormat::Unknown);
return spvContext.getSampledImageType(imageType);
}
emitError("unknown type %0 in vk namespace", srcLoc) << type;
Expand Down
26 changes: 22 additions & 4 deletions tools/clang/lib/SPIRV/SpirvEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4283,9 +4283,21 @@ SpirvInstruction *SpirvEmitter::processRWByteAddressBufferAtomicMethods(
SpirvInstruction *
SpirvEmitter::processGetSamplePosition(const CXXMemberCallExpr *expr) {
const auto *object = expr->getImplicitObjectArgument()->IgnoreParens();
auto *objectInstr = loadIfGLValue(object);
if (isSampledTexture(object->getType())) {
LowerTypeVisitor lowerTypeVisitor(astContext, spvContext, spirvOptions,
spvBuilder);
const SpirvType *spvType =
lowerTypeVisitor.lowerType(object->getType(), SpirvLayoutRule::Void,
llvm::None, expr->getExprLoc());
const auto *sampledType = cast<SampledImageType>(spvType);
const SpirvType *imgType = sampledType->getImageType();
objectInstr = spvBuilder.createUnaryOp(spv::Op::OpImage, imgType,
objectInstr, expr->getExprLoc());
}
auto *sampleCount = spvBuilder.createImageQuery(
spv::Op::OpImageQuerySamples, astContext.UnsignedIntTy,
expr->getExprLoc(), loadIfGLValue(object));
expr->getExprLoc(), objectInstr);
if (!spirvOptions.noWarnEmulatedFeatures)
emitWarning("GetSamplePosition is emulated using many SPIR-V instructions "
"due to lack of direct SPIR-V equivalent, so it only supports "
Expand Down Expand Up @@ -4393,7 +4405,11 @@ SpirvEmitter::processBufferTextureGetDimensions(const CXXMemberCallExpr *expr) {

if ((typeName == "Texture1D" && numArgs > 1) ||
(typeName == "Texture2D" && numArgs > 2) ||
(typeName == "SampledTexture1D" && numArgs > 1) ||
(typeName == "SampledTexture1DArray" && numArgs > 2) ||
(typeName == "SampledTexture2D" && numArgs > 2) ||
(typeName == "SampledTexture2DArray" && numArgs > 3) ||
(typeName == "SampledTexture3D" && numArgs > 3) ||
(typeName == "TextureCube" && numArgs > 2) ||
(typeName == "Texture3D" && numArgs > 3) ||
(typeName == "Texture1DArray" && numArgs > 2) ||
Expand All @@ -4402,7 +4418,8 @@ SpirvEmitter::processBufferTextureGetDimensions(const CXXMemberCallExpr *expr) {
mipLevel = expr->getArg(0);
numLevels = expr->getArg(numArgs - 1);
}
if (isTextureMS(type)) {

if (isSampledTextureMS(type) || isTextureMS(type)) {
numSamples = expr->getArg(numArgs - 1);
}

Expand Down Expand Up @@ -4743,7 +4760,7 @@ SpirvInstruction *SpirvEmitter::processBufferTextureLoad(

// For Texture2DMS and Texture2DMSArray, Sample must be used rather than Lod.
SpirvInstruction *sampleNumber = nullptr;
if (isTextureMS(type) || isSubpassInputMS(type)) {
if (isSampledTextureMS(type) || isTextureMS(type) || isSubpassInputMS(type)) {
sampleNumber = lod;
lod = nullptr;
}
Expand Down Expand Up @@ -6508,7 +6525,8 @@ SpirvEmitter::processBufferTextureLoad(const CXXMemberCallExpr *expr) {

const auto numArgs = expr->getNumArgs();
const auto *locationArg = expr->getArg(0);
const bool textureMS = isTextureMS(objectType);
const bool textureMS =
isTextureMS(objectType) || isSampledTextureMS(objectType);
const bool hasStatusArg =
expr->getArg(numArgs - 1)->getType()->isUnsignedIntegerType();
auto *status = hasStatusArg ? doExpr(expr->getArg(numArgs - 1)) : nullptr;
Expand Down
Loading