-
Notifications
You must be signed in to change notification settings - Fork 244
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
Supporting OpRuntimeArray #503
Comments
User defined runtime data arrays are implemented in #504. Adding support for slices is a matter of changing Runtime descriptor arrays, "static" descriptor arrays, and descriptors should all be handled together. There needs to be a special type for descriptor binding anyways to allow mutation of them since they are implicitly aliased.
I've been experimenting with syntax like this: struct Slice<T>([T]);
fn my_shader(
desc_rta_of_u8_rta: Bind<[Uniform<Slice<u8>>], 0, 0>,
) Rust playground sketch, implemented in my fork see SpirvAttribute::Bind handling in entry.rs and abi.rs (note that straight slices still don't work, but user defined DSTs like in #504 do). |
As of right now, I disagree that slices should be auto-wrapped in structs by the compiler. It causes a lot of issues (as you discovered), and I believe that if we do want to support straight-slice shader parameters ( |
This is kinda tangential, but after #504, basic things like the following seem to work: #[spirv(compute(threads(64)))]
pub fn main(
#[spirv(global_invocation_id)] index: u32,
#[spirv(uniform, descriptor_set = 0, binding = 0)] a: &RuntimeArray<f32>,
#[spirv(uniform, descriptor_set = 0, binding = 1)] b: &RuntimeArray<f32>,
#[spirv(uniform, descriptor_set = 0, binding = 2)] c: &mut RuntimeArray<f32>,
) {
let index = index as usize;
c.array[index] = a.array[index] * b.array[index];
}
pub struct RuntimeArray<T> {
array: [T],
} It does generate a lot of branching and unsafe fn get_runtime_array(array: &[f32], index: u32) -> f32 {
let mut output = f32::default();
asm! {
"%f32 = OpTypeFloat 32",
"%u32 = OpTypeInt 32 0",
"%u32_0 = OpConstant %u32 0",
"%runtime_array_f32 = OpTypeRuntimeArray %f32",
"%runtime_array_f32_ptr = OpTypePointer Generic %runtime_array_f32",
"%f32_ptr = OpAccessChain %runtime_array_f32_ptr {array_ptr} %u32_0 {index}",
"%output = OpLoad %f32 %f32_ptr",
"OpStore {output} %output",
array_ptr = in(reg) array.as_ptr(),
index = in(reg) index,
output = in(reg) &mut output
}
output
} However I got stuck with this error:
|
Fixed by #596? |
At the last meeting it was brought up about what would be required to support
OpTypeRuntimeArray
. In that discussion we mostly the task into two separate parts supporting runtime data arrays, and supporting runtime descriptor arrays. The latter of which is more tricky and may require a new type, while the former might be better suited to being represented as a data slice[T]
.The text was updated successfully, but these errors were encountered: