Skip to content

Validator pass for image instructions#953

Closed
atgoo wants to merge 3 commits intoKhronosGroup:masterfrom
atgoo:val_image
Closed

Validator pass for image instructions#953
atgoo wants to merge 3 commits intoKhronosGroup:masterfrom
atgoo:val_image

Conversation

@atgoo
Copy link
Copy Markdown

@atgoo atgoo commented Nov 8, 2017

Includes validation rules for 22 OpImageXXX opcodes and ImageOperand.

Doesn't include OpTypeImage and OpImageSparseXXX.

Includes validation rules for OpImageXXX and ImageOperand.

Doesn't include OpTypeImage and OpImageSparseXXX.
@atgoo
Copy link
Copy Markdown
Author

atgoo commented Nov 8, 2017

Passes Vulkan CTS master.

@atgoo atgoo changed the title WIP Validator pass for image instructions Validator pass for image instructions Nov 9, 2017
Copy link
Copy Markdown
Collaborator

@dneto0 dneto0 left a comment

Choose a reason for hiding this comment

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

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() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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)

SpvAccessQualifier access_qualifier = SpvAccessQualifierMax;
};

// Provides information on image type.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should also say that id can be either an OpTypeImage or OpTypeSampledImage
Explain the return value.

}

// Returns actual dimensionality of |info.dim|.
uint32_t GetPlaneSize(const ImageTypeInfo& info) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

return false;
}

bool IsProjLod(SpvOp opcode) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Need to reject if used with Cube dim.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

return _.diag(SPV_ERROR_INVALID_DATA)
<< "Expected Image Operand ConstOffsets to be a const object: "
<< spvOpcodeString(opcode);
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should reject if used with Cube dimension

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

<< "Expected Image Operand Offset to have " << plane_size
<< " components, but given " << offset_size << ": "
<< spvOpcodeString(opcode);
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should reject if used with Cube dimension

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

}

ImageTypeInfo info;
if (!GetImageTypeInfo(_, _.GetOperandTypeId(inst, 2), &info)) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

??
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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@KhronosGroup KhronosGroup deleted a comment from dneto0 Nov 17, 2017
Copy link
Copy Markdown
Author

@atgoo atgoo left a comment

Choose a reason for hiding this comment

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

I think I accidentally deleted one of the comments. Sorry about that.

}

if (mask & SpvImageOperandsLodMask) {
if (is_implcit_lod) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

<< "Expected Image Operand Offset to have " << plane_size
<< " components, but given " << offset_size << ": "
<< spvOpcodeString(opcode);
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

return _.diag(SPV_ERROR_INVALID_DATA)
<< "Expected Image Operand ConstOffsets to be a const object: "
<< spvOpcodeString(opcode);
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

}

ImageTypeInfo info;
if (!GetImageTypeInfo(_, _.GetOperandTypeId(inst, 2), &info)) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@atgoo
Copy link
Copy Markdown
Author

atgoo commented Nov 17, 2017

Feedback addressed.

Copy link
Copy Markdown
Collaborator

@dneto0 dneto0 left a comment

Choose a reason for hiding this comment

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

Thanks!

}

bool IsProjLod(SpvOp opcode) {
bool IdProj(SpvOp opcode) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

IsProj :-)

I can fix this before merge.

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:-)

@dneto0
Copy link
Copy Markdown
Collaborator

dneto0 commented Nov 22, 2017

Rebased, squashed, typo fixed, and pushed into master as f407ae2

@dneto0 dneto0 closed this Nov 22, 2017
dneto0 pushed a commit to dneto0/SPIRV-Tools that referenced this pull request Sep 14, 2024
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
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