MCPcopy Create free account
hub / github.com/Rust-GPU/rust-gpu / new

Method new

crates/rustc_codegen_spirv/src/builder_spirv.rs:404–479  ·  view source on GitHub ↗
(
        tcx: TyCtxt<'tcx>,
        sym: &Symbols,
        target: &SpirvTarget,
        features: &[TargetFeature],
    )

Source from the content-addressed store, hash-verified

402
403impl<'tcx> BuilderSpirv<'tcx> {
404 pub fn new(
405 tcx: TyCtxt<'tcx>,
406 sym: &Symbols,
407 target: &SpirvTarget,
408 features: &[TargetFeature],
409 ) -> Self {
410 let version = target.spirv_version();
411 let memory_model = target.memory_model();
412
413 let mut builder = Builder::new();
414 builder.set_version(version.0, version.1);
415 builder.module_mut().header.as_mut().unwrap().generator = 0x001B_0000;
416
417 let mut enabled_capabilities = FxHashSet::default();
418 let mut enabled_extensions = FxHashSet::default();
419
420 fn add_cap(
421 builder: &mut Builder,
422 enabled_capabilities: &mut FxHashSet<Capability>,
423 cap: Capability,
424 ) {
425 // This should be the only callsite of Builder::capability (aside from tests), to make
426 // sure the hashset stays in sync.
427 builder.capability(cap);
428 enabled_capabilities.insert(cap);
429 }
430 fn add_ext(builder: &mut Builder, enabled_extensions: &mut FxHashSet<Symbol>, ext: Symbol) {
431 // This should be the only callsite of Builder::extension (aside from tests), to make
432 // sure the hashset stays in sync.
433 builder.extension(ext.as_str());
434 enabled_extensions.insert(ext);
435 }
436
437 for feature in features {
438 match *feature {
439 TargetFeature::Capability(cap) => {
440 add_cap(&mut builder, &mut enabled_capabilities, cap);
441 }
442 TargetFeature::Extension(ext) => {
443 add_ext(&mut builder, &mut enabled_extensions, ext);
444 }
445 }
446 }
447
448 add_cap(&mut builder, &mut enabled_capabilities, Capability::Shader);
449 if memory_model == MemoryModel::Vulkan {
450 if version < (1, 5) {
451 add_ext(
452 &mut builder,
453 &mut enabled_extensions,
454 sym.spv_khr_vulkan_memory_model,
455 );
456 }
457 add_cap(
458 &mut builder,
459 &mut enabled_capabilities,
460 Capability::VulkanMemoryModel,
461 );

Callers

nothing calls this directly

Calls 2

spirv_versionMethod · 0.80
memory_modelMethod · 0.80

Tested by

no test coverage detected