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

Fix up how OpImageTexelPointer is interpreted. #1445

Closed
s-perron opened this issue Apr 2, 2018 · 3 comments
Closed

Fix up how OpImageTexelPointer is interpreted. #1445

s-perron opened this issue Apr 2, 2018 · 3 comments
Assignees

Comments

@s-perron
Copy link
Collaborator

s-perron commented Apr 2, 2018

The only spot we do anything special with OpImageTexelPointer is when trying to get the base pointer. In that place, we treat it like an OpAccessChain where it manipulates the operand pointer.

When looking at an example that uses it, I think this interpretation is not the best way of thinking about it. Consider the following example,

               OpCapability SampledBuffer
               OpCapability StorageImageExtendedFormats
               OpCapability ImageBuffer
               OpCapability Shader
          %1 = OpExtInstImport "GLSL.std.450"
               OpMemoryModel Logical GLSL450
               OpEntryPoint GLCompute %2 "min" %gl_GlobalInvocationID
               OpExecutionMode %2 LocalSize 64 1 1
               OpSource HLSL 600
               OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
               OpDecorate %4 DescriptorSet 4
               OpDecorate %4 Binding 70
       %uint = OpTypeInt 32 0
          %6 = OpTypeImage %uint Buffer 0 0 0 2 R32ui
%_ptr_UniformConstant_6 = OpTypePointer UniformConstant %6
%_ptr_Private_6 = OpTypePointer Private %6
       %void = OpTypeVoid
         %10 = OpTypeFunction %void
     %uint_0 = OpConstant %uint 0
     %uint_1 = OpConstant %uint 1
     %v3uint = OpTypeVector %uint 3
%_ptr_Input_v3uint = OpTypePointer Input %v3uint
%_ptr_Image_uint = OpTypePointer Image %uint
          %4 = OpVariable %_ptr_UniformConstant_6 UniformConstant
         %16 = OpVariable %_ptr_Private_6 Private
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
          %2 = OpFunction %void None %10
         %17 = OpLabel
         %18 = OpLoad %6 %4
               OpStore %16 %18
         %19 = OpImageTexelPointer %_ptr_Image_uint %16 %uint_0 %uint_0
         %20 = OpAtomicIAdd %uint %19 %uint_1 %uint_0 %uint_1
               OpReturn
               OpFunctionEnd

In this case, the atomic add is not updating the local variable. The best way of treating this is that the OpImageTexelPointer is like a load of the input pointer and a manipulation of the value loaded. We need to treat it that way.

In particular, ADCE needs to know treat it like a load so that the store to the local is not removed.

@s-perron s-perron self-assigned this Apr 2, 2018
@s-perron s-perron changed the title Fix up how OpImageTexel is interpreted. Fix up how OpImageTexelPointer is interpreted. Apr 2, 2018
s-perron added a commit to s-perron/SPIRV-Tools that referenced this issue Apr 2, 2018
Currently OpImageTexelPointer operations are treat like a use of the
pointer, but it does
not look for the memory being referenced to make sure stores are not
removed.

This change teaches it so identify the memory being accessed, and
treats it as if that memory is loaded.

Contributes to KhronosGroup#1445.
s-perron added a commit to s-perron/SPIRV-Tools that referenced this issue Apr 2, 2018
OpImageTexelPointer acts like a special kind of load.  It is not an
array load, but it also cannot be removed the same way a regular
load can.  The type of propagation that needs to be done is similar
to what we do for arrays, so I want to merge that code into that
optmization.

Contributers to KhronosGroup#1445.
s-perron added a commit to s-perron/SPIRV-Tools that referenced this issue Apr 2, 2018
OpImageTexelPointer acts like a special kind of load.  It is still
safe to change the storage class of a variable used in a
OpImageTexalPointer instruction.

Contributes to KhronosGroup#1445.
@greg-lunarg
Copy link
Contributor

greg-lunarg commented Apr 2, 2018

This code does not look "right" to me.

I think there is something missing in the SPIR-V spec.

Specifically, it is surprising to me that there is not a rule in the spec that requires the Storage Class of the Image in an OpImageTexelPointer to be "Image".

