├── docs ├── .gitignore ├── assets │ └── sky.jpg ├── book.toml └── src │ ├── introduction.md │ ├── rfcs │ └── 000-template.md │ └── SUMMARY.md ├── rustfmt.toml ├── clippy.toml ├── tests ├── compiletests │ ├── deps-helper │ │ ├── src │ │ │ └── lib.rs │ │ └── Cargo.toml │ └── ui │ │ ├── target_features_err.stderr │ │ ├── lang │ │ ├── control_flow │ │ │ ├── loop.rs │ │ │ ├── if.rs │ │ │ ├── while.rs │ │ │ ├── for_range.rs │ │ │ ├── for_range_signed.rs │ │ │ ├── ifx2.rs │ │ │ ├── if_else.rs │ │ │ ├── if_if.rs │ │ │ ├── while_break.rs │ │ │ ├── while_return.rs │ │ │ ├── if_while.rs │ │ │ ├── while_continue.rs │ │ │ ├── while_while.rs │ │ │ ├── if_return_else.rs │ │ │ ├── if_else_if_else.rs │ │ │ ├── if_return_else_return.rs │ │ │ ├── while_if_break.rs │ │ │ ├── while_if_continue.rs │ │ │ ├── while_while_break.rs │ │ │ ├── while_while_continue.rs │ │ │ ├── while_if_break_else_break.rs │ │ │ ├── issue_764.stderr │ │ │ ├── while_while_if_break.rs │ │ │ ├── while_if_continue_else_continue.rs │ │ │ ├── while_while_if_continue.rs │ │ │ ├── while_if_break_if_break.rs │ │ │ ├── defer.rs │ │ │ └── closure_multi.rs │ │ ├── consts │ │ │ ├── issue-834.rs │ │ │ ├── issue-329.rs │ │ │ ├── u8-const-cast-no-capability.rs │ │ │ ├── u32-from-u64-fail.rs │ │ │ ├── shallow-ref.rs │ │ │ ├── nested-ref.stderr │ │ │ ├── u32-from-u64-fail.stderr │ │ │ └── nested-ref-in-composite.rs │ │ ├── panic │ │ │ ├── simple.rs │ │ │ ├── builtin.rs │ │ │ ├── builtin_bounds_check.rs │ │ │ ├── track_caller.rs │ │ │ └── track_caller.stderr │ │ ├── u32 │ │ │ └── const_fold_div.rs │ │ ├── core │ │ │ ├── array │ │ │ │ ├── init_array_i32.rs │ │ │ │ ├── init_array_i8.rs │ │ │ │ ├── init_array_i16.rs │ │ │ │ └── init_array_i64.rs │ │ │ ├── ops │ │ │ │ ├── logical_and.rs │ │ │ │ └── range-contains.rs │ │ │ ├── ptr │ │ │ │ ├── allocate_null.rs │ │ │ │ ├── allocate_vec_like.stderr │ │ │ │ ├── allocate_vec_like.rs │ │ │ │ ├── allocate_const_scalar.rs │ │ │ │ └── allocate_const_scalar.stderr │ │ │ ├── ref │ │ │ │ ├── zst_member_ref_arg.rs │ │ │ │ ├── member_ref_arg.rs │ │ │ │ └── member_ref_arg.stderr │ │ │ ├── issue-424.rs │ │ │ ├── unwrap_or.rs │ │ │ ├── intrinsics │ │ │ │ ├── log10.rs │ │ │ │ └── black_box.stderr │ │ │ ├── mem │ │ │ │ └── create_unitialized_memory.rs │ │ │ └── unwrap_or.stderr │ │ ├── f32 │ │ │ └── signum.rs │ │ ├── issue-415.rs │ │ ├── issue-452.rs │ │ └── asm │ │ │ ├── const_args.rs │ │ │ ├── block_tracking_fail.stderr │ │ │ ├── block_tracking_pass.rs │ │ │ └── infer-access-chain-array.rs │ │ ├── arch │ │ ├── kill.rs │ │ ├── all_memory_barrier.stderr │ │ ├── device_memory_barrier.stderr │ │ ├── workgroup_memory_barrier.stderr │ │ ├── subgroup │ │ │ ├── subgroup_elect.stderr │ │ │ ├── subgroup_i_add_reduce.stderr │ │ │ ├── subgroup_broadcast_const.stderr │ │ │ ├── subgroup_broadcast_first.stderr │ │ │ ├── subgroup_ballot_bit_count.stderr │ │ │ ├── subgroup_i_add_clustered.stderr │ │ │ ├── subgroup_i_add_exclusive_scan.stderr │ │ │ ├── subgroup_i_add_inclusive_scan.stderr │ │ │ ├── subgroup_broadcast.stderr │ │ │ ├── subgroup_ballot.stderr │ │ │ ├── subgroup_elect.rs │ │ │ ├── subgroup_composite_enum.stderr │ │ │ ├── subgroup_composite_all_equals.stderr │ │ │ ├── subgroup_composite_shuffle.stderr │ │ │ ├── subgroup_ballot.rs │ │ │ ├── subgroup_broadcast_const.rs │ │ │ ├── subgroup_broadcast_first.rs │ │ │ ├── subgroup_ballot_bit_count.rs │ │ │ ├── subgroup_cluster_size_0_fail.rs │ │ │ ├── subgroup_cluster_size_non_power_of_two_fail.rs │ │ │ ├── subgroup_i_add_reduce.rs │ │ │ ├── subgroup_builtins.rs │ │ │ ├── subgroup_broadcast.rs │ │ │ ├── subgroup_i_add_exclusive_scan.rs │ │ │ ├── subgroup_i_add_inclusive_scan.rs │ │ │ └── subgroup_i_add_clustered.rs │ │ ├── all_memory_barrier_with_group_sync.stderr │ │ ├── device_memory_barrier_with_group_sync.stderr │ │ ├── workgroup_memory_barrier_with_group_sync.stderr │ │ ├── all.rs │ │ ├── any.rs │ │ ├── derivative.stderr │ │ ├── emit_vertex.rs │ │ ├── terminate_ray_khr.rs │ │ ├── end_primitive.rs │ │ ├── ignore_intersection_khr.rs │ │ ├── report_intersection_khr.rs │ │ ├── emit_stream_vertex.rs │ │ ├── end_stream_primitive.rs │ │ ├── task_shader.rs │ │ ├── demote_to_helper_invocation.rs │ │ ├── derivative.rs │ │ ├── derivative_control.stderr │ │ ├── task_shader_mispile.rs │ │ ├── workgroup_memory_barrier.rs │ │ ├── control_barrier.rs │ │ ├── memory_barrier.rs │ │ ├── execute_callable.rs │ │ ├── all_memory_barrier.rs │ │ ├── vector_extract_dynamic.rs │ │ ├── device_memory_barrier.rs │ │ ├── workgroup_memory_barrier_with_group_sync.rs │ │ ├── read_clock_khr.rs │ │ ├── index_unchecked.rs │ │ ├── task_shader_payload.rs │ │ ├── all_memory_barrier_with_group_sync.rs │ │ ├── derivative_control.rs │ │ ├── ray_query_get_ray_flags_khr.rs │ │ ├── ray_query_get_ray_t_min_khr.rs │ │ ├── device_memory_barrier_with_group_sync.rs │ │ ├── ray_query_terminate_khr.rs │ │ ├── ray_query_get_world_ray_origin_khr.rs │ │ ├── atomic_i_increment.rs │ │ ├── ray_query_get_world_ray_direction_khr.rs │ │ ├── vector_insert_dynamic.rs │ │ ├── ray_query_confirm_intersection_khr.rs │ │ ├── ray_query_get_intersection_candidate_aabb_opaque_khr.rs │ │ ├── ray_query_get_intersection_type_khr.rs │ │ ├── ray_query_get_intersection_t_khr.rs │ │ ├── ray_query_get_intersection_primitive_index_khr.rs │ │ ├── ray_query_get_intersection_front_face_khr.rs │ │ ├── ray_query_get_intersection_instance_id_khr.rs │ │ ├── ray_query_get_intersection_geometry_index_khr.rs │ │ ├── mesh_shader_output_points.rs │ │ ├── ray_query_get_intersection_instance_custom_index_khr.rs │ │ ├── ray_query_get_intersection_object_ray_origin_khr.rs │ │ ├── ray_query_get_intersection_barycentrics_khr.rs │ │ ├── ray_query_get_intersection_object_ray_direction_khr.rs │ │ ├── ray_query_get_intersection_shader_binding_table_record_offset_khr.rs │ │ ├── trace_ray_khr.rs │ │ ├── ray_query_get_intersection_object_to_world_khr.rs │ │ └── mesh_shader_output_lines.rs │ │ ├── dis │ │ ├── asm.stderr │ │ ├── add_two_ints.stderr │ │ ├── ptr_copy.via_intrinsic.stderr │ │ ├── asm_add_two_ints.stderr │ │ ├── issue-373.stderr │ │ ├── ptr_read.stderr │ │ ├── ptr_write.stderr │ │ ├── ptr_read_method.stderr │ │ ├── ptr_write_method.stderr │ │ ├── issue-723-output.stderr │ │ ├── custom_entry_point.stderr │ │ ├── add_two_ints.rs │ │ ├── index_user_dst.rs │ │ ├── generic-fn-op-name.stderr │ │ ├── issue-1062.rs │ │ ├── const-from-cast.stderr │ │ ├── const-int-cast.stderr │ │ ├── const-float-cast-optimized.stderr │ │ ├── asm.rs │ │ ├── const-narrowing-cast.stderr │ │ ├── index_user_dst.stderr │ │ ├── issue-731.rs │ │ ├── asm_add_two_ints.rs │ │ ├── pass-mode-cast-struct.stderr │ │ ├── entry-pass-mode-cast-array.stderr │ │ ├── ptr_read.rs │ │ ├── ptr_write.rs │ │ ├── issue-373.rs │ │ ├── const-float-cast.stderr │ │ ├── ptr_write_method.rs │ │ ├── ptr_read_method.rs │ │ ├── issue-731.stderr │ │ ├── complex_image_sample_inst.stderr │ │ ├── custom_entry_point.rs │ │ ├── entry-pass-mode-cast-array.rs │ │ ├── spec_constant-attr.stderr │ │ └── asm_op_decorate.stderr │ │ ├── spirv-attr │ │ ├── int-without-flat.rs │ │ ├── invariant.rs │ │ ├── invariant-invalid.rs │ │ ├── invalid-matrix-type-empty.stderr │ │ ├── invariant-invalid.stderr │ │ ├── invalid-matrix-type-empty.rs │ │ ├── uniform-constant-storage-class.rs │ │ ├── bool-inputs-err.rs │ │ ├── uniform-constant-storage-class.stderr │ │ ├── invalid-storage-class.rs │ │ ├── bool-inputs.rs │ │ ├── int-without-flat.stderr │ │ ├── invalid-matrix-type.rs │ │ ├── bad-deduce-storage-class.rs │ │ └── invalid-matrix-type.stderr │ │ ├── hello_world.rs │ │ ├── storage_class │ │ ├── int_lit_bindings.rs │ │ ├── runtime_descriptor_array_error.rs │ │ ├── storage_buffer-dst.rs │ │ ├── typed_buffer.rs │ │ ├── push_constant.rs │ │ ├── typed_buffer_slice.rs │ │ └── runtime_descriptor_array_error.stderr │ │ ├── target_features_err.rs │ │ ├── glam │ │ └── mat3_vec3_multiply.rs │ │ └── image │ │ ├── fetch.rs │ │ ├── format.rs │ │ ├── query │ │ ├── query_levels.rs │ │ ├── query_size.rs │ │ ├── query_samples.rs │ │ ├── query_size_lod.rs │ │ ├── query_levels_err.rs │ │ ├── query_size_err.rs │ │ ├── query_size_lod_err.rs │ │ ├── query_lod.rs │ │ ├── query_lod_err.rs │ │ ├── sampled_image_multisampled_query_size.rs │ │ └── sampled_image_rect_query_size_lod_err.rs │ │ ├── fetch_with_lod.rs │ │ ├── write_format_scalar.rs │ │ ├── write_format_vec4.rs │ │ ├── read.rs │ │ ├── issue-330.rs │ │ ├── read_subpass.rs │ │ ├── write_format_vec2.rs │ │ ├── write.rs │ │ ├── sample_with_project_coordinate │ │ ├── sample.rs │ │ ├── sample_lod.rs │ │ └── sample_gradient.rs │ │ ├── sample_depth_reference_with_project_coordinate │ │ ├── sample.rs │ │ ├── sample_lod.rs │ │ └── sample_gradient.rs │ │ ├── implicit_not_in_fragment.stderr │ │ ├── gather_err.rs │ │ └── issue_527.rs └── difftests │ ├── tests │ ├── arch │ │ ├── mod.rs │ │ ├── workgroup_memory │ │ │ ├── workgroup_memory-rust │ │ │ │ ├── src │ │ │ │ │ └── lib.rs │ │ │ │ └── Cargo.toml │ │ │ ├── workgroup_memory-wgsl │ │ │ │ └── Cargo.toml │ │ │ └── workgroup_memory-ash │ │ │ │ ├── src │ │ │ │ └── lib.rs │ │ │ │ └── Cargo.toml │ │ ├── memory_barriers │ │ │ ├── memory_barriers-wgsl │ │ │ │ └── Cargo.toml │ │ │ └── memory_barriers-rust │ │ │ │ └── Cargo.toml │ │ ├── vector_extract_insert │ │ │ ├── vector_extract_insert-wgsl │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ └── main.rs │ │ │ └── vector_extract_insert-rust │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ └── main.rs │ │ ├── atomic_ops │ │ │ ├── atomic_ops-wgsl │ │ │ │ └── Cargo.toml │ │ │ └── atomic_ops-rust │ │ │ │ └── Cargo.toml │ │ └── push_constants │ │ │ ├── push_constants-wgsl │ │ │ └── Cargo.toml │ │ │ └── push_constants-rust │ │ │ └── Cargo.toml │ ├── lang │ │ ├── abi │ │ │ ├── vector_layout │ │ │ │ ├── rust-gpu │ │ │ │ │ ├── src │ │ │ │ │ │ ├── lib.rs │ │ │ │ │ │ └── main.rs │ │ │ │ │ └── Cargo.toml │ │ │ │ └── cpu │ │ │ │ │ ├── src │ │ │ │ │ ├── main.rs │ │ │ │ │ ├── lib.rs │ │ │ │ │ ├── shader.rs │ │ │ │ │ ├── cpu_driver.rs │ │ │ │ │ └── shader_driver.rs │ │ │ │ │ └── Cargo.toml │ │ │ ├── vector_layout_cuda │ │ │ │ ├── rust-gpu │ │ │ │ │ ├── src │ │ │ │ │ │ ├── lib.rs │ │ │ │ │ │ └── main.rs │ │ │ │ │ └── Cargo.toml │ │ │ │ └── cpu │ │ │ │ │ ├── src │ │ │ │ │ └── main.rs │ │ │ │ │ └── Cargo.toml │ │ │ └── vector_layout_scalar_math │ │ │ │ ├── rust-gpu │ │ │ │ ├── src │ │ │ │ │ ├── lib.rs │ │ │ │ │ └── main.rs │ │ │ │ └── Cargo.toml │ │ │ │ └── cpu │ │ │ │ ├── src │ │ │ │ └── main.rs │ │ │ │ └── Cargo.toml │ │ ├── core │ │ │ ├── ops │ │ │ │ ├── const_fold_int │ │ │ │ │ ├── const-expr-shader │ │ │ │ │ │ ├── src │ │ │ │ │ │ │ ├── lib.rs │ │ │ │ │ │ │ └── main.rs │ │ │ │ │ │ └── Cargo.toml │ │ │ │ │ ├── const-fold-shader │ │ │ │ │ │ ├── src │ │ │ │ │ │ │ ├── lib.rs │ │ │ │ │ │ │ └── main.rs │ │ │ │ │ │ └── Cargo.toml │ │ │ │ │ ├── const-expr-cpu │ │ │ │ │ │ ├── src │ │ │ │ │ │ │ └── main.rs │ │ │ │ │ │ └── Cargo.toml │ │ │ │ │ ├── const-fold-cpu │ │ │ │ │ │ ├── src │ │ │ │ │ │ │ ├── main.rs │ │ │ │ │ │ │ ├── cpu_driver.rs │ │ │ │ │ │ │ ├── shader.rs │ │ │ │ │ │ │ └── shader_driver.rs │ │ │ │ │ │ └── Cargo.toml │ │ │ │ │ ├── dynamic-values-shader │ │ │ │ │ │ ├── src │ │ │ │ │ │ │ ├── lib.rs │ │ │ │ │ │ │ └── main.rs │ │ │ │ │ │ └── Cargo.toml │ │ │ │ │ └── dynamic-values-cpu │ │ │ │ │ │ ├── src │ │ │ │ │ │ └── main.rs │ │ │ │ │ │ └── Cargo.toml │ │ │ │ ├── trig_ops │ │ │ │ │ ├── trig_ops-wgsl │ │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ │ └── src │ │ │ │ │ │ │ └── main.rs │ │ │ │ │ └── trig_ops-rust │ │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ │ └── src │ │ │ │ │ │ └── main.rs │ │ │ │ ├── bitwise_ops │ │ │ │ │ ├── bitwise_ops-wgsl │ │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ │ └── src │ │ │ │ │ │ │ └── main.rs │ │ │ │ │ └── bitwise_ops-rust │ │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ │ └── src │ │ │ │ │ │ └── main.rs │ │ │ │ ├── vector_swizzle │ │ │ │ │ ├── vector_swizzle-wgsl │ │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ │ └── src │ │ │ │ │ │ │ └── main.rs │ │ │ │ │ └── vector_swizzle-rust │ │ │ │ │ │ ├── Cargo.toml │ │ │ │ │ │ └── src │ │ │ │ │ │ └── main.rs │ │ │ │ ├── math_ops │ │ │ │ │ ├── math_ops-wgsl │ │ │ │ │ │ └── Cargo.toml │ │ │ │ │ └── math_ops-rust │ │ │ │ │ │ └── Cargo.toml │ │ │ │ ├── matrix_ops │ │ │ │ │ ├── matrix_ops-wgsl │ │ │ │ │ │ └── Cargo.toml │ │ │ │ │ ├── matrix_ops-rust │ │ │ │ │ │ └── Cargo.toml │ │ │ │ │ └── mod.rs │ │ │ │ └── vector_ops │ │ │ │ │ ├── vector_ops-wgsl │ │ │ │ │ └── Cargo.toml │ │ │ │ │ └── vector_ops-rust │ │ │ │ │ └── Cargo.toml │ │ │ └── intrinsics │ │ │ │ └── black_box_noop │ │ │ │ ├── with-black-box │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ └── main.rs │ │ │ │ └── without-black-box │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ └── main.rs │ │ ├── control_flow_complex │ │ │ ├── control_flow_complex-wgsl │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ └── main.rs │ │ │ └── control_flow_complex-rust │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ └── main.rs │ │ └── control_flow │ │ │ ├── control_flow-wgsl │ │ │ └── Cargo.toml │ │ │ └── control_flow-rust │ │ │ └── Cargo.toml │ ├── simple-compute │ │ ├── simple-compute-wgsl │ │ │ ├── shader.wgsl │ │ │ ├── Cargo.toml │ │ │ └── src │ │ │ │ └── main.rs │ │ └── simple-compute-rust │ │ │ ├── src │ │ │ ├── lib.rs │ │ │ └── main.rs │ │ │ └── Cargo.toml │ └── storage_class │ │ └── array_access │ │ ├── array_access-wgsl │ │ └── Cargo.toml │ │ └── array_access-rust │ │ └── Cargo.toml │ └── lib │ └── src │ └── scaffold │ ├── mod.rs │ ├── compute │ └── mod.rs │ └── shader │ └── mod.rs ├── .github ├── CODEOWNERS ├── workflows │ ├── docs.sh │ └── deploy_docs.yml └── ISSUE_TEMPLATE │ └── enhancement.md ├── .gitignore ├── .gitattributes ├── crates ├── spirv-std │ ├── shared │ │ ├── src │ │ │ └── lib.rs │ │ ├── Cargo.toml │ │ └── README.md │ ├── macros │ │ ├── README.md │ │ └── Cargo.toml │ ├── src │ │ ├── debug_printf.rs │ │ └── sampler.rs │ └── release.toml ├── rustc_codegen_spirv-types │ ├── README.md │ ├── src │ │ └── lib.rs │ └── Cargo.toml ├── rustc_codegen_spirv-target-specs │ ├── Cargo.toml │ ├── README.md │ ├── src │ │ └── lib.rs │ └── target-specs │ │ ├── spirv-unknown-spv1.0.json │ │ ├── spirv-unknown-spv1.1.json │ │ ├── spirv-unknown-spv1.2.json │ │ └── spirv-unknown-spv1.3.json └── rustc_codegen_spirv │ ├── README.md │ └── src │ └── target_feature.rs ├── release.toml ├── examples ├── run-wasm │ ├── src │ │ └── main.rs │ └── Cargo.toml ├── runners │ ├── wgpu │ │ ├── src │ │ │ └── main.rs │ │ └── builder │ │ │ └── Cargo.toml │ └── cpu │ │ └── Cargo.toml ├── shaders │ ├── reduce │ │ └── Cargo.toml │ ├── simplest-shader │ │ ├── Cargo.toml │ │ └── src │ │ │ └── lib.rs │ ├── sky-shader │ │ └── Cargo.toml │ ├── mouse-shader │ │ └── Cargo.toml │ ├── shared │ │ └── Cargo.toml │ └── compute-shader │ │ └── Cargo.toml └── multibuilder │ ├── src │ └── main.rs │ └── Cargo.toml └── rust-toolchain.toml /docs/.gitignore: -------------------------------------------------------------------------------- 1 | book 2 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | style_edition = "2024" 2 | -------------------------------------------------------------------------------- /clippy.toml: -------------------------------------------------------------------------------- 1 | avoid-breaking-exported-api = false 2 | -------------------------------------------------------------------------------- /tests/compiletests/deps-helper/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @eddyb @LegNeato @Firestar99 @schell 2 | -------------------------------------------------------------------------------- /docs/assets/sky.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rust-GPU/rust-gpu/HEAD/docs/assets/sky.jpg -------------------------------------------------------------------------------- /tests/difftests/tests/arch/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod atomic_ops; 2 | pub mod workgroup_memory; 3 | pub mod workgroup_sizes; -------------------------------------------------------------------------------- /tests/difftests/tests/arch/workgroup_memory/workgroup_memory-rust/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | 3 | include!("shader.rs"); 4 | -------------------------------------------------------------------------------- /tests/difftests/lib/src/scaffold/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod compute; 2 | pub mod shader; 3 | pub mod skip; 4 | 5 | pub use skip::Skip; 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .vscode/ 3 | .vim/ 4 | tests/Cargo.lock 5 | .github/install-spirv-tools/Cargo.lock 6 | rustc-ice-*.txt 7 | .idea 8 | -------------------------------------------------------------------------------- /docs/book.toml: -------------------------------------------------------------------------------- 1 | [book] 2 | authors = ["The Rust GPU Project Developers"] 3 | language = "en" 4 | src = "src" 5 | title = "Rust GPU Dev Guide" 6 | -------------------------------------------------------------------------------- /tests/compiletests/ui/target_features_err.stderr: -------------------------------------------------------------------------------- 1 | error: Invalid Capability: `rayTracingKHR` 2 | 3 | error: aborting due to 1 previous error 4 | 5 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # configure GitHub linguist (language bar) https://github.com/github/linguist#overrides 2 | docs/* linguist-documentation 3 | * text=auto eol=lf 4 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/loop.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main() { 7 | loop {} 8 | } 9 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/kill.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main() { 7 | spirv_std::arch::kill(); 8 | } 9 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout/rust-gpu/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(target_arch = "spirv", no_std)] 2 | 3 | pub use abi_vector_layout_cpu::shader::main_cs; 4 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/asm.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpLabel 3 | OpLine %5 13 13 4 | OpMemoryBarrier %6 %7 5 | OpNoLine 6 | OpReturn 7 | OpFunctionEnd 8 | -------------------------------------------------------------------------------- /tests/compiletests/ui/spirv-attr/int-without-flat.rs: -------------------------------------------------------------------------------- 1 | // build-fail 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn fragment(int: u32, double: f64) {} 7 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout_cuda/rust-gpu/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(target_arch = "spirv", no_std)] 2 | 3 | pub use abi_vector_layout_cpu::shader::main_cs; 4 | -------------------------------------------------------------------------------- /tests/compiletests/ui/hello_world.rs: -------------------------------------------------------------------------------- 1 | // Simple single entrypoint function test. 2 | // build-pass 3 | 4 | use spirv_std::spirv; 5 | 6 | #[spirv(fragment)] 7 | pub fn main() {} 8 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/consts/issue-834.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main() { 7 | let arr = [0u32; 32]; 8 | } 9 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout_scalar_math/rust-gpu/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(target_arch = "spirv", no_std)] 2 | 3 | pub use abi_vector_layout_cpu::shader::main_cs; 4 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/all_memory_barrier.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpLabel 3 | OpLine %5 82 13 4 | OpMemoryBarrier %6 %7 5 | OpNoLine 6 | OpReturn 7 | OpFunctionEnd 8 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/if.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | if i > 0 {} 8 | } 9 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/device_memory_barrier.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpLabel 3 | OpLine %5 82 13 4 | OpMemoryBarrier %6 %7 5 | OpNoLine 6 | OpReturn 7 | OpFunctionEnd 8 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/workgroup_memory_barrier.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpLabel 3 | OpLine %5 82 13 4 | OpMemoryBarrier %6 %7 5 | OpNoLine 6 | OpReturn 7 | OpFunctionEnd 8 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/while.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | while i < 10 {} 8 | } 9 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_elect.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpLabel 3 | %6 = OpGroupNonUniformElect %2 %7 4 | OpNoLine 5 | OpReturnValue %6 6 | OpFunctionEnd 7 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/for_range.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: u32) { 7 | for _ in 0..i {} 8 | } 9 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/for_range_signed.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | for _ in 0..i {} 8 | } 9 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/all_memory_barrier_with_group_sync.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpLabel 3 | OpLine %5 47 13 4 | OpControlBarrier %6 %7 %8 5 | OpNoLine 6 | OpReturn 7 | OpFunctionEnd 8 | -------------------------------------------------------------------------------- /crates/spirv-std/shared/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![doc = include_str!("../README.md")] 2 | #![cfg_attr(not(feature = "std"), no_std)] 3 | 4 | pub mod image_params; 5 | #[cfg(feature = "std")] 6 | pub mod spirv_attr_version; 7 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/device_memory_barrier_with_group_sync.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpLabel 3 | OpLine %5 47 13 4 | OpControlBarrier %6 %7 %8 5 | OpNoLine 6 | OpReturn 7 | OpFunctionEnd 8 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/workgroup_memory_barrier_with_group_sync.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpLabel 3 | OpLine %5 47 13 4 | OpControlBarrier %6 %6 %7 5 | OpNoLine 6 | OpReturn 7 | OpFunctionEnd 8 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout/cpu/src/main.rs: -------------------------------------------------------------------------------- 1 | use abi_vector_layout_cpu::glam_features::GlamFeatures; 2 | 3 | fn main() { 4 | abi_vector_layout_cpu::cpu_driver::run(GlamFeatures::Default); 5 | } 6 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/ifx2.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | if i > 0 {} 8 | if i > 1 {} 9 | } 10 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/panic/simple.rs: -------------------------------------------------------------------------------- 1 | // Test that calling `panic!` works. 2 | // build-pass 3 | 4 | use spirv_std::spirv; 5 | 6 | #[spirv(fragment)] 7 | pub fn main() { 8 | panic!("aaa"); 9 | } 10 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout_cuda/cpu/src/main.rs: -------------------------------------------------------------------------------- 1 | use abi_vector_layout_cpu::glam_features::GlamFeatures; 2 | 3 | fn main() { 4 | abi_vector_layout_cpu::cpu_driver::run(GlamFeatures::Cuda); 5 | } 6 | -------------------------------------------------------------------------------- /tests/compiletests/ui/spirv-attr/invariant.rs: -------------------------------------------------------------------------------- 1 | // Tests that the invariant attribute works 2 | // build-pass 3 | 4 | use spirv_std::spirv; 5 | 6 | #[spirv(vertex)] 7 | pub fn main(#[spirv(invariant)] output: &mut f32) {} 8 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout/rust-gpu/src/main.rs: -------------------------------------------------------------------------------- 1 | use abi_vector_layout_cpu::glam_features::GlamFeatures; 2 | 3 | fn main() { 4 | abi_vector_layout_cpu::shader_driver::run(GlamFeatures::Default); 5 | } 6 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout_cuda/rust-gpu/src/main.rs: -------------------------------------------------------------------------------- 1 | use abi_vector_layout_cpu::glam_features::GlamFeatures; 2 | 3 | fn main() { 4 | abi_vector_layout_cpu::shader_driver::run(GlamFeatures::Cuda); 5 | } 6 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/const_fold_int/const-expr-shader/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(target_arch = "spirv", no_std)] 2 | #![allow(arithmetic_overflow)] 3 | 4 | pub use const_fold_int_const_fold_cpu::shader::main_cs; 5 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/const_fold_int/const-fold-shader/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(target_arch = "spirv", no_std)] 2 | #![allow(arithmetic_overflow)] 3 | 4 | pub use const_fold_int_const_fold_cpu::shader::main_cs; 5 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/trig_ops/trig_ops-wgsl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "trig_ops-wgsl" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | difftest.workspace = true -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/if_else.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | if i > 0 { 8 | } else { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout_scalar_math/cpu/src/main.rs: -------------------------------------------------------------------------------- 1 | use abi_vector_layout_cpu::glam_features::GlamFeatures; 2 | 3 | fn main() { 4 | abi_vector_layout_cpu::cpu_driver::run(GlamFeatures::ScalarMath); 5 | } 6 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/const_fold_int/const-expr-cpu/src/main.rs: -------------------------------------------------------------------------------- 1 | use const_fold_int_const_fold_cpu::Variants; 2 | 3 | fn main() { 4 | const_fold_int_const_fold_cpu::cpu_driver::run(Variants::ConstExpr); 5 | } 6 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/const_fold_int/const-fold-cpu/src/main.rs: -------------------------------------------------------------------------------- 1 | use const_fold_int_const_fold_cpu::Variants; 2 | 3 | fn main() { 4 | const_fold_int_const_fold_cpu::cpu_driver::run(Variants::ConstFold); 5 | } 6 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/const_fold_int/dynamic-values-shader/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(target_arch = "spirv", no_std)] 2 | #![allow(arithmetic_overflow)] 3 | 4 | pub use const_fold_int_const_fold_cpu::shader::main_cs; 5 | -------------------------------------------------------------------------------- /tests/difftests/tests/simple-compute/simple-compute-wgsl/shader.wgsl: -------------------------------------------------------------------------------- 1 | @group(0) @binding(0) 2 | var output: array; 3 | 4 | @compute @workgroup_size(1) 5 | fn main_cs() { 6 | output[0] = 42u; 7 | } 8 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/if_if.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | if i > 0 { 8 | if i < 10 {} 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/difftests/tests/arch/memory_barriers/memory_barriers-wgsl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "memory_barriers-wgsl" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | difftest.workspace = true -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/bitwise_ops/bitwise_ops-wgsl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bitwise_ops-wgsl" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | difftest.workspace = true -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/const_fold_int/const-expr-shader/src/main.rs: -------------------------------------------------------------------------------- 1 | use const_fold_int_const_fold_cpu::Variants; 2 | 3 | fn main() { 4 | const_fold_int_const_fold_cpu::shader_driver::run(Variants::ConstExpr); 5 | } 6 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/const_fold_int/const-fold-shader/src/main.rs: -------------------------------------------------------------------------------- 1 | use const_fold_int_const_fold_cpu::Variants; 2 | 3 | fn main() { 4 | const_fold_int_const_fold_cpu::shader_driver::run(Variants::ConstFold); 5 | } 6 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/const_fold_int/dynamic-values-cpu/src/main.rs: -------------------------------------------------------------------------------- 1 | use const_fold_int_const_fold_cpu::Variants; 2 | 3 | fn main() { 4 | const_fold_int_const_fold_cpu::cpu_driver::run(Variants::DynamicValues); 5 | } 6 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/while_break.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | while i < 10 { 8 | break; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/while_return.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | while i < 10 { 8 | return; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout_scalar_math/rust-gpu/src/main.rs: -------------------------------------------------------------------------------- 1 | use abi_vector_layout_cpu::glam_features::GlamFeatures; 2 | 3 | fn main() { 4 | abi_vector_layout_cpu::shader_driver::run(GlamFeatures::ScalarMath); 5 | } 6 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/all.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main() { 7 | let vector = glam::BVec2::new(true, true); 8 | assert!(spirv_std::arch::all(vector)); 9 | } 10 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/any.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main() { 7 | let vector = glam::BVec2::new(false, true); 8 | assert!(spirv_std::arch::any(vector)); 9 | } 10 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_i_add_reduce.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %2 3 | %5 = OpLabel 4 | %7 = OpGroupNonUniformIAdd %2 %8 Reduce %4 5 | OpNoLine 6 | OpReturnValue %7 7 | OpFunctionEnd 8 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/if_while.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | if i == 0 { 8 | while i < 10 {} 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/while_continue.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | while i < 10 { 8 | continue; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/compiletests/ui/spirv-attr/invariant-invalid.rs: -------------------------------------------------------------------------------- 1 | // Tests that the invariant attribute can't be applied on inputs 2 | // build-fail 3 | 4 | use spirv_std::spirv; 5 | 6 | #[spirv(vertex)] 7 | pub fn main(#[spirv(invariant)] input: f32) {} 8 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/const_fold_int/dynamic-values-shader/src/main.rs: -------------------------------------------------------------------------------- 1 | use const_fold_int_const_fold_cpu::Variants; 2 | 3 | fn main() { 4 | const_fold_int_const_fold_cpu::shader_driver::run(Variants::DynamicValues); 5 | } 6 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/vector_swizzle/vector_swizzle-wgsl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "vector_swizzle-wgsl" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | difftest.workspace = true -------------------------------------------------------------------------------- /tests/difftests/tests/simple-compute/simple-compute-wgsl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "simple-compute-wgsl" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | difftest.workspace = true 10 | -------------------------------------------------------------------------------- /crates/rustc_codegen_spirv-types/README.md: -------------------------------------------------------------------------------- 1 | # `rustc_codegen_spirv-types` 2 | 3 | SPIR-V backend types shared between `rustc_codegen_spirv` and `spirv-builder`. Please refer to [`spirv-builder`](https://docs.rs/spirv-builder/) for more information. 4 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_broadcast_const.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %2 3 | %5 = OpLabel 4 | %7 = OpGroupNonUniformBroadcast %2 %8 %4 %9 5 | OpNoLine 6 | OpReturnValue %7 7 | OpFunctionEnd 8 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/while_while.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | while i < 20 { 8 | while i < 10 {} 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/u32/const_fold_div.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | #![allow(unconditional_panic)] 4 | 5 | use spirv_std::spirv; 6 | 7 | #[spirv(fragment)] 8 | pub fn const_fold_div(out: &mut u32) { 9 | *out = 7u32 / 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/control_flow_complex/control_flow_complex-wgsl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "control_flow_complex-wgsl" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | difftest.workspace = true -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_broadcast_first.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %2 3 | %5 = OpLabel 4 | %7 = OpGroupNonUniformBroadcastFirst %2 %8 %4 5 | OpNoLine 6 | OpReturnValue %7 7 | OpFunctionEnd 8 | -------------------------------------------------------------------------------- /tests/difftests/tests/arch/vector_extract_insert/vector_extract_insert-wgsl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "vector_extract_insert-wgsl" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | difftest.workspace = true -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_ballot_bit_count.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %5 3 | %6 = OpLabel 4 | %8 = OpGroupNonUniformBallotBitCount %2 %9 Reduce %4 5 | OpNoLine 6 | OpReturnValue %8 7 | OpFunctionEnd 8 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_i_add_clustered.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %2 3 | %5 = OpLabel 4 | %7 = OpGroupNonUniformIAdd %2 %8 ClusteredReduce %4 %9 5 | OpNoLine 6 | OpReturnValue %7 7 | OpFunctionEnd 8 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_i_add_exclusive_scan.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %2 3 | %5 = OpLabel 4 | %7 = OpGroupNonUniformIAdd %2 %8 ExclusiveScan %4 5 | OpNoLine 6 | OpReturnValue %7 7 | OpFunctionEnd 8 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_i_add_inclusive_scan.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %2 3 | %5 = OpLabel 4 | %7 = OpGroupNonUniformIAdd %2 %8 InclusiveScan %4 5 | OpNoLine 6 | OpReturnValue %7 7 | OpFunctionEnd 8 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/if_return_else.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | if i < 10 { 8 | return; 9 | } else { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/difftests/tests/arch/atomic_ops/atomic_ops-wgsl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "atomic_ops-wgsl" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | difftest.workspace = true 10 | bytemuck.workspace = true -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/add_two_ints.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %2 3 | %5 = OpFunctionParameter %2 4 | %6 = OpLabel 5 | OpLine %7 7 4 6 | %8 = OpIAdd %2 %4 %5 7 | OpNoLine 8 | OpReturnValue %8 9 | OpFunctionEnd 10 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/ptr_copy.via_intrinsic.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %5 3 | %6 = OpFunctionParameter %5 4 | %7 = OpLabel 5 | OpLine %8 17 17 6 | OpCopyMemory %6 %4 7 | OpNoLine 8 | OpReturn 9 | OpFunctionEnd 10 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/if_else_if_else.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | if i > 0 { 8 | } else if i < 0 { 9 | } else { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/math_ops/math_ops-wgsl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "math_ops-wgsl" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | difftest.workspace = true 10 | bytemuck.workspace = true -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/array/init_array_i32.rs: -------------------------------------------------------------------------------- 1 | // Test creating an array. 2 | // build-pass 3 | 4 | use spirv_std::macros::spirv; 5 | 6 | #[spirv(fragment)] 7 | pub fn main(o: &mut i32) { 8 | let array = [0i32; 4]; 9 | *o = array[1]; 10 | } 11 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/f32/signum.rs: -------------------------------------------------------------------------------- 1 | // Test that `signum` works. 2 | // build-pass 3 | 4 | use spirv_std::num_traits::Float; 5 | use spirv_std::spirv; 6 | 7 | #[spirv(fragment)] 8 | pub fn main(i: f32, o: &mut f32) { 9 | *o = i.signum(); 10 | } 11 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/control_flow/control_flow-wgsl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "control_flow-wgsl" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | difftest.workspace = true 10 | bytemuck.workspace = true -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/matrix_ops/matrix_ops-wgsl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "matrix_ops-wgsl" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | difftest.workspace = true 10 | bytemuck.workspace = true -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/vector_ops/vector_ops-wgsl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "vector_ops-wgsl" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | difftest.workspace = true 10 | bytemuck.workspace = true -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/asm_add_two_ints.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %2 3 | %5 = OpFunctionParameter %2 4 | %6 = OpLabel 5 | OpLine %7 11 13 6 | %8 = OpIAdd %2 %4 %5 7 | OpNoLine 8 | OpReturnValue %8 9 | OpFunctionEnd 10 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/issue-373.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpLabel 3 | OpLine %5 24 11 4 | %6 = OpFunctionCall %7 %8 5 | %9 = OpCompositeExtract %10 %6 0 6 | OpLine %5 24 4 7 | OpStore %11 %9 8 | OpNoLine 9 | OpReturn 10 | OpFunctionEnd 11 | -------------------------------------------------------------------------------- /tests/difftests/tests/arch/push_constants/push_constants-wgsl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "push_constants-wgsl" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | difftest.workspace = true 10 | bytemuck.workspace = true -------------------------------------------------------------------------------- /tests/difftests/tests/storage_class/array_access/array_access-wgsl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "array_access-wgsl" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | difftest.workspace = true 10 | bytemuck.workspace = true -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/derivative.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpLabel 3 | OpLine %5 37 8 4 | %6 = OpDPdx %7 %8 5 | OpLine %5 79 8 6 | %9 = OpDPdy %7 %8 7 | OpLine %5 119 8 8 | %10 = OpFwidth %7 %8 9 | OpNoLine 10 | OpReturn 11 | OpFunctionEnd 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_broadcast.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %2 3 | %5 = OpFunctionParameter %6 4 | %7 = OpLabel 5 | %9 = OpGroupNonUniformBroadcast %2 %10 %4 %5 6 | OpNoLine 7 | OpReturnValue %9 8 | OpFunctionEnd 9 | -------------------------------------------------------------------------------- /tests/difftests/tests/arch/workgroup_memory/workgroup_memory-wgsl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "workgroup_memory-wgsl" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | difftest.workspace = true 10 | bytemuck.workspace = true -------------------------------------------------------------------------------- /tests/difftests/tests/simple-compute/simple-compute-rust/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(compute(threads(1)))] 6 | pub fn main_cs(#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] output: &mut [u32]) { 7 | output[0] = 42; 8 | } 9 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/if_return_else_return.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | if i < 10 { 8 | return; 9 | } else { 10 | return; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/while_if_break.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | while i < 10 { 8 | if i == 0 { 9 | break; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/ops/logical_and.rs: -------------------------------------------------------------------------------- 1 | // Test using `&&` operator. 2 | // build-pass 3 | 4 | use spirv_std::spirv; 5 | 6 | fn f(x: bool, y: bool) -> bool { 7 | x && y 8 | } 9 | 10 | #[spirv(fragment)] 11 | pub fn main() { 12 | f(false, true); 13 | } 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/storage_class/int_lit_bindings.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | use spirv_std::spirv; 3 | 4 | #[spirv(compute(threads(1, 2u32, 3i128)))] 5 | pub fn main(#[spirv(storage_buffer, descriptor_set = 42u8, binding = 69u64)] value: &mut f32) { 6 | *value = *value + 1.; 7 | } 8 | -------------------------------------------------------------------------------- /tests/compiletests/ui/target_features_err.rs: -------------------------------------------------------------------------------- 1 | // build-fail 2 | // compile-flags: -Ctarget-feature=+rayTracingKHR,+ext:SPV_KHR_ray_tracing 3 | 4 | use spirv_std::spirv; 5 | 6 | #[spirv(any_hit)] 7 | pub fn main() { 8 | unsafe { spirv_std::arch::terminate_ray() } 9 | } 10 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_ballot.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %2 3 | %5 = OpLabel 4 | %7 = OpGroupNonUniformBallot %8 %9 %4 5 | %10 = OpGroupNonUniformInverseBallot %2 %9 %7 6 | OpNoLine 7 | OpReturnValue %10 8 | OpFunctionEnd 9 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/ptr_read.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %5 3 | %6 = OpFunctionParameter %5 4 | %7 = OpLabel 5 | OpLine %8 1732 8 6 | %9 = OpLoad %10 %4 7 | OpLine %11 7 13 8 | OpStore %6 %9 9 | OpNoLine 10 | OpReturn 11 | OpFunctionEnd 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/ptr_write.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %5 3 | %6 = OpFunctionParameter %5 4 | %7 = OpLabel 5 | OpLine %8 7 35 6 | %9 = OpLoad %10 %4 7 | OpLine %11 1932 8 8 | OpStore %6 %9 9 | OpNoLine 10 | OpReturn 11 | OpFunctionEnd 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/while_if_continue.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | while i < 10 { 8 | if i == 0 { 9 | continue; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/while_while_break.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | while i < 20 { 8 | while i < 10 { 9 | break; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /crates/spirv-std/macros/README.md: -------------------------------------------------------------------------------- 1 | # `spirv-std-macros` 2 | 3 | This crate implements macros required for `spirv-std`. Most importantly, it implements the `#![spirv(..)]` attribute macro required for use in shader code. Please refer to [`spirv-std`](https://docs.rs/spirv-std/) for more information. 4 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/while_while_continue.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | while i < 20 { 8 | while i < 10 { 9 | continue; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/ptr_read_method.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %5 3 | %6 = OpFunctionParameter %5 4 | %7 = OpLabel 5 | OpLine %8 1732 8 6 | %9 = OpLoad %10 %4 7 | OpLine %11 7 13 8 | OpStore %6 %9 9 | OpNoLine 10 | OpReturn 11 | OpFunctionEnd 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/ptr_write_method.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %5 3 | %6 = OpFunctionParameter %5 4 | %7 = OpLabel 5 | OpLine %8 7 37 6 | %9 = OpLoad %10 %4 7 | OpLine %11 1932 8 8 | OpStore %6 %9 9 | OpNoLine 10 | OpReturn 11 | OpFunctionEnd 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/panic/builtin.rs: -------------------------------------------------------------------------------- 1 | // Test panics coming from the Rust language such as `1 / 0`. 2 | // build-pass 3 | 4 | use spirv_std::spirv; 5 | 6 | fn int_div(x: usize) -> usize { 7 | 1 / x 8 | } 9 | 10 | #[spirv(fragment)] 11 | pub fn main() { 12 | int_div(0); 13 | } 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/spirv-attr/invalid-matrix-type-empty.stderr: -------------------------------------------------------------------------------- 1 | error: `#[spirv(matrix)]` member types must all be the same 2 | --> $DIR/invalid-matrix-type-empty.rs:7:1 3 | | 4 | LL | pub struct EmptyStruct {} 5 | | ^^^^^^^^^^^^^^^^^^^^^^ 6 | 7 | error: aborting due to 1 previous error 8 | 9 | -------------------------------------------------------------------------------- /release.toml: -------------------------------------------------------------------------------- 1 | # You should just need to run this to do a release of both crates: 2 | # $ cargo release 3 | 4 | pre-release-commit-message = "Release {{version}}" 5 | tag-message = "Release `{{crate_name}}` {{version}}" 6 | tag-prefix = "" 7 | allow-branch = ["main"] 8 | shared-version = true 9 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/emit_vertex.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+Geometry 3 | 4 | use spirv_std::spirv; 5 | 6 | #[spirv(geometry(input_lines = 2, output_points = 2))] 7 | pub fn main() { 8 | unsafe { 9 | spirv_std::arch::emit_vertex(); 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/terminate_ray_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayTracingKHR,+ext:SPV_KHR_ray_tracing 3 | 4 | use spirv_std::spirv; 5 | 6 | #[spirv(any_hit)] 7 | pub fn main() { 8 | unsafe { 9 | spirv_std::arch::terminate_ray(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/issue-723-output.stderr: -------------------------------------------------------------------------------- 1 | OpCapability Shader 2 | OpMemoryModel Logical Simple 3 | OpEntryPoint Fragment %1 "main" 4 | OpExecutionMode %1 OriginUpperLeft 5 | %2 = OpString "$DIR/issue-723-output.rs" 6 | OpName %3 "issue_723_output::main" 7 | %4 = OpTypeVoid 8 | %5 = OpTypeFunction %4 9 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/end_primitive.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+Geometry 3 | 4 | use spirv_std::spirv; 5 | 6 | #[spirv(geometry(input_lines = 2, output_points = 2))] 7 | pub fn main() { 8 | unsafe { 9 | spirv_std::arch::end_primitive(); 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/array/init_array_i8.rs: -------------------------------------------------------------------------------- 1 | // Test creating an array. 2 | // build-pass 3 | // compile-flags: -C target-feature=+Int8 4 | 5 | use spirv_std::macros::spirv; 6 | 7 | #[spirv(fragment)] 8 | pub fn main(o: &mut i8) { 9 | let array = [0i8; 4]; 10 | *o = array[1]; 11 | } 12 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout/cpu/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(target_arch = "spirv", no_std)] 2 | 3 | #[cfg(not(target_arch = "spirv"))] 4 | pub mod cpu_driver; 5 | pub mod glam_features; 6 | pub mod layout; 7 | pub mod shader; 8 | #[cfg(not(target_arch = "spirv"))] 9 | pub mod shader_driver; 10 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/array/init_array_i16.rs: -------------------------------------------------------------------------------- 1 | // Test creating an array. 2 | // build-pass 3 | // compile-flags: -C target-feature=+Int16 4 | 5 | use spirv_std::macros::spirv; 6 | 7 | #[spirv(fragment)] 8 | pub fn main(o: &mut i16) { 9 | let array = [0i16; 4]; 10 | *o = array[1]; 11 | } 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/array/init_array_i64.rs: -------------------------------------------------------------------------------- 1 | // Test creating an array. 2 | // build-pass 3 | // compile-flags: -C target-feature=+Int64 4 | 5 | use spirv_std::macros::spirv; 6 | 7 | #[spirv(fragment)] 8 | pub fn main(o: &mut i64) { 9 | let array = [0i64; 4]; 10 | *o = array[1]; 11 | } 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/issue-415.rs: -------------------------------------------------------------------------------- 1 | // Test that zero sized unions don't ICE (even if unions are generally not supported yet) 2 | // build-pass 3 | 4 | use spirv_std::spirv; 5 | 6 | union U { 7 | a: (), 8 | } 9 | 10 | #[spirv(fragment)] 11 | pub fn main() { 12 | let _u = U { a: () }; 13 | } 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/spirv-attr/invariant-invalid.stderr: -------------------------------------------------------------------------------- 1 | error: `#[spirv(invariant)]` is only valid on Output variables 2 | --> $DIR/invariant-invalid.rs:7:21 3 | | 4 | LL | pub fn main(#[spirv(invariant)] input: f32) {} 5 | | ^^^^^^^^^ 6 | 7 | error: aborting due to 1 previous error 8 | 9 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ignore_intersection_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayTracingKHR,+ext:SPV_KHR_ray_tracing 3 | 4 | use spirv_std::spirv; 5 | 6 | #[spirv(any_hit)] 7 | pub fn main() { 8 | unsafe { 9 | spirv_std::arch::ignore_intersection(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/custom_entry_point.stderr: -------------------------------------------------------------------------------- 1 | OpCapability Shader 2 | OpMemoryModel Logical Simple 3 | OpEntryPoint Fragment %1 "hello_world" 4 | OpExecutionMode %1 OriginUpperLeft 5 | %2 = OpString "$DIR/custom_entry_point.rs" 6 | OpName %3 "custom_entry_point::main" 7 | %4 = OpTypeVoid 8 | %5 = OpTypeFunction %4 9 | -------------------------------------------------------------------------------- /crates/rustc_codegen_spirv-types/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![doc = include_str!("../README.md")] 2 | 3 | pub use rspirv::spirv::Capability; 4 | 5 | mod compile_result; 6 | pub use compile_result::*; 7 | 8 | // HACK(eddyb) allows downstream crates to access the correct version directly. 9 | pub use serde; 10 | pub use serde_json; 11 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/add_two_ints.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C llvm-args=--disassemble-fn=add_two_ints::add_two_ints 3 | 4 | use spirv_std::spirv; 5 | 6 | fn add_two_ints(x: u32, y: u32) -> u32 { 7 | x + y 8 | } 9 | #[spirv(fragment)] 10 | pub fn main() { 11 | add_two_ints(2, 3); 12 | } 13 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/ptr/allocate_null.rs: -------------------------------------------------------------------------------- 1 | // Tests allocating a null pointer at `const` time. 2 | // build-pass 3 | 4 | use spirv_std::spirv; 5 | 6 | use core::ptr::null; 7 | const NULL_PTR: *const i32 = null(); 8 | 9 | #[spirv(fragment)] 10 | pub fn main() { 11 | let _null_ptr = NULL_PTR; 12 | } 13 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/report_intersection_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayTracingKHR,+ext:SPV_KHR_ray_tracing 3 | 4 | use spirv_std::spirv; 5 | 6 | #[spirv(intersection)] 7 | pub fn main() { 8 | unsafe { 9 | spirv_std::arch::report_intersection(2.0, 4); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/glam/mat3_vec3_multiply.rs: -------------------------------------------------------------------------------- 1 | // Tests multiplying a `Mat3` by a `Vec3`. 2 | // build-pass 3 | 4 | use spirv_std::spirv; 5 | 6 | #[spirv(fragment)] 7 | pub fn main(input: glam::Mat3, output: &mut glam::Vec3) { 8 | let vector = input * glam::Vec3::new(1.0, 2.0, 3.0); 9 | *output = vector; 10 | } 11 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/ref/zst_member_ref_arg.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | struct A; 5 | struct B; 6 | 7 | struct S { 8 | x: A, 9 | y: B, 10 | } 11 | 12 | fn f(x: &B) {} 13 | 14 | #[spirv(fragment)] 15 | pub fn main() { 16 | let s = S { x: A, y: B }; 17 | f(&s.y); 18 | } 19 | -------------------------------------------------------------------------------- /examples/run-wasm/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | cargo_run_wasm::run_wasm_with_css( 3 | " 4 | html, body, canvas { 5 | outline: none; 6 | overflow: clip; 7 | margin: 0px; 8 | width: 100%; 9 | height: 100%; 10 | } 11 | ", 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /examples/runners/wgpu/src/main.rs: -------------------------------------------------------------------------------- 1 | #[cfg(target_os = "android")] 2 | const _: () = panic!( 3 | "executable not applicable for Android targets, \ 4 | make sure to pass `--lib` when building with `cargo-apk`" 5 | ); 6 | 7 | fn main() { 8 | #[cfg(not(target_os = "android"))] 9 | example_runner_wgpu::main(); 10 | } 11 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/emit_stream_vertex.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+Int64,+GeometryStreams 3 | 4 | use spirv_std::spirv; 5 | 6 | #[spirv(geometry(input_lines = 2, output_points = 2))] 7 | pub fn main() { 8 | unsafe { 9 | spirv_std::arch::emit_stream_vertex::<2>(); 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/while_if_break_else_break.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | while i < 10 { 8 | if i == 0 { 9 | break; 10 | } else { 11 | break; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/panic/builtin_bounds_check.rs: -------------------------------------------------------------------------------- 1 | // Test that bounds checking causes panics. 2 | // build-pass 3 | 4 | use spirv_std::spirv; 5 | 6 | fn array_bounds_check(x: [u32; 4], i: usize) -> u32 { 7 | x[i] 8 | } 9 | 10 | #[spirv(fragment)] 11 | pub fn main() { 12 | array_bounds_check([0, 1, 2, 3], 5); 13 | } 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/spirv-attr/invalid-matrix-type-empty.rs: -------------------------------------------------------------------------------- 1 | // Tests that matrix type inference fails correctly, for empty struct 2 | // build-fail 3 | 4 | use spirv_std::spirv; 5 | 6 | #[spirv(matrix)] 7 | pub struct EmptyStruct {} 8 | 9 | #[spirv(fragment)] 10 | pub fn entry(#[spirv(push_constant)] matrix: &EmptyStruct) {} 11 | -------------------------------------------------------------------------------- /crates/spirv-std/src/debug_printf.rs: -------------------------------------------------------------------------------- 1 | //! support functions for debug printf 2 | 3 | use crate::{Scalar, Vector}; 4 | 5 | #[doc(hidden)] 6 | pub fn assert_is_type(ty: T) -> T { 7 | ty 8 | } 9 | 10 | #[doc(hidden)] 11 | pub fn assert_is_vector, const SIZE: usize>(vec: V) -> V { 12 | vec 13 | } 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/end_stream_primitive.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+Int64,+GeometryStreams 3 | 4 | use spirv_std::spirv; 5 | 6 | #[spirv(geometry(input_lines = 2, output_points = 2))] 7 | pub fn main() { 8 | unsafe { 9 | spirv_std::arch::end_stream_primitive::<2>(); 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/issue_764.stderr: -------------------------------------------------------------------------------- 1 | error: module has recursion, which is not allowed: `<(i32, issue_764::Transform2D) as issue_764::GivesFinalTransform>::get_final_transform` calls `<(i32, issue_764::Transform2D) as issue_764::GivesFinalTransform>::get_final_transform` 2 | 3 | error: aborting due to 1 previous error 4 | 5 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/while_while_if_break.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | while i < 20 { 8 | while i < 10 { 9 | if i > 10 { 10 | break; 11 | } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/issue-424.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | #![no_std] 4 | 5 | use core::marker::PhantomData; 6 | use spirv_std::spirv; 7 | 8 | pub struct BitSlice { 9 | _ord: PhantomData, 10 | _typ: PhantomData<[T]>, 11 | _mem: [()], 12 | } 13 | 14 | #[spirv(compute(threads(1)))] 15 | pub fn issue424() {} 16 | -------------------------------------------------------------------------------- /rust-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "nightly-2025-06-30" 3 | components = ["rust-src", "rustc-dev", "llvm-tools"] 4 | # commit_hash = 35f6036521777bdc0dcea1f980be4c192962a168 5 | 6 | # Whenever changing the nightly channel, update the commit hash above, and 7 | # change `REQUIRED_RUST_TOOLCHAIN` in `crates/rustc_codegen_spirv/build.rs` too. 8 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/while_if_continue_else_continue.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | while i < 10 { 8 | if i == 0 { 9 | continue; 10 | } else { 11 | continue; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/while_while_if_continue.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | while i < 20 { 8 | while i < 10 { 9 | if i > 5 { 10 | continue; 11 | } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/while_if_break_if_break.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | while i < 10 { 8 | if i == 0 { 9 | break; 10 | } 11 | if i == 1 { 12 | break; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/difftests/tests/arch/workgroup_memory/workgroup_memory-ash/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | 3 | // Include the shader content from workgroup_memory-rust to keep them in sync 4 | // Note: We need to skip the #![no_std] from the included file 5 | include!(concat!( 6 | env!("CARGO_MANIFEST_DIR"), 7 | "/../workgroup_memory-rust/src/shader.rs" 8 | )); 9 | -------------------------------------------------------------------------------- /tests/compiletests/ui/spirv-attr/uniform-constant-storage-class.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::image::Image2d; 4 | use spirv_std::spirv; 5 | 6 | #[spirv(vertex)] 7 | pub fn main( 8 | #[spirv(descriptor_set = 0, binding = 0)] implicit: &Image2d, 9 | #[spirv(descriptor_set = 0, binding = 1, uniform_constant)] explicit: &Image2d, 10 | ) { 11 | } 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/task_shader.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // only-vulkan1.2 3 | // compile-flags: -Ctarget-feature=+MeshShadingEXT,+ext:SPV_EXT_mesh_shader 4 | 5 | use spirv_std::arch::emit_mesh_tasks_ext; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(task_ext(threads(1)))] 9 | pub fn main() { 10 | unsafe { 11 | emit_mesh_tasks_ext(1, 2, 3); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/storage_class/runtime_descriptor_array_error.rs: -------------------------------------------------------------------------------- 1 | // build-fail 2 | 3 | use spirv_std::{Image, RuntimeArray, spirv}; 4 | 5 | #[spirv(fragment)] 6 | pub fn main( 7 | #[spirv(descriptor_set = 0, binding = 0)] one: &[Image!(2D, type=f32, sampled)], 8 | #[spirv(uniform, descriptor_set = 0, binding = 0)] two: &RuntimeArray, 9 | ) { 10 | } 11 | -------------------------------------------------------------------------------- /tests/compiletests/ui/storage_class/storage_buffer-dst.rs: -------------------------------------------------------------------------------- 1 | // Test that using DST (i.e. slice) storage buffers passes (Vulkan) validation. 2 | 3 | // build-pass 4 | use spirv_std::spirv; 5 | 6 | #[spirv(fragment)] 7 | pub fn main(#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] slice: &mut [f32]) { 8 | let float: f32 = slice[0]; 9 | let _ = float; 10 | } 11 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/trig_ops/trig_ops-rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "trig_ops-rust" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # GPU deps 9 | [dependencies] 10 | spirv-std.workspace = true 11 | 12 | # CPU deps (for the test harness) 13 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 14 | difftest.workspace = true -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/vector_ops/vector_ops-rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "vector_ops-rust" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | spirv-std.workspace = true 10 | difftest.workspace = true 11 | 12 | # CPU deps 13 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 14 | bytemuck.workspace = true 15 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/index_user_dst.rs: -------------------------------------------------------------------------------- 1 | #![crate_name = "index_user_dst"] 2 | 3 | // build-pass 4 | // compile-flags: -C llvm-args=--disassemble-entry=main 5 | 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] slice: &mut [f32]) { 10 | let float: f32 = slice[0]; 11 | let _ = float; 12 | } 13 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/fetch.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | use spirv_std::{Image, arch}; 5 | 6 | #[spirv(fragment)] 7 | pub fn main( 8 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, type=f32, sampled), 9 | output: &mut glam::Vec4, 10 | ) { 11 | let texel = image.fetch(glam::IVec2::new(0, 1)); 12 | *output = texel; 13 | } 14 | -------------------------------------------------------------------------------- /tests/difftests/lib/src/scaffold/compute/mod.rs: -------------------------------------------------------------------------------- 1 | mod ash; 2 | mod backend; 3 | mod wgpu; 4 | 5 | pub use crate::scaffold::shader::*; 6 | pub use ash::AshBackend; 7 | pub use backend::{BufferConfig, BufferUsage, ComputeBackend, ComputeShaderTest, ComputeTest}; 8 | pub use wgpu::{ 9 | WgpuBackend, WgpuComputeTest, WgpuComputeTestMultiBuffer, WgpuComputeTestPushConstants, 10 | }; 11 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/bitwise_ops/bitwise_ops-rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bitwise_ops-rust" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # GPU deps 9 | [dependencies] 10 | spirv-std.workspace = true 11 | 12 | # CPU deps (for the test harness) 13 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 14 | difftest.workspace = true -------------------------------------------------------------------------------- /examples/shaders/reduce/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "reduce" 3 | version = "0.0.0" 4 | publish = false 5 | authors.workspace = true 6 | edition.workspace = true 7 | license.workspace = true 8 | repository.workspace = true 9 | 10 | [lints] 11 | workspace = true 12 | 13 | [dependencies] 14 | spirv-std = { workspace = true } 15 | 16 | [package.metadata.release] 17 | release = false 18 | -------------------------------------------------------------------------------- /tests/difftests/tests/arch/memory_barriers/memory_barriers-rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "memory_barriers-rust" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # GPU deps 9 | [dependencies] 10 | spirv-std.workspace = true 11 | 12 | # CPU deps (for the test harness) 13 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 14 | difftest.workspace = true -------------------------------------------------------------------------------- /tests/difftests/tests/simple-compute/simple-compute-rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "simple-compute-rust" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # Common deps 9 | [dependencies] 10 | 11 | # GPU deps 12 | spirv-std.workspace = true 13 | 14 | # CPU deps 15 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 16 | difftest.workspace = true 17 | -------------------------------------------------------------------------------- /crates/rustc_codegen_spirv-target-specs/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rustc_codegen_spirv-target-specs" 3 | description = "target spec json files of rust-gpu for the rustc compiler" 4 | version.workspace = true 5 | authors.workspace = true 6 | edition.workspace = true 7 | license.workspace = true 8 | repository.workspace = true 9 | 10 | [features] 11 | include_str = [] 12 | dir_path = [] 13 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/format.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | use spirv_std::{Image, arch}; 5 | 6 | #[spirv(fragment)] 7 | pub fn main( 8 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, format = rgba32f, sampled), 9 | output: &mut glam::Vec4, 10 | ) { 11 | let texel = image.fetch(glam::IVec2::new(0, 1)); 12 | *output = texel; 13 | } 14 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout/cpu/src/shader.rs: -------------------------------------------------------------------------------- 1 | use crate::layout::eval_layouts; 2 | use spirv_std::glam::UVec3; 3 | use spirv_std::spirv; 4 | 5 | #[spirv(compute(threads(1)))] 6 | pub fn main_cs( 7 | #[spirv(workgroup_id)] gid: UVec3, 8 | #[spirv(storage_buffer, descriptor_set = 0, binding = 0)] output: &mut [u32], 9 | ) { 10 | eval_layouts(gid.x, output); 11 | } 12 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout/rust-gpu/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "abi-vector-layout-rust-gpu" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | abi-vector-layout-cpu = { path = "../cpu" } 10 | 11 | # CPU deps (for the test harness) 12 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 13 | difftest.workspace = true 14 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/math_ops/math_ops-rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "math_ops-rust" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # Common deps 9 | [dependencies] 10 | spirv-std.workspace = true 11 | difftest.workspace = true 12 | 13 | # CPU deps 14 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 15 | bytemuck.workspace = true 16 | -------------------------------------------------------------------------------- /crates/spirv-std/shared/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spirv-std-types" 3 | description = "SPIR-V types shared between spirv-std, spirv-std-macros and rustc_codegen_spirv" 4 | version.workspace = true 5 | authors.workspace = true 6 | edition.workspace = true 7 | license.workspace = true 8 | repository.workspace = true 9 | 10 | [lints] 11 | workspace = true 12 | 13 | [features] 14 | std = [] 15 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/query/query_levels.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+ImageQuery 3 | 4 | use spirv_std::spirv; 5 | use spirv_std::{Image, arch}; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, type=f32, sampled), 10 | output: &mut u32, 11 | ) { 12 | *output = image.query_levels(); 13 | } 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/defer.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | #[spirv(fragment)] 6 | pub fn main(#[spirv(flat)] i: i32) { 7 | while i < 32 { 8 | let current_position = 0; 9 | if i < current_position { 10 | break; 11 | } 12 | if i < current_position { 13 | break; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/spirv-attr/bool-inputs-err.rs: -------------------------------------------------------------------------------- 1 | // build-fail 2 | 3 | use spirv_std::spirv; 4 | 5 | pub struct Boolthing { 6 | x: u32, 7 | y: u32, 8 | b: bool, 9 | } 10 | 11 | #[spirv(fragment)] 12 | pub fn fragment( 13 | input: bool, 14 | output: &mut bool, 15 | #[spirv(push_constant)] push: &bool, 16 | #[spirv(uniform)] uniform: &Boolthing, 17 | ) { 18 | } 19 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/matrix_ops/matrix_ops-rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "matrix_ops-rust" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # Common deps 9 | [dependencies] 10 | spirv-std.workspace = true 11 | difftest.workspace = true 12 | 13 | # CPU deps 14 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 15 | bytemuck.workspace = true 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/demote_to_helper_invocation.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // 3 | // compile-flags: -C target-feature=+DemoteToHelperInvocationEXT,+ext:SPV_EXT_demote_to_helper_invocation 4 | 5 | use spirv_std::spirv; 6 | 7 | #[spirv(fragment)] 8 | pub fn main() { 9 | unsafe { spirv_std::arch::demote_to_helper_invocation() }; 10 | assert!(spirv_std::arch::is_helper_invocation()); 11 | } 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/fetch_with_lod.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | use spirv_std::{Image, arch}; 5 | 6 | #[spirv(fragment)] 7 | pub fn main( 8 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, type=f32, sampled), 9 | output: &mut glam::Vec4, 10 | ) { 11 | let texel = image.fetch_with_lod(glam::IVec2::new(0, 1), 0); 12 | *output = texel; 13 | } 14 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/control_flow_complex/control_flow_complex-rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "control_flow_complex-rust" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # GPU deps 9 | [dependencies] 10 | spirv-std.workspace = true 11 | 12 | # CPU deps (for the test harness) 13 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 14 | difftest.workspace = true -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/intrinsics/black_box_noop/with-black-box/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "black_box-noop-with" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # GPU deps 9 | [dependencies] 10 | spirv-std.workspace = true 11 | 12 | # CPU deps (for the test harness) 13 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 14 | difftest.workspace = true 15 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/derivative.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C llvm-args=--disassemble-fn=derivative::derivative 3 | 4 | use spirv_std::arch::Derivative; 5 | use spirv_std::spirv; 6 | 7 | #[spirv(fragment)] 8 | pub fn main() { 9 | derivative(); 10 | } 11 | 12 | pub fn derivative() { 13 | Derivative::dfdx(0.); 14 | Derivative::dfdy(0.); 15 | Derivative::fwidth(0.); 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/generic-fn-op-name.stderr: -------------------------------------------------------------------------------- 1 | OpCapability Shader 2 | OpMemoryModel Logical Simple 3 | OpEntryPoint Fragment %1 "main" 4 | OpExecutionMode %1 OriginUpperLeft 5 | %2 = OpString "$DIR/generic-fn-op-name.rs" 6 | OpName %3 "generic_fn_op_name::main" 7 | OpName %4 "generic_fn_op_name::generic::" 8 | %5 = OpTypeVoid 9 | %6 = OpTypeFunction %5 10 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/query/query_size.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+ImageQuery 3 | 4 | use spirv_std::spirv; 5 | use spirv_std::{Image, arch}; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, type=f32, sampled=false), 10 | output: &mut glam::UVec2, 11 | ) { 12 | *output = image.query_size(); 13 | } 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/spirv-attr/uniform-constant-storage-class.stderr: -------------------------------------------------------------------------------- 1 | warning: redundant storage class attribute, storage class is deduced from type 2 | --> $DIR/uniform-constant-storage-class.rs:9:46 3 | | 4 | LL | #[spirv(descriptor_set = 0, binding = 1, uniform_constant)] explicit: &Image2d, 5 | | ^^^^^^^^^^^^^^^^ 6 | 7 | warning: 1 warning emitted 8 | 9 | -------------------------------------------------------------------------------- /tests/difftests/tests/arch/atomic_ops/atomic_ops-rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "atomic_ops-rust" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # Common deps 9 | [dependencies] 10 | 11 | # GPU deps 12 | spirv-std.workspace = true 13 | 14 | # CPU deps 15 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 16 | difftest.workspace = true 17 | bytemuck.workspace = true -------------------------------------------------------------------------------- /examples/run-wasm/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "run-wasm" 3 | description = "cargo-run-wasm helper/wrapper (see cargo-run-wasm docs)" 4 | version = "0.0.0" 5 | publish = false 6 | authors.workspace = true 7 | edition.workspace = true 8 | license.workspace = true 9 | repository.workspace = true 10 | 11 | [dependencies] 12 | cargo-run-wasm = "0.3.2" 13 | 14 | [package.metadata.release] 15 | release = false 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/query/query_samples.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+ImageQuery 3 | 4 | use spirv_std::spirv; 5 | use spirv_std::{Image, arch}; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, type=f32, sampled, multisampled), 10 | output: &mut u32, 11 | ) { 12 | *output = image.query_samples(); 13 | } 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/query/query_size_lod.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+ImageQuery 3 | 4 | use spirv_std::spirv; 5 | use spirv_std::{Image, arch}; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, type=f32, sampled), 10 | output: &mut glam::UVec2, 11 | ) { 12 | *output = image.query_size_lod(0); 13 | } 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/spirv-attr/invalid-storage-class.rs: -------------------------------------------------------------------------------- 1 | // Tests that certain storage class `#[spirv(...)]` attributes are disallowed. 2 | 3 | // build-fail 4 | 5 | use spirv_std::spirv; 6 | 7 | #[spirv(vertex)] 8 | fn _entry( 9 | #[spirv(input)] _: (), 10 | #[spirv(output)] _: (), 11 | #[spirv(private)] _: (), 12 | #[spirv(function)] _: (), 13 | #[spirv(generic)] _: (), 14 | ) { 15 | } 16 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/control_flow/control_flow-rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "control_flow-rust" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # Common deps 9 | [dependencies] 10 | 11 | # GPU deps 12 | spirv-std.workspace = true 13 | 14 | # CPU deps 15 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 16 | difftest.workspace = true 17 | bytemuck.workspace = true -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/intrinsics/black_box_noop/without-black-box/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "black_box-noop-without" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # GPU deps 9 | [dependencies] 10 | spirv-std.workspace = true 11 | 12 | # CPU deps (for the test harness) 13 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 14 | difftest.workspace = true 15 | 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/issue-452.rs: -------------------------------------------------------------------------------- 1 | // build-fail 2 | 3 | use spirv_std::spirv; 4 | 5 | #[derive(Clone, Copy)] 6 | struct Position(u32); 7 | 8 | fn use_cmp(cmp: fn(&Position) -> u32) { 9 | let a = Position(0); 10 | let b = Position(1); 11 | 12 | let _ = if cmp(&a) <= cmp(&b) { a } else { b }; 13 | } 14 | 15 | #[spirv(compute(threads(1)))] 16 | pub fn main() { 17 | use_cmp(|p| p.0); 18 | } 19 | -------------------------------------------------------------------------------- /crates/spirv-std/shared/README.md: -------------------------------------------------------------------------------- 1 | # `spirv-std-types` 2 | 3 | Small shared crate, to share definitions between [`spirv-std`](https://docs.rs/spirv-std/), [`spirv-std-macros`](https://docs.rs/spirv-std-macros/) and [`rustc_codegen_spirv`](https://docs.rs/rustc_codegen_spirv/). Should only contain symbols that compile in a `no_std` context. 4 | 5 | Please refer to [`spirv-std`](https://docs.rs/spirv-std/) for more information. 6 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/ptr/allocate_vec_like.stderr: -------------------------------------------------------------------------------- 1 | warning: the feature `ptr_internals` is internal to the compiler or standard library 2 | --> $DIR/allocate_vec_like.rs:4:12 3 | | 4 | LL | #![feature(ptr_internals)] 5 | | ^^^^^^^^^^^^^ 6 | | 7 | = note: using it is strongly discouraged 8 | = note: `#[warn(internal_features)]` on by default 9 | 10 | warning: 1 warning emitted 11 | 12 | -------------------------------------------------------------------------------- /tests/difftests/tests/arch/workgroup_memory/workgroup_memory-ash/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "workgroup_memory-ash" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # Common deps 9 | [dependencies] 10 | 11 | # GPU deps 12 | spirv-std.workspace = true 13 | 14 | # CPU deps 15 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 16 | difftest.workspace = true 17 | bytemuck.workspace = true -------------------------------------------------------------------------------- /tests/difftests/tests/arch/workgroup_memory/workgroup_memory-rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "workgroup_memory-rust" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # Common deps 9 | [dependencies] 10 | 11 | # GPU deps 12 | spirv-std.workspace = true 13 | 14 | # CPU deps 15 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 16 | difftest.workspace = true 17 | bytemuck.workspace = true -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/vector_swizzle/vector_swizzle-rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "vector_swizzle-rust" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # GPU deps 9 | [dependencies] 10 | spirv-std.workspace = true 11 | glam.workspace = true 12 | 13 | # CPU deps (for the test harness) 14 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 15 | difftest.workspace = true -------------------------------------------------------------------------------- /tests/difftests/tests/storage_class/array_access/array_access-rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "array_access-rust" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # Common deps 9 | [dependencies] 10 | 11 | # GPU deps 12 | spirv-std.workspace = true 13 | 14 | # CPU deps 15 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 16 | difftest.workspace = true 17 | bytemuck.workspace = true -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/panic/track_caller.rs: -------------------------------------------------------------------------------- 1 | // Test that propagating `#[track_caller]` doesn't cause constant-related errors. 2 | 3 | // build-pass 4 | 5 | use spirv_std::spirv; 6 | 7 | #[track_caller] 8 | fn track_caller_maybe_panic(x: u32) { 9 | if x > 0 { 10 | panic!(); 11 | } 12 | } 13 | 14 | #[spirv(fragment)] 15 | pub fn main(#[spirv(flat)] x: u32) { 16 | track_caller_maybe_panic(x); 17 | } 18 | -------------------------------------------------------------------------------- /crates/rustc_codegen_spirv-target-specs/README.md: -------------------------------------------------------------------------------- 1 | # `rustc_codegen_spirv-target-specs` 2 | 3 | The target spec json files of rust-gpu to hand to the rustc compiler, declaring various metadata about our codegen backend. 4 | 5 | ## Features 6 | * `include_str`: include target specs as string constants, for bundling with `cargo-gpu` 7 | * `dir_path`: export a path to the target specs dir, for `spirv-builder` and `compiletest` in this repo 8 | -------------------------------------------------------------------------------- /examples/multibuilder/src/main.rs: -------------------------------------------------------------------------------- 1 | use spirv_builder::{MetadataPrintout, SpirvBuilder}; 2 | 3 | fn main() { 4 | let result = SpirvBuilder::new( 5 | concat!(env!("CARGO_MANIFEST_DIR"), "/../shaders/sky-shader"), 6 | "spirv-unknown-spv1.3", 7 | ) 8 | .print_metadata(MetadataPrintout::DependencyOnly) 9 | .multimodule(true) 10 | .build() 11 | .unwrap(); 12 | println!("{result:#?}"); 13 | } 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/spirv-attr/bool-inputs.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+FragmentFullyCoveredEXT,+ext:SPV_EXT_fragment_fully_covered 3 | 4 | use spirv_std::spirv; 5 | 6 | #[spirv(fragment)] 7 | pub fn fragment( 8 | #[spirv(front_facing)] front_facing: bool, 9 | #[spirv(fully_covered_ext)] fully_covered_ext: bool, 10 | #[spirv(helper_invocation)] helper_invocation: bool, 11 | ) { 12 | } 13 | -------------------------------------------------------------------------------- /tests/difftests/tests/arch/vector_extract_insert/vector_extract_insert-rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "vector_extract_insert-rust" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # GPU deps 9 | [dependencies] 10 | spirv-std.workspace = true 11 | glam.workspace = true 12 | 13 | # CPU deps (for the test harness) 14 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 15 | difftest.workspace = true -------------------------------------------------------------------------------- /crates/rustc_codegen_spirv-target-specs/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![doc = include_str!("../README.md")] 2 | 3 | /// directory with all the `target-specs` jsons for our codegen backend 4 | #[cfg(feature = "dir_path")] 5 | pub const TARGET_SPEC_DIR_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/target-specs"); 6 | 7 | #[cfg(feature = "include_str")] 8 | mod include_str; 9 | #[cfg(feature = "include_str")] 10 | pub use include_str::TARGET_SPECS; 11 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/issue-1062.rs: -------------------------------------------------------------------------------- 1 | #![crate_name = "issue_1062"] 2 | 3 | // Test that rotates take the correct path for non-zero bit amounts. 4 | 5 | // build-pass 6 | // compile-flags: -C llvm-args=--disassemble-entry=main 7 | 8 | use spirv_std::spirv; 9 | 10 | #[spirv(fragment)] 11 | pub fn main(#[spirv(flat)] x: u32, #[spirv(flat)] s: u32, out: &mut (u32, u32)) { 12 | *out = (x.rotate_left(s), x.rotate_right(s)); 13 | } 14 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout_cuda/rust-gpu/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "abi-vector-layout-cuda-rust-gpu" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | abi-vector-layout-cpu = { path = "../../vector_layout/cpu", features = ["cuda"] } 10 | 11 | # CPU deps (for the test harness) 12 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 13 | difftest.workspace = true 14 | -------------------------------------------------------------------------------- /examples/shaders/simplest-shader/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "simplest-shader" 3 | version = "0.0.0" 4 | publish = false 5 | authors.workspace = true 6 | edition.workspace = true 7 | license.workspace = true 8 | repository.workspace = true 9 | 10 | [lints] 11 | workspace = true 12 | 13 | [dependencies] 14 | spirv-std = { workspace = true } 15 | shared = { path = "../shared" } 16 | 17 | [package.metadata.release] 18 | release = false 19 | -------------------------------------------------------------------------------- /examples/shaders/sky-shader/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sky-shader" 3 | version = "0.0.0" 4 | publish = false 5 | authors.workspace = true 6 | edition.workspace = true 7 | license.workspace = true 8 | repository.workspace = true 9 | 10 | [lints] 11 | workspace = true 12 | 13 | [dependencies] 14 | shared = { path = "../../shaders/shared" } 15 | spirv-std = { workspace = true } 16 | 17 | [package.metadata.release] 18 | release = false 19 | -------------------------------------------------------------------------------- /tests/compiletests/deps-helper/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "compiletests-deps-helper" 3 | description = "Shared dependencies of all the compiletest tests" 4 | version = "0.0.0" 5 | publish = false 6 | authors.workspace = true 7 | edition.workspace = true 8 | license.workspace = true 9 | repository.workspace = true 10 | 11 | [dependencies] 12 | spirv-std = { workspace = true } 13 | 14 | [package.metadata.release] 15 | release = false 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/const-from-cast.stderr: -------------------------------------------------------------------------------- 1 | OpCapability Shader 2 | OpMemoryModel Logical Simple 3 | OpEntryPoint Fragment %1 "main" %2 4 | OpExecutionMode %1 OriginUpperLeft 5 | %3 = OpString "$DIR/const-from-cast.rs" 6 | OpName %2 "output" 7 | OpDecorate %2 Location 0 8 | %4 = OpTypeInt 32 0 9 | %5 = OpTypePointer Output %4 10 | %6 = OpTypeVoid 11 | %7 = OpTypeFunction %6 12 | %2 = OpVariable %5 Output 13 | %8 = OpConstant %4 42 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/const-int-cast.stderr: -------------------------------------------------------------------------------- 1 | OpCapability Shader 2 | OpMemoryModel Logical Simple 3 | OpEntryPoint Fragment %1 "main" %2 4 | OpExecutionMode %1 OriginUpperLeft 5 | %3 = OpString "$DIR/const-int-cast.rs" 6 | OpName %2 "output" 7 | OpDecorate %2 Location 0 8 | %4 = OpTypeInt 32 0 9 | %5 = OpTypePointer Output %4 10 | %6 = OpTypeVoid 11 | %7 = OpTypeFunction %6 12 | %2 = OpVariable %5 Output 13 | %8 = OpConstant %4 40 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/panic/track_caller.stderr: -------------------------------------------------------------------------------- 1 | warning: `#[inline(never)]` function `track_caller::track_caller_maybe_panic::panic_cold_explicit` has been inlined 2 | --> $DIR/track_caller.rs:10:9 3 | | 4 | LL | panic!(); 5 | | ^^^^^^^^ 6 | | 7 | = note: inlining was required due to panicking 8 | = note: called from `track_caller::track_caller_maybe_panic` 9 | 10 | warning: 1 warning emitted 11 | 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/storage_class/typed_buffer.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use glam::Vec4; 4 | use spirv_std::TypedBuffer; 5 | use spirv_std::spirv; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(storage_buffer, descriptor_set = 0, binding = 0)] single: &TypedBuffer, 10 | #[spirv(storage_buffer, descriptor_set = 0, binding = 1)] single_mut: &mut TypedBuffer, 11 | ) { 12 | **single_mut = **single; 13 | } 14 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout_cuda/cpu/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "abi-vector-layout-cuda-cpu" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # GPU deps 9 | [dependencies] 10 | abi-vector-layout-cpu = { path = "../../vector_layout/cpu", features = ["cuda"] } 11 | 12 | # CPU deps (for the test harness) 13 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 14 | difftest.workspace = true 15 | -------------------------------------------------------------------------------- /examples/shaders/mouse-shader/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mouse-shader" 3 | version = "0.0.0" 4 | publish = false 5 | authors.workspace = true 6 | edition.workspace = true 7 | license.workspace = true 8 | repository.workspace = true 9 | 10 | [lints] 11 | workspace = true 12 | 13 | [dependencies] 14 | shared = { path = "../../shaders/shared" } 15 | spirv-std = { workspace = true } 16 | 17 | [package.metadata.release] 18 | release = false 19 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/derivative_control.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpLabel 3 | OpLine %5 50 8 4 | %6 = OpDPdxFine %7 %8 5 | OpLine %5 92 8 6 | %9 = OpDPdyFine %7 %8 7 | OpLine %5 131 8 8 | %10 = OpFwidthFine %7 %8 9 | OpLine %5 65 8 10 | %11 = OpDPdxCoarse %7 %8 11 | OpLine %5 107 8 12 | %12 = OpDPdyCoarse %7 %8 13 | OpLine %5 143 8 14 | %13 = OpFwidthCoarse %7 %8 15 | OpNoLine 16 | OpReturn 17 | OpFunctionEnd 18 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/task_shader_mispile.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // only-vulkan1.2 3 | // compile-flags: -Ctarget-feature=+MeshShadingEXT,+ext:SPV_EXT_mesh_shader 4 | 5 | use spirv_std::arch::emit_mesh_tasks_ext; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(task_ext(threads(1)))] 9 | pub fn main(#[spirv(push_constant)] push: &u32) { 10 | let count = 20 / *push; 11 | unsafe { 12 | emit_mesh_tasks_ext(1, 2, 3); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/ptr/allocate_vec_like.rs: -------------------------------------------------------------------------------- 1 | // Tests using a vector like pointer at `const` time. 2 | // build-pass 3 | 4 | #![feature(ptr_internals)] 5 | 6 | use spirv_std::spirv; 7 | 8 | use core::ptr::Unique; 9 | const VEC_LIKE: (Unique, usize, usize) = (Unique::::dangling(), 0, 0); 10 | 11 | pub fn assign_vec_like() { 12 | let _vec_like = VEC_LIKE; 13 | } 14 | 15 | #[spirv(fragment)] 16 | pub fn main() {} 17 | -------------------------------------------------------------------------------- /tests/difftests/tests/arch/push_constants/push_constants-rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "push_constants-rust" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # GPU deps 9 | [dependencies] 10 | spirv-std.workspace = true 11 | bytemuck.workspace = true 12 | 13 | # CPU deps (for the test harness) 14 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 15 | difftest.workspace = true 16 | bytemuck.workspace = true -------------------------------------------------------------------------------- /examples/shaders/shared/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "shared" 3 | version = "0.0.0" 4 | publish = false 5 | authors.workspace = true 6 | edition.workspace = true 7 | license.workspace = true 8 | repository.workspace = true 9 | 10 | [lints] 11 | workspace = true 12 | 13 | [dependencies] 14 | spirv-std = { workspace = true } 15 | bytemuck = { version = "1.18.0", features = ["derive"] } 16 | 17 | [package.metadata.release] 18 | release = false 19 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/workgroup_memory_barrier.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C llvm-args=--disassemble-fn=workgroup_memory_barrier::workgroup_memory_barrier 3 | 4 | use spirv_std::spirv; 5 | 6 | unsafe fn workgroup_memory_barrier() { 7 | spirv_std::arch::workgroup_memory_barrier(); 8 | } 9 | 10 | #[spirv(compute(threads(1, 1, 1)))] 11 | pub fn main() { 12 | unsafe { 13 | workgroup_memory_barrier(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/write_format_scalar.rs: -------------------------------------------------------------------------------- 1 | // Test `OpImageWrite` 2 | // build-pass 3 | 4 | use spirv_std::glam::*; 5 | use spirv_std::spirv; 6 | use spirv_std::{Image, arch}; 7 | 8 | #[spirv(fragment)] 9 | pub fn main( 10 | texels: f32, 11 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, format = r32f, sampled = false), 12 | ) { 13 | unsafe { 14 | image.write(UVec2::new(0, 1), texels); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/write_format_vec4.rs: -------------------------------------------------------------------------------- 1 | // Test `OpImageWrite` 2 | // build-pass 3 | 4 | use spirv_std::glam::*; 5 | use spirv_std::spirv; 6 | use spirv_std::{Image, arch}; 7 | 8 | #[spirv(fragment)] 9 | pub fn main( 10 | texels: Vec4, 11 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, format = rgba32f, sampled = false), 12 | ) { 13 | unsafe { 14 | image.write(UVec2::new(0, 1), texels); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/consts/issue-329.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | const OFFSETS: [f32; 18] = [ 6 | 0.000000, 1.494118, 3.486275, 5.478431, 7.470588, 9.462745, 11.454902, 13.447059, 15.439216, 7 | 17.431373, 19.423529, 21.415686, 23.407843, 25.400000, 27.392157, 29.384314, 31.376471, 8 | 33.368627, 9 | ]; 10 | 11 | #[spirv(fragment)] 12 | pub fn main(x: &mut u32) { 13 | *x = OFFSETS.len() as u32; 14 | } 15 | -------------------------------------------------------------------------------- /tests/compiletests/ui/storage_class/push_constant.rs: -------------------------------------------------------------------------------- 1 | // Test that using push constants passes (Vulkan) validation. 2 | 3 | // build-pass 4 | use spirv_std::spirv; 5 | 6 | #[derive(Copy, Clone)] 7 | pub struct ShaderConstants { 8 | pub width: u32, 9 | pub height: u32, 10 | pub time: f32, 11 | } 12 | 13 | #[spirv(fragment)] 14 | pub fn main(#[spirv(push_constant)] constants: &ShaderConstants) { 15 | let _constants = *constants; 16 | } 17 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout_scalar_math/rust-gpu/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "abi-vector-layout-scalar-math-rust-gpu" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [dependencies] 9 | abi-vector-layout-cpu = { path = "../../vector_layout/cpu", features = ["scalar-math"] } 10 | 11 | # CPU deps (for the test harness) 12 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 13 | difftest.workspace = true 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/query/query_levels_err.rs: -------------------------------------------------------------------------------- 1 | // build-fail 2 | // normalize-stderr-test "\S*/crates/spirv-std/src/" -> "$$SPIRV_STD_SRC/" 3 | // compile-flags: -C target-feature=+ImageQuery 4 | 5 | use spirv_std::{Image, arch, spirv}; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(rect, type=f32, sampled), 10 | output: &mut u32, 11 | ) { 12 | *output = image.query_levels(); 13 | } 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/unwrap_or.rs: -------------------------------------------------------------------------------- 1 | #![crate_name = "unwrap_or"] 2 | 3 | // unwrap_or generates some memory-bools (as u8). Test to make sure they're fused away. 4 | // OpINotEqual, as well as %bool, should not appear in the output. 5 | 6 | // build-pass 7 | // compile-flags: -C llvm-args=--disassemble-entry=main 8 | 9 | use spirv_std::spirv; 10 | 11 | #[spirv(fragment)] 12 | pub fn main(out: &mut u32) { 13 | *out = None.unwrap_or(15); 14 | } 15 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/query/query_size_err.rs: -------------------------------------------------------------------------------- 1 | // build-fail 2 | // normalize-stderr-test "\S*/crates/spirv-std/src/" -> "$$SPIRV_STD_SRC/" 3 | // compile-flags: -C target-feature=+ImageQuery 4 | 5 | use spirv_std::{Image, arch, spirv}; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, type=f32, sampled), 10 | output: &mut glam::UVec2, 11 | ) { 12 | *output = image.query_size(); 13 | } 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/ptr/allocate_const_scalar.rs: -------------------------------------------------------------------------------- 1 | // Doesn't work, only worked before because I think it got optimized away before 2 | // hitting the backend. 3 | 4 | // build-fail 5 | 6 | #![feature(ptr_internals)] 7 | 8 | use spirv_std::spirv; 9 | 10 | use core::ptr::Unique; 11 | 12 | const POINTER: Unique<()> = Unique::<()>::dangling(); 13 | 14 | #[spirv(fragment)] 15 | pub fn main(output: &mut Unique<()>) { 16 | *output = POINTER; 17 | } 18 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout_scalar_math/cpu/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "abi-vector-layout-scalar-math-cpu" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # GPU deps 9 | [dependencies] 10 | abi-vector-layout-cpu = { path = "../../vector_layout/cpu", features = ["scalar-math"] } 11 | 12 | # CPU deps (for the test harness) 13 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 14 | difftest.workspace = true 15 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/const_fold_int/const-expr-cpu/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "const_fold_int-const-expr-cpu" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # GPU deps 9 | [dependencies] 10 | const_fold_int-const-fold-cpu = { path = "../const-fold-cpu" } 11 | 12 | # CPU deps (for the test harness) 13 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 14 | difftest.workspace = true 15 | bytemuck.workspace = true 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/query/query_size_lod_err.rs: -------------------------------------------------------------------------------- 1 | // build-fail 2 | // normalize-stderr-test "\S*/crates/spirv-std/src/" -> "$$SPIRV_STD_SRC/" 3 | // compile-flags: -C target-feature=+ImageQuery 4 | 5 | use spirv_std::{Image, arch, spirv}; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(rect, type=f32, sampled), 10 | output: &mut glam::UVec2, 11 | ) { 12 | *output = image.query_size_lod(0); 13 | } 14 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/const_fold_int/const-expr-shader/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "const_fold_int-const-expr-shader" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # GPU deps 9 | [dependencies] 10 | const_fold_int-const-fold-cpu = { path = "../const-fold-cpu" } 11 | 12 | # CPU deps (for the test harness) 13 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 14 | difftest.workspace = true 15 | bytemuck.workspace = true 16 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/const_fold_int/const-fold-shader/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "const_fold_int-const-fold-shader" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # GPU deps 9 | [dependencies] 10 | const_fold_int-const-fold-cpu = { path = "../const-fold-cpu" } 11 | 12 | # CPU deps (for the test harness) 13 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 14 | difftest.workspace = true 15 | bytemuck.workspace = true 16 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/const_fold_int/dynamic-values-cpu/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "const_fold_int-dynamic-values-cpu" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # GPU deps 9 | [dependencies] 10 | const_fold_int-const-fold-cpu = { path = "../const-fold-cpu" } 11 | 12 | # CPU deps (for the test harness) 13 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 14 | difftest.workspace = true 15 | bytemuck.workspace = true 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/asm/const_args.rs: -------------------------------------------------------------------------------- 1 | // Tests using `asm!` with a const argument. 2 | // build-pass 3 | 4 | use core::arch::asm; 5 | use spirv_std::spirv; 6 | 7 | fn asm() { 8 | unsafe { 9 | const N: usize = 3; 10 | asm!( 11 | "%int = OpTypeInt 32 0", 12 | "%value = OpConstant %int {len}", 13 | len = const N, 14 | ); 15 | } 16 | } 17 | 18 | #[spirv(fragment)] 19 | pub fn main() { 20 | asm(); 21 | } 22 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/consts/u8-const-cast-no-capability.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // Test that u8 constants cast to u32 don't require Int8 capability when optimized away 3 | 4 | #![no_std] 5 | use spirv_std::spirv; 6 | 7 | const K: u8 = 20; 8 | 9 | #[spirv(fragment)] 10 | pub fn main(output: &mut u32) { 11 | // This should not require Int8 capability as K is only used as u32 12 | // and the optimization should fold the constant cast 13 | *output = K as u32; 14 | } 15 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/read.rs: -------------------------------------------------------------------------------- 1 | // Test `OpImageRead` 2 | // build-pass 3 | // compile-flags: -C target-feature=+StorageImageReadWithoutFormat 4 | 5 | use spirv_std::spirv; 6 | use spirv_std::{Image, arch}; 7 | 8 | #[spirv(fragment)] 9 | pub fn main( 10 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, type=f32, sampled=false), 11 | output: &mut glam::Vec4, 12 | ) { 13 | let coords = image.read(glam::IVec2::new(0, 1)); 14 | *output = coords; 15 | } 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/storage_class/typed_buffer_slice.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use glam::Vec4; 4 | use spirv_std::TypedBuffer; 5 | use spirv_std::spirv; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(storage_buffer, descriptor_set = 0, binding = 0)] slice: &TypedBuffer<[Vec4]>, 10 | #[spirv(storage_buffer, descriptor_set = 0, binding = 1)] slice_mut: &mut TypedBuffer<[Vec4]>, 11 | ) { 12 | for i in 0..5 { 13 | slice_mut[i] = slice[i]; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/const_fold_int/dynamic-values-shader/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "const_fold_int-dynamic-values-shader" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # GPU deps 9 | [dependencies] 10 | const_fold_int-const-fold-cpu = { path = "../const-fold-cpu" } 11 | 12 | # CPU deps (for the test harness) 13 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 14 | difftest.workspace = true 15 | bytemuck.workspace = true 16 | -------------------------------------------------------------------------------- /examples/shaders/compute-shader/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "compute-shader" 3 | version = "0.0.0" 4 | publish = false 5 | authors.workspace = true 6 | edition.workspace = true 7 | license.workspace = true 8 | repository.workspace = true 9 | 10 | [lints] 11 | workspace = true 12 | 13 | [dependencies] 14 | spirv-std = { workspace = true } 15 | 16 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 17 | rayon = "1.5" 18 | 19 | [package.metadata.release] 20 | release = false 21 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/issue-330.rs: -------------------------------------------------------------------------------- 1 | use spirv_std::glam::Vec4; 2 | use spirv_std::spirv; 3 | use spirv_std::{Sampler, image::Image2dArray}; 4 | 5 | #[spirv(fragment)] 6 | pub fn ps_main_stereo( 7 | output: &mut Vec4, 8 | #[spirv(descriptor_set = 0, binding = 0)] in_texture: &Image2dArray, 9 | ) { 10 | let mut color = Vec4::splat(0.0); 11 | 12 | let mut n = 0; 13 | while n < 10 { 14 | let x = *in_texture; 15 | } 16 | 17 | *output = color; 18 | } 19 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/control_flow/closure_multi.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std; 4 | use spirv_std::spirv; 5 | 6 | fn closure_user(ptr: &u32, xmax: u32, mut callback: F) { 7 | for i in 0..xmax { 8 | callback(ptr, i); 9 | } 10 | } 11 | 12 | #[spirv(fragment)] 13 | pub fn main(ptr: &mut u32) { 14 | closure_user(ptr, 10, |ptr, i| { 15 | if *ptr == i { 16 | spirv_std::arch::kill(); 17 | } 18 | }); 19 | } 20 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/control_barrier.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | #![feature(adt_const_params)] 4 | #![allow(incomplete_features)] 5 | 6 | use spirv_std::memory::{Scope, Semantics}; 7 | use spirv_std::spirv; 8 | 9 | #[spirv(fragment)] 10 | pub fn main() { 11 | unsafe { 12 | spirv_std::arch::control_barrier::< 13 | { Scope::Subgroup as u32 }, 14 | { Scope::Subgroup as u32 }, 15 | { Semantics::NONE.bits() }, 16 | >(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/memory_barrier.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | #![feature(adt_const_params)] 4 | #![allow(incomplete_features)] 5 | 6 | use spirv_std::memory::{Scope, Semantics}; 7 | use spirv_std::spirv; 8 | 9 | #[spirv(fragment)] 10 | pub fn main() { 11 | unsafe { 12 | spirv_std::arch::memory_barrier::< 13 | { Scope::Subgroup as u32 }, 14 | { Semantics::ACQUIRE_RELEASE.bits() | Semantics::UNIFORM_MEMORY.bits() }, 15 | >(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/read_subpass.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+InputAttachment 3 | 4 | use spirv_std::spirv; 5 | use spirv_std::{Image, arch}; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(descriptor_set = 0, binding = 0, input_attachment_index = 0)] image: &Image!(subpass, type=f32, sampled=false), 10 | output: &mut glam::Vec4, 11 | ) { 12 | let coords = image.read_subpass(glam::IVec2::new(0, 0)); 13 | *output = coords; 14 | } 15 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/const_fold_int/const-fold-cpu/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "const_fold_int-const-fold-cpu" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | # GPU deps 9 | [dependencies] 10 | spirv-std.workspace = true 11 | num_enum = { version = "0.7.4", default-features = false } 12 | 13 | # CPU deps (for the test harness) 14 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 15 | difftest.workspace = true 16 | bytemuck.workspace = true 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/const-float-cast-optimized.stderr: -------------------------------------------------------------------------------- 1 | OpCapability Shader 2 | OpCapability Float64 3 | OpMemoryModel Logical Simple 4 | OpEntryPoint Fragment %1 "main" %2 5 | OpExecutionMode %1 OriginUpperLeft 6 | %3 = OpString "$DIR/const-float-cast-optimized.rs" 7 | OpName %2 "output" 8 | OpDecorate %2 Location 0 9 | %4 = OpTypeFloat 64 10 | %5 = OpTypePointer Output %4 11 | %6 = OpTypeVoid 12 | %7 = OpTypeFunction %6 13 | %2 = OpVariable %5 Output 14 | %8 = OpConstant %4 4626463454704697344 15 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/query/query_lod.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+ImageQuery 3 | 4 | use spirv_std::spirv; 5 | use spirv_std::{Image, Sampler, arch}; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, type=f32, sampled), 10 | #[spirv(descriptor_set = 0, binding = 1)] sampler: &Sampler, 11 | output: &mut glam::Vec2, 12 | ) { 13 | *output = image.query_lod(*sampler, glam::Vec2::new(0.0, 1.0)); 14 | } 15 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/execute_callable.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayTracingKHR,+ext:SPV_KHR_ray_tracing 3 | 4 | use spirv_std::spirv; 5 | 6 | #[spirv(ray_generation)] 7 | pub fn main( 8 | #[spirv(descriptor_set = 0, binding = 0)] 9 | acceleration_structure: &spirv_std::ray_tracing::AccelerationStructure, 10 | #[spirv(callable_data)] payload: &glam::Vec3, 11 | ) { 12 | unsafe { 13 | spirv_std::arch::execute_callable::<_, 5>(payload); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/asm.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C llvm-args=--disassemble-fn=asm::asm 3 | 4 | use core::arch::asm; 5 | use spirv_std::spirv; 6 | 7 | fn asm() { 8 | unsafe { 9 | asm!( 10 | "%int = OpTypeInt 32 0", 11 | "%scope = OpConstant %int 3", 12 | "%semantics = OpConstant %int 72", 13 | "OpMemoryBarrier %scope %semantics", 14 | ); 15 | } 16 | } 17 | #[spirv(fragment)] 18 | pub fn main() { 19 | asm(); 20 | } 21 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/const_fold_int/const-fold-cpu/src/cpu_driver.rs: -------------------------------------------------------------------------------- 1 | use crate::{INTERESTING_PATTERNS, Variants}; 2 | use difftest::config::Config; 3 | 4 | pub fn run(variant: Variants) { 5 | let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap(); 6 | let result = variant 7 | .eval(&INTERESTING_PATTERNS) 8 | .into_iter() 9 | .flatten() 10 | .flatten() 11 | .collect::>(); 12 | config.write_result(&result).unwrap() 13 | } 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/all_memory_barrier.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+VulkanMemoryModelDeviceScopeKHR,+ext:SPV_KHR_vulkan_memory_model 3 | // compile-flags: -C llvm-args=--disassemble-fn=all_memory_barrier::all_memory_barrier 4 | 5 | use spirv_std::spirv; 6 | 7 | unsafe fn all_memory_barrier() { 8 | spirv_std::arch::all_memory_barrier(); 9 | } 10 | 11 | #[spirv(compute(threads(1, 1, 1)))] 12 | pub fn main() { 13 | unsafe { 14 | all_memory_barrier(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/write_format_vec2.rs: -------------------------------------------------------------------------------- 1 | // Test `OpImageWrite` 2 | // build-pass 3 | // compile-flags: -C target-feature=+StorageImageExtendedFormats 4 | 5 | use spirv_std::glam::*; 6 | use spirv_std::spirv; 7 | use spirv_std::{Image, arch}; 8 | 9 | #[spirv(fragment)] 10 | pub fn main( 11 | texels: Vec2, 12 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, format = rg32f, sampled = false), 13 | ) { 14 | unsafe { 15 | image.write(UVec2::new(0, 1), texels); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/vector_extract_dynamic.rs: -------------------------------------------------------------------------------- 1 | // Test `OpVectorExtractDynamic` 2 | // build-pass 3 | 4 | use spirv_std::arch; 5 | use spirv_std::spirv; 6 | 7 | #[spirv(fragment)] 8 | pub fn main() { 9 | let vector = glam::Vec2::new(1.0, 2.0); 10 | let element = unsafe { arch::vector_extract_dynamic(vector, 1) }; 11 | assert!(2.0 == element); 12 | let uvector = glam::UVec2::new(1, 2); 13 | let uelement = unsafe { arch::vector_extract_dynamic(uvector, 1) }; 14 | assert!(2 == uelement); 15 | } 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/write.rs: -------------------------------------------------------------------------------- 1 | // Test `OpImageWrite` 2 | // build-pass 3 | // compile-flags: -C target-feature=+StorageImageWriteWithoutFormat 4 | 5 | use spirv_std::glam::*; 6 | use spirv_std::spirv; 7 | use spirv_std::{Image, arch}; 8 | 9 | #[spirv(fragment)] 10 | pub fn main( 11 | texels: Vec2, 12 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, type=f32, sampled=false), 13 | ) { 14 | unsafe { 15 | image.write(UVec2::new(0, 1), Vec4::from((texels, 0., 0.))); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout/cpu/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "abi-vector-layout-cpu" 3 | edition.workspace = true 4 | 5 | [lints] 6 | workspace = true 7 | 8 | [features] 9 | cuda = ["glam/cuda"] 10 | scalar-math = ["glam/scalar-math"] 11 | 12 | # GPU deps 13 | [dependencies] 14 | spirv-std.workspace = true 15 | glam.workspace = true 16 | bytemuck.workspace = true 17 | 18 | # CPU deps (for the test harness) 19 | [target.'cfg(not(target_arch = "spirv"))'.dependencies] 20 | difftest.workspace = true 21 | -------------------------------------------------------------------------------- /crates/spirv-std/src/sampler.rs: -------------------------------------------------------------------------------- 1 | /// An opaque reference to settings that describe how to access, filter, or 2 | /// sample an image. 3 | #[spirv(sampler)] 4 | #[derive(Copy, Clone)] 5 | // HACK(eddyb) avoids "transparent newtype of `_anti_zst_padding`" misinterpretation. 6 | #[repr(C)] 7 | pub struct Sampler { 8 | // HACK(eddyb) avoids the layout becoming ZST (and being elided in one way 9 | // or another, before `#[spirv(sampler)]` can special-case it). 10 | _anti_zst_padding: core::mem::MaybeUninit, 11 | } 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/const-narrowing-cast.stderr: -------------------------------------------------------------------------------- 1 | OpCapability Shader 2 | OpCapability Int8 3 | OpMemoryModel Logical Simple 4 | OpEntryPoint Fragment %1 "main" %2 5 | OpExecutionMode %1 OriginUpperLeft 6 | %3 = OpString "$DIR/const-narrowing-cast.rs" 7 | OpName %2 "output" 8 | OpDecorate %2 Location 0 9 | %4 = OpTypeInt 32 0 10 | %5 = OpTypePointer Output %4 11 | %6 = OpTypeVoid 12 | %7 = OpTypeFunction %6 13 | %8 = OpTypeInt 8 0 14 | %9 = OpConstant %4 300 15 | %2 = OpVariable %5 Output 16 | %10 = OpConstant %4 20 17 | -------------------------------------------------------------------------------- /crates/rustc_codegen_spirv-types/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rustc_codegen_spirv-types" 3 | description = "SPIR-V backend types shared between rustc_codegen_spirv and spirv-builder" 4 | version.workspace = true 5 | authors.workspace = true 6 | edition.workspace = true 7 | license.workspace = true 8 | repository.workspace = true 9 | 10 | [dependencies] 11 | spirv = { version = "0.3.0", features = ["serialize", "deserialize"] } 12 | rspirv = "0.12" 13 | serde = { version = "1.0", features = ["derive"] } 14 | serde_json = "1.0" 15 | -------------------------------------------------------------------------------- /docs/src/introduction.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | Welcome to the Rust-GPU dev guide! This documentation is meant for documenting 4 | how to use and develop on Rust-GPU. 5 | 6 | If you're looking to get started with writing your own shaders in Rust, 7 | check out the [_"Writing Shader Crates"_](./writing-shader-crates.md) section for 8 | more information on how to get started. 9 | 10 | Alternatively if you're looking to contribute to the `rust-gpu` project, have 11 | a look at [_"Building Rust-GPU"_](./building-rust-gpu.md) section. 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/intrinsics/log10.rs: -------------------------------------------------------------------------------- 1 | // Test log10 intrinsic 2 | // build-pass 3 | 4 | #![allow(internal_features)] 5 | #![feature(core_intrinsics)] 6 | #![no_std] 7 | 8 | use spirv_std::num_traits::Float as _; 9 | use spirv_std::spirv; 10 | 11 | #[spirv(compute(threads(1)))] 12 | pub fn main( 13 | #[spirv(storage_buffer, descriptor_set = 0, binding = 0)] input: &[f32], 14 | #[spirv(storage_buffer, descriptor_set = 0, binding = 1)] output: &mut [f32], 15 | ) { 16 | output[0] = input[0].log10(); 17 | } 18 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/mem/create_unitialized_memory.rs: -------------------------------------------------------------------------------- 1 | // Test creating uninitialized memory. 2 | // build-pass 3 | 4 | use spirv_std::spirv; 5 | 6 | use core::mem::MaybeUninit; 7 | const MAYBEI32: MaybeUninit<&i32> = MaybeUninit::<&i32>::uninit(); 8 | 9 | pub fn create_uninit_and_write() { 10 | let mut maybei32 = MAYBEI32; 11 | unsafe { 12 | maybei32.as_mut_ptr().write(&0); 13 | } 14 | let _maybei32 = unsafe { maybei32.assume_init() }; 15 | } 16 | 17 | #[spirv(fragment)] 18 | pub fn main() {} 19 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/device_memory_barrier.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+VulkanMemoryModelDeviceScopeKHR,+ext:SPV_KHR_vulkan_memory_model 3 | // compile-flags: -C llvm-args=--disassemble-fn=device_memory_barrier::device_memory_barrier 4 | 5 | use spirv_std::spirv; 6 | 7 | unsafe fn device_memory_barrier() { 8 | spirv_std::arch::device_memory_barrier(); 9 | } 10 | 11 | #[spirv(compute(threads(1, 1, 1)))] 12 | pub fn main() { 13 | unsafe { 14 | device_memory_barrier(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/workgroup_memory_barrier_with_group_sync.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C llvm-args=--disassemble-fn=workgroup_memory_barrier_with_group_sync::workgroup_memory_barrier_with_group_sync 3 | 4 | use spirv_std::spirv; 5 | 6 | unsafe fn workgroup_memory_barrier_with_group_sync() { 7 | spirv_std::arch::workgroup_memory_barrier_with_group_sync(); 8 | } 9 | 10 | #[spirv(compute(threads(1, 1, 1)))] 11 | pub fn main() { 12 | unsafe { 13 | workgroup_memory_barrier_with_group_sync(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /crates/spirv-std/macros/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spirv-std-macros" 3 | description = "Macros for spirv-std" 4 | version.workspace = true 5 | authors.workspace = true 6 | edition.workspace = true 7 | license.workspace = true 8 | repository.workspace = true 9 | 10 | [lints] 11 | workspace = true 12 | 13 | [lib] 14 | proc-macro = true 15 | 16 | [dependencies] 17 | spirv-std-types = { workspace = true, features = ["std"] } 18 | proc-macro2 = "1.0.24" 19 | quote = "1.0.8" 20 | syn = { version = "2.0.90", features = ["full", "visit-mut"] } 21 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_elect.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+GroupNonUniform,+ext:SPV_KHR_vulkan_memory_model 3 | // compile-flags: -C llvm-args=--disassemble-fn=subgroup_elect::subgroup_elect 4 | // normalize-stderr-test "OpLine .*\n" -> "" 5 | 6 | use spirv_std::spirv; 7 | 8 | unsafe fn subgroup_elect() -> bool { 9 | spirv_std::arch::subgroup_elect() 10 | } 11 | 12 | #[spirv(compute(threads(1, 1, 1)))] 13 | pub fn main() { 14 | unsafe { 15 | subgroup_elect(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/index_user_dst.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpLabel 3 | OpLine %5 9 12 4 | %6 = OpInBoundsAccessChain %7 %8 %9 5 | %10 = OpArrayLength %11 %8 0 6 | OpLine %5 10 21 7 | %12 = OpULessThan %13 %9 %10 8 | OpNoLine 9 | OpSelectionMerge %14 None 10 | OpBranchConditional %12 %15 %16 11 | %15 = OpLabel 12 | OpBranch %14 13 | %16 = OpLabel 14 | OpReturn 15 | %14 = OpLabel 16 | OpLine %5 10 21 17 | %17 = OpInBoundsAccessChain %18 %6 %9 18 | %19 = OpLoad %20 %17 19 | OpNoLine 20 | OpReturn 21 | OpFunctionEnd 22 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/matrix_ops/mod.rs: -------------------------------------------------------------------------------- 1 | use crate::test_framework::*; 2 | 3 | pub const MODULE: &str = "lang/core/ops/matrix_ops"; 4 | 5 | pub fn matrix_ops() -> TestCase { 6 | TestCase::new( 7 | "matrix_ops", 8 | MODULE, 9 | WgpuComputeTest::new( 10 | |value: u32| [value as f32, (value + 1) as f32, (value + 2) as f32, (value + 3) as f32], 11 | |_input, _output| { 12 | // Default comparison will check exact equality 13 | }, 14 | ), 15 | ) 16 | } -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/read_clock_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+Int64,+ShaderClockKHR,+ext:SPV_KHR_shader_clock 3 | 4 | use glam::UVec2; 5 | use spirv_std::spirv; 6 | use spirv_std::{ 7 | arch::{read_clock_khr, read_clock_uvec2_khr}, 8 | memory::Scope, 9 | }; 10 | 11 | #[spirv(fragment)] 12 | pub fn main() { 13 | let clock_time = unsafe { read_clock_khr::<{ Scope::Subgroup as u32 }>() }; 14 | 15 | let clock_time_uvec2: UVec2 = unsafe { read_clock_uvec2_khr::<{ Scope::Subgroup as u32 }>() }; 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/issue-731.rs: -------------------------------------------------------------------------------- 1 | // Test that non-immediate (i.e. not one of scalar/scalar-pair/vector) inputs 2 | // get properly copied out of the global (`Input`) `OpVariable` and mutation is 3 | // only ever done on `fn`-local `OpVariable`s, not on the original global. 4 | 5 | // build-pass 6 | // compile-flags: -C llvm-args=--disassemble-entry=main 7 | 8 | use spirv_std::spirv; 9 | 10 | #[spirv(fragment)] 11 | pub fn main(mut in_array: [f32; 3], out_array: &mut [f32; 3]) { 12 | in_array[0] += 1.0; 13 | *out_array = in_array; 14 | } 15 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout/cpu/src/cpu_driver.rs: -------------------------------------------------------------------------------- 1 | use crate::glam_features::GlamFeatures; 2 | use crate::layout::{LAYOUT_LEN, LAYOUT_RANGE, eval_layouts}; 3 | use difftest::config::Config; 4 | 5 | pub fn run(glam_feature: GlamFeatures) { 6 | glam_feature.assert(); 7 | let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap(); 8 | let mut out = vec![0; LAYOUT_LEN]; 9 | for gid in LAYOUT_RANGE { 10 | eval_layouts(gid as u32, &mut out); 11 | } 12 | config.write_result(&out).unwrap() 13 | } 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/index_unchecked.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::arch::IndexUnchecked; 4 | use spirv_std::spirv; 5 | 6 | #[spirv(fragment)] 7 | pub fn main( 8 | #[spirv(descriptor_set = 0, binding = 0, storage_buffer)] runtime_array: &mut [u32], 9 | #[spirv(descriptor_set = 1, binding = 1, storage_buffer)] array: &mut [u32; 5], 10 | ) { 11 | unsafe { 12 | *runtime_array.index_unchecked_mut(0) = *array.index_unchecked(0); 13 | *array.index_unchecked_mut(1) = *runtime_array.index_unchecked(1); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/ops/range-contains.rs: -------------------------------------------------------------------------------- 1 | // Test that using `(a..b).contains(&x)`, which is starting to get used 2 | // in `core` (see https://github.com/rust-lang/rust/pull/87723), cannot 3 | // cause a fatal error, but at most a zombie or SPIR-V validation error. 4 | 5 | // build-pass 6 | 7 | use spirv_std::spirv; 8 | 9 | fn has_two_decimal_digits(x: u32) -> bool { 10 | (10..100).contains(&x) 11 | } 12 | 13 | #[spirv(fragment)] 14 | pub fn main(#[spirv(flat)] i: u32, o: &mut u32) { 15 | *o = has_two_decimal_digits(i) as u32; 16 | } 17 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/intrinsics/black_box_noop/with-black-box/src/main.rs: -------------------------------------------------------------------------------- 1 | use difftest::config::{Config, TestMetadata}; 2 | use difftest::scaffold::compute::{RustComputeShader, WgpuComputeTest}; 3 | 4 | fn main() { 5 | let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap(); 6 | let test = WgpuComputeTest::new(RustComputeShader::default(), [1, 1, 1], 12 * 4); 7 | test.run_test(&config).unwrap(); 8 | config 9 | .write_metadata(&TestMetadata::u32()) 10 | .expect("Failed to write metadata"); 11 | } 12 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_composite_enum.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %2 3 | %5 = OpFunctionParameter %2 4 | %6 = OpLabel 5 | %8 = OpGroupNonUniformShuffle %2 %9 %4 %5 6 | OpNoLine 7 | OpSelectionMerge %10 None 8 | OpSwitch %8 %11 0 %12 1 %13 2 %14 9 | %11 = OpLabel 10 | OpBranch %10 11 | %12 = OpLabel 12 | OpBranch %10 13 | %13 = OpLabel 14 | OpBranch %10 15 | %14 = OpLabel 16 | OpBranch %10 17 | %10 = OpLabel 18 | %15 = OpPhi %2 %16 %11 %16 %12 %17 %13 %18 %14 19 | OpReturnValue %15 20 | OpFunctionEnd 21 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/intrinsics/black_box_noop/without-black-box/src/main.rs: -------------------------------------------------------------------------------- 1 | use difftest::config::{Config, TestMetadata}; 2 | use difftest::scaffold::compute::{RustComputeShader, WgpuComputeTest}; 3 | 4 | fn main() { 5 | let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap(); 6 | let test = WgpuComputeTest::new(RustComputeShader::default(), [1, 1, 1], 12 * 4); 7 | test.run_test(&config).unwrap(); 8 | config 9 | .write_metadata(&TestMetadata::u32()) 10 | .expect("Failed to write metadata"); 11 | } 12 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/trig_ops/trig_ops-rust/src/main.rs: -------------------------------------------------------------------------------- 1 | use difftest::config::Config; 2 | use difftest::scaffold::compute::{RustComputeShader, WgpuComputeTestMultiBuffer}; 3 | 4 | fn main() { 5 | let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap(); 6 | 7 | let buffer_size = 1024; 8 | let test = WgpuComputeTestMultiBuffer::new_with_sizes( 9 | RustComputeShader::default(), 10 | [64, 1, 1], 11 | &[buffer_size, buffer_size], 12 | ); 13 | 14 | test.run_test(&config).unwrap(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/trig_ops/trig_ops-wgsl/src/main.rs: -------------------------------------------------------------------------------- 1 | use difftest::config::Config; 2 | use difftest::scaffold::compute::{WgpuComputeTestMultiBuffer, WgslComputeShader}; 3 | 4 | fn main() { 5 | let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap(); 6 | 7 | let buffer_size = 1024; 8 | let test = WgpuComputeTestMultiBuffer::new_with_sizes( 9 | WgslComputeShader::default(), 10 | [64, 1, 1], 11 | &[buffer_size, buffer_size], 12 | ); 13 | 14 | test.run_test(&config).unwrap(); 15 | } 16 | -------------------------------------------------------------------------------- /examples/runners/cpu/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "example-runner-cpu" 3 | version = "0.0.0" 4 | publish = false 5 | authors.workspace = true 6 | edition.workspace = true 7 | license.workspace = true 8 | repository.workspace = true 9 | 10 | [dependencies] 11 | minifb = "0.28.0" 12 | # bring in the shader as natively compiled code 13 | shared = { path = "../../shaders/shared" } 14 | sky-shader = { path = "../../shaders/sky-shader" } 15 | 16 | # for parallelism, not really needed though 17 | rayon = "1.5" 18 | 19 | [package.metadata.release] 20 | release = false 21 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/sample_with_project_coordinate/sample.rs: -------------------------------------------------------------------------------- 1 | // Test `OpImageSampleProjImplicitLod` 2 | // build-pass 3 | 4 | use spirv_std::spirv; 5 | use spirv_std::{Image, Sampler}; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(descriptor_set = 0, binding = 0)] image2d: &Image!(2D, type=f32, sampled), 10 | #[spirv(descriptor_set = 1, binding = 1)] sampler: &Sampler, 11 | output: &mut glam::Vec4, 12 | ) { 13 | let v3 = glam::Vec3::new(0.0, 1.0, 0.5); 14 | *output = image2d.sample_with_project_coordinate(*sampler, v3); 15 | } 16 | -------------------------------------------------------------------------------- /.github/workflows/docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | if [[ -z "${CI}" ]]; then 5 | FEAT="use-compiled-tools" 6 | else 7 | FEAT="use-installed-tools" 8 | fi 9 | 10 | function doc() { 11 | echo ::group::"$1" 12 | cargo doc \ 13 | --manifest-path "$1/Cargo.toml" \ 14 | --no-default-features \ 15 | --features "$FEAT" 16 | echo ::endgroup:: 17 | } 18 | 19 | # Core crates only! 20 | cargo doc --manifest-path "crates/spirv-std/Cargo.toml" --all-features 21 | doc crates/rustc_codegen_spirv 22 | doc crates/spirv-builder 23 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/asm_add_two_ints.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C llvm-args=--disassemble-fn=asm_add_two_ints::add_two_ints 3 | 4 | use core::arch::asm; 5 | use spirv_std::spirv; 6 | 7 | fn add_two_ints(x: u32, y: u32) -> u32 { 8 | let result; 9 | unsafe { 10 | asm!( 11 | "{0} = OpIAdd typeof{0} {1} {2}", 12 | out(reg) result, 13 | in(reg) x, 14 | in(reg) y, 15 | ); 16 | } 17 | result 18 | } 19 | #[spirv(fragment)] 20 | pub fn main() { 21 | add_two_ints(2, 3); 22 | } 23 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/query/query_lod_err.rs: -------------------------------------------------------------------------------- 1 | // build-fail 2 | // normalize-stderr-test "\S*/crates/spirv-std/src/" -> "$$SPIRV_STD_SRC/" 3 | // compile-flags: -C target-feature=+ImageQuery 4 | 5 | use spirv_std::{Image, Sampler, arch, spirv}; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(rect, type=f32, sampled), 10 | #[spirv(descriptor_set = 0, binding = 1)] sampler: &Sampler, 11 | output: &mut glam::Vec2, 12 | ) { 13 | *output = image.query_lod(*sampler, glam::Vec2::new(0.0, 1.0)); 14 | } 15 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/ref/member_ref_arg.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::spirv; 4 | 5 | struct S { 6 | x: u32, 7 | y: u32, 8 | } 9 | 10 | // NOTE(eddyb) `#[inline(never)]` is for blocking inlining at the e.g. MIR level, 11 | // whereas any Rust-GPU-specific legalization will intentionally ignore it. 12 | 13 | #[inline(never)] 14 | fn f(x: &u32) {} 15 | 16 | #[inline(never)] 17 | fn g(xy: (&u32, &u32)) {} 18 | 19 | #[spirv(fragment)] 20 | pub fn main() { 21 | let s = S { x: 2, y: 2 }; 22 | f(&s.x); 23 | g((&s.x, &s.y)); 24 | } 25 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/vector_swizzle/vector_swizzle-rust/src/main.rs: -------------------------------------------------------------------------------- 1 | use difftest::config::Config; 2 | use difftest::scaffold::compute::{RustComputeShader, WgpuComputeTestMultiBuffer}; 3 | 4 | fn main() { 5 | let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap(); 6 | 7 | let buffer_size = 1024; 8 | let test = WgpuComputeTestMultiBuffer::new_with_sizes( 9 | RustComputeShader::default(), 10 | [64, 1, 1], 11 | &[buffer_size, buffer_size], 12 | ); 13 | 14 | test.run_test(&config).unwrap(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/vector_swizzle/vector_swizzle-wgsl/src/main.rs: -------------------------------------------------------------------------------- 1 | use difftest::config::Config; 2 | use difftest::scaffold::compute::{WgpuComputeTestMultiBuffer, WgslComputeShader}; 3 | 4 | fn main() { 5 | let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap(); 6 | 7 | let buffer_size = 1024; 8 | let test = WgpuComputeTestMultiBuffer::new_with_sizes( 9 | WgslComputeShader::default(), 10 | [64, 1, 1], 11 | &[buffer_size, buffer_size], 12 | ); 13 | 14 | test.run_test(&config).unwrap(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_composite_all_equals.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %5 3 | %6 = OpLabel 4 | %8 = OpCompositeExtract %9 %4 0 5 | %11 = OpGroupNonUniformAllEqual %2 %12 %8 6 | %13 = OpLogicalAnd %2 %14 %11 7 | %15 = OpCompositeExtract %16 %4 1 8 | %17 = OpGroupNonUniformAllEqual %2 %12 %15 9 | %18 = OpLogicalAnd %2 %13 %17 10 | %19 = OpCompositeExtract %20 %4 2 11 | %21 = OpGroupNonUniformAllEqual %2 %12 %19 12 | %22 = OpLogicalAnd %2 %18 %21 13 | OpNoLine 14 | OpReturnValue %22 15 | OpFunctionEnd 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/spirv-attr/int-without-flat.stderr: -------------------------------------------------------------------------------- 1 | error: `Fragment` entry-point `Input` parameter must be decorated with `#[spirv(flat)]` 2 | --> $DIR/int-without-flat.rs:6:22 3 | | 4 | LL | pub fn fragment(int: u32, double: f64) {} 5 | | ^^^ 6 | 7 | error: `Fragment` entry-point `Input` parameter must be decorated with `#[spirv(flat)]` 8 | --> $DIR/int-without-flat.rs:6:35 9 | | 10 | LL | pub fn fragment(int: u32, double: f64) {} 11 | | ^^^ 12 | 13 | error: aborting due to 2 previous errors 14 | 15 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/control_flow_complex/control_flow_complex-rust/src/main.rs: -------------------------------------------------------------------------------- 1 | use difftest::config::Config; 2 | use difftest::scaffold::compute::{RustComputeShader, WgpuComputeTestMultiBuffer}; 3 | 4 | fn main() { 5 | let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap(); 6 | 7 | let buffer_size = 1024; 8 | let test = WgpuComputeTestMultiBuffer::new_with_sizes( 9 | RustComputeShader::default(), 10 | [64, 1, 1], 11 | &[buffer_size, buffer_size], 12 | ); 13 | 14 | test.run_test(&config).unwrap(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/control_flow_complex/control_flow_complex-wgsl/src/main.rs: -------------------------------------------------------------------------------- 1 | use difftest::config::Config; 2 | use difftest::scaffold::compute::{WgpuComputeTestMultiBuffer, WgslComputeShader}; 3 | 4 | fn main() { 5 | let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap(); 6 | 7 | let buffer_size = 1024; 8 | let test = WgpuComputeTestMultiBuffer::new_with_sizes( 9 | WgslComputeShader::default(), 10 | [64, 1, 1], 11 | &[buffer_size, buffer_size], 12 | ); 13 | 14 | test.run_test(&config).unwrap(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/pass-mode-cast-struct.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpLabel 3 | OpLine %5 29 12 4 | %6 = OpLoad %7 %8 5 | OpLine %5 30 14 6 | %9 = OpFunctionCall %10 %11 %6 7 | OpLine %5 31 15 8 | %12 = OpCompositeExtract %13 %9 0 9 | OpLine %5 31 24 10 | %14 = OpCompositeExtract %15 %9 1 11 | OpLine %5 31 32 12 | %16 = OpCompositeExtract %15 %9 2 13 | OpLine %5 31 23 14 | %17 = OpIAdd %15 %14 %16 15 | %18 = OpUConvert %13 %17 16 | OpLine %5 31 4 17 | %19 = OpIAdd %13 %12 %18 18 | OpStore %20 %19 19 | OpNoLine 20 | OpReturn 21 | OpFunctionEnd 22 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/intrinsics/black_box.stderr: -------------------------------------------------------------------------------- 1 | warning: black_box intrinsic does not prevent optimization in Rust GPU 2 | 3 | %1 = OpFunction %2 DontInline %3 4 | %4 = OpLabel 5 | OpLine %5 32 17 6 | %6 = OpIAdd %7 %8 %9 7 | OpLine %5 41 19 8 | %10 = OpIAdd %7 %11 %12 9 | OpLine %5 47 8 10 | %13 = OpBitcast %7 %14 11 | OpLine %15 1092 17 12 | %16 = OpBitcast %7 %17 13 | OpLine %5 46 4 14 | %18 = OpCompositeConstruct %2 %13 %16 %19 %20 %21 %22 %6 %23 %10 %24 %24 %24 15 | OpNoLine 16 | OpReturnValue %18 17 | OpFunctionEnd 18 | warning: 1 warning emitted 19 | 20 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/bitwise_ops/bitwise_ops-rust/src/main.rs: -------------------------------------------------------------------------------- 1 | use difftest::config::Config; 2 | use difftest::scaffold::compute::{RustComputeShader, WgpuComputeTestMultiBuffer}; 3 | 4 | fn main() { 5 | let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap(); 6 | 7 | let buffer_size = 1024; 8 | let test = WgpuComputeTestMultiBuffer::new_with_sizes( 9 | RustComputeShader::default(), 10 | [64, 1, 1], 11 | &[buffer_size, buffer_size, buffer_size], 12 | ); 13 | 14 | test.run_test(&config).unwrap(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/bitwise_ops/bitwise_ops-wgsl/src/main.rs: -------------------------------------------------------------------------------- 1 | use difftest::config::Config; 2 | use difftest::scaffold::compute::{WgpuComputeTestMultiBuffer, WgslComputeShader}; 3 | 4 | fn main() { 5 | let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap(); 6 | 7 | let buffer_size = 1024; 8 | let test = WgpuComputeTestMultiBuffer::new_with_sizes( 9 | WgslComputeShader::default(), 10 | [64, 1, 1], 11 | &[buffer_size, buffer_size, buffer_size], 12 | ); 13 | 14 | test.run_test(&config).unwrap(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/sample_with_project_coordinate/sample_lod.rs: -------------------------------------------------------------------------------- 1 | // Test `OpImageSampleProjExplicitLod` 2 | // build-pass 3 | 4 | use spirv_std::spirv; 5 | use spirv_std::{Image, Sampler, arch}; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(descriptor_set = 0, binding = 0)] image2d: &Image!(2D, type=f32, sampled), 10 | #[spirv(descriptor_set = 1, binding = 1)] sampler: &Sampler, 11 | output: &mut glam::Vec4, 12 | ) { 13 | let v3 = glam::Vec3::new(0.0, 1.0, 0.5); 14 | *output = image2d.sample_with_project_coordinate_by_lod(*sampler, v3, 0.0); 15 | } 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/query/sampled_image_multisampled_query_size.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+ImageQuery 3 | 4 | use spirv_std::spirv; 5 | use spirv_std::{Image, arch, image::SampledImage}; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(descriptor_set = 0, binding = 0)] sampled_image2d_ms: &SampledImage< 10 | Image!(2D, type=f32, multisampled, sampled), 11 | >, 12 | output: &mut glam::UVec2, 13 | ) { 14 | // Multisampled sampled images can use query_size directly 15 | *output = sampled_image2d_ms.query_size(); 16 | } 17 | -------------------------------------------------------------------------------- /tests/difftests/tests/arch/vector_extract_insert/vector_extract_insert-rust/src/main.rs: -------------------------------------------------------------------------------- 1 | use difftest::config::Config; 2 | use difftest::scaffold::compute::{RustComputeShader, WgpuComputeTestMultiBuffer}; 3 | 4 | fn main() { 5 | let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap(); 6 | 7 | let buffer_size = 1024; 8 | let test = WgpuComputeTestMultiBuffer::new_with_sizes( 9 | RustComputeShader::default(), 10 | [64, 1, 1], 11 | &[buffer_size, buffer_size, buffer_size], 12 | ); 13 | 14 | test.run_test(&config).unwrap(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/difftests/tests/arch/vector_extract_insert/vector_extract_insert-wgsl/src/main.rs: -------------------------------------------------------------------------------- 1 | use difftest::config::Config; 2 | use difftest::scaffold::compute::{WgpuComputeTestMultiBuffer, WgslComputeShader}; 3 | 4 | fn main() { 5 | let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap(); 6 | 7 | let buffer_size = 1024; 8 | let test = WgpuComputeTestMultiBuffer::new_with_sizes( 9 | WgslComputeShader::default(), 10 | [64, 1, 1], 11 | &[buffer_size, buffer_size, buffer_size], 12 | ); 13 | 14 | test.run_test(&config).unwrap(); 15 | } 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/spirv-attr/invalid-matrix-type.rs: -------------------------------------------------------------------------------- 1 | // Tests that matrix type inference fails correctly 2 | // build-fail 3 | 4 | use spirv_std::spirv; 5 | 6 | #[spirv(matrix)] 7 | pub struct _FewerFields { 8 | _v: glam::Vec3, 9 | } 10 | 11 | #[spirv(matrix)] 12 | pub struct _NotVectorField { 13 | _x: f32, 14 | _y: f32, 15 | _z: f32, 16 | } 17 | 18 | #[spirv(matrix)] 19 | pub struct _DifferentType { 20 | _x: glam::Vec3, 21 | _y: glam::Vec2, 22 | } 23 | 24 | #[spirv(fragment)] 25 | pub fn _entry(_arg1: _FewerFields, _arg2: _NotVectorField, _arg3: _DifferentType) {} 26 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/const_fold_int/const-fold-cpu/src/shader.rs: -------------------------------------------------------------------------------- 1 | use crate::{EvalResult, Variants}; 2 | use spirv_std::spirv; 3 | 4 | #[spirv(compute(threads(1)))] 5 | pub fn main_cs( 6 | #[spirv(storage_buffer, descriptor_set = 0, binding = 0)] variant: &u32, 7 | #[spirv(storage_buffer, descriptor_set = 0, binding = 1)] input_patterns: &[u32; 8], 8 | #[spirv(storage_buffer, descriptor_set = 0, binding = 2)] output: &mut EvalResult, 9 | ) { 10 | if let Ok(variant) = Variants::try_from(*variant) { 11 | *output = variant.eval(input_patterns); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/multibuilder/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "multibuilder" 3 | version = "0.0.0" 4 | publish = false 5 | authors.workspace = true 6 | edition.workspace = true 7 | license.workspace = true 8 | repository.workspace = true 9 | 10 | # See rustc_codegen_spirv/Cargo.toml for details on these features 11 | [features] 12 | default = ["use-compiled-tools"] 13 | use-installed-tools = ["spirv-builder/use-installed-tools"] 14 | use-compiled-tools = ["spirv-builder/use-compiled-tools"] 15 | 16 | [dependencies] 17 | spirv-builder.workspace = true 18 | 19 | [package.metadata.release] 20 | release = false 21 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/sample_depth_reference_with_project_coordinate/sample.rs: -------------------------------------------------------------------------------- 1 | // Test `OpImageSampleProjDrefImplicitLod` 2 | // build-pass 3 | 4 | use spirv_std::spirv; 5 | use spirv_std::{Image, Sampler, arch}; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, type=f32, sampled), 10 | #[spirv(descriptor_set = 1, binding = 1)] sampler: &Sampler, 11 | output: &mut f32, 12 | ) { 13 | let v3 = glam::Vec3A::new(0.0, 0.0, 1.0); 14 | *output = image.sample_depth_reference_with_project_coordinate(*sampler, v3, 1.0); 15 | } 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/unwrap_or.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpLabel 3 | OpLine %5 13 11 4 | %6 = OpCompositeInsert %7 %8 %9 0 5 | %10 = OpCompositeExtract %11 %6 1 6 | OpLine %12 1026 14 7 | %13 = OpBitcast %14 %8 8 | OpLine %12 1026 8 9 | %15 = OpINotEqual %16 %13 %17 10 | OpNoLine 11 | OpSelectionMerge %18 None 12 | OpBranchConditional %15 %19 %20 13 | %19 = OpLabel 14 | OpBranch %18 15 | %20 = OpLabel 16 | OpBranch %18 17 | %18 = OpLabel 18 | %21 = OpPhi %11 %10 %19 %22 %20 19 | OpLine %5 13 4 20 | OpStore %23 %21 21 | OpNoLine 22 | OpReturn 23 | OpFunctionEnd 24 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/consts/u32-from-u64-fail.rs: -------------------------------------------------------------------------------- 1 | // Test that u32::from(u64) fails to compile since From is not implemented for u32 2 | // This ensures our From trait optimization doesn't accidentally allow invalid conversions 3 | 4 | // build-fail 5 | 6 | use spirv_std::spirv; 7 | 8 | const K: u64 = 42; 9 | 10 | #[spirv(fragment)] 11 | pub fn main(output: &mut u32) { 12 | // This should fail to compile because From is not implemented for u32 13 | // (u64 to u32 is a narrowing conversion that could lose data) 14 | let value = u32::from(K); 15 | *output = value; 16 | } 17 | -------------------------------------------------------------------------------- /tests/difftests/tests/simple-compute/simple-compute-rust/src/main.rs: -------------------------------------------------------------------------------- 1 | use difftest::config::Config; 2 | use difftest::scaffold::compute::{RustComputeShader, WgpuComputeTest}; 3 | 4 | fn main() { 5 | // Load the config from the harness. 6 | let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap(); 7 | 8 | // Define test parameters, loading the rust shader from the current crate. 9 | let test = WgpuComputeTest::new(RustComputeShader::default(), [1, 1, 1], 1024); 10 | 11 | // Run the test and write the output to a file. 12 | test.run_test(&config).unwrap(); 13 | } 14 | -------------------------------------------------------------------------------- /tests/difftests/tests/simple-compute/simple-compute-wgsl/src/main.rs: -------------------------------------------------------------------------------- 1 | use difftest::config::Config; 2 | use difftest::scaffold::compute::{WgpuComputeTest, WgslComputeShader}; 3 | 4 | fn main() { 5 | // Load the config from the harness. 6 | let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap(); 7 | 8 | // Define test parameters, loading the wgsl shader from the crate directory. 9 | let test = WgpuComputeTest::new(WgslComputeShader::default(), [1, 1, 1], 1024); 10 | 11 | // Run the test and write the output to a file. 12 | test.run_test(&config).unwrap(); 13 | } 14 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/task_shader_payload.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // only-vulkan1.2 3 | // compile-flags: -Ctarget-feature=+MeshShadingEXT,+ext:SPV_EXT_mesh_shader 4 | 5 | use spirv_std::arch::emit_mesh_tasks_ext_payload; 6 | use spirv_std::spirv; 7 | 8 | pub struct Payload { 9 | pub first: u32, 10 | pub second: i32, 11 | } 12 | 13 | #[spirv(task_ext(threads(1)))] 14 | pub fn main(#[spirv(task_payload_workgroup_ext)] payload: &mut Payload) { 15 | payload.first = 1; 16 | payload.second = 2; 17 | 18 | unsafe { 19 | emit_mesh_tasks_ext_payload(3, 4, 5, payload); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/sample_depth_reference_with_project_coordinate/sample_lod.rs: -------------------------------------------------------------------------------- 1 | // Test `OpImageSampleProjDrefExplicitLod` 2 | // build-pass 3 | 4 | use spirv_std::spirv; 5 | use spirv_std::{Image, Sampler}; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, type=f32, sampled), 10 | #[spirv(descriptor_set = 1, binding = 1)] sampler: &Sampler, 11 | output: &mut f32, 12 | ) { 13 | let v3 = glam::Vec3A::new(0.0, 0.0, 1.0); 14 | *output = image.sample_depth_reference_with_project_coordinate_by_lod(*sampler, v3, 1.0, 0.0); 15 | } 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/all_memory_barrier_with_group_sync.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+VulkanMemoryModelDeviceScopeKHR,+ext:SPV_KHR_vulkan_memory_model 3 | // compile-flags: -C llvm-args=--disassemble-fn=all_memory_barrier_with_group_sync::all_memory_barrier_with_group_sync 4 | 5 | use spirv_std::spirv; 6 | 7 | unsafe fn all_memory_barrier_with_group_sync() { 8 | spirv_std::arch::all_memory_barrier_with_group_sync(); 9 | } 10 | 11 | #[spirv(compute(threads(1, 1, 1)))] 12 | pub fn main() { 13 | unsafe { 14 | all_memory_barrier_with_group_sync(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/derivative_control.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+DerivativeControl 3 | // compile-flags: -C llvm-args=--disassemble-fn=derivative_control::derivative 4 | 5 | use spirv_std::arch::Derivative; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main() { 10 | derivative(); 11 | } 12 | 13 | pub fn derivative() { 14 | Derivative::dfdx_fine(0.); 15 | Derivative::dfdy_fine(0.); 16 | Derivative::fwidth_fine(0.); 17 | 18 | Derivative::dfdx_coarse(0.); 19 | Derivative::dfdy_coarse(0.); 20 | Derivative::fwidth_coarse(0.); 21 | } 22 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_get_ray_flags_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 10 | unsafe { 11 | spirv_std::ray_query!(let mut handle); 12 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 13 | let flags = handle.get_ray_flags(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_get_ray_t_min_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 10 | unsafe { 11 | spirv_std::ray_query!(let mut handle); 12 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 13 | let tmin = handle.get_ray_t_min(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/entry-pass-mode-cast-array.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpLabel 3 | OpLine %5 13 12 4 | %6 = OpLoad %7 %8 5 | %9 = OpCompositeExtract %10 %6 0 6 | %11 = OpCompositeExtract %10 %6 1 7 | %12 = OpCompositeConstruct %13 %9 %11 8 | OpLine %5 14 4 9 | %14 = OpCompositeExtract %10 %12 0 10 | %15 = OpFAdd %10 %14 %16 11 | %17 = OpCompositeInsert %13 %15 %12 0 12 | OpLine %5 15 4 13 | %18 = OpCompositeExtract %10 %17 0 14 | %19 = OpCompositeExtract %10 %17 1 15 | %20 = OpCompositeConstruct %7 %18 %19 16 | OpStore %21 %20 17 | OpNoLine 18 | OpReturn 19 | OpFunctionEnd 20 | -------------------------------------------------------------------------------- /crates/rustc_codegen_spirv/README.md: -------------------------------------------------------------------------------- 1 | # `rustc_codegen_spirv` 2 | 3 | Compiler backend for the `SPIR-V` target architecture. This crate is not intended to be used directly. Please refer to [`spirv-builder`](https://docs.rs/spirv-builder/) for more information. 4 | 5 | ## Documentation 6 | 7 | Because of its nature, this crate can only be built using a very specific nightly version of the Rust toolchain. As such, the `docs.rs` build of the API documentation will likely fail. Please refer to the [documentation in the `rust-gpu` github repo](https://rust-gpu.github.io/rust-gpu/api/rustc_codegen_spirv/index.html) for properly built docs. 8 | -------------------------------------------------------------------------------- /examples/runners/wgpu/builder/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "example-runner-wgpu-builder" 3 | version = "0.0.0" 4 | publish = false 5 | authors.workspace = true 6 | edition.workspace = true 7 | license.workspace = true 8 | repository.workspace = true 9 | 10 | # See rustc_codegen_spirv/Cargo.toml for details on these features 11 | [features] 12 | default = ["use-compiled-tools"] 13 | use-installed-tools = ["spirv-builder/use-installed-tools"] 14 | use-compiled-tools = ["spirv-builder/use-compiled-tools"] 15 | 16 | [dependencies] 17 | spirv-builder.workspace = true 18 | 19 | [package.metadata.release] 20 | release = false 21 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/device_memory_barrier_with_group_sync.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+VulkanMemoryModelDeviceScopeKHR,+ext:SPV_KHR_vulkan_memory_model 3 | // compile-flags: -C llvm-args=--disassemble-fn=device_memory_barrier_with_group_sync::device_memory_barrier_with_group_sync 4 | 5 | use spirv_std::spirv; 6 | 7 | unsafe fn device_memory_barrier_with_group_sync() { 8 | spirv_std::arch::device_memory_barrier_with_group_sync(); 9 | } 10 | 11 | #[spirv(compute(threads(1, 1, 1)))] 12 | pub fn main() { 13 | unsafe { 14 | device_memory_barrier_with_group_sync(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/spirv-attr/bad-deduce-storage-class.rs: -------------------------------------------------------------------------------- 1 | // Tests that storage class deduction (from entry-point signature) fails correctly 2 | // build-fail 3 | 4 | use spirv_std::{Image, spirv}; 5 | 6 | #[spirv(vertex)] 7 | pub fn main( 8 | #[spirv(descriptor_set = 0, binding = 0, uniform)] error: &Image!(2D, type=f32), 9 | #[spirv(descriptor_set = 0, binding = 1, uniform_constant)] warning: &Image!(2D, type=f32), 10 | ) { 11 | } 12 | 13 | // https://github.com/EmbarkStudios/rust-gpu/issues/585 14 | #[spirv(vertex)] 15 | pub fn issue_585(#[spirv(descriptor_set = 0, binding = 0)] invalid: Image!(2D, type=f32)) {} 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_terminate_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 10 | unsafe { 11 | spirv_std::ray_query!(let mut handle); 12 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 13 | assert!(handle.proceed()); 14 | handle.terminate(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_composite_shuffle.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %2 3 | %5 = OpFunctionParameter %6 4 | %7 = OpLabel 5 | %9 = OpCompositeExtract %10 %4 0 6 | %12 = OpGroupNonUniformShuffle %10 %13 %9 %5 7 | %14 = OpCompositeExtract %15 %4 1 8 | %16 = OpGroupNonUniformShuffle %15 %13 %14 %5 9 | %17 = OpCompositeExtract %18 %4 2 10 | %19 = OpGroupNonUniformShuffle %18 %13 %17 %5 11 | %20 = OpCompositeInsert %2 %12 %21 0 12 | %22 = OpCompositeInsert %2 %16 %20 1 13 | %23 = OpCompositeInsert %2 %19 %22 2 14 | OpNoLine 15 | OpReturnValue %23 16 | OpFunctionEnd 17 | -------------------------------------------------------------------------------- /docs/src/rfcs/000-template.md: -------------------------------------------------------------------------------- 1 | 2 | # Summary 3 | 4 | State the problem that this RFC is trying to address clearly but briefly 5 | 6 | # Explanation 7 | 8 | Give examples, elaborate on the proposal 9 | 10 | # Drawbacks 11 | 12 | List potential issues that one would want to have discussed in the RFC comment section 13 | 14 | # Alternatives 15 | 16 | A list of potential alternatives, though sometimes they can arise from the comments as well. 17 | 18 | # Prior art 19 | 20 | Usually this will involve looking at current shading languages out there to see if we can either borrow concepts from them, or if we can improve upon existing concepts. -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_get_world_ray_origin_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 10 | unsafe { 11 | spirv_std::ray_query!(let mut handle); 12 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 13 | let origin: glam::Vec3 = handle.get_world_ray_origin(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/atomic_i_increment.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | 3 | use spirv_std::arch::IndexUnchecked; 4 | use spirv_std::spirv; 5 | 6 | #[spirv(compute(threads(64)))] 7 | pub fn main(#[spirv(descriptor_set = 0, binding = 0, storage_buffer)] buffer: &mut [u32]) { 8 | let reference = unsafe { buffer.index_unchecked_mut(0) }; 9 | 10 | let old = unsafe { 11 | spirv_std::arch::atomic_i_increment::< 12 | _, 13 | { spirv_std::memory::Scope::Workgroup as u32 }, 14 | { spirv_std::memory::Semantics::NONE.bits() as u32 }, 15 | >(reference) 16 | }; 17 | assert!(old == 0); 18 | } 19 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/sample_with_project_coordinate/sample_gradient.rs: -------------------------------------------------------------------------------- 1 | // Test `OpImageSampleProjExplicitLod` 2 | // build-pass 3 | 4 | use spirv_std::spirv; 5 | use spirv_std::{Image, Sampler, arch}; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(descriptor_set = 0, binding = 0)] image2d: &Image!(2D, type=f32, sampled), 10 | #[spirv(descriptor_set = 1, binding = 1)] sampler: &Sampler, 11 | output: &mut glam::Vec4, 12 | ) { 13 | let v2 = glam::Vec2::new(0.0, 1.0); 14 | let v3 = glam::Vec3::new(0.0, 1.0, 0.5); 15 | *output = image2d.sample_with_project_coordinate_by_gradient(*sampler, v3, v2, v2); 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_get_world_ray_direction_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 10 | unsafe { 11 | spirv_std::ray_query!(let mut handle); 12 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 13 | let direction: glam::Vec3 = handle.get_world_ray_direction(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/vector_insert_dynamic.rs: -------------------------------------------------------------------------------- 1 | // Test `OpVectorInsertDynamic` 2 | // build-pass 3 | 4 | use spirv_std::arch; 5 | use spirv_std::spirv; 6 | 7 | #[spirv(fragment)] 8 | pub fn main() { 9 | let vector = glam::Vec2::new(1.0, 2.0); 10 | let expected = glam::Vec2::new(1.0, 3.0); 11 | let new_vector = unsafe { arch::vector_insert_dynamic(vector, 1, 3.0) }; 12 | assert!(new_vector == expected); 13 | let uvector = glam::UVec2::new(1, 2); 14 | let uexpected = glam::UVec2::new(1, 3); 15 | let unew_vector = unsafe { arch::vector_insert_dynamic(uvector, 1, 3) }; 16 | assert!(unew_vector == uexpected); 17 | } 18 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_confirm_intersection_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 10 | unsafe { 11 | spirv_std::ray_query!(let mut handle); 12 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 13 | assert!(handle.proceed()); 14 | handle.confirm_intersection(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_get_intersection_candidate_aabb_opaque_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 10 | unsafe { 11 | spirv_std::ray_query!(let mut handle); 12 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 13 | handle.get_intersection_candidate_aabb_opaque(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_ballot.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+GroupNonUniform,+GroupNonUniformBallot,+ext:SPV_KHR_vulkan_memory_model 3 | // compile-flags: -C llvm-args=--disassemble-fn=subgroup_ballot::subgroup_ballot 4 | // normalize-stderr-test "OpLine .*\n" -> "" 5 | 6 | use spirv_std::spirv; 7 | 8 | unsafe fn subgroup_ballot(predicate: bool) -> bool { 9 | let ballot = spirv_std::arch::subgroup_ballot(predicate); 10 | spirv_std::arch::subgroup_inverse_ballot(ballot) 11 | } 12 | 13 | #[spirv(compute(threads(1, 1, 1)))] 14 | pub fn main() { 15 | unsafe { 16 | subgroup_ballot(true); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_broadcast_const.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+GroupNonUniform,+GroupNonUniformBallot,+ext:SPV_KHR_vulkan_memory_model 3 | // compile-flags: -C llvm-args=--disassemble-fn=subgroup_broadcast_const::disassembly 4 | // normalize-stderr-test "OpLine .*\n" -> "" 5 | 6 | use spirv_std::arch::{GroupOperation, SubgroupMask}; 7 | use spirv_std::spirv; 8 | 9 | unsafe fn disassembly(value: i32) -> i32 { 10 | spirv_std::arch::subgroup_broadcast_const::<_, 5>(value) 11 | } 12 | 13 | #[spirv(compute(threads(32, 1, 1)))] 14 | pub fn main() { 15 | unsafe { 16 | disassembly(-42); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/ptr_read.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C llvm-args=--disassemble-fn=ptr_read::copy_via_raw_ptr 3 | 4 | use spirv_std::spirv; 5 | 6 | fn copy_via_raw_ptr(src: &f32, dst: &mut f32) { 7 | unsafe { *dst = core::ptr::read(src) } 8 | } 9 | #[spirv(fragment)] 10 | pub fn main(i: f32, o: &mut f32) { 11 | copy_via_raw_ptr(&i, o); 12 | // FIXME(eddyb) above call results in inlining `copy_via_raw_ptr`, 13 | // due to the to `Output` storage classe, so to get the disassembled 14 | // function we also need `Function`-local pointers: 15 | let (src, mut dst) = (0.0, 0.0); 16 | copy_via_raw_ptr(&src, &mut dst); 17 | } 18 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/ptr_write.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C llvm-args=--disassemble-fn=ptr_write::copy_via_raw_ptr 3 | 4 | use spirv_std::spirv; 5 | 6 | fn copy_via_raw_ptr(src: &f32, dst: &mut f32) { 7 | unsafe { core::ptr::write(dst, *src) } 8 | } 9 | #[spirv(fragment)] 10 | pub fn main(i: f32, o: &mut f32) { 11 | copy_via_raw_ptr(&i, o); 12 | // FIXME(eddyb) above call results in inlining `copy_via_raw_ptr`, 13 | // due to the to `Output` storage classe, so to get the disassembled 14 | // function we also need `Function`-local pointers: 15 | let (src, mut dst) = (0.0, 0.0); 16 | copy_via_raw_ptr(&src, &mut dst); 17 | } 18 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/asm/block_tracking_fail.stderr: -------------------------------------------------------------------------------- 1 | error: `noreturn` requires a terminator at the end 2 | --> $DIR/block_tracking_fail.rs:11:15 3 | | 4 | LL | asm!("", options(noreturn)); 5 | | ^ 6 | 7 | error: trailing terminator `OpUnreachable` requires `options(noreturn)` 8 | --> $DIR/block_tracking_fail.rs:18:15 9 | | 10 | LL | asm!("OpUnreachable"); 11 | | ^^^^^^^^^^^^^ 12 | 13 | error: expected `OpLabel` after terminator `OpKill` 14 | --> $DIR/block_tracking_fail.rs:26:14 15 | | 16 | LL | "OpKill", 17 | | ^^^^^^ 18 | 19 | error: aborting due to 3 previous errors 20 | 21 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/ptr/allocate_const_scalar.stderr: -------------------------------------------------------------------------------- 1 | warning: the feature `ptr_internals` is internal to the compiler or standard library 2 | --> $DIR/allocate_const_scalar.rs:6:12 3 | | 4 | LL | #![feature(ptr_internals)] 5 | | ^^^^^^^^^^^^^ 6 | | 7 | = note: using it is strongly discouraged 8 | = note: `#[warn(internal_features)]` on by default 9 | 10 | error: Type not supported in Input or Output declarations 11 | --> $DIR/allocate_const_scalar.rs:15:21 12 | | 13 | LL | pub fn main(output: &mut Unique<()>) { 14 | | ^^^^^^^^^^^^^^^ 15 | 16 | error: aborting due to 1 previous error; 1 warning emitted 17 | 18 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/issue-373.rs: -------------------------------------------------------------------------------- 1 | #![crate_name = "issue_373"] 2 | 3 | // Test that returning a single-scalar-field `#[repr(C)] struct` doesn't generate 4 | // unsupported pointer casts (the problem was the use of `PassMode::Cast`, through 5 | // the default Rust ABI adjustments, that we now override through query hooks). 6 | 7 | // build-pass 8 | // compile-flags: -C llvm-args=--disassemble-entry=main 9 | 10 | use spirv_std::spirv; 11 | 12 | #[derive(Copy, Clone)] 13 | #[repr(C)] 14 | pub struct S { 15 | x: f32, 16 | } 17 | 18 | fn f() -> S { 19 | S { x: 2.0 } 20 | } 21 | 22 | #[spirv(fragment)] 23 | pub fn main(out: &mut f32) { 24 | *out = f().x; 25 | } 26 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_get_intersection_type_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 10 | unsafe { 11 | spirv_std::ray_query!(let mut handle); 12 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 13 | handle.get_candidate_intersection_type(); 14 | handle.get_committed_intersection_type(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/const-float-cast.stderr: -------------------------------------------------------------------------------- 1 | OpCapability Shader 2 | OpCapability Float64 3 | OpMemoryModel Logical Simple 4 | OpEntryPoint Fragment %1 "main" %2 5 | OpExecutionMode %1 OriginUpperLeft 6 | %3 = OpString "$DIR/const-float-cast.rs" 7 | OpName %2 "output" 8 | OpDecorate %2 Location 0 9 | %4 = OpTypeFloat 32 10 | %5 = OpTypePointer Output %4 11 | %6 = OpTypeVoid 12 | %7 = OpTypeFunction %6 13 | %8 = OpTypeFloat 64 14 | %9 = OpConstant %8 4638387860618067575 15 | %2 = OpVariable %5 Output 16 | %10 = OpConstant %8 4626463454704697344 17 | %11 = OpConstant %4 1065353216 18 | %12 = OpConstant %4 1101266944 19 | %13 = OpTypeInt 32 0 20 | %14 = OpConstant %13 42 21 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/ptr_write_method.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C llvm-args=--disassemble-fn=ptr_write_method::copy_via_raw_ptr 3 | 4 | use spirv_std::spirv; 5 | 6 | fn copy_via_raw_ptr(src: &f32, dst: &mut f32) { 7 | unsafe { (dst as *mut f32).write(*src) } 8 | } 9 | #[spirv(fragment)] 10 | pub fn main(i: f32, o: &mut f32) { 11 | copy_via_raw_ptr(&i, o); 12 | // FIXME(eddyb) above call results in inlining `copy_via_raw_ptr`, 13 | // due to the to `Output` storage classe, so to get the disassembled 14 | // function we also need `Function`-local pointers: 15 | let (src, mut dst) = (0.0, 0.0); 16 | copy_via_raw_ptr(&src, &mut dst); 17 | } 18 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_get_intersection_t_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 10 | unsafe { 11 | spirv_std::ray_query!(let mut handle); 12 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 13 | let t = handle.get_candidate_intersection_t(); 14 | let t = handle.get_committed_intersection_t(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_broadcast_first.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+GroupNonUniform,+GroupNonUniformBallot,+ext:SPV_KHR_vulkan_memory_model 3 | // compile-flags: -C llvm-args=--disassemble-fn=subgroup_broadcast_first::subgroup_broadcast_first 4 | // normalize-stderr-test "OpLine .*\n" -> "" 5 | 6 | use glam::Vec3; 7 | use spirv_std::spirv; 8 | 9 | unsafe fn subgroup_broadcast_first(vec: Vec3) -> Vec3 { 10 | spirv_std::arch::subgroup_broadcast_first::(vec) 11 | } 12 | 13 | #[spirv(compute(threads(1, 1, 1)))] 14 | pub fn main() { 15 | unsafe { 16 | subgroup_broadcast_first(Vec3::new(1., 2., 3.)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/ptr_read_method.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C llvm-args=--disassemble-fn=ptr_read_method::copy_via_raw_ptr 3 | 4 | use spirv_std::spirv; 5 | 6 | fn copy_via_raw_ptr(src: &f32, dst: &mut f32) { 7 | unsafe { *dst = (src as *const f32).read() } 8 | } 9 | #[spirv(fragment)] 10 | pub fn main(i: f32, o: &mut f32) { 11 | copy_via_raw_ptr(&i, o); 12 | // FIXME(eddyb) above call results in inlining `copy_via_raw_ptr`, 13 | // due to the to `Output` storage classe, so to get the disassembled 14 | // function we also need `Function`-local pointers: 15 | let (src, mut dst) = (0.0, 0.0); 16 | copy_via_raw_ptr(&src, &mut dst); 17 | } 18 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/issue-731.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpLabel 3 | OpLine %5 11 12 4 | %6 = OpLoad %7 %8 5 | %9 = OpCompositeExtract %10 %6 0 6 | %11 = OpCompositeExtract %10 %6 1 7 | %12 = OpCompositeExtract %10 %6 2 8 | %13 = OpCompositeConstruct %14 %9 %11 %12 9 | OpLine %5 12 4 10 | %15 = OpCompositeExtract %10 %13 0 11 | %16 = OpFAdd %10 %15 %17 12 | %18 = OpCompositeInsert %14 %16 %13 0 13 | OpLine %5 13 4 14 | %19 = OpCompositeExtract %10 %18 0 15 | %20 = OpCompositeExtract %10 %18 1 16 | %21 = OpCompositeExtract %10 %18 2 17 | %22 = OpCompositeConstruct %7 %19 %20 %21 18 | OpStore %23 %22 19 | OpNoLine 20 | OpReturn 21 | OpFunctionEnd 22 | -------------------------------------------------------------------------------- /tests/difftests/lib/src/scaffold/shader/mod.rs: -------------------------------------------------------------------------------- 1 | mod rust_gpu_shader; 2 | mod wgsl_shader; 3 | 4 | pub use rust_gpu_shader::RustComputeShader; 5 | pub use wgsl_shader::WgslComputeShader; 6 | 7 | /// Trait for shaders that can provide SPIRV bytes. 8 | pub trait SpirvShader { 9 | /// Returns the SPIRV bytes and entry point name. 10 | fn spirv_bytes(&self) -> anyhow::Result<(Vec, String)>; 11 | } 12 | 13 | /// Trait for shaders that can create wgpu modules. 14 | pub trait WgpuShader { 15 | /// Creates a wgpu shader module. 16 | fn create_module( 17 | &self, 18 | device: &wgpu::Device, 19 | ) -> anyhow::Result<(wgpu::ShaderModule, Option)>; 20 | } 21 | -------------------------------------------------------------------------------- /examples/shaders/simplest-shader/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(target_arch = "spirv", no_std)] 2 | // HACK(eddyb) can't easily see warnings otherwise from `spirv-builder` builds. 3 | #![deny(warnings)] 4 | 5 | use shared::glam::{Vec4, vec4}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main_fs(output: &mut Vec4) { 10 | *output = vec4(1.0, 0.0, 0.0, 1.0); 11 | } 12 | 13 | #[spirv(vertex)] 14 | pub fn main_vs( 15 | #[spirv(vertex_index)] vert_id: i32, 16 | #[spirv(position, invariant)] out_pos: &mut Vec4, 17 | ) { 18 | *out_pos = vec4( 19 | (vert_id - 1) as f32, 20 | ((vert_id & 1) * 2 - 1) as f32, 21 | 0.0, 22 | 1.0, 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/complex_image_sample_inst.stderr: -------------------------------------------------------------------------------- 1 | %1 = OpFunction %2 None %3 2 | %4 = OpFunctionParameter %2 3 | %5 = OpFunctionParameter %6 4 | %7 = OpFunctionParameter %6 5 | %8 = OpLabel 6 | %9 = OpCompositeExtract %10 %5 0 7 | %11 = OpCompositeExtract %10 %5 1 8 | %12 = OpCompositeConstruct %6 %9 %11 9 | %13 = OpCompositeExtract %10 %7 0 10 | %14 = OpCompositeExtract %10 %7 1 11 | %15 = OpCompositeConstruct %6 %13 %14 12 | OpLine %16 29 13 13 | %17 = OpAccessChain %18 %19 %20 14 | OpLine %16 30 13 15 | %21 = OpLoad %22 %17 16 | OpLine %16 34 13 17 | %23 = OpImageSampleProjExplicitLod %2 %21 %4 Grad %12 %15 18 | OpNoLine 19 | OpReturnValue %23 20 | OpFunctionEnd 21 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/core/ref/member_ref_arg.stderr: -------------------------------------------------------------------------------- 1 | warning: `#[inline(never)]` function `member_ref_arg::f` has been inlined 2 | --> $DIR/member_ref_arg.rs:14:4 3 | | 4 | LL | fn f(x: &u32) {} 5 | | ^ 6 | | 7 | = note: inlining was required due to illegal (pointer) argument 8 | = note: called from `member_ref_arg::main` 9 | 10 | warning: `#[inline(never)]` function `member_ref_arg::g` has been inlined 11 | --> $DIR/member_ref_arg.rs:17:4 12 | | 13 | LL | fn g(xy: (&u32, &u32)) {} 14 | | ^ 15 | | 16 | = note: inlining was required due to illegal (pointer) argument 17 | = note: called from `member_ref_arg::main` 18 | 19 | warning: 2 warnings emitted 20 | 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/enhancement.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Enhancement 3 | about: Propose a minor improvement or feature to the project. 4 | title: "(My enhancement)" 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | 20 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_get_intersection_primitive_index_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 10 | unsafe { 11 | spirv_std::ray_query!(let mut handle); 12 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 13 | handle.get_candidate_intersection_primitive_index(); 14 | handle.get_committed_intersection_primitive_index(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/custom_entry_point.rs: -------------------------------------------------------------------------------- 1 | #![crate_name = "custom_entry_point"] 2 | 3 | // build-pass 4 | // compile-flags: -C llvm-args=--disassemble-globals 5 | // normalize-stderr-test "OpCapability VulkanMemoryModel\n" -> "" 6 | // normalize-stderr-test "OpSource .*\n" -> "" 7 | // normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> "" 8 | // normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple" 9 | 10 | // HACK(eddyb) `compiletest` handles `ui\dis\`, but not `ui\\dis\\`, on Windows. 11 | // normalize-stderr-test "ui/dis/" -> "$$DIR/" 12 | 13 | use spirv_std::spirv; 14 | 15 | #[spirv(fragment(entry_point_name = "hello_world"))] 16 | pub fn main() {} 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_get_intersection_front_face_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 10 | unsafe { 11 | spirv_std::ray_query!(let mut handle); 12 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 13 | assert!(handle.get_candidate_intersection_front_face()); 14 | assert!(handle.get_committed_intersection_front_face()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/asm/block_tracking_pass.rs: -------------------------------------------------------------------------------- 1 | // Tests validating tracking of basic blocks 2 | // within the `asm!` macro. 3 | // build-pass 4 | 5 | use core::arch::asm; 6 | use spirv_std::spirv; 7 | 8 | fn asm_label() { 9 | unsafe { 10 | asm!( 11 | "OpKill", // close active block 12 | "%unused = OpLabel", // open new block 13 | ); 14 | } 15 | } 16 | 17 | fn asm_noreturn_single() -> ! { 18 | unsafe { 19 | asm!( 20 | "OpKill", // close active block 21 | options(noreturn), 22 | ); 23 | } 24 | } 25 | 26 | #[spirv(fragment)] 27 | pub fn main() { 28 | asm_label(); 29 | asm_noreturn_single(); 30 | } 31 | -------------------------------------------------------------------------------- /tests/compiletests/ui/spirv-attr/invalid-matrix-type.stderr: -------------------------------------------------------------------------------- 1 | error: `#[spirv(matrix)]` must have 2, 3 or 4 members 2 | --> $DIR/invalid-matrix-type.rs:7:1 3 | | 4 | LL | pub struct _FewerFields { 5 | | ^^^^^^^^^^^^^^^^^^^^^^^ 6 | 7 | error: `#[spirv(matrix)]` type fields must all be vectors 8 | --> $DIR/invalid-matrix-type.rs:12:1 9 | | 10 | LL | pub struct _NotVectorField { 11 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 12 | | 13 | = note: field type is f32 14 | 15 | error: `#[spirv(matrix)]` member types must all be the same 16 | --> $DIR/invalid-matrix-type.rs:19:1 17 | | 18 | LL | pub struct _DifferentType { 19 | | ^^^^^^^^^^^^^^^^^^^^^^^^^ 20 | 21 | error: aborting due to 3 previous errors 22 | 23 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_get_intersection_instance_id_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 10 | unsafe { 11 | spirv_std::ray_query!(let mut handle); 12 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 13 | let id = handle.get_candidate_intersection_instance_id(); 14 | let id = handle.get_committed_intersection_instance_id(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_get_intersection_geometry_index_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 10 | unsafe { 11 | spirv_std::ray_query!(let mut handle); 12 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 13 | let t = handle.get_candidate_intersection_geometry_index(); 14 | let t = handle.get_committed_intersection_geometry_index(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/entry-pass-mode-cast-array.rs: -------------------------------------------------------------------------------- 1 | // This is a similar setup to the `issue-731` test, but instead of "just" the 2 | // missing copy out of the global (`Input`) `OpVariable`, small enough types 3 | // would fail much earlier (by generating unsupported pointer casts). 4 | // (Just like `issue-373`, the problem was the use of `PassMode::Cast`, through 5 | // the default Rust ABI adjustments, that we now override through query hooks) 6 | 7 | // build-pass 8 | // compile-flags: -C llvm-args=--disassemble-entry=main 9 | 10 | use spirv_std::spirv; 11 | 12 | #[spirv(fragment)] 13 | pub fn main(mut in_array: [f32; 2], out_array: &mut [f32; 2]) { 14 | in_array[0] += 1.0; 15 | *out_array = in_array; 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/consts/shallow-ref.rs: -------------------------------------------------------------------------------- 1 | // Test `&'static T` constants where the `T` values don't themselves contain 2 | // references, and where the `T` values aren't immediately loaded from. 3 | 4 | // build-pass 5 | 6 | use spirv_std::spirv; 7 | 8 | use glam::{Mat2, Vec2}; 9 | 10 | #[inline(never)] 11 | fn scalar_load(r: &'static u32) -> u32 { 12 | *r 13 | } 14 | 15 | const ROT90: Mat2 = Mat2::from_cols_array_2d(&[[0.0, 1.0], [-1.0, 0.0]]); 16 | 17 | #[spirv(fragment)] 18 | pub fn main(scalar_out: &mut u32, vec_in: Vec2, bool_out: &mut u32, vec_out: &mut Vec2) { 19 | *scalar_out = scalar_load(&123); 20 | *bool_out = (vec_in == Vec2::ZERO) as u32; 21 | *vec_out = ROT90.transpose() * vec_in; 22 | } 23 | -------------------------------------------------------------------------------- /docs/src/SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | - [Introduction](./introduction.md) 4 | - [Contributing to Rust-GPU]() 5 | - [Building](./building-rust-gpu.md) 6 | - [Testing](./testing.md) 7 | - [Debugging](./tracing) 8 | - [Tracing](./tracing.md) 9 | - [Minimizing bugs in SPIR-V](./spirv-minimization.md) 10 | - ["Codegen args" (flags/options) supported by the Rust-GPU codegen backend](./codegen-args.md) 11 | - [Publishing Rust-GPU on crates.io](./publishing-rust-gpu.md) 12 | - [Platform Support](./platform-support.md) 13 | - [Writing Shader Crates](./writing-shader-crates.md) 14 | - [Features]() 15 | - [Attribute syntax](./attributes.md) 16 | - [Inline Assembly](./inline-asm.md) 17 | - [Image type syntax](./image.md) 18 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/asm/infer-access-chain-array.rs: -------------------------------------------------------------------------------- 1 | // Tests that `asm!` can infer the result type of `OpAccessChain`, 2 | // when used to index arrays. 3 | 4 | // build-pass 5 | 6 | use core::arch::asm; 7 | use glam::Vec4; 8 | use spirv_std::spirv; 9 | 10 | #[spirv(fragment)] 11 | pub fn main(#[spirv(push_constant)] array_in: &[Vec4; 16], #[spirv(flat)] i: u32, out: &mut Vec4) { 12 | unsafe { 13 | asm!( 14 | "%val_ptr = OpAccessChain _ {array_ptr} {index}", 15 | "%val = OpLoad _ %val_ptr", 16 | "OpStore {out_ptr} %val", 17 | array_ptr = in(reg) array_in, 18 | index = in(reg) i, 19 | out_ptr = in(reg) out, 20 | ); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /crates/spirv-std/release.toml: -------------------------------------------------------------------------------- 1 | # this crate updates the changelog in the root of the repo 2 | pre-release-replacements = [ 3 | { file = "../../CHANGELOG.md", search = "## \\[Unreleased\\]", replace = "## [{{version}}] - {{date}}" }, 4 | { file = "../../CHANGELOG.md", search = "\\[Unreleased\\]: https://github.com/rust-gpu/rust-gpu/compare/v\\d+.\\d+.\\d+...HEAD", replace = "[{{version}}]: https://github.com/rust-gpu/rust-gpu/releases/tag/{{tag_name}}" }, 5 | { file = "../../CHANGELOG.md", search = "", replace = "\n## [Unreleased]" }, 6 | { file = "../../CHANGELOG.md", search = "", replace = "\n[Unreleased]: https://github.com/rust-gpu/rust-gpu/compare/{{tag_name}}...HEAD" }, 7 | ] 8 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/mesh_shader_output_points.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // only-vulkan1.2 3 | // compile-flags: -Ctarget-feature=+MeshShadingEXT,+ext:SPV_EXT_mesh_shader 4 | 5 | use spirv_std::arch::set_mesh_outputs_ext; 6 | use spirv_std::glam::{UVec2, Vec4}; 7 | use spirv_std::spirv; 8 | 9 | #[spirv(mesh_ext( 10 | threads(1), 11 | output_vertices = 1, 12 | output_primitives_ext = 1, 13 | output_points 14 | ))] 15 | pub fn main( 16 | #[spirv(position)] positions: &mut [Vec4; 1], 17 | #[spirv(primitive_point_indices_ext)] indices: &mut [u32; 1], 18 | ) { 19 | unsafe { 20 | set_mesh_outputs_ext(1, 1); 21 | } 22 | 23 | positions[0] = Vec4::new(-0.5, 0.5, 0.0, 1.0); 24 | 25 | indices[0] = 0; 26 | } 27 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/sample_depth_reference_with_project_coordinate/sample_gradient.rs: -------------------------------------------------------------------------------- 1 | // Test `OpImageSampleProjDrefExplicitLod` 2 | // build-pass 3 | 4 | use spirv_std::spirv; 5 | use spirv_std::{Image, Sampler}; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(descriptor_set = 0, binding = 0)] image: &Image!(2D, type=f32, sampled), 10 | #[spirv(descriptor_set = 1, binding = 1)] sampler: &Sampler, 11 | output: &mut f32, 12 | ) { 13 | let v2_dx = glam::Vec2::new(0.0, 1.0); 14 | let v2_dy = glam::Vec2::new(0.0, 1.0); 15 | let v3 = glam::Vec3A::new(0.0, 0.0, 1.0); 16 | *output = image.sample_depth_reference_with_project_coordinate_by_gradient( 17 | *sampler, v3, 1.0, v2_dx, v2_dy, 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /tests/compiletests/ui/storage_class/runtime_descriptor_array_error.stderr: -------------------------------------------------------------------------------- 1 | error: descriptor indexing must use &RuntimeArray, not &[T] 2 | --> $DIR/runtime_descriptor_array_error.rs:7:52 3 | | 4 | LL | #[spirv(descriptor_set = 0, binding = 0)] one: &[Image!(2D, type=f32, sampled)], 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6 | 7 | warning: use &[T] instead of &RuntimeArray 8 | --> $DIR/runtime_descriptor_array_error.rs:8:61 9 | | 10 | LL | #[spirv(uniform, descriptor_set = 0, binding = 0)] two: &RuntimeArray, 11 | | ^^^^^^^^^^^^^^^^^^ 12 | 13 | error: aborting due to 1 previous error; 1 warning emitted 14 | 15 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_ballot_bit_count.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+GroupNonUniform,+GroupNonUniformBallot,+ext:SPV_KHR_vulkan_memory_model 3 | // compile-flags: -C llvm-args=--disassemble-fn=subgroup_ballot_bit_count::subgroup_ballot_bit_count 4 | // normalize-stderr-test "OpLine .*\n" -> "" 5 | 6 | use spirv_std::arch::{GroupOperation, SubgroupMask}; 7 | use spirv_std::spirv; 8 | 9 | unsafe fn subgroup_ballot_bit_count(ballot: SubgroupMask) -> u32 { 10 | spirv_std::arch::subgroup_ballot_bit_count(ballot) 11 | } 12 | 13 | #[spirv(compute(threads(1, 1, 1)))] 14 | pub fn main() { 15 | unsafe { 16 | subgroup_ballot_bit_count(spirv_std::arch::subgroup_ballot(true)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_cluster_size_0_fail.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+GroupNonUniform,+GroupNonUniformArithmetic,+GroupNonUniformClustered,+ext:SPV_KHR_vulkan_memory_model 3 | // normalize-stderr-test "\S*/crates/spirv-std/src/" -> "$$SPIRV_STD_SRC/" 4 | 5 | use glam::UVec3; 6 | use spirv_std::arch::{GroupOperation, SubgroupMask}; 7 | use spirv_std::spirv; 8 | 9 | unsafe fn subgroup_test_fail(value: u32) -> u32 { 10 | spirv_std::arch::subgroup_clustered_i_add::<0, _>(value) 11 | } 12 | 13 | #[spirv(compute(threads(32, 1, 1)))] 14 | pub fn main(#[spirv(local_invocation_id)] local_invocation_id: UVec3) { 15 | unsafe { 16 | subgroup_test_fail(local_invocation_id.x); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_get_intersection_instance_custom_index_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 10 | unsafe { 11 | spirv_std::ray_query!(let mut handle); 12 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 13 | let index = handle.get_candidate_intersection_instance_custom_index(); 14 | let index = handle.get_committed_intersection_instance_custom_index(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /crates/rustc_codegen_spirv/src/target_feature.rs: -------------------------------------------------------------------------------- 1 | use rustc_span::symbol::Symbol; 2 | 3 | #[derive(Clone, Debug, Eq, PartialEq)] 4 | pub enum TargetFeature { 5 | Extension(Symbol), 6 | Capability(rspirv::spirv::Capability), 7 | } 8 | 9 | impl std::str::FromStr for TargetFeature { 10 | type Err = String; 11 | 12 | fn from_str(input: &str) -> Result { 13 | const EXT_PREFIX: &str = "ext:"; 14 | 15 | if let Some(input) = input.strip_prefix(EXT_PREFIX) { 16 | Ok(Self::Extension(Symbol::intern(input))) 17 | } else { 18 | Ok(Self::Capability(input.parse().map_err(|_err| { 19 | format!("Invalid Capability: `{input}`") 20 | })?)) 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/consts/nested-ref.stderr: -------------------------------------------------------------------------------- 1 | warning: `#[inline(never)]` function `nested_ref::deep_load` has been inlined 2 | --> $DIR/nested-ref.rs:12:4 3 | | 4 | LL | fn deep_load(r: &'static &'static u32) -> u32 { 5 | | ^^^^^^^^^ 6 | | 7 | = note: inlining was required due to illegal parameter type 8 | = note: called from `nested_ref::main` 9 | 10 | warning: `#[inline(never)]` function `nested_ref::deep_transpose` has been inlined 11 | --> $DIR/nested-ref.rs:19:4 12 | | 13 | LL | fn deep_transpose(r: &'static &'static Mat2) -> Mat2 { 14 | | ^^^^^^^^^^^^^^ 15 | | 16 | = note: inlining was required due to illegal parameter type 17 | = note: called from `nested_ref::main` 18 | 19 | warning: 2 warnings emitted 20 | 21 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_cluster_size_non_power_of_two_fail.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+GroupNonUniform,+GroupNonUniformArithmetic,+GroupNonUniformClustered,+ext:SPV_KHR_vulkan_memory_model 3 | // normalize-stderr-test "\S*/crates/spirv-std/src/" -> "$$SPIRV_STD_SRC/" 4 | 5 | use glam::UVec3; 6 | use spirv_std::arch::{GroupOperation, SubgroupMask}; 7 | use spirv_std::spirv; 8 | 9 | unsafe fn subgroup_test_fail(value: u32) -> u32 { 10 | spirv_std::arch::subgroup_clustered_i_add::<5, _>(value) 11 | } 12 | 13 | #[spirv(compute(threads(32, 1, 1)))] 14 | pub fn main(#[spirv(local_invocation_id)] local_invocation_id: UVec3) { 15 | unsafe { 16 | subgroup_test_fail(local_invocation_id.x); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_get_intersection_object_ray_origin_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 10 | unsafe { 11 | spirv_std::ray_query!(let mut handle); 12 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 13 | let origin: glam::Vec3 = handle.get_candidate_intersection_object_ray_origin(); 14 | let origin: glam::Vec3 = handle.get_committed_intersection_object_ray_origin(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_i_add_reduce.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+GroupNonUniform,+GroupNonUniformArithmetic,+ext:SPV_KHR_vulkan_memory_model 3 | // compile-flags: -C llvm-args=--disassemble-fn=subgroup_i_add_reduce::subgroup_i_add_reduce 4 | // normalize-stderr-test "OpLine .*\n" -> "" 5 | 6 | use glam::UVec3; 7 | use spirv_std::arch::{GroupOperation, SubgroupMask}; 8 | use spirv_std::spirv; 9 | 10 | unsafe fn subgroup_i_add_reduce(value: u32) -> u32 { 11 | spirv_std::arch::subgroup_i_add(value) 12 | } 13 | 14 | #[spirv(compute(threads(32, 1, 1)))] 15 | pub fn main(#[spirv(local_invocation_id)] local_invocation_id: UVec3) { 16 | unsafe { 17 | subgroup_i_add_reduce(local_invocation_id.x); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/implicit_not_in_fragment.stderr: -------------------------------------------------------------------------------- 1 | error: ImageSampleImplicitLod cannot be used outside a fragment shader 2 | | 3 | = note: Stack: 4 | >::sample:: 5 | implicit_not_in_fragment::deeper_stack 6 | implicit_not_in_fragment::deep_stack 7 | implicit_not_in_fragment::main 8 | main 9 | 10 | error: ImageSampleImplicitLod cannot be used outside a fragment shader 11 | | 12 | = note: Stack: 13 | >::sample:: 14 | implicit_not_in_fragment::main 15 | main 16 | 17 | error: aborting due to 2 previous errors 18 | 19 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_get_intersection_barycentrics_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 10 | unsafe { 11 | spirv_std::ray_query!(let mut handle); 12 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 13 | let barycentric_coords: glam::Vec2 = handle.get_candidate_intersection_barycentrics(); 14 | let barycentric_coords: glam::Vec2 = handle.get_committed_intersection_barycentrics(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_builtins.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+GroupNonUniformBallot,+ext:SPV_KHR_vulkan_memory_model 3 | 4 | use spirv_std::arch::SubgroupMask; 5 | use spirv_std::spirv; 6 | 7 | #[spirv(compute(threads(1, 1, 1)))] 8 | pub fn main( 9 | #[spirv(subgroup_id)] subgroup_id: u32, 10 | #[spirv(subgroup_local_invocation_id)] subgroup_local_invocation_id: u32, 11 | #[spirv(subgroup_eq_mask)] subgroup_eq_mask: SubgroupMask, 12 | #[spirv(subgroup_ge_mask)] subgroup_ge_mask: SubgroupMask, 13 | #[spirv(subgroup_gt_mask)] subgroup_gt_mask: SubgroupMask, 14 | #[spirv(subgroup_le_mask)] subgroup_le_mask: SubgroupMask, 15 | #[spirv(subgroup_lt_mask)] subgroup_lt_mask: SubgroupMask, 16 | ) { 17 | } 18 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/consts/u32-from-u64-fail.stderr: -------------------------------------------------------------------------------- 1 | error[E0277]: the trait bound `u32: From` is not satisfied 2 | --> $DIR/u32-from-u64-fail.rs:14:17 3 | | 4 | LL | let value = u32::from(K); 5 | | ^^^ the trait `From` is not implemented for `u32` 6 | | 7 | = help: the following other types implement trait `From`: 8 | `u32` implements `From` 9 | `u32` implements `From` 10 | `u32` implements `From` 11 | `u32` implements `From` 12 | `u32` implements `From` 13 | `u32` implements `From` 14 | 15 | error: aborting due to 1 previous error 16 | 17 | For more information about this error, try `rustc --explain E0277`. 18 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/abi/vector_layout/cpu/src/shader_driver.rs: -------------------------------------------------------------------------------- 1 | use crate::glam_features::GlamFeatures; 2 | use crate::layout::{LAYOUT_LEN, LAYOUT_RANGE}; 3 | use difftest::config::Config; 4 | use difftest::scaffold::compute::{BufferConfig, RustComputeShader, WgpuComputeTestMultiBuffer}; 5 | 6 | pub fn run(glam_feature: GlamFeatures) { 7 | glam_feature.assert(); 8 | let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap(); 9 | assert_eq!(0, LAYOUT_RANGE.start); 10 | let test = WgpuComputeTestMultiBuffer::new( 11 | RustComputeShader::default(), 12 | [LAYOUT_RANGE.end as u32, 1, 1], 13 | Vec::from(&[BufferConfig::writeback(LAYOUT_LEN * size_of::())]), 14 | ); 15 | test.run_test(&config).unwrap(); 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_get_intersection_object_ray_direction_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 10 | unsafe { 11 | spirv_std::ray_query!(let mut handle); 12 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 13 | let direction: glam::Vec3 = handle.get_candidate_intersection_object_ray_direction(); 14 | let direction: glam::Vec3 = handle.get_committed_intersection_object_ray_direction(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/gather_err.rs: -------------------------------------------------------------------------------- 1 | // build-fail 2 | // normalize-stderr-test "\S*/crates/spirv-std/src/" -> "$$SPIRV_STD_SRC/" 3 | // compile-flags: -Ctarget-feature=+Sampled1D 4 | 5 | use spirv_std::{Image, Sampler, arch, spirv}; 6 | 7 | #[spirv(fragment)] 8 | pub fn main( 9 | #[spirv(descriptor_set = 0, binding = 0)] image1d: &Image!(1D, type=f32, sampled), 10 | #[spirv(descriptor_set = 2, binding = 1)] image3d: &Image!(3D, type=f32, sampled), 11 | #[spirv(descriptor_set = 3, binding = 3)] sampler: &Sampler, 12 | output: &mut glam::Vec4, 13 | ) { 14 | let v3 = glam::Vec3::new(0.0, 1.0, 0.5); 15 | let r1: glam::Vec4 = image1d.gather(*sampler, 0.0f32, 0); 16 | let r2: glam::Vec4 = image3d.gather(*sampler, v3, 0); 17 | *output = r1 + r2; 18 | } 19 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/spec_constant-attr.stderr: -------------------------------------------------------------------------------- 1 | OpCapability Shader 2 | OpMemoryModel Logical Simple 3 | OpEntryPoint Fragment %1 "main" %2 4 | OpExecutionMode %1 OriginUpperLeft 5 | %3 = OpString "$DIR/spec_constant-attr.rs" 6 | OpName %4 "no_default" 7 | OpName %5 "default_0" 8 | OpName %6 "default_123" 9 | OpName %7 "max_id_and_default" 10 | OpName %2 "out" 11 | OpDecorate %4 SpecId 1 12 | OpDecorate %5 SpecId 2 13 | OpDecorate %6 SpecId 123 14 | OpDecorate %7 SpecId 4294967295 15 | OpDecorate %2 Location 0 16 | %8 = OpTypeInt 32 0 17 | %9 = OpTypePointer Output %8 18 | %10 = OpTypeVoid 19 | %11 = OpTypeFunction %10 20 | %4 = OpSpecConstant %8 0 21 | %5 = OpSpecConstant %8 0 22 | %6 = OpSpecConstant %8 123 23 | %7 = OpSpecConstant %8 4294967295 24 | %2 = OpVariable %9 Output 25 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_get_intersection_shader_binding_table_record_offset_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 6 | use spirv_std::spirv; 7 | 8 | #[spirv(fragment)] 9 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 10 | unsafe { 11 | spirv_std::ray_query!(let mut handle); 12 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 13 | let offset = handle.get_candidate_intersection_shader_binding_table_record_offset(); 14 | let offset = handle.get_committed_intersection_shader_binding_table_record_offset(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/trace_ray_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayTracingKHR,+ext:SPV_KHR_ray_tracing 3 | 4 | use spirv_std::spirv; 5 | 6 | #[spirv(ray_generation)] 7 | pub fn main( 8 | #[spirv(descriptor_set = 0, binding = 0)] 9 | acceleration_structure: &spirv_std::ray_tracing::AccelerationStructure, 10 | #[spirv(ray_payload)] payload: &mut glam::Vec3, 11 | ) { 12 | unsafe { 13 | acceleration_structure.trace_ray( 14 | spirv_std::ray_tracing::RayFlags::NONE, 15 | 0, 16 | 0, 17 | 0, 18 | 0, 19 | glam::vec3(1.0, 2.0, 3.0), 20 | 0.5, 21 | glam::vec3(3.0, 2.0, 1.0), 22 | 1.0, 23 | payload, 24 | ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/ray_query_get_intersection_object_to_world_khr.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -Ctarget-feature=+RayQueryKHR,+ext:SPV_KHR_ray_query 3 | 4 | use glam::Vec3; 5 | use spirv_std::matrix::Matrix4x3; 6 | use spirv_std::ray_tracing::{AccelerationStructure, RayFlags, RayQuery}; 7 | use spirv_std::spirv; 8 | 9 | #[spirv(fragment)] 10 | pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStructure) { 11 | unsafe { 12 | spirv_std::ray_query!(let mut handle); 13 | handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); 14 | let matrix: Matrix4x3 = handle.get_candidate_intersection_object_to_world(); 15 | let matrix: Matrix4x3 = handle.get_committed_intersection_object_to_world(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/query/sampled_image_rect_query_size_lod_err.rs: -------------------------------------------------------------------------------- 1 | // build-fail 2 | // normalize-stderr-test "\S*/crates/spirv-std/src/" -> "$SPIRV_STD_SRC/" 3 | // compile-flags: -C target-feature=+ImageQuery,+SampledRect 4 | // ignore-vulkan1.0 5 | // ignore-vulkan1.1 6 | // ignore-vulkan1.1spv1.4 7 | // ignore-vulkan1.2 8 | // ignore-vulkan1.3 9 | // ignore-vulkan1.4 10 | 11 | use spirv_std::{Image, arch, image::SampledImage, spirv}; 12 | 13 | #[spirv(fragment)] 14 | pub fn main( 15 | #[spirv(descriptor_set = 0, binding = 0)] rect_sampled: &SampledImage< 16 | Image!(rect, type=f32, sampled), 17 | >, 18 | output: &mut glam::UVec2, 19 | ) { 20 | // This should fail because rect images don't support query_size_lod 21 | *output = rect_sampled.query_size_lod(0); 22 | } 23 | -------------------------------------------------------------------------------- /.github/workflows/deploy_docs.yml: -------------------------------------------------------------------------------- 1 | name: Deploy docs 2 | on: 3 | push: 4 | branches: 5 | - main 6 | jobs: 7 | build: 8 | runs-on: macos-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - run: brew install mdbook spirv-tools 12 | - run: mkdir docs-build/ 13 | - run: $(cd docs && mdbook build -d ../docs-build/book) 14 | - run: .github/workflows/docs.sh 15 | - run: mv target/doc docs-build/api 16 | - uses: JamesIves/github-pages-deploy-action@3.7.1 17 | with: 18 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 19 | BRANCH: gh-pages # The branch the action should deploy to. 20 | FOLDER: docs-build # The folder the action should deploy. 21 | CLEAN: true # Automatically remove deleted files from the deploy branch 22 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_broadcast.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+GroupNonUniform,+GroupNonUniformBallot,+ext:SPV_KHR_vulkan_memory_model 3 | // compile-flags: -C llvm-args=--disassemble-fn=subgroup_broadcast::disassembly 4 | // normalize-stderr-test "OpLine .*\n" -> "" 5 | // ignore-vulkan1.0 6 | // ignore-vulkan1.1 7 | // ignore-spv1.0 8 | // ignore-spv1.1 9 | // ignore-spv1.2 10 | // ignore-spv1.3 11 | // ignore-spv1.4 12 | 13 | use spirv_std::arch::{GroupOperation, SubgroupMask}; 14 | use spirv_std::spirv; 15 | 16 | unsafe fn disassembly(value: i32, id: u32) -> i32 { 17 | spirv_std::arch::subgroup_broadcast(value, id) 18 | } 19 | 20 | #[spirv(compute(threads(32, 1, 1)))] 21 | pub fn main() { 22 | unsafe { 23 | disassembly(42, 5); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/compiletests/ui/dis/asm_op_decorate.stderr: -------------------------------------------------------------------------------- 1 | OpCapability Shader 2 | OpCapability RuntimeDescriptorArray 3 | OpExtension "SPV_EXT_descriptor_indexing" 4 | OpMemoryModel Logical Simple 5 | OpEntryPoint Fragment %1 "main" 6 | OpExecutionMode %1 OriginUpperLeft 7 | %2 = OpString "$DIR/asm_op_decorate.rs" 8 | OpName %3 "asm_op_decorate::main" 9 | OpName %4 "asm_op_decorate::add_decorate" 10 | OpDecorate %5 Binding 0 11 | OpDecorate %5 DescriptorSet 0 12 | %6 = OpTypeVoid 13 | %7 = OpTypeFunction %6 14 | %8 = OpTypeFloat 32 15 | %9 = OpTypeImage %8 2D 0 0 0 1 Unknown 16 | %10 = OpTypeSampledImage %9 17 | %11 = OpTypePointer UniformConstant %10 18 | %12 = OpTypeRuntimeArray %10 19 | %13 = OpTypePointer UniformConstant %12 20 | %5 = OpVariable %13 UniformConstant 21 | %14 = OpTypeInt 32 0 22 | %15 = OpConstant %14 1 23 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/mesh_shader_output_lines.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // only-vulkan1.2 3 | // compile-flags: -Ctarget-feature=+MeshShadingEXT,+ext:SPV_EXT_mesh_shader 4 | 5 | use spirv_std::arch::set_mesh_outputs_ext; 6 | use spirv_std::glam::{UVec2, Vec4}; 7 | use spirv_std::spirv; 8 | 9 | #[spirv(mesh_ext( 10 | threads(1), 11 | output_vertices = 2, 12 | output_primitives_ext = 1, 13 | output_lines_ext 14 | ))] 15 | pub fn main( 16 | #[spirv(position)] positions: &mut [Vec4; 2], 17 | #[spirv(primitive_line_indices_ext)] indices: &mut [UVec2; 1], 18 | ) { 19 | unsafe { 20 | set_mesh_outputs_ext(2, 1); 21 | } 22 | 23 | positions[0] = Vec4::new(-0.5, 0.5, 0.0, 1.0); 24 | positions[1] = Vec4::new(0.5, 0.5, 0.0, 1.0); 25 | 26 | indices[0] = UVec2::new(0, 1); 27 | } 28 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_i_add_exclusive_scan.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+GroupNonUniform,+GroupNonUniformArithmetic,+ext:SPV_KHR_vulkan_memory_model 3 | // compile-flags: -C llvm-args=--disassemble-fn=subgroup_i_add_exclusive_scan::subgroup_i_add_exclusive_scan 4 | // normalize-stderr-test "OpLine .*\n" -> "" 5 | 6 | use glam::UVec3; 7 | use spirv_std::arch::{GroupOperation, SubgroupMask}; 8 | use spirv_std::spirv; 9 | 10 | unsafe fn subgroup_i_add_exclusive_scan(value: u32) -> u32 { 11 | spirv_std::arch::subgroup_exclusive_i_add(value) 12 | } 13 | 14 | #[spirv(compute(threads(32, 1, 1)))] 15 | pub fn main(#[spirv(local_invocation_id)] local_invocation_id: UVec3) { 16 | unsafe { 17 | subgroup_i_add_exclusive_scan(local_invocation_id.x); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_i_add_inclusive_scan.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+GroupNonUniform,+GroupNonUniformArithmetic,+ext:SPV_KHR_vulkan_memory_model 3 | // compile-flags: -C llvm-args=--disassemble-fn=subgroup_i_add_inclusive_scan::subgroup_i_add_inclusive_scan 4 | // normalize-stderr-test "OpLine .*\n" -> "" 5 | 6 | use glam::UVec3; 7 | use spirv_std::arch::{GroupOperation, SubgroupMask}; 8 | use spirv_std::spirv; 9 | 10 | unsafe fn subgroup_i_add_inclusive_scan(value: u32) -> u32 { 11 | spirv_std::arch::subgroup_inclusive_i_add(value) 12 | } 13 | 14 | #[spirv(compute(threads(32, 1, 1)))] 15 | pub fn main(#[spirv(local_invocation_id)] local_invocation_id: UVec3) { 16 | unsafe { 17 | subgroup_i_add_inclusive_scan(local_invocation_id.x); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/difftests/tests/lang/core/ops/const_fold_int/const-fold-cpu/src/shader_driver.rs: -------------------------------------------------------------------------------- 1 | use crate::{EvalResult, INTERESTING_PATTERNS, Variants}; 2 | use difftest::config::Config; 3 | use difftest::scaffold::compute::{BufferConfig, RustComputeShader, WgpuComputeTestMultiBuffer}; 4 | 5 | pub fn run(variant: Variants) { 6 | let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap(); 7 | 8 | let test = WgpuComputeTestMultiBuffer::new( 9 | RustComputeShader::default(), 10 | [64, 1, 1], 11 | Vec::from(&[ 12 | BufferConfig::read_only(&[u32::from(variant)]), 13 | BufferConfig::read_only(&INTERESTING_PATTERNS), 14 | BufferConfig::writeback(size_of::()), 15 | ]), 16 | ); 17 | 18 | test.run_test(&config).unwrap(); 19 | } 20 | -------------------------------------------------------------------------------- /tests/compiletests/ui/arch/subgroup/subgroup_i_add_clustered.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+GroupNonUniform,+GroupNonUniformArithmetic,+GroupNonUniformClustered,+ext:SPV_KHR_vulkan_memory_model 3 | // compile-flags: -C llvm-args=--disassemble-fn=subgroup_i_add_clustered::subgroup_i_add_clustered 4 | // normalize-stderr-test "OpLine .*\n" -> "" 5 | 6 | use glam::UVec3; 7 | use spirv_std::arch::{GroupOperation, SubgroupMask}; 8 | use spirv_std::spirv; 9 | 10 | unsafe fn subgroup_i_add_clustered(value: u32) -> u32 { 11 | spirv_std::arch::subgroup_clustered_i_add::<8, _>(value) 12 | } 13 | 14 | #[spirv(compute(threads(32, 1, 1)))] 15 | pub fn main(#[spirv(local_invocation_id)] local_invocation_id: UVec3) { 16 | unsafe { 17 | subgroup_i_add_clustered(local_invocation_id.x); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/compiletests/ui/lang/consts/nested-ref-in-composite.rs: -------------------------------------------------------------------------------- 1 | // Test `&'static T` constants where the `T` values themselves contain references, 2 | // nested in `OpConstantComposite` (structs/arrays) - currently these are disallowed. 3 | 4 | // build-fail 5 | 6 | use spirv_std::spirv; 7 | 8 | #[inline(never)] 9 | fn pair_deep_load(r: &'static (&'static u32, &'static f32)) -> (u32, f32) { 10 | (*r.0, *r.1) 11 | } 12 | 13 | #[inline(never)] 14 | fn array3_deep_load(r: &'static [&'static u32; 3]) -> [u32; 3] { 15 | [*r[0], *r[1], *r[2]] 16 | } 17 | 18 | #[spirv(fragment)] 19 | pub fn main_pair(pair_out: &mut (u32, f32)) { 20 | *pair_out = pair_deep_load(&(&123, &3.14)); 21 | } 22 | 23 | #[spirv(fragment)] 24 | pub fn main_array3(array3_out: &mut [u32; 3]) { 25 | *array3_out = array3_deep_load(&[&0, &1, &2]); 26 | } 27 | -------------------------------------------------------------------------------- /tests/compiletests/ui/image/issue_527.rs: -------------------------------------------------------------------------------- 1 | // build-pass 2 | // compile-flags: -C target-feature=+StorageImageWriteWithoutFormat 3 | 4 | use glam::*; 5 | use spirv_std::spirv; 6 | 7 | #[spirv(compute(threads(1)))] 8 | pub fn main_cs( 9 | #[spirv(global_invocation_id)] id: UVec3, 10 | #[spirv(storage_buffer, descriptor_set = 0, binding = 0)] points_buffer: &mut [UVec2; 100], 11 | #[spirv(descriptor_set = 1, binding = 1)] image: &spirv_std::Image!(2D, type=f32, sampled=false), 12 | ) { 13 | let position = id.xy(); 14 | for i in 0..100usize { 15 | let p0 = &points_buffer[i]; 16 | let p1 = &points_buffer[i + 1]; 17 | if p0.x == position.x && p1.y == position.y { 18 | unsafe { 19 | image.write(position, vec4(3.0, 2.0, 1.0, 0.0)); 20 | }; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.0.json: -------------------------------------------------------------------------------- 1 | { 2 | "allows-weak-linkage": false, 3 | "arch": "spirv", 4 | "crt-objects-fallback": "false", 5 | "crt-static-allows-dylibs": true, 6 | "crt-static-respected": true, 7 | "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", 8 | "dll-prefix": "", 9 | "dll-suffix": ".spv.json", 10 | "dynamic-linking": true, 11 | "emit-debug-gdb-scripts": false, 12 | "env": "spv1.0", 13 | "linker-flavor": "unix", 14 | "linker-is-gnu": false, 15 | "llvm-target": "spirv-unknown-spv1.0", 16 | "main-needs-argc-argv": false, 17 | "metadata": { 18 | "description": null, 19 | "host_tools": null, 20 | "std": null, 21 | "tier": null 22 | }, 23 | "panic-strategy": "abort", 24 | "simd-types-indirect": false, 25 | "target-pointer-width": "32" 26 | } 27 | -------------------------------------------------------------------------------- /crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.1.json: -------------------------------------------------------------------------------- 1 | { 2 | "allows-weak-linkage": false, 3 | "arch": "spirv", 4 | "crt-objects-fallback": "false", 5 | "crt-static-allows-dylibs": true, 6 | "crt-static-respected": true, 7 | "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", 8 | "dll-prefix": "", 9 | "dll-suffix": ".spv.json", 10 | "dynamic-linking": true, 11 | "emit-debug-gdb-scripts": false, 12 | "env": "spv1.1", 13 | "linker-flavor": "unix", 14 | "linker-is-gnu": false, 15 | "llvm-target": "spirv-unknown-spv1.1", 16 | "main-needs-argc-argv": false, 17 | "metadata": { 18 | "description": null, 19 | "host_tools": null, 20 | "std": null, 21 | "tier": null 22 | }, 23 | "panic-strategy": "abort", 24 | "simd-types-indirect": false, 25 | "target-pointer-width": "32" 26 | } 27 | -------------------------------------------------------------------------------- /crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.2.json: -------------------------------------------------------------------------------- 1 | { 2 | "allows-weak-linkage": false, 3 | "arch": "spirv", 4 | "crt-objects-fallback": "false", 5 | "crt-static-allows-dylibs": true, 6 | "crt-static-respected": true, 7 | "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", 8 | "dll-prefix": "", 9 | "dll-suffix": ".spv.json", 10 | "dynamic-linking": true, 11 | "emit-debug-gdb-scripts": false, 12 | "env": "spv1.2", 13 | "linker-flavor": "unix", 14 | "linker-is-gnu": false, 15 | "llvm-target": "spirv-unknown-spv1.2", 16 | "main-needs-argc-argv": false, 17 | "metadata": { 18 | "description": null, 19 | "host_tools": null, 20 | "std": null, 21 | "tier": null 22 | }, 23 | "panic-strategy": "abort", 24 | "simd-types-indirect": false, 25 | "target-pointer-width": "32" 26 | } 27 | -------------------------------------------------------------------------------- /crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.3.json: -------------------------------------------------------------------------------- 1 | { 2 | "allows-weak-linkage": false, 3 | "arch": "spirv", 4 | "crt-objects-fallback": "false", 5 | "crt-static-allows-dylibs": true, 6 | "crt-static-respected": true, 7 | "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", 8 | "dll-prefix": "", 9 | "dll-suffix": ".spv.json", 10 | "dynamic-linking": true, 11 | "emit-debug-gdb-scripts": false, 12 | "env": "spv1.3", 13 | "linker-flavor": "unix", 14 | "linker-is-gnu": false, 15 | "llvm-target": "spirv-unknown-spv1.3", 16 | "main-needs-argc-argv": false, 17 | "metadata": { 18 | "description": null, 19 | "host_tools": null, 20 | "std": null, 21 | "tier": null 22 | }, 23 | "panic-strategy": "abort", 24 | "simd-types-indirect": false, 25 | "target-pointer-width": "32" 26 | } 27 | --------------------------------------------------------------------------------