I have a prototype that lets you write an entry-point's builtin arguments with newtype wrappers. Would you like to see a completed PR for this?
Example entry-point:
#[spirv(compute(threads(1024)))]
pub fn entry(
// local_invocation_index old:
#[spirv(local_invocation_index)]
local_idx_old: u32,
// New:
local_idx_new: LocalInvocationIndex,
// local_invocation_id old:
#[spirv(local_invocation_index)]
local_id: UVec3,
local_id_new: LocalInvocationId,
) { .. }
There's less code to write in the newtyped version, and in my opinion it's easier to write this correctly without looking through rust-gpu book to find both the required type and builtin name. Instead spirv_std could have a module of these builtin wrapper newtypes, and the user could just select the right one without leaving their IDE.
The newtype wrappers for the current prototype are simple to add, here's approximately what could go in spirv_std:
#[spirv(builtin_wrapper("local_invocation_index"))]
#[repr(transparent)]
pub struct LocalInvocationIndex(pub u32);
#[spirv(builtin_wrapper("local_invocation_id"))]
#[repr(transparent)]
pub struct LocalInvocationId(pub UVec3);
In rustc_codegen_spirv I currently have a match statement to map from spirv::BuiltIn::_ to the abi type. That could probably be moved into the #[spirv(builtin_wrapper(..)] attribute in spirv_std also, or perhaps inferred from the contents of the newtype?
The current changes for the implementation in rustc_codegen_spirv are only ~75 lines, but before a PR would be ready I'd need to add some more tests, some documentation, and probably better diagnostics. Shall I polish this up for a PR?
I have a prototype that lets you write an entry-point's builtin arguments with newtype wrappers. Would you like to see a completed PR for this?
Example entry-point:
There's less code to write in the
newtyped version, and in my opinion it's easier to write this correctly without looking throughrust-gpubook to find both the required type and builtin name. Insteadspirv_stdcould have a module of these builtin wrappernewtypes, and the user could just select the right one without leaving their IDE.The
newtypewrappers for the current prototype are simple to add, here's approximately what could go inspirv_std:In
rustc_codegen_spirvI currently have a match statement to map fromspirv::BuiltIn::_to the abi type. That could probably be moved into the#[spirv(builtin_wrapper(..)]attribute inspirv_stdalso, or perhaps inferred from the contents of the newtype?The current changes for the implementation in
rustc_codegen_spirvare only ~75 lines, but before a PR would be ready I'd need to add some more tests, some documentation, and probably better diagnostics. Shall I polish this up for a PR?