Descriptorless Rendering in Vulkan
2021 September 17
Bindless Rendering
Descriptorless Rendering
fn resource_from_handle<T>(resource: u64) -> T { .. }#[repr(C)]
#[derive(Copy, Clone)]
pub struct MeshConstants {
material: Buffer,
}
#[spirv(fragment)]
pub fn mesh_fs(
a_texcoord: f32x2,
#[spirv(flat)] a_material_id: u32,
output: &mut f32x4,
#[spirv(push_constant)] constants: &MeshConstants,
) {
// Buffer(u64) -> RuntimeArray<MaterialData> -> index @ material_id
let material_data: &mut MaterialData =
unsafe { constants.material.index_mut(a_material_id as _) };
let mut diffuse = material_data.albedo_color;
// '0' used as invalid handle for now
if material_data.albedo_map != 0 {
// u64 -> combined image sampler
let albedo_tex: f32x4 = unsafe {
resource_from_handle::<SampledImage<Image2d>>(material_data.albedo_map)
.sample(a_texcoord)
};
diffuse *= albedo_tex;
}
*output = diffuse;
}Conclusion
Last updated