mirror of
https://github.com/Rust-GPU/rust-gpu.git
synced 2026-06-07 01:59:51 +09:00
37 lines
17 KiB
HTML
37 lines
17 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Abstract trait representing a SPIR-V vector type."><title>Vector in spirv_std - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-17e0aaed.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="spirv_std" data-themes="" data-resource-suffix="" data-rustdoc-version="1.96.0-nightly (02c7f9bec 2026-04-10)" data-channel="nightly" data-search-js="search-b5634cc7.js" data-stringdex-js="stringdex-2da4960a.js" data-settings-js="settings-170eb4bf.js" ><script src="../static.files/storage-41dd4d93.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-5013f961.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-f7c3ffd8.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><a class="skip-main-content" href="#main-content">Skip to main content</a><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">Vector</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../spirv_std/index.html">spirv_<wbr>std</a><span class="version">0.10.0-alpha.1</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Vector</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#example" title="Example">Example</a></li><li><a href="#safety" title="Safety">Safety</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-Vector%3Cbool,+2%3E-for-BVec2" title="BVec2">BVec2</a></li><li><a href="#impl-Vector%3Cbool,+3%3E-for-BVec3" title="BVec3">BVec3</a></li><li><a href="#impl-Vector%3Cbool,+4%3E-for-BVec4" title="BVec4">BVec4</a></li><li><a href="#impl-Vector%3Cf64,+2%3E-for-DVec2" title="DVec2">DVec2</a></li><li><a href="#impl-Vector%3Cf64,+3%3E-for-DVec3" title="DVec3">DVec3</a></li><li><a href="#impl-Vector%3Cf64,+4%3E-for-DVec4" title="DVec4">DVec4</a></li><li><a href="#impl-Vector%3Ci32,+2%3E-for-IVec2" title="IVec2">IVec2</a></li><li><a href="#impl-Vector%3Ci32,+3%3E-for-IVec3" title="IVec3">IVec3</a></li><li><a href="#impl-Vector%3Ci32,+4%3E-for-IVec4" title="IVec4">IVec4</a></li><li><a href="#impl-Vector%3Cu32,+2%3E-for-UVec2" title="UVec2">UVec2</a></li><li><a href="#impl-Vector%3Cu32,+3%3E-for-UVec3" title="UVec3">UVec3</a></li><li><a href="#impl-Vector%3Cu32,+4%3E-for-UVec4" title="UVec4">UVec4</a></li><li><a href="#impl-Vector%3Cf32,+2%3E-for-Vec2" title="Vec2">Vec2</a></li><li><a href="#impl-Vector%3Cf32,+3%3E-for-Vec3" title="Vec3">Vec3</a></li><li><a href="#impl-Vector%3Cf32,+4%3E-for-Vec4" title="Vec4">Vec4</a></li><li><a href="#impl-Vector%3Cf32,+3%3E-for-Vec3A" title="Vec3A">Vec3A</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate spirv_<wbr>std</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content" tabindex="-1"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="index.html">spirv_std</a></div><h1>Trait <span class="trait">Vector</span> <button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/spirv_std/vector.rs.html#54">Source</a> </span></div><pre class="rust item-decl"><code>pub unsafe trait Vector<T: <a class="trait" href="trait.Scalar.html" title="trait spirv_std::Scalar">Scalar</a>, const N: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>>: <a class="trait" href="trait.ScalarOrVector.html" title="trait spirv_std::ScalarOrVector">ScalarOrVector</a><Scalar = T> { }</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Abstract trait representing a SPIR-V vector type.</p>
|
||
<p>To implement this trait, your struct must be marked with:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[cfg_attr(target_arch = <span class="string">"spirv"</span>, rust_gpu::vector::v1)]</span></code></pre></div>
|
||
<p>This places these additional constraints on your type, checked by the spirv codegen:</p>
|
||
<ul>
|
||
<li>must be a struct</li>
|
||
<li>members must be a spirv <a href="trait.Scalar.html" title="trait spirv_std::Scalar"><code>Scalar</code></a> type, which includes:
|
||
<ul>
|
||
<li>Floating-point type: f32, f64</li>
|
||
<li>Integer type: u8, u16, u32, u64, i8, i16, i32, i64</li>
|
||
<li>Boolean type: bool</li>
|
||
</ul>
|
||
</li>
|
||
<li>all members must be of the same primitive type</li>
|
||
<li>must have 2, 3 or 4 vector components / members</li>
|
||
<li>type must derive Copy, Clone, Default</li>
|
||
</ul>
|
||
<p>The spirv codegen backend will then emit your type as an <code>OpTypeVector</code> instead of an <code>OpTypeStruct</code>. The layout of
|
||
your type is unaffected, the size, alignment and member offsets will follow standard rustc layout rules. This hint
|
||
does nothing on other target platforms.</p>
|
||
<p>See the SPIRV spec on <a href="https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_types">Types</a> and the
|
||
โData rulesโ in the <a href="https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_universal_validation_rules">Universal Validation Rules</a>.</p>
|
||
<h2 id="example"><a class="doc-anchor" href="#example">ยง</a>Example</h2>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[derive(Copy, Clone, Default)]
|
||
#[cfg_attr(target_arch = <span class="string">"spirv"</span>, rust_gpu::vector::v1)]
|
||
</span><span class="kw">struct </span>MyColor {
|
||
r: f32,
|
||
b: f32,
|
||
g: f32,
|
||
}</code></pre></div><h2 id="safety"><a class="doc-anchor" href="#safety">ยง</a>Safety</h2>
|
||
<ul>
|
||
<li>Must only be implemented on types that the spirv codegen emits as valid <code>OpTypeVector</code>. This includes all structs
|
||
marked with <code>#[rust_gpu::vector::v1]</code>, like <a href="../glam/index.html" title="mod glam"><code>glam</code></a>โs non-SIMD โscalarโ vector types.</li>
|
||
<li><code>ScalarOrVector::DIM == N</code>, since const equality is behind rustc feature <code>associated_const_equality</code></li>
|
||
</ul>
|
||
</div></details><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">ยง</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">ยง</a></h2><section id="impl-Vector%3Cbool,+2%3E-for-BVec2" class="impl"><a class="src rightside" href="../src/spirv_std/vector.rs.html#75-92">Source</a><a href="#impl-Vector%3Cbool,+2%3E-for-BVec2" class="anchor">ยง</a><h3 class="code-header">impl <a class="trait" href="trait.Vector.html" title="trait spirv_std::Vector">Vector</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, 2> for <a class="struct" href="../glam/bool/bvec2/struct.BVec2.html" title="struct glam::bool::bvec2::BVec2">BVec2</a></h3></section><section id="impl-Vector%3Cbool,+3%3E-for-BVec3" class="impl"><a class="src rightside" href="../src/spirv_std/vector.rs.html#75-92">Source</a><a href="#impl-Vector%3Cbool,+3%3E-for-BVec3" class="anchor">ยง</a><h3 class="code-header">impl <a class="trait" href="trait.Vector.html" title="trait spirv_std::Vector">Vector</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, 3> for <a class="struct" href="../glam/bool/bvec3/struct.BVec3.html" title="struct glam::bool::bvec3::BVec3">BVec3</a></h3></section><section id="impl-Vector%3Cbool,+4%3E-for-BVec4" class="impl"><a class="src rightside" href="../src/spirv_std/vector.rs.html#75-92">Source</a><a href="#impl-Vector%3Cbool,+4%3E-for-BVec4" class="anchor">ยง</a><h3 class="code-header">impl <a class="trait" href="trait.Vector.html" title="trait spirv_std::Vector">Vector</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, 4> for <a class="struct" href="../glam/bool/bvec4/struct.BVec4.html" title="struct glam::bool::bvec4::BVec4">BVec4</a></h3></section><section id="impl-Vector%3Cf32,+2%3E-for-Vec2" class="impl"><a class="src rightside" href="../src/spirv_std/vector.rs.html#75-92">Source</a><a href="#impl-Vector%3Cf32,+2%3E-for-Vec2" class="anchor">ยง</a><h3 class="code-header">impl <a class="trait" href="trait.Vector.html" title="trait spirv_std::Vector">Vector</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f32.html">f32</a>, 2> for <a class="struct" href="../glam/f32/vec2/struct.Vec2.html" title="struct glam::f32::vec2::Vec2">Vec2</a></h3></section><section id="impl-Vector%3Cf32,+3%3E-for-Vec3A" class="impl"><a class="src rightside" href="../src/spirv_std/vector.rs.html#75-92">Source</a><a href="#impl-Vector%3Cf32,+3%3E-for-Vec3A" class="anchor">ยง</a><h3 class="code-header">impl <a class="trait" href="trait.Vector.html" title="trait spirv_std::Vector">Vector</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f32.html">f32</a>, 3> for <a class="struct" href="../glam/f32/neon/vec3a/struct.Vec3A.html" title="struct glam::f32::neon::vec3a::Vec3A">Vec3A</a></h3></section><section id="impl-Vector%3Cf32,+3%3E-for-Vec3" class="impl"><a class="src rightside" href="../src/spirv_std/vector.rs.html#75-92">Source</a><a href="#impl-Vector%3Cf32,+3%3E-for-Vec3" class="anchor">ยง</a><h3 class="code-header">impl <a class="trait" href="trait.Vector.html" title="trait spirv_std::Vector">Vector</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f32.html">f32</a>, 3> for <a class="struct" href="../glam/f32/vec3/struct.Vec3.html" title="struct glam::f32::vec3::Vec3">Vec3</a></h3></section><section id="impl-Vector%3Cf32,+4%3E-for-Vec4" class="impl"><a class="src rightside" href="../src/spirv_std/vector.rs.html#75-92">Source</a><a href="#impl-Vector%3Cf32,+4%3E-for-Vec4" class="anchor">ยง</a><h3 class="code-header">impl <a class="trait" href="trait.Vector.html" title="trait spirv_std::Vector">Vector</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f32.html">f32</a>, 4> for <a class="struct" href="../glam/f32/neon/vec4/struct.Vec4.html" title="struct glam::f32::neon::vec4::Vec4">Vec4</a></h3></section><section id="impl-Vector%3Cf64,+2%3E-for-DVec2" class="impl"><a class="src rightside" href="../src/spirv_std/vector.rs.html#75-92">Source</a><a href="#impl-Vector%3Cf64,+2%3E-for-DVec2" class="anchor">ยง</a><h3 class="code-header">impl <a class="trait" href="trait.Vector.html" title="trait spirv_std::Vector">Vector</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f64.html">f64</a>, 2> for <a class="struct" href="../glam/f64/dvec2/struct.DVec2.html" title="struct glam::f64::dvec2::DVec2">DVec2</a></h3></section><section id="impl-Vector%3Cf64,+3%3E-for-DVec3" class="impl"><a class="src rightside" href="../src/spirv_std/vector.rs.html#75-92">Source</a><a href="#impl-Vector%3Cf64,+3%3E-for-DVec3" class="anchor">ยง</a><h3 class="code-header">impl <a class="trait" href="trait.Vector.html" title="trait spirv_std::Vector">Vector</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f64.html">f64</a>, 3> for <a class="struct" href="../glam/f64/dvec3/struct.DVec3.html" title="struct glam::f64::dvec3::DVec3">DVec3</a></h3></section><section id="impl-Vector%3Cf64,+4%3E-for-DVec4" class="impl"><a class="src rightside" href="../src/spirv_std/vector.rs.html#75-92">Source</a><a href="#impl-Vector%3Cf64,+4%3E-for-DVec4" class="anchor">ยง</a><h3 class="code-header">impl <a class="trait" href="trait.Vector.html" title="trait spirv_std::Vector">Vector</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f64.html">f64</a>, 4> for <a class="struct" href="../glam/f64/dvec4/struct.DVec4.html" title="struct glam::f64::dvec4::DVec4">DVec4</a></h3></section><section id="impl-Vector%3Ci32,+2%3E-for-IVec2" class="impl"><a class="src rightside" href="../src/spirv_std/vector.rs.html#75-92">Source</a><a href="#impl-Vector%3Ci32,+2%3E-for-IVec2" class="anchor">ยง</a><h3 class="code-header">impl <a class="trait" href="trait.Vector.html" title="trait spirv_std::Vector">Vector</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>, 2> for <a class="struct" href="../glam/i32/ivec2/struct.IVec2.html" title="struct glam::i32::ivec2::IVec2">IVec2</a></h3></section><section id="impl-Vector%3Ci32,+3%3E-for-IVec3" class="impl"><a class="src rightside" href="../src/spirv_std/vector.rs.html#75-92">Source</a><a href="#impl-Vector%3Ci32,+3%3E-for-IVec3" class="anchor">ยง</a><h3 class="code-header">impl <a class="trait" href="trait.Vector.html" title="trait spirv_std::Vector">Vector</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>, 3> for <a class="struct" href="../glam/i32/ivec3/struct.IVec3.html" title="struct glam::i32::ivec3::IVec3">IVec3</a></h3></section><section id="impl-Vector%3Ci32,+4%3E-for-IVec4" class="impl"><a class="src rightside" href="../src/spirv_std/vector.rs.html#75-92">Source</a><a href="#impl-Vector%3Ci32,+4%3E-for-IVec4" class="anchor">ยง</a><h3 class="code-header">impl <a class="trait" href="trait.Vector.html" title="trait spirv_std::Vector">Vector</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>, 4> for <a class="struct" href="../glam/i32/ivec4/struct.IVec4.html" title="struct glam::i32::ivec4::IVec4">IVec4</a></h3></section><section id="impl-Vector%3Cu32,+2%3E-for-UVec2" class="impl"><a class="src rightside" href="../src/spirv_std/vector.rs.html#75-92">Source</a><a href="#impl-Vector%3Cu32,+2%3E-for-UVec2" class="anchor">ยง</a><h3 class="code-header">impl <a class="trait" href="trait.Vector.html" title="trait spirv_std::Vector">Vector</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, 2> for <a class="struct" href="../glam/u32/uvec2/struct.UVec2.html" title="struct glam::u32::uvec2::UVec2">UVec2</a></h3></section><section id="impl-Vector%3Cu32,+3%3E-for-UVec3" class="impl"><a class="src rightside" href="../src/spirv_std/vector.rs.html#75-92">Source</a><a href="#impl-Vector%3Cu32,+3%3E-for-UVec3" class="anchor">ยง</a><h3 class="code-header">impl <a class="trait" href="trait.Vector.html" title="trait spirv_std::Vector">Vector</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, 3> for <a class="struct" href="../glam/u32/uvec3/struct.UVec3.html" title="struct glam::u32::uvec3::UVec3">UVec3</a></h3></section><section id="impl-Vector%3Cu32,+4%3E-for-UVec4" class="impl"><a class="src rightside" href="../src/spirv_std/vector.rs.html#75-92">Source</a><a href="#impl-Vector%3Cu32,+4%3E-for-UVec4" class="anchor">ยง</a><h3 class="code-header">impl <a class="trait" href="trait.Vector.html" title="trait spirv_std::Vector">Vector</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, 4> for <a class="struct" href="../glam/u32/uvec4/struct.UVec4.html" title="struct glam::u32::uvec4::UVec4">UVec4</a></h3></section><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">ยง</a></h2><div id="implementors-list"></div><script src="../trait.impl/spirv_std/vector/trait.Vector.js" data-ignore-extern-crates="glam" async></script></section></div></main></body></html> |