Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gfx examples framework #52

Merged
merged 9 commits into from Feb 4, 2019

Conversation

@kvark
Copy link
Member

commented Feb 1, 2019

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

  • the example framework
  • sampler support
  • vertex/index buffer description
  • buffer to texture copies

@kvark kvark requested a review from grovesNL Feb 1, 2019

@kvark kvark force-pushed the kvark:gfx-examples branch from b0f3c2a to d4c8c88 Feb 3, 2019

@kvark

This comment has been minimized.

Copy link
Member Author

commented Feb 4, 2019

Mission accomplished (Metal):
screen shot 2019-02-03 at 22 17 46

@grovesNL
Copy link
Member

left a comment

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.

Copy link
@grovesNL

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-rs is 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.

Copy link
@grovesNL

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.

Copy link
@grovesNL

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.

Copy link
@grovesNL

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.

Copy link
@grovesNL

grovesNL Feb 4, 2019

Member

nit: maybe have a constant for 8

match address {
Am::ClampToEdge => W::Clamp,
Am::Repeat => W::Tile,
Am::MirrorRepeat => {

This comment has been minimized.

Copy link
@grovesNL

grovesNL Feb 4, 2019

Member

How does W::Mirror differ?

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.

Copy link
@grovesNL

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.

Copy link
@grovesNL

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.

Copy link
@kvark

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.

Copy link
@grovesNL

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.

Copy link
@kvark

kvark Feb 5, 2019

Author Member

That's how the W3C group agreed to do things on IDL side, interestingly.

extern crate cgmath;
extern crate wgpu;

#[path="framework.rs"]

This comment has been minimized.

Copy link
@grovesNL

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.

Copy link
@grovesNL

grovesNL Feb 4, 2019

Member

We could have edition = "2018" in Cargo.toml and remove these extern crates

@kvark

This comment has been minimized.

Copy link
Member Author

commented Feb 4, 2019

Amazing input, thank you @grovesNL !
I believe everything is addressed now. I also took the liberty of modifying the cube texture to show that, well, we have a texture:
wgpu-cube-fractal

bors r=grovesNL

bors bot added a commit that referenced this pull request Feb 4, 2019

Merge #52
52: Gfx examples framework r=grovesNL a=kvark

Fixes #37 
It's not functional yet, I think it needs a proper resize event handler. We can do this incrementally.

Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
@bors

This comment has been minimized.

Copy link
Contributor

commented Feb 4, 2019

@bors bors bot merged commit c74f8e8 into gfx-rs:master Feb 4, 2019

2 checks passed

bors Build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@kvark kvark deleted the kvark:gfx-examples branch Feb 4, 2019

@kvark

This comment has been minimized.

Copy link
Member Author

commented Feb 5, 2019

Update: this works on Vulkan 🎉 although I haven't checked for validation issues.
DX12 doesn't work because of missing update_buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.