@@ -4693,9 +4693,11 @@ SpirvInstruction *SpirvEmitter::processBufferTextureLoad(
46934693 // The result type of an OpImageFetch must be a vec4 of float or int.
46944694 const auto type = object->getType();
46954695 assert(isBuffer(type) || isRWBuffer(type) || isTexture(type) ||
4696- isRWTexture(type) || isSubpassInput(type) || isSubpassInputMS(type));
4696+ isRWTexture(type) || isSubpassInput(type) || isSubpassInputMS(type) ||
4697+ isSampledTexture(type));
46974698
4698- const bool doFetch = isBuffer(type) || isTexture(type);
4699+ const bool doFetch =
4700+ isBuffer(type) || isTexture(type) || isSampledTexture(type);
46994701 const bool rasterizerOrdered = isRasterizerOrderedView(type);
47004702
47014703 if (rasterizerOrdered) {
@@ -4759,6 +4761,18 @@ SpirvInstruction *SpirvEmitter::processBufferTextureLoad(
47594761
47604762 // OpImageFetch and OpImageRead can only fetch a vector of 4 elements.
47614763 const QualType texelType = astContext.getExtVectorType(elemType, 4u);
4764+
4765+ if (isSampledTexture(type)) {
4766+ LowerTypeVisitor lowerTypeVisitor(astContext, spvContext, spirvOptions,
4767+ spvBuilder);
4768+ const SpirvType *spvType = lowerTypeVisitor.lowerType(
4769+ type, SpirvLayoutRule::Void, llvm::None, loc);
4770+ // Get image type based on type, assuming type is a sampledimage type
4771+ const auto *sampledImageType = cast<SampledImageType>(spvType);
4772+ const SpirvType *imgType = sampledImageType->getImageType();
4773+ objectInfo =
4774+ spvBuilder.createUnaryOp(spv::Op::OpImage, imgType, objectInfo, loc);
4775+ }
47624776 auto *texel = spvBuilder.createImageFetchOrRead(
47634777 doFetch, texelType, type, objectInfo, location, lod, constOffset,
47644778 /*constOffsets*/ nullptr, sampleNumber, residencyCode, loc, range);
@@ -6345,7 +6359,8 @@ SpirvEmitter::processTextureSampleCmpLevel(const CXXMemberCallExpr *expr) {
63456359SpirvInstruction *
63466360SpirvEmitter::processBufferTextureLoad(const CXXMemberCallExpr *expr) {
63476361 // Signature:
6348- // For Texture1D, Texture1DArray, Texture2D, Texture2DArray, Texture3D:
6362+ // For Texture1D, Texture1DArray, Texture2D, Texture2DArray, Texture3D
6363+ // and their SampledTexture variants:
63496364 // ret Object.Load(int Location
63506365 // [, int Offset]
63516366 // [, uint status]);
@@ -6403,7 +6418,7 @@ SpirvEmitter::processBufferTextureLoad(const CXXMemberCallExpr *expr) {
64036418 // and 1 for location.
64046419 const bool hasOffsetArg = numArgs - hasStatusArg - textureMS - 1 > 0;
64056420
6406- if (isTexture(objectType)) {
6421+ if (isTexture(objectType) || isSampledTexture(objectType) ) {
64076422 // .Load() has a second optional paramter for offset.
64086423 SpirvInstruction *location = doExpr(locationArg);
64096424 SpirvInstruction *constOffset = nullptr, *varOffset = nullptr;
0 commit comments