You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Trac3r-rust/doc/vulkano_shaders/index.html

103 lines
12 KiB

5 years ago
<!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="API documentation for the Rust `vulkano_shaders` crate."><meta name="keywords" content="rust, rustlang, rust-lang, vulkano_shaders"><title>vulkano_shaders - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../dark.css"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script src="../storage.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="shortcut icon" href="../favicon.ico"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../vulkano_shaders/index.html'><div class='logo-container'><img src='https://raw.githubusercontent.com/vulkano-rs/vulkano/master/logo.png' alt='logo'></div></a><p class='location'>Crate vulkano_shaders</p><div class="sidebar-elems"><a id='all-types' href='all.html'><p>See all vulkano_shaders's items</p></a><div class="block items"><ul><li><a href="#macros">Macros</a></li></ul></div><p class='location'></p><script>window.sidebarCurrent = {name: 'vulkano_shaders', ty: 'mod', relpath: '../'};</script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form js-only"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>&#x2212;</span>]</a></span><a class='srclink' href='../src/vulkano_shaders/lib.rs.html#1-308' title='goto source code'>[src]</a></span><span class='in-band'>Crate <a class="mod" href=''>vulkano_shaders</a></span></h1><div class='docblock'><p>The procedural macro for vulkano's shader system.
Manages the compile-time compilation of GLSL into SPIR-V and generation of assosciated rust code.</p>
<h1 id="basic-usage" class="section-header"><a href="#basic-usage">Basic usage</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">mod</span> <span class="ident">vs</span> {
<span class="ident">vulkano_shaders</span>::<span class="macro">shader</span><span class="macro">!</span>{
<span class="ident">ty</span>: <span class="string">&quot;vertex&quot;</span>,
<span class="ident">src</span>: <span class="string">&quot;
#version 450
layout(location = 0) in vec3 position;
void main() {
gl_Position = vec4(position, 1.0);
}&quot;</span>
}
}</pre></div>
<h1 id="details" class="section-header"><a href="#details">Details</a></h1>
<p>If you want to take a look at what the macro generates, your best options
are to either read through the code that handles the generation (the
<a href="https://github.com/vulkano-rs/vulkano/blob/master/vulkano-shaders/src/lib.rs#L67"><code>reflect</code></a> function in the <code>vulkano-shaders</code> crate) or use a tool
such as <a href="https://github.com/dtolnay/cargo-expand">cargo-expand</a> to view the expansion of the macro in your
own code. It is unfortunately not possible to provide a <code>generated_example</code>
module like some normal macro crates do since derive macros cannot be used from
the crate they are declared in. On the other hand, if you are looking for a
high-level overview, you can see the below section.</p>
<h1 id="generated-code-overview" class="section-header"><a href="#generated-code-overview">Generated code overview</a></h1>
<p>The macro generates the following items of interest:</p>
<ul>
<li>The <code>Shader</code> struct. This contains a single field, <code>shader</code>, which is an
<code>Arc&lt;ShaderModule&gt;</code>.</li>
<li>The <code>Shader::load</code> constructor. This method takes an <code>Arc&lt;Device&gt;</code>, calls
<a href="https://docs.rs/vulkano/*/vulkano/pipeline/shader/struct.ShaderModule.html#method.new"><code>ShaderModule::new</code></a> with the passed-in device and the
shader data provided via the macro, and returns <code>Result&lt;Shader, OomError&gt;</code>.
Before doing so, it loops through every capability instruction in the shader
data, verifying that the passed-in <code>Device</code> has the appropriate features
enabled. <strong>This function currently panics if a feature required by the shader
is not enabled on the device.</strong> At some point in the future it will return
an error instead.</li>
<li>The <code>Shader::module</code> method. This method simply returns a reference to the
<code>Arc&lt;ShaderModule&gt;</code> contained within the <code>shader</code> field of the <code>Shader</code>
struct.</li>
<li>Methods for each entry point of the shader module. These construct and
return the various entry point structs that can be found in the
<a href="https://docs.rs/vulkano/*/vulkano/pipeline/shader/index.html">vulkano::pipeline::shader</a> module.</li>
<li>A Rust struct translated from each struct contained in the shader data.</li>
<li>The <code>Layout</code> newtype. This contains a <a href="https://docs.rs/vulkano/*/vulkano/descriptor/descriptor/struct.ShaderStages.html"><code>ShaderStages</code></a> struct.
An implementation of <a href="https://docs.rs/vulkano/*/vulkano/descriptor/pipeline_layout/trait.PipelineLayoutDesc.html"><code>PipelineLayoutDesc</code></a> is also
generated for the newtype.</li>
<li>The <code>SpecializationConstants</code> struct. This contains a field for every
specialization constant found in the shader data. Implementations of
<code>Default</code> and <a href="https://docs.rs/vulkano/*/vulkano/pipeline/shader/trait.SpecializationConstants.html"><code>SpecializationConstants</code></a> are also
generated for the struct.</li>
</ul>
<p>All of these generated items will be accessed through the module specified
by <code>mod_name: foo</code> If you wanted to store the <code>Shader</code> in a struct of your own,
you could do something like this:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="comment">// various use statements</span>
<span class="comment">// `vertex_shader` module with shader derive</span>
<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">Shaders</span> {
<span class="kw">pub</span> <span class="ident">vs</span>: <span class="ident">vs</span>::<span class="ident">Shader</span>
}
<span class="kw">impl</span> <span class="ident">Shaders</span> {
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">load</span>(<span class="ident">device</span>: <span class="ident">Arc</span><span class="op">&lt;</span><span class="ident">Device</span><span class="op">&gt;</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="self">Self</span>, <span class="ident">OomError</span><span class="op">&gt;</span> {
<span class="prelude-val">Ok</span>(<span class="self">Self</span> {
<span class="ident">vs</span>: <span class="ident">vs</span>::<span class="ident">Shader</span>::<span class="ident">load</span>(<span class="ident">device</span>)<span class="question-mark">?</span>,
})
}
}</pre></div>
<h1 id="options" class="section-header"><a href="#options">Options</a></h1>
<p>The options available are in the form of the following attributes:</p>
<h2 id="ty-" class="section-header"><a href="#ty-"><code>ty: &quot;...&quot;</code></a></h2>
<p>This defines what shader type the given GLSL source will be compiled into.
The type can be any of the following:</p>
<ul>
<li><code>vertex</code></li>
<li><code>fragment</code></li>
<li><code>geometry</code></li>
<li><code>tess_ctrl</code></li>
<li><code>tess_eval</code></li>
<li><code>compute</code></li>
</ul>
<p>For details on what these shader types mean, <a href="https://docs.rs/vulkano/*/vulkano/pipeline/index.html">see Vulkano's documentation</a>.</p>
<h2 id="src-" class="section-header"><a href="#src-"><code>src: &quot;...&quot;</code></a></h2>
<p>Provides the raw GLSL source to be compiled in the form of a string. Cannot
be used in conjunction with the <code>path</code> field.</p>
<h2 id="path-" class="section-header"><a href="#path-"><code>path: &quot;...&quot;</code></a></h2>
<p>Provides the path to the GLSL source to be compiled, relative to <code>Cargo.toml</code>.
Cannot be used in conjunction with the <code>src</code> field.</p>
<h2 id="include----" class="section-header"><a href="#include----"><code>include: [&quot;...&quot;, &quot;...&quot;, ..., &quot;...&quot;]</code></a></h2>
<p>Specifies the standard include directories to be searched through when using the
<code>#include &lt;...&gt;</code> directive within a shader source.
If <code>path</code> was specified, relative paths can also be used (<code>#include &quot;...&quot;</code>), without the need
to specify one or more standard include directories. Relative paths are relative to the
directory, which contains the source file the <code>#include &quot;...&quot;</code> directive is declared in.</p>
<h2 id="dump-true" class="section-header"><a href="#dump-true"><code>dump: true</code></a></h2>
<p>The crate fails to compile but prints the generated rust code to stdout.</p>
</div><h2 id='macros' class='section-header'><a href="#macros">Macros</a></h2>
<table><tr class='module-item'><td><a class="macro" href="macro.shader.html" title='vulkano_shaders::shader macro'>shader</a></td><td class='docblock-short'></td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd></kbd></dt><dd>Move up in search results</dd><dt><kbd></kbd></dt><dd>Move down in search results</dd><dt><kbd></kbd></dt><dd>Switch tab</dd><dt><kbd>&#9166;</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><div class="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g., <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g., <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../";window.currentCrate = "vulkano_shaders";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>