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

.mips operator function not supported Texture2D #4201

Closed
chaoticbob opened this issue May 21, 2024 · 1 comment · Fixed by #4310
Closed

.mips operator function not supported Texture2D #4201

chaoticbob opened this issue May 21, 2024 · 1 comment · Fixed by #4310
Assignees
Labels
goal:client support Needed to support a slang use case GoodFirstBug Great bug for people getting going in slang codebase kind:enhancement a desirable new feature, option, or behavior

Comments

@chaoticbob
Copy link
Collaborator

chaoticbob commented May 21, 2024

The shader below fails to compile using slangc (52b5bb4):

$ slangc -target spirv -emit-spirv-directly -lang slang -profile cs_6_0 -entry csmain texture2d_mips.slang
texture2d_mips.slang(19): error 30027: 'mips' is not a member of 'Texture2D<float>'.
    Dst[0] = Src.mips[2][g_PixelReadback.pixelPosition.xy];

Shader source

struct PixelReadbackConstants
{
    int2    pixelPosition;
    int2    dummy;
};

cbuffer c_PixelReadback : register(b0)
{
    PixelReadbackConstants g_PixelReadback;
};

Texture2D<float> Src : register(t1);
RWBuffer<float>  Dst : register(u2);

[shader("compute")]
[numthreads(1, 1, 1)]
void csmain()
{
    Dst[0] = Src.mips[2][g_PixelReadback.pixelPosition.xy];
}


DXC emits the below SPIR-V for the above shader when targeting Vulkan 1.3:

; SPIR-V
; Version: 1.6
; Generator: Google spiregg; 0
; Bound: 32
; Schema: 0
               OpCapability Shader
               OpCapability SampledBuffer
               OpCapability ImageBuffer
               OpCapability StorageImageReadWithoutFormat
               OpMemoryModel Logical GLSL450
               OpEntryPoint GLCompute %csmain "csmain" %c_PixelReadback %Src %Dst
               OpExecutionMode %csmain LocalSize 1 1 1
               OpSource HLSL 600
               OpName %type_c_PixelReadback "type.c_PixelReadback"
               OpMemberName %type_c_PixelReadback 0 "g_PixelReadback"
               OpName %PixelReadbackConstants "PixelReadbackConstants"
               OpMemberName %PixelReadbackConstants 0 "pixelPosition"
               OpMemberName %PixelReadbackConstants 1 "dummy"
               OpName %c_PixelReadback "c_PixelReadback"
               OpName %type_2d_image "type.2d.image"
               OpName %Src "Src"
               OpName %type_buffer_image "type.buffer.image"
               OpName %Dst "Dst"
               OpName %csmain "csmain"
               OpDecorate %c_PixelReadback DescriptorSet 0
               OpDecorate %c_PixelReadback Binding 0
               OpDecorate %Src DescriptorSet 0
               OpDecorate %Src Binding 1
               OpDecorate %Dst DescriptorSet 0
               OpDecorate %Dst Binding 2
               OpMemberDecorate %PixelReadbackConstants 0 Offset 0
               OpMemberDecorate %PixelReadbackConstants 1 Offset 8
               OpMemberDecorate %type_c_PixelReadback 0 Offset 0
               OpDecorate %type_c_PixelReadback Block
       %uint = OpTypeInt 32 0
     %uint_2 = OpConstant %uint 2
        %int = OpTypeInt 32 1
      %int_0 = OpConstant %int 0
     %uint_0 = OpConstant %uint 0
      %v2int = OpTypeVector %int 2
%PixelReadbackConstants = OpTypeStruct %v2int %v2int
%type_c_PixelReadback = OpTypeStruct %PixelReadbackConstants
%_ptr_Uniform_type_c_PixelReadback = OpTypePointer Uniform %type_c_PixelReadback
      %float = OpTypeFloat 32
%type_2d_image = OpTypeImage %float 2D 2 0 0 1 Unknown
%_ptr_UniformConstant_type_2d_image = OpTypePointer UniformConstant %type_2d_image
%type_buffer_image = OpTypeImage %float Buffer 2 0 0 2 R32f
%_ptr_UniformConstant_type_buffer_image = OpTypePointer UniformConstant %type_buffer_image
       %void = OpTypeVoid
         %20 = OpTypeFunction %void
%_ptr_Uniform_v2int = OpTypePointer Uniform %v2int
     %v2uint = OpTypeVector %uint 2
    %v4float = OpTypeVector %float 4
%c_PixelReadback = OpVariable %_ptr_Uniform_type_c_PixelReadback Uniform
        %Src = OpVariable %_ptr_UniformConstant_type_2d_image UniformConstant
        %Dst = OpVariable %_ptr_UniformConstant_type_buffer_image UniformConstant
     %csmain = OpFunction %void None %20
         %24 = OpLabel
         %25 = OpAccessChain %_ptr_Uniform_v2int %c_PixelReadback %int_0 %int_0
         %26 = OpLoad %v2int %25
         %27 = OpBitcast %v2uint %26
         %28 = OpLoad %type_2d_image %Src
         %29 = OpImageFetch %v4float %28 %27 Lod %uint_2
         %30 = OpCompositeExtract %float %29 0
         %31 = OpLoad %type_buffer_image %Dst
               OpImageWrite %31 %uint_0 %30 None
               OpReturn
               OpFunctionEnd
@ArielG-NV ArielG-NV added kind:enhancement a desirable new feature, option, or behavior GoodFirstBug Great bug for people getting going in slang codebase goal:client support Needed to support a slang use case labels May 21, 2024
@ArielG-NV ArielG-NV self-assigned this May 28, 2024
@bmillsNV bmillsNV added this to the Q3 2024 (Summer) milestone May 28, 2024
@ArielG-NV ArielG-NV removed their assignment May 28, 2024
@ArielG-NV
Copy link
Collaborator

Note: requires deciding how we want to implement subscript operators on property like type's (new getter, embedding __subscript in a property, etc.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:client support Needed to support a slang use case GoodFirstBug Great bug for people getting going in slang codebase kind:enhancement a desirable new feature, option, or behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants