Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
548952d
Implement `vk::SampledTexture2D` type and `Sample` method.
luciechoi Jan 7, 2026
38d4d70
Implement optional arguments
luciechoi Jan 8, 2026
3ee8a37
Implement CalculateLevelOfDetail
luciechoi Jan 9, 2026
4a8bf5f
formatting
luciechoi Jan 9, 2026
eed699e
Address comments
luciechoi Jan 22, 2026
5736a97
Address comments
luciechoi Jan 27, 2026
f7493d5
address comments
luciechoi Jan 27, 2026
cefc175
Re-implement type and function declaration using auto-generation
luciechoi Feb 5, 2026
faab2c7
Bring back uint test and increase shader module version
luciechoi Feb 9, 2026
d234341
Remove unncessary setImplicit
luciechoi Feb 9, 2026
ad89dd1
CalculateLevelOfDetailUnclamped
luciechoi Jan 16, 2026
ba93cf5
Gather
luciechoi Jan 16, 2026
afd6f26
Restructure based on comments
luciechoi Jan 23, 2026
2d27226
Update Gather and CalculateLodUnclamped with new implementation
luciechoi Feb 9, 2026
ce5079c
GetDimensions
luciechoi Jan 17, 2026
1122171
Implement `GetDimensions` based on new method.
luciechoi Feb 9, 2026
0420f30
Load
luciechoi Jan 24, 2026
b4507d6
Implement using new method
luciechoi Feb 9, 2026
4b78177
SampleBias
luciechoi Jan 26, 2026
c619302
SampleLevel
luciechoi Jan 26, 2026
54462b5
SampleGrad
luciechoi Jan 26, 2026
4bbdb16
SampleCmp
luciechoi Jan 26, 2026
4d62932
SampleCmpLevelZero
luciechoi Jan 26, 2026
98cc988
SampleCmpLevel
luciechoi Jan 26, 2026
6e2c259
SampleCmpGrad
luciechoi Jan 26, 2026
b46b960
SampleCmpBias
luciechoi Jan 26, 2026
ca7714f
Implement remaining Sample functions using a new method
luciechoi Feb 9, 2026
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
3 changes: 2 additions & 1 deletion include/dxc/dxcapi.internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ enum LEGAL_INTRINSIC_COMPTYPES {

#ifdef ENABLE_SPIRV_CODEGEN
LICOMPTYPE_VK_BUFFER_POINTER = 55,
LICOMPTYPE_COUNT = 56
LICOMPTYPE_VK_SAMPLED_TEXTURE2D = 56,
LICOMPTYPE_COUNT = 57
#else
LICOMPTYPE_COUNT = 55
#endif
Expand Down
4 changes: 4 additions & 0 deletions tools/clang/include/clang/AST/HlslTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ clang::CXXRecordDecl *
DeclareVkBufferPointerType(clang::ASTContext &context,
clang::DeclContext *declContext);

clang::CXXRecordDecl *DeclareVkSampledTextureType(
clang::ASTContext &context, clang::DeclContext *declContext,
llvm::StringRef hlslTypeName, clang::QualType defaultParamType);

clang::CXXRecordDecl *DeclareInlineSpirvType(clang::ASTContext &context,
clang::DeclContext *declContext,
llvm::StringRef typeName,
Expand Down
3 changes: 3 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,9 @@ bool isTexture(QualType);
/// Texture2DMSArray type.
bool isTextureMS(QualType);

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

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

Expand Down
8 changes: 8 additions & 0 deletions tools/clang/include/clang/SPIRV/SpirvBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ class SpirvBuilder {
/// If compareVal is given a non-zero value, *Dref* variants of OpImageSample*
/// will be generated.
///
/// If sampler is set, it defines the sampler along *image* to create the
/// combined image sampler. Otherwise, the *image* parameter must point to a
/// sampled image.
///
/// If lod or grad is given a non-zero value, *ExplicitLod variants of
/// OpImageSample* will be generated; otherwise, *ImplicitLod variant will
/// be generated.
Expand Down Expand Up @@ -335,6 +339,10 @@ class SpirvBuilder {

/// \brief Creates SPIR-V instructions for gathering the given image.
///
/// If the of `image` is a sampled image, then that image will be gathered.
/// In this case, `sampler` must be `nullptr`. If `image` is not a sampled
/// image, a sampled image will be created by combining `image` and `sampler`.
///
/// If compareVal is given a non-null value, OpImageDrefGather or
/// OpImageSparseDrefGather will be generated; otherwise, OpImageGather or
/// OpImageSparseGather will be generated.
Expand Down
20 changes: 20 additions & 0 deletions tools/clang/lib/AST/ASTContextHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,26 @@ CXXRecordDecl *hlsl::DeclareNodeOrRecordType(
}

#ifdef ENABLE_SPIRV_CODEGEN
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);

TemplateTypeParmDecl *TyParamDecl =
Builder.addTypeTemplateParam("SampledTextureType", defaultParamType);

Builder.startDefinition();

QualType paramType = QualType(TyParamDecl->getTypeForDecl(), 0);
CXXRecordDecl *recordDecl = Builder.getRecordDecl();

return recordDecl;
}

CXXRecordDecl *hlsl::DeclareVkBufferPointerType(ASTContext &context,
DeclContext *declContext) {
BuiltinTypeDeclBuilder Builder(declContext, "BufferPointer",
Expand Down
11 changes: 11 additions & 0 deletions tools/clang/lib/SPIRV/AstTypeProbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,17 @@ bool isTexture(QualType type) {
return false;
}

bool isSampledTexture(QualType type) {
if (const auto *rt = type->getAs<RecordType>()) {
const auto name = rt->getDecl()->getName();
// TODO(https://github.com/microsoft/DirectXShaderCompiler/issues/7979): Add
// other sampled texture types as needed.
if (name == "SampledTexture2D")
return true;
}
return false;
}

bool isTextureMS(QualType type) {
if (const auto *rt = type->getAs<RecordType>()) {
const auto name = rt->getDecl()->getName();
Expand Down
20 changes: 19 additions & 1 deletion tools/clang/lib/SPIRV/LowerTypeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,23 @@ const SpirvType *LowerTypeVisitor::lowerVkTypeInVkNamespace(
assert(visitedTypeStack.size() == visitedTypeStackSize);
return pointerType;
}
if (name == "SampledTexture2D") {
const auto sampledType = hlsl::GetHLSLResourceResultType(type);
auto loweredType = lowerType(getElementType(astContext, sampledType), rule,
/*isRowMajor*/ llvm::None, srcLoc);

// Bool does not have a defined size in SPIR-V, so it cannot be
// used in the external interface.
if (loweredType == spvContext.getBoolType()) {
loweredType = spvContext.getUIntType(32);
}

const auto *imageType = spvContext.getImageType(
loweredType, spv::Dim::Dim2D, ImageType::WithDepth::No,
false /* array */, false /* ms */, ImageType::WithSampler::Yes,
spv::ImageFormat::Unknown);
return spvContext.getSampledImageType(imageType);
}
emitError("unknown type %0 in vk namespace", srcLoc) << type;
return nullptr;
}
Expand Down Expand Up @@ -892,7 +909,8 @@ LowerTypeVisitor::lowerResourceType(QualType type, SpirvLayoutRule rule,
auto loweredType =
lowerType(getElementType(astContext, sampledType), rule,
/*isRowMajor*/ llvm::None, srcLoc);
// Treat bool textures as uint for compatibility with OpTypeImage.
// Bool does not have a defined size in SPIR-V, so it cannot be
// used in the external interface.
if (loweredType == spvContext.getBoolType()) {
loweredType = spvContext.getUIntType(32);
}
Expand Down
22 changes: 18 additions & 4 deletions tools/clang/lib/SPIRV/SpirvBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,15 @@ SpirvInstruction *SpirvBuilder::createImageSample(
assert(lod == nullptr || minLod == nullptr);

// An OpSampledImage is required to do the image sampling.
auto *sampledImage =
createSampledImage(imageType, image, sampler, loc, range);
// Skip creating OpSampledImage if the imageType is a sampled texture.
SpirvInstruction *sampledImage;
if (isSampledTexture(imageType)) {
assert(!sampler &&
"sampler must be null when sampling from a sampled texture");
sampledImage = image;
} else {
sampledImage = createSampledImage(imageType, image, sampler, loc, range);
}

const auto mask = composeImageOperandsMask(
bias, lod, grad, constOffset, varOffset, constOffsets, sample, minLod);
Expand Down Expand Up @@ -707,8 +714,15 @@ SpirvInstruction *SpirvBuilder::createImageGather(
assert(insertPoint && "null insert point");

// An OpSampledImage is required to do the image sampling.
auto *sampledImage =
createSampledImage(imageType, image, sampler, loc, range);
// Skip creating OpSampledImage if the imageType is a sampled texture.
SpirvInstruction *sampledImage = nullptr;
if (isSampledTexture(imageType)) {
assert(!sampler &&
"sampler must be null when sampling from a sampled texture");
sampledImage = image;
} else {
sampledImage = createSampledImage(imageType, image, sampler, loc, range);
}

// TODO: Update ImageGather to accept minLod if necessary.
const auto mask = composeImageOperandsMask(
Expand Down
Loading
Loading