Comments (2)
Hi! Great to see someone using this in practice!
Nethertheless, the bind groups, bind groups layouts are still making me puzzled.
That only means you're human :) I tried to explain it here. Any suggestions for improving this text are very welcome indeed. I think an image would also help a lot.
I think the main issue in your code is that in the shader you are defining one buffer object for each matrix, while you've actually combined the matrices into one buffer object (which is good practice in general). So your shader should be more like:
@python2shader
def tex_vertex_shader(
in_pos: ("input", 0, vec4),
in_texcoord: ("input", 1, vec2),
out_pos: ("output", "Position", vec4),
v_texcoord: ("output", 0, vec2),
uni: ("uniform", (0, 2), uniform_type),
):
ndc = uni.projection * uni.view * uni.model * uni.transform * in_pos
out_pos = vec4(ndc.xy, 0, 1) # noqa - shader output
v_texcoord = in_texcoord # noqa - shader output
In other words, you have one uniform buffer object, which is a struct, that contains multiple matrices. These lines are key:
uniform_type = Struct(transform=mat4, projection=mat4, view=mat4, model=mat4)
uniform_data = np.asarray(shadertype_as_ctype(uniform_type)())
Where the uniform_type
is something that python_shader
understands, so it can generate the correct SpirV. And by transforming that to a numpy struct, you have a matching data struct. (There is a step via ctypes there because we do not want to depend on numpy in wgpu-py
.)
Could you tell me how to complete the pipeline initialization ?
That bind group looks good. That 2
in "binding": 2, #?
should match the 2
in uni: ("uniform", (0, 2), uniform_type),
.
and update them:
In the code you showed, you upload the new data to a new buffer. Now you need to copy that buffer to the existing buffer.
command_encoder = self._device.create_command_encoder()
command_encoder.copy_buffer_to_buffer(tmp_buffer, 0, actual_buffer, boffset, bsize)
self._device.default_queue.submit([command_encoder.finish()])
This may seem a bit odd, but it seems to be the preferred way. The alternative is to map the existing buffer for writing, but this is slower.
Note that we may change the API a bit, so that creation of the tmp bufer may soon look something like create_buffer_from_data(...)
. See #98
from wgpu-py.
Ah ah! Thanks, so just my shader declaration was wrong, got it. Works perfectly now!
So I have a first version of my pygame-wgpu integration, if you'd like to have a look, tell me!
I'll review the docs about the bind groups. But from a first pass, yeah, a good drawing will save thousands of words :)
Not that clear to me what is the benefit of grouping bindings (vs independent ones, best practice?) and what is the value brought by layouts. I need to think about it :)
from wgpu-py.
Related Issues (20)
- Roadmap to maturity
- Raspberry Pi 4B setup log HOT 7
- Error when no draw function is provided HOT 1
- Warnings on import HOT 1
- test_glfw_canvas_del Windows fatal exception: access violation HOT 6
- Full-screen mode HOT 7
- Rolling out shadertoy HOT 5
- Run examples on CI on Windows / Mac / Linux
- Use webgpu.yml for parsing HOT 2
- Kivy support HOT 1
- HDR Support HOT 1
- Blocking render call HOT 2
- The expression may only be indexed by a constant HOT 3
- Update testing mechanics
- GPU info and identification HOT 21
- WxWgpuWindow object has no attribute 'add_event_handler' HOT 7
- Idea: auto-generated bindings for webgpu-native HOT 3
- Retry release for v0.15.1 ? HOT 1
- Change emum/flag implementation
- Minimal backend canvas API
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wgpu-py.