wgpu | Cross-platform , safe , pure-rust graphics api
kandi X-RAY | wgpu Summary
kandi X-RAY | wgpu Summary
The repository hosts the following libraries:. For an overview of all the components in the gfx-rs ecosystem, see the big picture.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of wgpu
wgpu Key Features
wgpu Examples and Code Snippets
Community Discussions
Trending Discussions on wgpu
QUESTION
I'm trying write a WGSL shader that reads an octree that is stored in a storage buffer. The problem is, the compiler doesn't like the dynamic index I'm calculating to access leaves in the storage buffer. wgpu produces the following validation error:
...ANSWER
Answered 2022-Feb-02 at 18:39Indexing into storage buffers is totally fine. What Naga doesn't like is this line:
QUESTION
In (an artificial simplification of) my project, I have a struct ContainsData
which can only be modified through a handle HoldsRef<'a>
, which holds a ref to some field in ContainsData
. In addition, after use of the handle, some cleanup
method must be called.
ANSWER
Answered 2021-Dec-29 at 13:44Edit: Found a partial solution below.
Let's understand what's going on here.
Lifetimes in closures (impl Fn(&T)
, and also impl Fn(T<'_>)
, which is the same as yours impl Fn(HoldsRef)
), do not desugar into generic lifetimes like normal elided lifetimes (where fn foo(_: &T)
desugars into fn foo<'a>(_: &'a T)
); instead, they're desugared into higher ranked trait bounds.
That is, impl Fn(&T)
desugars into impl for<'a> Fn(&'a T)
, and in the same manner, impl Fn(HoldsRef)
desugars into impl for<'a> Fn(HoldsRef<'a>)
. See also How does for<> syntax differ from a regular lifetime bound?.
HRTB (Higher-Ranked Traits Bounds) means that the lifetime can be any lifetime. And "any lifetime" includes, of course, 'static
. And because 'static
is the longest lifetime possible, the compiler just use this as if you've written impl Fn(HoldsRef<'static>)
. Note this is only true from the callback's point of view, that is, the callback must be able to handle this case but modify()
can call it with whatever lifetime it wants, not only static (as opposed to what would happen if you'd specify impl Fn(HoldsRef<'static>)
, then you'd have to pass a HoldsRef<'static>
).
Because the HoldsRef::set()
method takes &'a i64
, and 'a
is 'static
, so it's like it takes &'static i64
. Now you will understand why the compiler complains when you provide a shorter lifetime.
You may think that the solution is just to take a generic lifetime instead of HRTB, and tie it to self
:
QUESTION
I'm trying to follow along the "hello compute" example from wgpu on Windows 10 (with some minor modifications, mainly gutting the shader so it does basically no actual computing), but when I read the buffer at the end, it's always zeroed out.
This is the shader I'm trying to run, it compiles fine and I think it's correct
...ANSWER
Answered 2021-Aug-31 at 02:25The program works fine when I'm running it on my discrete graphics card, but wgpu is bugged on my integrated Intel HD Graphics 630, which is why the program appeared not to work.
QUESTION
I create a wgpu::TextureView
within a render
method as below:
ANSWER
Answered 2021-Aug-22 at 12:20This can be solved by forcing the SurfaceTexture
to be dropped after the TextureView
.
QUESTION
I'm trying to implement a tree structure where each node is updated using some output from its children.
The output can't be cloned or moved in the final applicaton. I'm running into multiple borrows errors, when I give the node ref's of its children to update it.
I'm using the indextree crate.
Can't get my head around it... Can't find anything like this with this updating behavior.
my example code :
The tree contains dynamic nodes like this
...ANSWER
Answered 2021-Aug-21 at 20:25The CalcNode::update
function does not actually need access to its children - really it just wants the value that is calculated from them, so you can move the calculation out of the update
function to prevent aliasing references:
QUESTION
I am using wgpu-rs and writing shaders in WGSL. To test an example shader, I copied some sample code from here: https://www.w3.org/TR/WGSL/#var-and-let.
Here is my simple shader:
...ANSWER
Answered 2021-Aug-19 at 04:05It appears the wgpu-rs
shader validation is favoring the built-in step()
function over a variable declared with the same name. Going by the W3 WGSL docs, this should resolve to the variable since it is in a closer scope.
Renaming the step
variable to something else should fix the immediate problem.
There is already an issue created to track this, but I've added this as another example.
QUESTION
I use wgpu as my graphics backend for my project.
this is my current implementation:
...ANSWER
Answered 2021-Aug-16 at 14:56Untested but should work:
QUESTION
I have the following class
...ANSWER
Answered 2021-Mar-07 at 06:18Thanks to @trentcl for pointing out the solution. I did not realize that functions can have lifetime annotations independently from traits, so I came up with the very convoluted annotations which did not convey my intent properly. Simplifying to the following fixed my issue
QUESTION
I'm making a tutorial for computing tangents and bitangents in a WGPU (Vulkan GLSL) compute shader. I'm creating the vertex buffer on the CPU from a .obj I made in blender.
Here's the code for the compute shader.
...ANSWER
Answered 2020-Oct-08 at 08:31Turns out Vulkan style GLSL aligns to the largest field in the struct when using std430
.
https://github.com/KhronosGroup/glslang/issues/264
In my case it's vec3
. The vec2 tex_coord
is throwing it off causing the shader to pull data from the wrong parts of the vertex buffer.
The fix was to change the struct
in model_load.comp
to specify the individual components instead.
QUESTION
Using wgpu-rs, I'm trying to get a 3x3 cgmath matrix into a shader (compiled using glsl-to-spirv). However, the resulting mat3 in the shader has incorrect data. When I replace the mat3 and Matrix3 with mat4 and Matrix4, everything works fine and the matrix has correct data.
Vertex Shader:
...ANSWER
Answered 2020-May-13 at 16:24This is an open issue in wgpu-rs
. Indeed the simplest workaround may be to make your mat3 into a mat4 until it is resolved.
The problem seems to be a mistake of alignment in generating SPIR-V
. The actual alignment is:
- If the member is a scalar consuming N basic machine units, the base alignment is N.
- If the member is a two- or four-component vector with components consuming N basic machine units, the base alignment is 2N or 4N, respectively.
- If the member is a three-component vector with components consuming N basic machine units, the base alignment is 4N.
- If the member is an array of scalars or vectors, the base alignment and array stride are set to match the base alignment of a single array element, according to rules (1), (2), and (3), and rounded up to the base alignment of a vec4. The array may have padding at the end; the base offset of the member following the array is rounded up to the next multiple of the base alignment.
You are in case 4. Having a mat4 should leave no extra padding on the end and not give any possibility for misalignment issues.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install wgpu
Rust is installed and managed by the rustup tool. Rust has a 6-week rapid release process and supports a great number of platforms, so there are many builds of Rust available at any time. Please refer rust-lang.org for more information.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page