Type safety #7886
Replies: 4 comments 5 replies
-
Okay, after getting over that speed bump I'm getting lots of other errors so I think the answer is that it's pretty type safe. I reread the readme and it does mention "safe", but what does that mean? Is the usize vs u16 issue above a bug? There's other stuff, like array stride, where the api (I assume) prioritizes speed over safety (1d array vs nested arrays, or some type that encodes multi dimensions), etc. |
Beta Was this translation helpful? Give feedback.
-
Ah, I found a similar issue here: #5470 The argument is that buffers hold arbitrary byte data, so any type checks would prevent some use case. I guess this is based on the fact that the analysis is one-sided (i.e. the rust has no idea what the shader code is doing). IIUC rust reads/writes data but has no idea how it's being used, the shader reads/writes data and just assumes it's in the right format, and naga also just checks internal consistency? There's no extra metadata passed between rust and naga? It looks like So with naga and encase, you can get rid of data layout/access errors but there's still the possibility of doing correctly structured accesses on the wrong structure in the shader/rust code. |
Beta Was this translation helpful? Give feedback.
-
Ah! Here on the other hand it the project aims for complete safety (although maybe they also only mean WRT invalid memory accesses) https://github.com/gfx-rs/wgpu/wiki/Debugging-wgpu-Applications - this references
area: validation
So... it is a goal, but it's not a cornerstone of the project so it's WIP? |
Beta Was this translation helpful? Give feedback.
-
I just found |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! I've been hacking at the cube example. I just spent 2 hours where nothing was rendered... I thought I was going crazy since even checking every vertex/tex/index value against the example one by one nothing was different. It turned out the culprit was that I accidentally made the vertex index vec element type usize instead of u16 (implicitly, due to type deduction), and I have no idea what sort of memory accesses were going on but I guess they weren't right.
I have limited experience with graphics in general, but just looking at the interfaces it feels like this is probably a risk every time you use arrays/buffers/whatever. It kind of blindsided me since type safety is less of a problem in JS (my only recent experience) which only has 1 number type and apparently the webgl api is able to introspect and do the memory stuff correctly.
So... to get to the core of my question, is there any way I can make this a safe experience? Prevent crazy casting, check shader layout mismatches, get warned at compile time or, failing that, at runtime?
TBH I've been looking to dig in here for a long time, and I had previously looked at Vulkano, but I'm not really sure which library I need and since this seemed like the most popular I thought I'd start here.
Beta Was this translation helpful? Give feedback.
All reactions