The spec requires the Storage Class of the Result Type pointee to be "Image". Shouldn't the Storage Class of the result's pointee and the referenced pointee match? It is hard to imagine why these should not be required to match. What good is the requirement for the pointer otherwise?

If indeed it is decided that the Image must be of Storage Class "Image", then the code in this issue is invalid and this issue can be closed. I suspect the other issues related to this one can then also be closed as such pointers cannot be interpreted to point at Private or Function scope variables.

s-perron added a commit to s-perron/SPIRV-Tools that referenced this issue Apr 3, 2018
Currently OpImageTexelPointer operations are treat like a use of the
pointer, but it does
not look for the memory being referenced to make sure stores are not
removed.

This change teaches it so identify the memory being accessed, and
treats it as if that memory is loaded.

Contributes to KhronosGroup#1445.
s-perron added a commit to s-perron/SPIRV-Tools that referenced this issue Apr 3, 2018
OpImageTexelPointer acts like a special kind of load.  It is still
safe to change the storage class of a variable used in a
OpImageTexalPointer instruction.

Contributes to KhronosGroup#1445.
@dnovillo
Copy link
Contributor

dnovillo commented Apr 3, 2018

@greg-lunarg isn't the spec saying that now? In https://www.khronos.org/registry/spir-v/specs/1.2/SPIRV.html#OpImageTexelPointer, it states: "Image must have a type of OpTypePointer with Type OpTypeImage. The Sampled Type of the type of Image must be the same as the Type pointed to by Result Type. The Dim operand of Type cannot be SubpassData."

Which is what this code seems to be doing. I may be reading something wrong, though.

We need to keep %16 live. The OpImageTexelPointer instruction just does a type cast. So, the store into %19, must be considered a store into %16.

@dneto0, could you confirm?

@s-perron
Copy link
Collaborator Author

s-perron commented Apr 4, 2018

We discussed with @greg-lunarg. When looking at the code that is currently generated for an OpImageWrite, it looks like the the current model that an OpLoad of an image variable returns a "handle" to the image. It is consistent that an OpImageTexelPointer is treated the way I am dealing with it. Also, alternative solutions would require significant changes to the FE. So we will put merge the PRs associated with this issue.

However, this is still odd. Why would an OpImageTexelPointer take a pointer to an image instead of an image? We need to verify that the semantics I have given to OpImageTexelPointer is correct. @greg-lunarg will open a follow-up issue to discuss this. We can then implement any changes that come out of that discuss.

s-perron added a commit that referenced this issue Apr 4, 2018
OpImageTexelPointer acts like a special kind of load.  It is still
safe to change the storage class of a variable used in a
OpImageTexalPointer instruction.

Contributes to #1445.
s-perron added a commit that referenced this issue Apr 4, 2018
OpImageTexelPointer acts like a special kind of load.  It is not an
array load, but it also cannot be removed the same way a regular
load can.  The type of propagation that needs to be done is similar
to what we do for arrays, so I want to merge that code into that
optmization.

Contributers to #1445.
s-perron added a commit to s-perron/SPIRV-Tools that referenced this issue Apr 4, 2018
Currently OpImageTexelPointer operations are treat like a use of the
pointer, but it does
not look for the memory being referenced to make sure stores are not
removed.

This change teaches it so identify the memory being accessed, and
treats it as if that memory is loaded.

Fixes to KhronosGroup#1445.
@s-perron s-perron closed this as completed Apr 5, 2018
dneto0 pushed a commit to dneto0/SPIRV-Tools that referenced this issue Sep 14, 2024
Roll third_party/glslang/ b60e067..f257e0e (11 commits)

KhronosGroup/glslang@b60e067...f257e0e

