Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPIR-V][Feature Request][SM6.7] Implement texture sample/load with a non-constant offset #6612

Open
Keenuts opened this issue May 13, 2024 · 1 comment
Assignees
Labels
enhancement Feature suggestion sm6.7 spirv Work related to SPIR-V

Comments

@Keenuts
Copy link
Collaborator

Keenuts commented May 13, 2024

Starting SM6.7, offsets can be variables in the sample/load texture operations.
Right now, this is not supported in the SPIR-V backend, as we use an sample instruction which cannot use the Offset operand, but only the ConstOffset.

See Programmable Offsets.

Seems like we should be able to implement this using the OpImageGather instruction, but haven't looked into it very carefully.

Texture2D<float> tex;
SamplerState samplerState;
RWStructuredBuffer<uint2> buffer;

float4 main() : SV_Target {
  float tmp = tex.Sample(samplerState, float2(0, 0), buffer[0]);
  return tmp.xxxx;
}
$ dxc -T ps_6_7 shader.hlsl -spirv -fspv-target-env=vulkan1.3
fatal error: generated SPIR-V is invalid: [VUID-StandaloneSpirv-Offset-04663] Image Operand Offset can only be used with OpImage*Gather operations
  %36 = OpImageSampleImplicitLod %v4float %35 %14 Offset %34

note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible
@Keenuts Keenuts added enhancement Feature suggestion spirv Work related to SPIR-V sm6.7 labels May 13, 2024
@s-perron s-perron self-assigned this May 31, 2024
@s-perron
Copy link
Collaborator

The programmable offset cannot be done in Vulkan. As Nathan mentioned, only the Gather instructions can use the Offset image operand, so most sampling instruction cannot have a variable offset.

In general, the Gather instructions cannot be used to implement the other instructions. The main issue is that OpImageGather requires a component number, so it is not possible to load all components of a texel with a single load. It is also more limited in the types of images it supports.

I suggest we close this issue until SPIR-V is extended to implement this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature suggestion sm6.7 spirv Work related to SPIR-V
Projects
None yet
Development

No branches or pull requests

2 participants