Skip to content

spirv-val: Add OpSizeOf#6497

Open
spencer-lunarg wants to merge 3 commits intoKhronosGroup:mainfrom
spencer-lunarg:spencer-lunarg-sizeof
Open

spirv-val: Add OpSizeOf#6497
spencer-lunarg wants to merge 3 commits intoKhronosGroup:mainfrom
spencer-lunarg:spencer-lunarg-sizeof

Conversation

@spencer-lunarg
Copy link
Contributor

in pursuit of learning more about OpenCL, found some un-validated instructions

return SPV_SUCCESS;
}

spv_result_t ValidateSizeOf(ValidationState_t& _, const Instruction* inst) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For completeness, could you add check for the pointer operand? It must point to a concrete. I don't think untyped pointers are allowed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so I tried to add a IsConcreteType helper, from what I can read from SPV_KHR_untyped_pointers, there is no reason I can see why an untyped pointer would not be allowed, as long as it is Physical

Copy link
Contributor

Choose a reason for hiding this comment

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

An untyped pointer could be returned I suppose, but I meant pointer that OpSizeOf has an operand which is a pointer and it returns the size of the object pointed to by that pointer. Untyped pointers don't carry the information to make that check easy. Also, I don't think the extension modified this instruction. So you could have a function variable containing an untyped pointer (say to cross-workgroup), but not an untyped function variable I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, so ya, this makes sense... I guess my question is I am over following the spec, trying to think where in the spec would be where to make a change to make this explicit

For this, since I did the check as IsConcreteType, where would I then look for the untyped pointer exception... is this suppose to mean that an untyped pointer is abstract?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's like the following: if pointer has OpTypePointer, then check that the pointee is concrete. Because OpenCL uses Physical32 or Physical64 addressing model, all pointers (including untyped) are physical, and thus concrete. I'm on the fence about banning untyped pointers as the pointer operand since OpSizeOf is not particularly well described. I briefly spent some time on godbolt.org trying to generate it and I couldn't find a situation where it was not statically known very easily.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated with a condition to ban untyped

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