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
4 changes: 3 additions & 1 deletion include/dxc/dxcapi.internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ enum LEGAL_INTRINSIC_COMPTYPES {
LICOMPTYPE_VK_BUFFER_POINTER = 56,
LICOMPTYPE_VK_SAMPLED_TEXTURE2D = 57,
LICOMPTYPE_VK_SAMPLED_TEXTURE2D_ARRAY = 58,
LICOMPTYPE_COUNT = 59
LICOMPTYPE_VK_SAMPLED_TEXTURE2DMS = 59,
LICOMPTYPE_VK_SAMPLED_TEXTURE2DMS_ARRAY = 60,
LICOMPTYPE_COUNT = 61
#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
12 changes: 11 additions & 1 deletion tools/clang/lib/SPIRV/AstTypeProbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,8 @@ 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" || name == "SampledTexture2DArray")
if (name == "SampledTexture2D" || name == "SampledTexture2DArray" ||
name == "SampledTexture2DMS" || name == "SampledTexture2DMSArray")
return true;
}
return false;
Expand All @@ -946,6 +947,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
12 changes: 8 additions & 4 deletions tools/clang/lib/SPIRV/LowerTypeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,8 @@ const SpirvType *LowerTypeVisitor::lowerVkTypeInVkNamespace(
assert(visitedTypeStack.size() == visitedTypeStackSize);
return pointerType;
}
if (name == "SampledTexture2D" || name == "SampledTexture2DArray") {
if (name == "SampledTexture2D" || name == "SampledTexture2DArray" ||
name == "SampledTexture2DMS" || name == "SampledTexture2DMSArray") {
const auto sampledType = hlsl::GetHLSLResourceResultType(type);
auto loweredType = lowerType(getElementType(astContext, sampledType), rule,
/*isRowMajor*/ llvm::None, srcLoc);
Expand All @@ -860,11 +861,14 @@ const SpirvType *LowerTypeVisitor::lowerVkTypeInVkNamespace(
loweredType = spvContext.getUIntType(32);
}

const bool isArray = (name == "SampledTexture2DArray");
const bool isArray =
(name == "SampledTexture2DArray" || name == "SampledTexture2DMSArray");
const bool isMS =
(name == "SampledTexture2DMS" || name == "SampledTexture2DMSArray");

const auto *imageType = spvContext.getImageType(
loweredType, spv::Dim::Dim2D, ImageType::WithDepth::No, isArray,
false /* ms */, ImageType::WithSampler::Yes, spv::ImageFormat::Unknown);
loweredType, spv::Dim::Dim2D, 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
22 changes: 18 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 @@ -4403,7 +4415,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 @@ -4744,7 +4757,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 @@ -6509,7 +6522,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
43 changes: 38 additions & 5 deletions tools/clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ enum ArBasicKind {
AR_OBJECT_VK_BUFFER_POINTER,
AR_OBJECT_VK_SAMPLED_TEXTURE2D,
AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY,
AR_OBJECT_VK_SAMPLED_TEXTURE2DMS,
AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY,
#endif // ENABLE_SPIRV_CODEGEN
// SPIRV change ends

Expand Down Expand Up @@ -564,6 +566,8 @@ const UINT g_uBasicKindProps[] = {
BPROP_OBJECT, // AR_OBJECT_VK_BUFFER_POINTER use recordType
BPROP_OBJECT | BPROP_RBUFFER, // AR_OBJECT_VK_SAMPLED_TEXTURE2D
BPROP_OBJECT | BPROP_RBUFFER, // AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY
BPROP_OBJECT | BPROP_RBUFFER, // AR_OBJECT_VK_SAMPLED_TEXTURE2DMS
BPROP_OBJECT | BPROP_RBUFFER, // AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY
#endif // ENABLE_SPIRV_CODEGEN
// SPIRV change ends

Expand Down Expand Up @@ -1276,6 +1280,10 @@ static const ArBasicKind g_VKSampledTexture2DCT[] = {
AR_OBJECT_VK_SAMPLED_TEXTURE2D, AR_BASIC_UNKNOWN};
static const ArBasicKind g_VKSampledTexture2DArrayCT[] = {
AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY, AR_BASIC_UNKNOWN};
static const ArBasicKind g_VKSampledTexture2DMSCT[] = {
AR_OBJECT_VK_SAMPLED_TEXTURE2DMS, AR_BASIC_UNKNOWN};
static const ArBasicKind g_VKSampledTexture2DMSArrayCT[] = {
AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY, AR_BASIC_UNKNOWN};
#endif

// Basic kinds, indexed by a LEGAL_INTRINSIC_COMPTYPES value.
Expand Down Expand Up @@ -1338,9 +1346,11 @@ const ArBasicKind *g_LegalIntrinsicCompTypes[] = {
g_LinAlgCT, // LICOMPTYPE_LINALG
g_BuiltInTrianglePositionsCT, // LICOMPTYPE_BUILTIN_TRIANGLE_POSITIONS
#ifdef ENABLE_SPIRV_CODEGEN
g_VKBufferPointerCT, // LICOMPTYPE_VK_BUFFER_POINTER
g_VKSampledTexture2DCT, // LICOMPTYPE_VK_SAMPLED_TEXTURE2D
g_VKSampledTexture2DArrayCT, // LICOMPTYPE_VK_SAMPLED_TEXTURE2D_ARRAY
g_VKBufferPointerCT, // LICOMPTYPE_VK_BUFFER_POINTER
g_VKSampledTexture2DCT, // LICOMPTYPE_VK_SAMPLED_TEXTURE2D
g_VKSampledTexture2DArrayCT, // LICOMPTYPE_VK_SAMPLED_TEXTURE2D_ARRAY
g_VKSampledTexture2DMSCT, // LICOMPTYPE_VK_SAMPLED_TEXTURE2DMS
g_VKSampledTexture2DMSArrayCT, // LICOMPTYPE_VK_SAMPLED_TEXTURE2DMS_ARRAY
#endif
};
static_assert(
Expand Down Expand Up @@ -1401,7 +1411,8 @@ static const ArBasicKind g_ArBasicKindsAsTypes[] = {
AR_OBJECT_VK_INTEGRAL_CONSTANT, AR_OBJECT_VK_LITERAL,
AR_OBJECT_VK_SPV_INTRINSIC_TYPE, AR_OBJECT_VK_SPV_INTRINSIC_RESULT_ID,
AR_OBJECT_VK_BUFFER_POINTER, AR_OBJECT_VK_SAMPLED_TEXTURE2D,
AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY,
AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY, AR_OBJECT_VK_SAMPLED_TEXTURE2DMS,
AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY,
#endif // ENABLE_SPIRV_CODEGEN
// SPIRV change ends

Expand Down Expand Up @@ -1515,6 +1526,8 @@ static const uint8_t g_ArBasicKindsTemplateCount[] = {
2, // AR_OBJECT_VK_BUFFER_POINTER
1, // AR_OBJECT_VK_SAMPLED_TEXTURE2D
1, // AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY
1, // AR_OBJECT_VK_SAMPLED_TEXTURE2DMS
1, // AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY
#endif // ENABLE_SPIRV_CODEGEN
// SPIRV change ends

Expand Down Expand Up @@ -1670,6 +1683,8 @@ static const SubscriptOperatorRecord g_ArBasicKindsSubscripts[] = {
{0, MipsFalse, SampleFalse}, // AR_OBJECT_VK_BUFFER_POINTER
{2, MipsTrue, SampleFalse}, // AR_OBJECT_VK_SAMPLED_TEXTURE2D
{3, MipsTrue, SampleFalse}, // AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY
{2, MipsFalse, SampleTrue}, // AR_OBJECT_VK_SAMPLED_TEXTURE2DMS
{3, MipsFalse, SampleTrue}, // AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY
#endif // ENABLE_SPIRV_CODEGEN
// SPIRV change ends

Expand Down Expand Up @@ -1841,6 +1856,8 @@ static const char *g_ArBasicTypeNames[] = {
"BufferPointer",
"SampledTexture2D",
"SampledTexture2DArray",
"SampledTexture2DMS",
"SampledTexture2DMSArray",
#endif // ENABLE_SPIRV_CODEGEN
// SPIRV change ends

Expand Down Expand Up @@ -2502,6 +2519,14 @@ static void GetIntrinsicMethods(ArBasicKind kind,
*intrinsics = g_VkSampledTexture2DArrayMethods;
*intrinsicCount = _countof(g_VkSampledTexture2DArrayMethods);
break;
case AR_OBJECT_VK_SAMPLED_TEXTURE2DMS:
*intrinsics = g_VkSampledTexture2DMSMethods;
*intrinsicCount = _countof(g_VkSampledTexture2DMSMethods);
break;
case AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY:
*intrinsics = g_VkSampledTexture2DMSArrayMethods;
*intrinsicCount = _countof(g_VkSampledTexture2DMSArrayMethods);
break;
#endif
case AR_OBJECT_HIT_OBJECT:
*intrinsics = g_DxHitObjectMethods;
Expand Down Expand Up @@ -4108,7 +4133,9 @@ class HLSLExternalSource : public ExternalSemaSource {
recordDecl->setImplicit(true);
m_vkBufferPointerTemplateDecl = recordDecl->getDescribedClassTemplate();
} else if (kind == AR_OBJECT_VK_SAMPLED_TEXTURE2D ||
kind == AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY) {
kind == AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY ||
kind == AR_OBJECT_VK_SAMPLED_TEXTURE2DMS ||
kind == AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY) {
if (!m_vkNSDecl)
continue;
QualType float4Type =
Expand Down Expand Up @@ -5103,6 +5130,9 @@ class HLSLExternalSource : public ExternalSemaSource {
ResClass = DXIL::ResourceClass::SRV;
return true;
case AR_OBJECT_TEXTURE2DMS:
#ifdef ENABLE_SPIRV_CODEGEN
case AR_OBJECT_VK_SAMPLED_TEXTURE2DMS:
#endif
ResKind = DXIL::ResourceKind::Texture2DMS;
ResClass = DXIL::ResourceClass::SRV;
return true;
Expand All @@ -5111,6 +5141,9 @@ class HLSLExternalSource : public ExternalSemaSource {
ResClass = DXIL::ResourceClass::UAV;
return true;
case AR_OBJECT_TEXTURE2DMS_ARRAY:
#ifdef ENABLE_SPIRV_CODEGEN
case AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY:
#endif
ResKind = DXIL::ResourceKind::Texture2DMSArray;
ResClass = DXIL::ResourceClass::SRV;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@
// CHECK: [[type_2d_sampled_image:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image]]
// CHECK: [[type_2d_image_array:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 1 0 1 Unknown
// CHECK: [[type_2d_sampled_image_array:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image_array]]
// CHECK: [[type_2d_image_ms:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 0 1 1 Unknown
// CHECK: [[type_2d_sampled_image_ms:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image_ms]]
// CHECK: [[type_2d_image_ms_array:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 1 1 1 Unknown
// CHECK: [[type_2d_sampled_image_ms_array:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image_ms_array]]

vk::SampledTexture2D<float4> tex2d;
vk::SampledTexture2DArray<float4> tex2dArray;
vk::SampledTexture2DMS<float4> tex2dMS;
vk::SampledTexture2DMSArray<float4> tex2dMSArray;

void main() {
uint mipLevel = 1;
uint width, height, numLevels, elements;
uint width, height, numLevels, elements, numSamples;

// CHECK: [[t1_load:%[0-9]+]] = OpLoad [[type_2d_sampled_image]] %tex2d
// CHECK-NEXT: [[image1:%[0-9]+]] = OpImage [[type_2d_image]] [[t1_load]]
Expand Down Expand Up @@ -61,6 +67,30 @@ void main() {
// CHECK-NEXT: OpStore %numLevels [[query_level_4]]
tex2dArray.GetDimensions(mipLevel, width, height, elements, numLevels);

// CHECK: [[t3_load:%[0-9]+]] = OpLoad [[type_2d_sampled_image_ms]] %tex2dMS
// CHECK-NEXT: [[image5:%[0-9]+]] = OpImage [[type_2d_image_ms]] [[t3_load]]
// CHECK-NEXT: [[query5:%[0-9]+]] = OpImageQuerySize %v2uint [[image5]]
// CHECK-NEXT: [[query5_0:%[0-9]+]] = OpCompositeExtract %uint [[query5]] 0
// CHECK-NEXT: OpStore %width [[query5_0]]
// CHECK-NEXT: [[query5_1:%[0-9]+]] = OpCompositeExtract %uint [[query5]] 1
// CHECK-NEXT: OpStore %height [[query5_1]]
// CHECK-NEXT: [[query5_samples:%[0-9]+]] = OpImageQuerySamples %uint [[image5]]
// CHECK-NEXT: OpStore %numSamples [[query5_samples]]
tex2dMS.GetDimensions(width, height, numSamples);

// CHECK: [[t4_load:%[0-9]+]] = OpLoad [[type_2d_sampled_image_ms_array]] %tex2dMSArray
// CHECK-NEXT: [[image6:%[0-9]+]] = OpImage [[type_2d_image_ms_array]] [[t4_load]]
// CHECK-NEXT: [[query6:%[0-9]+]] = OpImageQuerySize %v3uint [[image6]]
// CHECK-NEXT: [[query6_0:%[0-9]+]] = OpCompositeExtract %uint [[query6]] 0
// CHECK-NEXT: OpStore %width [[query6_0]]
// CHECK-NEXT: [[query6_1:%[0-9]+]] = OpCompositeExtract %uint [[query6]] 1
// CHECK-NEXT: OpStore %height [[query6_1]]
// CHECK-NEXT: [[query6_2:%[0-9]+]] = OpCompositeExtract %uint [[query6]] 2
// CHECK-NEXT: OpStore %elements [[query6_2]]
// CHECK-NEXT: [[query6_samples:%[0-9]+]] = OpImageQuerySamples %uint [[image6]]
// CHECK-NEXT: OpStore %numSamples [[query6_samples]]
tex2dMSArray.GetDimensions(width, height, elements, numSamples);

float f_width, f_height, f_numLevels;
// CHECK: [[t1_load:%[0-9]+]] = OpLoad [[type_2d_sampled_image]] %tex2d
// CHECK-NEXT: [[image1:%[0-9]+]] = OpImage [[type_2d_image]] [[t1_load]]
Expand Down
Loading