Validator pass for image instructions#953
Conversation
Includes validation rules for OpImageXXX and ImageOperand. Doesn't include OpTypeImage and OpImageSparseXXX.
|
Passes Vulkan CTS master. |
dneto0
left a comment
There was a problem hiding this comment.
This is good, detailed work.
Many of the questionable bits match the spec issues you have filed, so I've not commented on them here.
I have filed issues for followup in some areas.
Otherwise, I'd like some small fixups, including adding checks in three places where the Cube dim is disallowed.
Thanks for your patience waiting for this review!
| // this module. If SpvImageOperandsXXX list changes, this function will fail the | ||
| // build. | ||
| // For all other purposes this is a dummy function. | ||
| bool CheckAllImageOperandsHandled() { |
There was a problem hiding this comment.
I'm glad you're checking this.
The approach is unorthodox. But I see it works.
| } | ||
|
|
||
| // Returns number of '1' bits in a word. | ||
| uint32_t CountSetBits(uint32_t word) { |
There was a problem hiding this comment.
It's worth mentioning that compilers have builtins for this: GCC and Clang have __builtin_popcount, MSVC has __popcnt.
But probably not worth implementing the fast path. (Measure before optimizing)
source/validate_image.cpp
Outdated
| SpvAccessQualifier access_qualifier = SpvAccessQualifierMax; | ||
| }; | ||
|
|
||
| // Provides information on image type. |
There was a problem hiding this comment.
Should also say that id can be either an OpTypeImage or OpTypeSampledImage
Explain the return value.
source/validate_image.cpp
Outdated
| } | ||
|
|
||
| // Returns actual dimensionality of |info.dim|. | ||
| uint32_t GetPlaneSize(const ImageTypeInfo& info) { |
There was a problem hiding this comment.
I find this name confusing. Should it be GetPlaneCoordComponentCount or to match other names, GetPlaneCoordSize, GetPlaneDimension ?
And update the comment to "Returns the number of components in a coordinate used to access a texel in a single plane of an image with the given parameters." ???
I like that "Plane" is included because we're factoring out the array-ness of the image.
source/validate_image.cpp
Outdated
| return false; | ||
| } | ||
|
|
||
| bool IsProjLod(SpvOp opcode) { |
There was a problem hiding this comment.
Should rename to IsProj
These instructions are only different from others because they have "Proj".
| return _.diag(SPV_ERROR_INVALID_DATA) | ||
| << "Expected Image Operand ConstOffset to have " << plane_size | ||
| << " components, but given " << offset_size << ": " | ||
| << spvOpcodeString(opcode); |
There was a problem hiding this comment.
Need to reject if used with Cube dim.
| return _.diag(SPV_ERROR_INVALID_DATA) | ||
| << "Expected Image Operand ConstOffsets to be a const object: " | ||
| << spvOpcodeString(opcode); | ||
| } |
There was a problem hiding this comment.
Should reject if used with Cube dimension
| << "Expected Image Operand Offset to have " << plane_size | ||
| << " components, but given " << offset_size << ": " | ||
| << spvOpcodeString(opcode); | ||
| } |
There was a problem hiding this comment.
Should reject if used with Cube dimension
source/validate_image.cpp
Outdated
| } | ||
|
|
||
| ImageTypeInfo info; | ||
| if (!GetImageTypeInfo(_, _.GetOperandTypeId(inst, 2), &info)) { |
There was a problem hiding this comment.
Because GetImageTypeInfo will trace through an OpTypeSampledImage, it seems this will permit an OpSampledImage to have an image operand which itself has type OpTypeSampledImage.
I think the code must independently check that the image operand has type OpTypeImage
There was a problem hiding this comment.
Done. I believe it is done so at other locations.
| } | ||
|
|
||
| #if 0 | ||
| // TODO(atgoo@github.com) The spec doesn't whitelist all Dims supported by |
There was a problem hiding this comment.
??
SPIR-V 1.2 seems to whitelist the dimensionality in the description of the Image argument:
Its Dim operand must be one of Rect or Buffer, or if its MS is 1, it can be 2D, or, if its Sampled Type is 0 or 2, it can be 2D or 3D.
So it's Rect, Buffer, 2D, 3D.
The same list is implied by the description of the result type.
There was a problem hiding this comment.
But it doesn't whitelist all of them:
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/imageSize.xhtml
atgoo
left a comment
There was a problem hiding this comment.
I think I accidentally deleted one of the comments. Sorry about that.
source/validate_image.cpp
Outdated
| } | ||
|
|
||
| if (mask & SpvImageOperandsLodMask) { | ||
| if (is_implcit_lod) { |
There was a problem hiding this comment.
Added a TODO. There is a spec issue about this, as the spec does allude that not only ExplicitLod opcodes are possible.
Lod
A following operand is the explicit level-of-detail to use. Only valid with explicit-lod instructions. For sampling operations, it must be a floating-point type scalar. For fetch operations, it must be an integer type scalar.
| return _.diag(SPV_ERROR_INVALID_DATA) | ||
| << "Expected Image Operand ConstOffset to have " << plane_size | ||
| << " components, but given " << offset_size << ": " | ||
| << spvOpcodeString(opcode); |
| << "Expected Image Operand Offset to have " << plane_size | ||
| << " components, but given " << offset_size << ": " | ||
| << spvOpcodeString(opcode); | ||
| } |
| return _.diag(SPV_ERROR_INVALID_DATA) | ||
| << "Expected Image Operand ConstOffsets to be a const object: " | ||
| << spvOpcodeString(opcode); | ||
| } |
source/validate_image.cpp
Outdated
| } | ||
|
|
||
| ImageTypeInfo info; | ||
| if (!GetImageTypeInfo(_, _.GetOperandTypeId(inst, 2), &info)) { |
There was a problem hiding this comment.
Done. I believe it is done so at other locations.
| } | ||
|
|
||
| #if 0 | ||
| // TODO(atgoo@github.com) The spec doesn't whitelist all Dims supported by |
There was a problem hiding this comment.
But it doesn't whitelist all of them:
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/imageSize.xhtml
|
Feedback addressed. |
| } | ||
|
|
||
| bool IsProjLod(SpvOp opcode) { | ||
| bool IdProj(SpvOp opcode) { |
There was a problem hiding this comment.
IsProj :-)
I can fix this before merge.
test/val/val_image_test.cpp
Outdated
| const std::string body = R"( | ||
| %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001 | ||
| %sampler = OpLoad %type_sampler %uniform_sampler | ||
| %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %sampler %sampler |
|
Rebased, squashed, typo fixed, and pushed into master as f407ae2 |
Roll third_party/glslang/ 40801e3..d203754 (6 commits) KhronosGroup/glslang@40801e3...d203754 $ git log 40801e3..d203754 --date=short --no-merges --format='%ad %ae %s' 2020-01-07 cepheus Fix KhronosGroup#1829: Add "--" command-line options for macro def/undef. 2020-01-08 laddoc Move symbol builtin check to grammar stage 2020-01-06 lryer Add missing extension defination 2019-11-26 laddoc Add support for ARB_gpu_shader_fp64 2020-01-03 lryer Fix glslang can't link multiple AST in a single stage 2019-12-25 laddoc Modify atomic_uint binding check Roll third_party/googletest/ 306f3754a..d854bd6ac (4 commits) google/googletest@306f375...d854bd6 $ git log 306f3754a..d854bd6ac --date=short --no-merges --format='%ad %ae %s' 2020-01-09 absl-team Googletest export 2020-01-09 absl-team Googletest export 2020-01-07 absl-team Googletest export 2020-01-07 absl-team Googletest export Roll third_party/re2/ 00af5b44d..85c014206 (2 commits) google/re2@00af5b4...85c0142 $ git log 00af5b44d..85c014206 --date=short --no-merges --format='%ad %ae %s' 2020-01-12 junyer Tidy up a test. 2020-01-07 junyer Prevent ShortVisit() from crashing fuzzers. Roll third_party/spirv-cross/ 961b9014a..172e39f03 (14 commits) KhronosGroup/SPIRV-Cross@961b901...172e39f $ git log 961b9014a..172e39f03 --date=short --no-merges --format='%ad %ae %s' 2020-01-09 post HLSL: Add a resource remapping API similar to MSL. 2020-01-09 post MSL: Deal with sign on wave min/max. 2020-01-09 post HLSL: Deal with casting for WaveActiveMin/Max. 2020-01-09 post GLSL: Deal with sign in subgroup Min/Max operations. 2020-01-08 post Run format_all.sh. 2020-01-08 post HLSL: Fix bug when reading and writing structs from SSBO. 2020-01-08 post HLSL: Implement stores for complex composites in ByteAddressBuffers. 2020-01-08 post HLSL: Support loading complex composites from ByteAddressBuffer. 2020-01-08 post Run format_all.sh. 2020-01-07 post MSL: Deal with padded fragment output + Component decoration. 2020-01-07 post MSL: Explicitly don't support component packing for tessellation. 2020-01-07 post MSL: Don't set OrigID when emitting component packed vectors. 2020-01-07 post MSL: Deal with packing vectors for vertex input/fragment output. 2020-01-07 post MSL: Add trivial tests for Component decoration. Roll third_party/spirv-tools/ c8bf143..18b3b94 (6 commits) KhronosGroup/SPIRV-Tools@c8bf143...18b3b94 $ git log c8bf143..18b3b94 --date=short --no-merges --format='%ad %ae %s' 2020-01-10 33791085+aqnuep Remove names and decorations of imported symbols (KhronosGroup#3081) 2020-01-08 dneto Fix GN build for OpenCL.DebugInfo.100 update (KhronosGroup#3134) 2020-01-08 bclayton Fix bad parameter names in error message (KhronosGroup#3129) 2020-01-07 alanbaker Revert PR KhronosGroup#3093 (KhronosGroup#3131) 2020-01-07 alanbaker Disallow forward references in arrays (KhronosGroup#3093) 2020-01-07 afdx spirv-fuzz: Add fuzzer pass to perform module donation (KhronosGroup#3117) Created with: roll-dep third_party/effcee third_party/glslang third_party/googletest third_party/re2 third_party/spirv-cross third_party/spirv-headers third_party/spirv-tools
Includes validation rules for 22 OpImageXXX opcodes and ImageOperand.
Doesn't include OpTypeImage and OpImageSparseXXX.