Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upGfx examples framework #52
Conversation
kvark
requested a review
from grovesNL
Feb 1, 2019
kvark
added some commits
Feb 1, 2019
kvark
force-pushed the
kvark:gfx-examples
branch
from
b0f3c2a
to
d4c8c88
Feb 3, 2019
kvark
added some commits
Feb 3, 2019
This comment has been minimized.
This comment has been minimized.
grovesNL
reviewed
Feb 4, 2019
|
Awesome work porting the cube example over, this looks great! |
| @@ -0,0 +1,6 @@ | |||
| # gfx pre-ll examples | |||
|
|
|||
| Original gfx-rs examples were growing for years, but then got abandoned once we changed the API to match vulkan: | |||
This comment has been minimized.
This comment has been minimized.
grovesNL
Feb 4, 2019
Member
Maybe this could be rephrased a bit:
The original gfx-rs examples had grown over several years, but they were abandoned when the gfx API was changed to match Vulkan.
https://github.com/gfx-rs/gfx/tree/pre-ll/examples
wgpu-rsis considered to be the spiritual successor of gfx pre-ll, so this is the new home for the examples.
| @@ -0,0 +1,13 @@ | |||
| #version 450 | |||
| #extension GL_ARB_separate_shader_objects : enable | |||
This comment has been minimized.
This comment has been minimized.
grovesNL
Feb 4, 2019
Member
We shouldn't actually need in either shader AFAIK (see Overv/VulkanTutorial#112)
|
|
||
| void main() { | ||
| vec4 tex = texture(sampler2D(t_Color, s_Color), v_TexCoord); | ||
| float blend = dot(v_TexCoord-vec2(0.5,0.5), v_TexCoord-vec2(0.5,0.5)); |
This comment has been minimized.
This comment has been minimized.
grovesNL
Feb 4, 2019
Member
This could be simplified a bit:
float mag = length(v_TexCoord - vec2(0.5));
o_Target = mix(tex, vec4(0.0), mag * mag);| use std::path::PathBuf; | ||
|
|
||
| let base_path = PathBuf::from("data").join(name); | ||
| let code_vs = read_to_string(base_path.with_extension("vert")).unwrap(); |
This comment has been minimized.
This comment has been minimized.
grovesNL
Feb 4, 2019
Member
nit: to keep framework light, maybe we could just have load_glsl and pass the cube.vert and ShaderType::Vertex, then we could use this for compute shaders too
| }); | ||
| } | ||
|
|
||
| let bytes_per_texel = conv::map_texture_format(dst_texture.format).surface_desc().bits as u32 / 8; |
This comment has been minimized.
This comment has been minimized.
| match address { | ||
| Am::ClampToEdge => W::Clamp, | ||
| Am::Repeat => W::Tile, | ||
| Am::MirrorRepeat => { |
This comment has been minimized.
This comment has been minimized.
| let desc_vbs = unsafe { | ||
| slice::from_raw_parts(desc.vertex_buffer_state.vertex_buffers, desc.vertex_buffer_state.vertex_buffers_count) | ||
| }; | ||
| let mut vertex_buffers: Vec<hal::pso::VertexBufferDesc> = Vec::with_capacity(desc_vbs.len()); |
This comment has been minimized.
This comment has been minimized.
grovesNL
Feb 4, 2019
Member
nit: we don't need the type annotations for either of these unless you prefer it
| ) | ||
| impl<'a> Drop for SwapChainOutput<'a> { | ||
| fn drop(&mut self) { | ||
| wgn::wgpu_swap_chain_present(*self.swap_chain_id); |
This comment has been minimized.
This comment has been minimized.
grovesNL
Feb 4, 2019
Member
I think this could be a bit unexpected by users. If the concern is that the frame is accidentally held by the user after drop, maybe we could keep the explicit present and have an assert on drop or similar?
This comment has been minimized.
This comment has been minimized.
kvark
Feb 4, 2019
Author
Member
The swapchain output is now holding the swapchain from modification: they can't get new frames anyway. There is nothing the user can do to screw this up. They can only stop using the output and drop it.
We could totally have explicit "present", but I didn't find it useful. Open for re-consideration ;)
This comment has been minimized.
This comment has been minimized.
grovesNL
Feb 4, 2019
Member
I think it's a bit unexpected not to have the usual present or swap_buffers at the end of rendering a frame (although WebGL does this implicitly too). Also drop causes some work to be performed here, which doesn't seem very common.
This could be confusing, especially if the user is trying to map calls between the WebGPU specification and wgpu-rs and doesn't notice where the missing present went. Principle of least astonishment and all that :)
This comment has been minimized.
This comment has been minimized.
kvark
Feb 5, 2019
Author
Member
That's how the W3C group agreed to do things on IDL side, interestingly.
grovesNL
reviewed
Feb 4, 2019
| extern crate cgmath; | ||
| extern crate wgpu; | ||
|
|
||
| #[path="framework.rs"] |
This comment has been minimized.
This comment has been minimized.
grovesNL
Feb 4, 2019
Member
I think path= isn't commonly used so maybe we should just have framework or use an alias here
| @@ -0,0 +1,310 @@ | |||
| extern crate cgmath; | |||
| extern crate wgpu; | |||
This comment has been minimized.
This comment has been minimized.
grovesNL
Feb 4, 2019
Member
We could have edition = "2018" in Cargo.toml and remove these extern crates
This comment has been minimized.
This comment has been minimized.
|
Amazing input, thank you @grovesNL ! bors r=grovesNL |
bors bot
added a commit
that referenced
this pull request
Feb 4, 2019
This comment has been minimized.
This comment has been minimized.
Build succeeded |
bors
bot
merged commit c74f8e8
into
gfx-rs:master
Feb 4, 2019
kvark
deleted the
kvark:gfx-examples
branch
Feb 4, 2019
This comment has been minimized.
This comment has been minimized.
|
Update: this works on Vulkan |


kvark commentedFeb 1, 2019
•
edited
Fixes #37
🎉 . Includes a few pieces:
It's not functional yet, I think it needs a proper resize event handler. We can do this incrementally.Draws a cube