diff --git a/include/dxc/dxcapi.internal.h b/include/dxc/dxcapi.internal.h index ca4b892748..80c218ed0d 100644 --- a/include/dxc/dxcapi.internal.h +++ b/include/dxc/dxcapi.internal.h @@ -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 diff --git a/tools/clang/include/clang/SPIRV/AstTypeProbe.h b/tools/clang/include/clang/SPIRV/AstTypeProbe.h index 1479075f12..214df82d45 100644 --- a/tools/clang/include/clang/SPIRV/AstTypeProbe.h +++ b/tools/clang/include/clang/SPIRV/AstTypeProbe.h @@ -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); diff --git a/tools/clang/lib/SPIRV/AstTypeProbe.cpp b/tools/clang/lib/SPIRV/AstTypeProbe.cpp index 6833b443f9..ea92107890 100644 --- a/tools/clang/lib/SPIRV/AstTypeProbe.cpp +++ b/tools/clang/lib/SPIRV/AstTypeProbe.cpp @@ -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; @@ -946,6 +947,15 @@ bool isTextureMS(QualType type) { return false; } +bool isSampledTextureMS(QualType type) { + if (const auto *rt = type->getAs()) { + 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()) { const auto name = rt->getDecl()->getName(); diff --git a/tools/clang/lib/SPIRV/LowerTypeVisitor.cpp b/tools/clang/lib/SPIRV/LowerTypeVisitor.cpp index f057507834..907cc0655f 100644 --- a/tools/clang/lib/SPIRV/LowerTypeVisitor.cpp +++ b/tools/clang/lib/SPIRV/LowerTypeVisitor.cpp @@ -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); @@ -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; diff --git a/tools/clang/lib/SPIRV/SpirvEmitter.cpp b/tools/clang/lib/SPIRV/SpirvEmitter.cpp index 7eedd5de99..2f61757df7 100644 --- a/tools/clang/lib/SPIRV/SpirvEmitter.cpp +++ b/tools/clang/lib/SPIRV/SpirvEmitter.cpp @@ -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(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 " @@ -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); } @@ -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; } @@ -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; diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index 1ab813afb0..f04b54db89 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -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 @@ -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 @@ -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. @@ -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( @@ -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 @@ -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 @@ -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 @@ -1841,6 +1856,8 @@ static const char *g_ArBasicTypeNames[] = { "BufferPointer", "SampledTexture2D", "SampledTexture2DArray", + "SampledTexture2DMS", + "SampledTexture2DMSArray", #endif // ENABLE_SPIRV_CODEGEN // SPIRV change ends @@ -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; @@ -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 = @@ -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; @@ -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; diff --git a/tools/clang/test/CodeGenSPIRV/vk.sampledtexture.get-dimensions.hlsl b/tools/clang/test/CodeGenSPIRV/vk.sampledtexture.get-dimensions.hlsl index fb7fff01f1..f43e65c640 100644 --- a/tools/clang/test/CodeGenSPIRV/vk.sampledtexture.get-dimensions.hlsl +++ b/tools/clang/test/CodeGenSPIRV/vk.sampledtexture.get-dimensions.hlsl @@ -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 tex2d; vk::SampledTexture2DArray tex2dArray; +vk::SampledTexture2DMS tex2dMS; +vk::SampledTexture2DMSArray 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]] @@ -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]] diff --git a/tools/clang/test/CodeGenSPIRV/vk.sampledtexture.get-sample-position.hlsl b/tools/clang/test/CodeGenSPIRV/vk.sampledtexture.get-sample-position.hlsl new file mode 100644 index 0000000000..277ff069f8 --- /dev/null +++ b/tools/clang/test/CodeGenSPIRV/vk.sampledtexture.get-sample-position.hlsl @@ -0,0 +1,130 @@ +// RUN: %dxc -T ps_6_0 -E main -fcgl %s -spirv | FileCheck %s + +// CHECK-DAG: [[type_2d_image_ms:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 0 1 1 Unknown +// CHECK-DAG: [[type_2d_sampled_image_ms:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image_ms]] +// CHECK-DAG: [[type_2d_image_ms_array:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 1 1 1 Unknown +// CHECK-DAG: [[type_2d_sampled_image_ms_array:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image_ms_array]] + +// CHECK-DAG: [[pos2_0:%[0-9]+]] = OpConstantComposite %v2float %float_0_25 %float_0_25 +// CHECK-DAG: [[pos2_1:%[0-9]+]] = OpConstantComposite %v2float %float_n0_25 %float_n0_25 +// CHECK-DAG: [[pos2:%[0-9]+]] = OpConstantComposite %_arr_v2float_uint_2 [[pos2_0]] [[pos2_1]] + +// CHECK-DAG: [[pos4_0:%[0-9]+]] = OpConstantComposite %v2float %float_n0_125 %float_n0_375 +// CHECK-DAG: [[pos4_1:%[0-9]+]] = OpConstantComposite %v2float %float_0_375 %float_n0_125 +// CHECK-DAG: [[pos4_2:%[0-9]+]] = OpConstantComposite %v2float %float_n0_375 %float_0_125 +// CHECK-DAG: [[pos4_3:%[0-9]+]] = OpConstantComposite %v2float %float_0_125 %float_0_375 +// CHECK-DAG: [[pos4:%[0-9]+]] = OpConstantComposite %_arr_v2float_uint_4 [[pos4_0]] [[pos4_1]] [[pos4_2]] [[pos4_3]] + +// CHECK-DAG: [[pos8_0:%[0-9]+]] = OpConstantComposite %v2float %float_0_0625 %float_n0_1875 +// CHECK-DAG: [[pos8_1:%[0-9]+]] = OpConstantComposite %v2float %float_n0_0625 %float_0_1875 +// CHECK-DAG: [[pos8_2:%[0-9]+]] = OpConstantComposite %v2float %float_0_3125 %float_0_0625 +// CHECK-DAG: [[pos8_3:%[0-9]+]] = OpConstantComposite %v2float %float_n0_1875 %float_n0_3125 +// CHECK-DAG: [[pos8_4:%[0-9]+]] = OpConstantComposite %v2float %float_n0_3125 %float_0_3125 +// CHECK-DAG: [[pos8_5:%[0-9]+]] = OpConstantComposite %v2float %float_n0_4375 %float_n0_0625 +// CHECK-DAG: [[pos8_6:%[0-9]+]] = OpConstantComposite %v2float %float_0_1875 %float_0_4375 +// CHECK-DAG: [[pos8_7:%[0-9]+]] = OpConstantComposite %v2float %float_0_4375 %float_n0_4375 +// CHECK-DAG: [[pos8:%[0-9]+]] = OpConstantComposite %_arr_v2float_uint_8 [[pos8_0]] [[pos8_1]] [[pos8_2]] [[pos8_3]] [[pos8_4]] [[pos8_5]] [[pos8_6]] [[pos8_7]] + +// CHECK-DAG: [[pos16_00:%[0-9]+]] = OpConstantComposite %v2float %float_0_0625 %float_0_0625 +// CHECK-DAG: [[pos16_01:%[0-9]+]] = OpConstantComposite %v2float %float_n0_0625 %float_n0_1875 +// CHECK-DAG: [[pos16_02:%[0-9]+]] = OpConstantComposite %v2float %float_n0_1875 %float_0_125 +// CHECK-DAG: [[pos16_03:%[0-9]+]] = OpConstantComposite %v2float %float_0_25 %float_n0_0625 +// CHECK-DAG: [[pos16_04:%[0-9]+]] = OpConstantComposite %v2float %float_n0_3125 %float_n0_125 +// CHECK-DAG: [[pos16_05:%[0-9]+]] = OpConstantComposite %v2float %float_0_125 %float_0_3125 +// CHECK-DAG: [[pos16_06:%[0-9]+]] = OpConstantComposite %v2float %float_0_3125 %float_0_1875 +// CHECK-DAG: [[pos16_07:%[0-9]+]] = OpConstantComposite %v2float %float_0_1875 %float_n0_3125 +// CHECK-DAG: [[pos16_08:%[0-9]+]] = OpConstantComposite %v2float %float_n0_125 %float_0_375 +// CHECK-DAG: [[pos16_09:%[0-9]+]] = OpConstantComposite %v2float %float_0 %float_n0_4375 +// CHECK-DAG: [[pos16_10:%[0-9]+]] = OpConstantComposite %v2float %float_n0_25 %float_n0_375 +// CHECK-DAG: [[pos16_11:%[0-9]+]] = OpConstantComposite %v2float %float_n0_375 %float_0_25 +// CHECK-DAG: [[pos16_12:%[0-9]+]] = OpConstantComposite %v2float %float_n0_5 %float_0 +// CHECK-DAG: [[pos16_13:%[0-9]+]] = OpConstantComposite %v2float %float_0_4375 %float_n0_25 +// CHECK-DAG: [[pos16_14:%[0-9]+]] = OpConstantComposite %v2float %float_0_375 %float_0_4375 +// CHECK-DAG: [[pos16_15:%[0-9]+]] = OpConstantComposite %v2float %float_n0_4375 %float_n0_5 +// CHECK-DAG: [[pos16:%[0-9]+]] = OpConstantComposite %_arr_v2float_uint_16 [[pos16_00]] [[pos16_01]] [[pos16_02]] [[pos16_03]] [[pos16_04]] [[pos16_05]] [[pos16_06]] [[pos16_07]] [[pos16_08]] [[pos16_09]] [[pos16_10]] [[pos16_11]] [[pos16_12]] [[pos16_13]] [[pos16_14]] [[pos16_15]] + +// CHECK-DAG: [[zero:%[0-9]+]] = OpConstantComposite %v2float %float_0 %float_0 + +vk::SampledTexture2DMS tex2dMS; +vk::SampledTexture2DMSArray tex2dMSArray; + +void main(int index : INDEX) { +// CHECK: %var_GetSamplePosition_data_2 = OpVariable %_ptr_Function__arr_v2float_uint_2 Function +// CHECK: %var_GetSamplePosition_data_4 = OpVariable %_ptr_Function__arr_v2float_uint_4 Function +// CHECK: %var_GetSamplePosition_data_8 = OpVariable %_ptr_Function__arr_v2float_uint_8 Function +// CHECK: %var_GetSamplePosition_data_16 = OpVariable %_ptr_Function__arr_v2float_uint_16 Function +// CHECK: %var_GetSamplePosition_result = OpVariable %_ptr_Function_v2float Function + +// CHECK: [[tex_ms:%[0-9]+]] = OpLoad [[type_2d_sampled_image_ms]] %tex2dMS +// CHECK-NEXT: [[img_ms:%[0-9]+]] = OpImage [[type_2d_image_ms]] [[tex_ms]] +// CHECK-NEXT:[[count_ms:%[0-9]+]] = OpImageQuerySamples %uint [[img_ms]] +// CHECK-NEXT: [[index:%[0-9]+]] = OpLoad %int %index +// CHECK-NEXT: OpStore %var_GetSamplePosition_data_2 [[pos2]] +// CHECK-NEXT: OpStore %var_GetSamplePosition_data_4 [[pos4]] +// CHECK-NEXT: OpStore %var_GetSamplePosition_data_8 [[pos8]] +// CHECK-NEXT: OpStore %var_GetSamplePosition_data_16 [[pos16]] + +// CHECK-NEXT: [[eq2:%[0-9]+]] = OpIEqual %bool [[count_ms]] %uint_2 +// CHECK-NEXT: OpSelectionMerge %if_GetSamplePosition_merge2 None +// CHECK-NEXT: OpBranchConditional [[eq2]] %if_GetSamplePosition_then2 %if_GetSamplePosition_else2 + +// CHECK-NEXT: %if_GetSamplePosition_then2 = OpLabel +// CHECK-NEXT: [[ac:%[0-9]+]] = OpAccessChain %_ptr_Function_v2float %var_GetSamplePosition_data_2 [[index]] +// CHECK-NEXT: [[val:%[0-9]+]] = OpLoad %v2float [[ac]] +// CHECK-NEXT: OpStore %var_GetSamplePosition_result [[val]] +// CHECK-NEXT: OpBranch %if_GetSamplePosition_merge2 + +// CHECK-NEXT: %if_GetSamplePosition_else2 = OpLabel +// CHECK-NEXT: [[eq4:%[0-9]+]] = OpIEqual %bool [[count_ms]] %uint_4 +// CHECK-NEXT: OpSelectionMerge %if_GetSamplePosition_merge4 None +// CHECK-NEXT: OpBranchConditional [[eq4]] %if_GetSamplePosition_then4 %if_GetSamplePosition_else4 + +// CHECK-NEXT: %if_GetSamplePosition_then4 = OpLabel +// CHECK-NEXT: [[ac_0:%[0-9]+]] = OpAccessChain %_ptr_Function_v2float %var_GetSamplePosition_data_4 [[index]] +// CHECK-NEXT: [[val_0:%[0-9]+]] = OpLoad %v2float [[ac_0]] +// CHECK-NEXT: OpStore %var_GetSamplePosition_result [[val_0]] +// CHECK-NEXT: OpBranch %if_GetSamplePosition_merge4 + +// CHECK-NEXT: %if_GetSamplePosition_else4 = OpLabel +// CHECK-NEXT: [[eq8:%[0-9]+]] = OpIEqual %bool [[count_ms]] %uint_8 +// CHECK-NEXT: OpSelectionMerge %if_GetSamplePosition_merge8 None +// CHECK-NEXT: OpBranchConditional [[eq8]] %if_GetSamplePosition_then8 %if_GetSamplePosition_else8 + +// CHECK-NEXT: %if_GetSamplePosition_then8 = OpLabel +// CHECK-NEXT: [[ac_1:%[0-9]+]] = OpAccessChain %_ptr_Function_v2float %var_GetSamplePosition_data_8 [[index]] +// CHECK-NEXT: [[val_1:%[0-9]+]] = OpLoad %v2float [[ac_1]] +// CHECK-NEXT: OpStore %var_GetSamplePosition_result [[val_1]] +// CHECK-NEXT: OpBranch %if_GetSamplePosition_merge8 + +// CHECK-NEXT: %if_GetSamplePosition_else8 = OpLabel +// CHECK-NEXT: [[eq16:%[0-9]+]] = OpIEqual %bool [[count_ms]] %uint_16 +// CHECK-NEXT: OpSelectionMerge %if_GetSamplePosition_merge16 None +// CHECK-NEXT: OpBranchConditional [[eq16]] %if_GetSamplePosition_then16 %if_GetSamplePosition_else16 + +// CHECK-NEXT: %if_GetSamplePosition_then16 = OpLabel +// CHECK-NEXT: [[ac_2:%[0-9]+]] = OpAccessChain %_ptr_Function_v2float %var_GetSamplePosition_data_16 [[index]] +// CHECK-NEXT: [[val_2:%[0-9]+]] = OpLoad %v2float [[ac_2]] +// CHECK-NEXT: OpStore %var_GetSamplePosition_result [[val_2]] +// CHECK-NEXT: OpBranch %if_GetSamplePosition_merge16 + +// CHECK-NEXT: %if_GetSamplePosition_else16 = OpLabel +// CHECK-NEXT: OpStore %var_GetSamplePosition_result [[zero]] +// CHECK-NEXT: OpBranch %if_GetSamplePosition_merge16 + +// CHECK-NEXT: %if_GetSamplePosition_merge16 = OpLabel +// CHECK-NEXT: OpBranch %if_GetSamplePosition_merge8 +// CHECK-NEXT: %if_GetSamplePosition_merge8 = OpLabel +// CHECK-NEXT: OpBranch %if_GetSamplePosition_merge4 +// CHECK-NEXT: %if_GetSamplePosition_merge4 = OpLabel +// CHECK-NEXT: OpBranch %if_GetSamplePosition_merge2 +// CHECK-NEXT: %if_GetSamplePosition_merge2 = OpLabel +// CHECK-NEXT: [[val_3:%[0-9]+]] = OpLoad %v2float %var_GetSamplePosition_result +// CHECK-NEXT: OpStore %posMS [[val_3]] + float2 posMS = tex2dMS.GetSamplePosition(index); + +// CHECK: [[tex_msa:%[0-9]+]] = OpLoad [[type_2d_sampled_image_ms_array]] %tex2dMSArray +// CHECK-NEXT: [[img_msa:%[0-9]+]] = OpImage [[type_2d_image_ms_array]] [[tex_msa]] +// CHECK-NEXT:[[count_msa:%[0-9]+]] = OpImageQuerySamples %uint [[img_msa]] + float2 posMSArray = tex2dMSArray.GetSamplePosition(index); + +} diff --git a/tools/clang/test/CodeGenSPIRV/vk.sampledtexture.load.hlsl b/tools/clang/test/CodeGenSPIRV/vk.sampledtexture.load.hlsl index 930b4a96f4..e522c82ce6 100644 --- a/tools/clang/test/CodeGenSPIRV/vk.sampledtexture.load.hlsl +++ b/tools/clang/test/CodeGenSPIRV/vk.sampledtexture.load.hlsl @@ -6,9 +6,15 @@ // 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 tex2d; vk::SampledTexture2DArray tex2dArray; +vk::SampledTexture2DMS tex2dMS; +vk::SampledTexture2DMSArray tex2dMSArray; float4 main(int3 location3: A, int4 location4: B) : SV_Target { uint status; @@ -53,5 +59,23 @@ float4 main(int3 location3: A, int4 location4: B) : SV_Target { // CHECK-NEXT: {{%[0-9]+}} = OpImageFetch %v4float [[tex_img]] [[coord_0]] Lod [[lod_0]] float4 val4 = tex2dArray.Load(location4); +// CHECK: [[loc_ms:%[0-9]+]] = OpLoad %v3int %location3 +// CHECK-NEXT:[[coord_ms:%[0-9]+]] = OpVectorShuffle %v2int [[loc_ms]] [[loc_ms]] 0 1 +// CHECK-NEXT:[[sample_ms_ptr:%[0-9]+]] = OpAccessChain %_ptr_Function_int %location3 %int_2 +// CHECK-NEXT: [[sample_ms:%[0-9]+]] = OpLoad %int [[sample_ms_ptr]] +// CHECK-NEXT: [[tex_ms:%[0-9]+]] = OpLoad [[type_2d_sampled_image_ms]] %tex2dMS +// CHECK-NEXT:[[tex_ms_img:%[0-9]+]] = OpImage [[type_2d_image_ms]] [[tex_ms]] +// CHECK-NEXT: {{%[0-9]+}} = OpImageFetch %v4float [[tex_ms_img]] [[coord_ms]] Sample [[sample_ms]] + float4 val5 = tex2dMS.Load(location3.xy, location3.z); + +// CHECK: [[loc_msa:%[0-9]+]] = OpLoad %v4int %location4 +// CHECK-NEXT:[[coord_msa:%[0-9]+]] = OpVectorShuffle %v3int [[loc_msa]] [[loc_msa]] 0 1 2 +// CHECK-NEXT:[[sample_msa_ptr:%[0-9]+]] = OpAccessChain %_ptr_Function_int %location4 %int_3 +// CHECK-NEXT: [[sample_msa:%[0-9]+]] = OpLoad %int [[sample_msa_ptr]] +// CHECK-NEXT: [[tex_msa:%[0-9]+]] = OpLoad [[type_2d_sampled_image_ms_array]] %tex2dMSArray +// CHECK-NEXT:[[tex_msa_img:%[0-9]+]] = OpImage [[type_2d_image_ms_array]] [[tex_msa]] +// CHECK-NEXT: {{%[0-9]+}} = OpImageFetch %v4float [[tex_msa_img]] [[coord_msa]] Sample [[sample_msa]] + float4 val6 = tex2dMSArray.Load(location4.xyz, location4.w); + return 1.0; } diff --git a/tools/clang/test/CodeGenSPIRV/vk.sampledtexture.sample-access.hlsl b/tools/clang/test/CodeGenSPIRV/vk.sampledtexture.sample-access.hlsl new file mode 100644 index 0000000000..246c1a5b53 --- /dev/null +++ b/tools/clang/test/CodeGenSPIRV/vk.sampledtexture.sample-access.hlsl @@ -0,0 +1,29 @@ +// RUN: %dxc -T ps_6_0 -E main -fcgl %s -spirv | FileCheck %s + +// CHECK: [[type_2d_image_ms:%[a-zA-Z0-9_]+]] = OpTypeImage %int 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::SampledTexture2DMS tex2dMS; +vk::SampledTexture2DMSArray tex2dMSArray; + +void main() { + uint2 pos2 = uint2(1,2); + +// CHECK: [[pos2:%[0-9]+]] = OpLoad %v2uint %pos2 +// CHECK-NEXT: [[tex1:%[0-9]+]] = OpLoad [[type_2d_sampled_image_ms]] %tex2dMS +// CHECK-NEXT: [[img1:%[0-9]+]] = OpImage [[type_2d_image_ms]] [[tex1]] +// CHECK-NEXT: [[f1:%[0-9]+]] = OpImageFetch %v4int [[img1]] [[pos2]] Sample %uint_3 +// CHECK-NEXT: [[val1:%[0-9]+]] = OpVectorShuffle %v3int [[f1]] [[f1]] 0 1 2 +// CHECK-NEXT: OpStore %a1 [[val1]] + int3 a1 = tex2dMS.sample[3][pos2]; + +// CHECK: [[pos3:%[0-9]+]] = OpLoad %v3uint %pos3 +// CHECK-NEXT: [[tex2:%[0-9]+]] = OpLoad [[type_2d_sampled_image_ms_array]] %tex2dMSArray +// CHECK-NEXT: [[img2:%[0-9]+]] = OpImage [[type_2d_image_ms_array]] [[tex2]] +// CHECK-NEXT: [[f2:%[0-9]+]] = OpImageFetch %v4float [[img2]] [[pos3]] Sample %uint_4 +// CHECK-NEXT: OpStore %a2 [[f2]] + uint3 pos3 = uint3(1,2,3); + float4 a2 = tex2dMSArray.sample[4][pos3]; +} diff --git a/utils/hct/gen_intrin_main.txt b/utils/hct/gen_intrin_main.txt index 49aa2f151b..69079fafe8 100644 --- a/utils/hct/gen_intrin_main.txt +++ b/utils/hct/gen_intrin_main.txt @@ -1414,3 +1414,21 @@ namespace VkSampledTexture2DArrayMethods { $match<0, -1> void<4> [[]] GatherRaw(in float<3> x, in int<2> o, out uint_only status); } namespace +namespace VkSampledTexture2DMSMethods { + void [[]] GetDimensions(out uint_only width, out $type1 height, out $type2 samples) : resinfo_uint_o; + void [[]] GetDimensions(out float_like width, out $type1 height, out $type2 samples) : resinfo_o; + float_like<2> [[ro]] GetSamplePosition(in int s) : samplepos; + $classT [[]] Load(in int<2> x, in int s) : texture2d_ms; + $classT [[]] Load(in int<2> x, in int s, in int<2> o) : texture2d_ms_o; + $classT [[]] Load(in int<2> x, in int s, in int<2> o, out uint_only status) : texture2d_ms_o_s; +} namespace + + +namespace VkSampledTexture2DMSArrayMethods { + void [[]] GetDimensions(out uint_only width, out $type1 height, out $type1 elements, out $type1 samples) : resinfo_uint_o; + void [[]] GetDimensions(out float_like width, out $type1 height, out $type1 elements, out $type1 samples) : resinfo_o; + float_like<2> [[ro]] GetSamplePosition(in int s) : samplepos; + $classT [[ro]] Load(in int<3> x, in int s) : texture2darray_ms; + $classT [[ro]] Load(in int<3> x, in int s, in int<2> o) : texture2darray_ms_o; + $classT [[]] Load(in int<3> x, in int s, in int<2> o, out uint_only status) : texture2darray_ms_o_s; +} namespace