$ git log b60e067..f257e0e --date=short --no-merges --format='%ad %ae %s'
2020-08-14 john Build: fix a build warning
2020-08-14 rafael.fariasmarinheiro Use --test-root to pass files to Bazel tests.
2020-08-14 john Fix KhronosGroup#2366, fix KhronosGroup#2358, correctly separate out numerical feature checking
2020-08-14 john Non-functional (almost): Refactor when 'extensionRequested' is called.
2020-08-14 john Non-functional: Remove reinventing the scalar type, note code issues
2020-08-11 john Non-functional: spellings of "destinaton" and "addPairConversion"
2020-08-12 alanbaker Update test expectations
2020-08-12 alanbaker Update SPIRV-Tools and SPIRV-Headers known good
2020-08-10 ezdiy GLSLANG_EXPORT for C APIs.
2020-08-07 john Non-functional: correctly do GL_EXT_buffer_reference2 semantic checking
2020-08-06 john Non-functional: consistently use 'const TSourceLoc&' to pass location.

Created with:
  roll-dep third_party/glslang

Roll third_party/googletest/ 3af06fe16..adeef1929 (4 commits)

google/googletest@3af06fe...adeef19

$ git log 3af06fe16..adeef1929 --date=short --no-merges --format='%ad %ae %s'
2020-08-12 krzysio Googletest export
2020-08-11 absl-team Googletest export
2020-08-11 dmauro Googletest export
2020-08-10 absl-team Googletest export

Created with:
  roll-dep third_party/googletest

Roll third_party/spirv-cross/ 82d1c43e4..4c7944bb4 (1 commit)

KhronosGroup/SPIRV-Cross@82d1c43...4c7944b

$ git log 82d1c43e4..4c7944bb4 --date=short --no-merges --format='%ad %ae %s'
2020-08-13 lehoangq Fix KhronosGroup#1445: MSL: Enclose args when convert distance(a,b) to abs(a-b)

Created with:
  roll-dep third_party/spirv-cross

Roll third_party/spirv-tools/ 2990a21..b8de4f5 (19 commits)

KhronosGroup/SPIRV-Tools@2990a21...b8de4f5

$ git log 2990a21..b8de4f5 --date=short --no-merges --format='%ad %ae %s'
2020-08-16 jaebaek Allow DebugTypeTemplate for Type operand (KhronosGroup#3702)
2020-08-14 antonikarp spirv-fuzz: Improve code coverage of tests (KhronosGroup#3686)
2020-08-14 stefanomil spirv-fuzz: Fuzzer pass to randomly apply loop preheaders (KhronosGroup#3668)
2020-08-14 vasniktel spirv-fuzz: Support identical predecessors in TransformationPropagateInstructionUp (KhronosGroup#3689)
2020-08-13 alanbaker Improve non-semantic instruction handling in the optimizer (KhronosGroup#3693)
2020-08-13 vasniktel Fix the bug (KhronosGroup#3680)
2020-08-12 andreperezmaselco.developer spirv-fuzz: Check integer and float width capabilities (KhronosGroup#3670)
2020-08-12 andreperezmaselco.developer spirv-fuzz: consider additional access chain instructions (KhronosGroup#3672)
2020-08-12 andreperezmaselco.developer spirv-fuzz: Ignore specialization constants (KhronosGroup#3664)
2020-08-12 vasniktel Fix the bug (KhronosGroup#3683)
2020-08-12 vasniktel spirv-fuzz: Fix width in FuzzerPassAddEquationInstructions (KhronosGroup#3685)
2020-08-12 jaebaek Preserve debug info in dead-insert-elim pass (KhronosGroup#3652)
2020-08-12 jaebaek Validate more OpenCL.DebugInfo.100 instructions (KhronosGroup#3684)
2020-08-11 alanbaker Only validation locations for appropriate execution models (KhronosGroup#3656)
2020-08-11 andreperezmaselco.developer spirv-fuzz: Fix in operand type assertion (KhronosGroup#3666)
2020-08-11 andreperezmaselco.developer spirv-opt: Add spvOpcodeIsAccessChain (KhronosGroup#3682)
2020-08-11 vasniktel spirv-fuzz: FuzzerPassPropagateInstructionsUp (KhronosGroup#3478)
2020-08-10 stevenperron Handle no index access chain in local access chain convert (KhronosGroup#3678)
2020-08-10 rharrison Roll 2 dependencies (KhronosGroup#3677)

Created with:
  roll-dep third_party/spirv-tools
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

No branches or pull requests

3 participants