pub(super) fn str_bytes_to_words(bytes: &[u8]) -> Vec<Word> { letmut words = bytes_to_words(bytes); if bytes.len().is_multiple_of(4) { // nul-termination
words.push(0x0u32);
}
words
}
/// split a string into chunks and keep utf8 valid #[allow(unstable_name_collisions)] pub(super) fn string_to_byte_chunks(input: &str, limit: usize) -> Vec<&[u8]> { letmut offset: usize = 0; letmut start: usize = 0; letmut words = vec![]; while offset < input.len() {
offset = input.floor_char_boundary_polyfill(offset + limit); // Clippy wants us to call as_bytes() first to avoid the UTF-8 check, // but we want to assert the output is valid UTF-8. #[allow(clippy::sliced_string_as_bytes)]
words.push(input[start..offset].as_bytes());
start = offset;
}
words
}
pub(super) constfn map_storage_class(space: crate::AddressSpace) -> spirv::StorageClass { match space { crate::AddressSpace::Handle => spirv::StorageClass::UniformConstant, crate::AddressSpace::Function => spirv::StorageClass::Function, crate::AddressSpace::Private => spirv::StorageClass::Private, crate::AddressSpace::Storage { .. } => spirv::StorageClass::StorageBuffer, crate::AddressSpace::Uniform => spirv::StorageClass::Uniform, crate::AddressSpace::WorkGroup => spirv::StorageClass::Workgroup, crate::AddressSpace::Immediate => spirv::StorageClass::PushConstant, crate::AddressSpace::TaskPayload => spirv::StorageClass::TaskPayloadWorkgroupEXT, // We can't require capabilities here but we request capabilities on the ray pipeline stages // and when writing global variables - global variables because we may be writing an // uncompacted module and pipeline stages for all other cases because these can only be //accessed in a ray tracing pipeline stage. crate::AddressSpace::RayPayload => spirv::StorageClass::RayPayloadKHR, crate::AddressSpace::IncomingRayPayload => spirv::StorageClass::IncomingRayPayloadKHR,
}
}
/// Return true if the global requires a type decorated with `Block`. /// /// See [`back::spv::GlobalVariable`] for details. /// /// [`back::spv::GlobalVariable`]: super::GlobalVariable pubfn global_needs_wrapper(ir_module: &crate::Module, var: &n style='color:red'>crate::GlobalVariable) -> bool { match var.space { crate::AddressSpace::Uniform
| crate::AddressSpace::Storage { .. }
| crate::AddressSpace::Immediate => {}
_ => returnfalse,
}; match ir_module.types[var.ty].inner { crate::TypeInner::Struct { ref members,
span: _,
} => match members.last() {
Some(member) => match ir_module.types[member.ty].inner { // Structs with dynamically sized arrays can't be copied and can't be wrapped. crate::TypeInner::Array {
size: crate::ArraySize::Dynamic,
..
} => false,
_ => true,
},
None => false,
}, crate::TypeInner::BindingArray { .. } => false, // if it's not a structure or a binding array, let's wrap it to be able to put "Block"
_ => true,
}
}
/// Returns true if `pointer` refers to two-row matrix which is a member of a /// struct in the [`crate::AddressSpace::Uniform`] address space. pubfn is_uniform_matcx2_struct_member_access(
ir_function: &crate::Function,
fun_info: &crate::valid::FunctionInfo,
ir_module: &crate::Module,
pointer: Handle<crate::Expression>,
) -> bool { ifletcrate::TypeInner::Pointer {
base: pointer_base_type,
space: crate::AddressSpace::Uniform,
} = *fun_info[pointer].ty.inner_with(&ir_module.types)
{ ifletcrate::TypeInner::Matrix {
rows: crate::VectorSize::Bi,
..
} = ir_module.types[pointer_base_type].inner
{ ifletcrate::Expression::AccessIndex {
base: parent_pointer,
..
} = ir_function.expressions[pointer]
{ ifletcrate::TypeInner::Pointer {
base: parent_type, ..
} = *fun_info[parent_pointer].ty.inner_with(&ir_module.types)
{ ifletcrate::TypeInner::Struct { .. } = ir_module.types[parent_type].inner { returntrue;
}
}
}
}
}
false
}
///HACK: this is taken from std unstable, remove it when std's floor_char_boundary is stable /// and available in our msrv. trait U8Internal { fn is_utf8_char_boundary_polyfill(&self) -> bool;
}
impl U8Internal for u8 { fn is_utf8_char_boundary_polyfill(&self) -> bool { // This is bit magic equivalent to: b < 128 || b >= 192
(*selfas i8) >= -0x40
}
}
impl StrUnstable for str { fn floor_char_boundary_polyfill(&self, index: usize) -> usize { if index >= self.len() { self.len()
} else { let lower_bound = index.saturating_sub(3); let new_index = self.as_bytes()[lower_bound..=index]
.iter()
.rposition(|b| b.is_utf8_char_boundary_polyfill());
// We know that the character boundary will be within four bytes.
lower_bound + new_index.unwrap()
}
}
}
pubenum BindingDecorations {
BuiltIn(spirv::BuiltIn, ArrayVec<spirv::Decoration, 2>),
Location {
location: u32,
others: ArrayVec<spirv::Decoration, 5>, /// If this is `Some`, use Decoration::Index with blend_src as an operand
blend_src: Option<Word>,
},
None,
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.