Skip to content

[SYCL] Fix bindless image sample instruction generation#21345

Open
0x12CC wants to merge 2 commits intointel:syclfrom
0x12CC:fix/sample-image-result-type
Open

[SYCL] Fix bindless image sample instruction generation#21345
0x12CC wants to merge 2 commits intointel:syclfrom
0x12CC:fix/sample-image-result-type

Conversation

@0x12CC
Copy link
Contributor

@0x12CC 0x12CC commented Feb 23, 2026

The SPIR-V specification requires the result type of the OpImageSampleExplicitLod instruction to be a vector of four components. The SYCL bindless images extension allows the user to specify a return type for the sample_image call that may not be a vector. This commit ensures the SYCL headers correctly convert between the user-specified type and the type required by the SPIR-V specification to prevent generating invalid SPIR-V modules.

Signed-off-by: Michael Aziz <michael.aziz@intel.com>
Signed-off-by: Michael Aziz <michael.aziz@intel.com>
@0x12CC
Copy link
Contributor Author

0x12CC commented Feb 25, 2026

@slawekptak, friendly ping.

template <typename RetType, typename SmpImageT, typename CoordT>
static RetType __invoke__ImageReadLod(SmpImageT SmpImg, CoordT Coords,
float Level) {
// The result type of the SPIR-V instruction OpImageSampleExplicitLod must be
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requirement is also true for OpImageFetch. This change must be applied to all uses of that SPIRV Op.

Moreover, this change and the above suggested change will apply to many of the other "invoke" functions here since they all map to the same OpImageSampleExplicitLod and OpImageFetch.

And as discussed in this issue, #21366, the OpenCL restriction of requiring 4-vec returns or writes for unsampled images implies that DPC++ should also generate SPIR-V that adheres to that restriction, despite it not being stated in the OpenCL env spec! Nearly every invocation in this file will need to adhere to this requirement.

template <typename RetType, typename SmpImageT, typename CoordT>
static RetType __invoke__ImageReadLod(SmpImageT SmpImg, CoordT Coords,
float Level) {
// The result type of the SPIR-V instruction OpImageSampleExplicitLod must be
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an aside, this file has piled up technical debt where many different __invoke__ funcs all make use of many different __spirv__ funcs which then all map to a few actual SPIR-V Ops, alongside some confusing naming being present (fetch vs read).

AFAICT, there are really only 4 different distinct SPIR-V operations being generated here:

  • OpImageRead
    • __invoke__ImageRead
    • __invoke__ImageArrayRead
    • __invoke__ImageFetch
    • __invoke__ImageArrayFetch
  • OpImageWrite
    • __invoke__ImageWrite
    • __invoke__ImageArrayWrite
  • OpImageFetch
    • __invoke__SampledImageFetch
    • __invoke__SampledImageArrayFetch
  • OpSampleExplicitLod
    • __invoke__ImageReadLod
    • __invoke__ImageReadGrad
    • __invoke__ImageReadSampler
    • __invoke__ImageReadCubemap

The current design encodes the distinction between image operands and image types in the function name resulting in 10+ __spirv_ declarations all collapsing to the same 4 SPIR-V Ops. Do you think it'd be worth cleaning this up? I can also see bindless_images.hpp adds to this confusion by generating different invocations depending on whether __SPIR__ is defined or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants