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

Separate object identity from storage #62

Merged
merged 2 commits into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ before_install:

script:
- cargo test
- cargo check --manifest-path wgpu-native/Cargo.toml --features remote
- cargo check --manifest-path wgpu-native/Cargo.toml
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ examples-native: lib-native wgpu-bindings/wgpu.h $(wildcard wgpu-native/**/*.c)
#$(MAKE) -C examples

examples-rust: lib-rust examples/Cargo.toml $(wildcard wgpu-native/**/*.rs)
cargo build --manifest-path examples/Cargo.toml --features winit,$(FEATURE_RUST)
cargo build --manifest-path examples/Cargo.toml --features $(FEATURE_RUST)

examples-gfx: lib-rust gfx-examples/Cargo.toml $(wildcard gfx-examples/*.rs)
cargo build --manifest-path gfx-examples/Cargo.toml --features $(FEATURE_RUST)
4 changes: 2 additions & 2 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ path = "hello_compute_rust/main.rs"

[features]
default = []
remote = ["wgpu-native/remote"]
local = ["wgpu-native/local"]
metal = ["wgpu/metal"]
dx11 = ["wgpu/dx11"]
dx12 = ["wgpu/dx12"]
vulkan = ["wgpu/vulkan"]

[dependencies]
wgpu-native = { path = "../wgpu-native" }
wgpu = { path = "../wgpu-rs", features=["winit"] }
wgpu = { path = "../wgpu-rs" }
env_logger = "0.5"
1 change: 0 additions & 1 deletion examples/hello_compute_rust/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ fn main() {
layout: &pipeline_layout,
compute_stage: wgpu::PipelineStageDescriptor {
module: &cs_module,
stage: wgpu::ShaderStage::Compute,
entry_point: "main",
},
});
Expand Down
48 changes: 24 additions & 24 deletions examples/hello_triangle_rust/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,36 @@ fn main() {
bind_group_layouts: &[&bind_group_layout],
});

let blend_state0 = device.create_blend_state(&wgpu::BlendStateDescriptor::REPLACE);
let depth_stencil_state =
device.create_depth_stencil_state(&wgpu::DepthStencilStateDescriptor::IGNORE);

let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
layout: &pipeline_layout,
stages: &[
wgpu::PipelineStageDescriptor {
module: &vs_module,
stage: wgpu::ShaderStage::Vertex,
entry_point: "main",
},
wgpu::PipelineStageDescriptor {
module: &fs_module,
stage: wgpu::ShaderStage::Fragment,
entry_point: "main",
},
],
vertex_stage: wgpu::PipelineStageDescriptor {
module: &vs_module,
entry_point: "main",
},
fragment_stage: wgpu::PipelineStageDescriptor {
module: &fs_module,
entry_point: "main",
},
rasterization_state: wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Ccw,
cull_mode: wgpu::CullMode::None,
depth_bias: 0,
depth_bias_slope_scale: 0.0,
depth_bias_clamp: wgpu::MAX_DEPTH_BIAS_CLAMP,
},
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
attachments_state: wgpu::AttachmentsState {
color_attachments: &[wgpu::Attachment {
color_states: &[
wgpu::ColorStateDescriptor {
format: wgpu::TextureFormat::B8g8r8a8Unorm,
samples: 1,
}],
depth_stencil_attachment: None,
},
blend_states: &[&blend_state0],
depth_stencil_state: &depth_stencil_state,
color: wgpu::BlendDescriptor::REPLACE,
alpha: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWriteFlags::ALL,
},
],
depth_stencil_state: None,
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[],
sample_count: 1,
});

use wgpu::winit::{ControlFlow, Event, ElementState, EventsLoop, KeyboardInput, Window, WindowEvent, VirtualKeyCode};
Expand Down
2 changes: 1 addition & 1 deletion gfx-examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dx12 = ["wgpu/dx12"]
vulkan = ["wgpu/vulkan"]

[dependencies]
wgpu = { path = "../wgpu-rs", features = ["winit"] }
wgpu = { path = "../wgpu-rs" }
cgmath = "0.17"
env_logger = "0.5"
glsl-to-spirv = "0.1"
Expand Down
54 changes: 27 additions & 27 deletions gfx-examples/src/cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl framework::Example for Cube {
format: wgpu::TextureFormat::R8g8b8a8Unorm,
usage: wgpu::TextureUsageFlags::SAMPLED | wgpu::TextureUsageFlags::TRANSFER_DST
});
let texture_view = texture.create_default_texture_view();
let texture_view = texture.create_default_view();
let temp_buf = device.create_buffer(&wgpu::BufferDescriptor {
size: texels.len() as u32,
usage: wgpu::BufferUsageFlags::TRANSFER_SRC | wgpu::BufferUsageFlags::TRANSFER_DST
Expand Down Expand Up @@ -232,39 +232,38 @@ impl framework::Example for Cube {
});

// Create the render pipeline
let vs_bytes = framework::load_glsl("cube.vert", wgpu::ShaderStage::Vertex);
let fs_bytes = framework::load_glsl("cube.frag", wgpu::ShaderStage::Fragment);
let vs_bytes = framework::load_glsl("cube.vert", framework::ShaderStage::Vertex);
let fs_bytes = framework::load_glsl("cube.frag", framework::ShaderStage::Fragment);
let vs_module = device.create_shader_module(&vs_bytes);
let fs_module = device.create_shader_module(&fs_bytes);

let blend_state0 = device.create_blend_state(&wgpu::BlendStateDescriptor::REPLACE);
let depth_stencil_state =
device.create_depth_stencil_state(&wgpu::DepthStencilStateDescriptor::IGNORE);

let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
layout: &pipeline_layout,
stages: &[
wgpu::PipelineStageDescriptor {
module: &vs_module,
stage: wgpu::ShaderStage::Vertex,
entry_point: "main",
},
wgpu::PipelineStageDescriptor {
module: &fs_module,
stage: wgpu::ShaderStage::Fragment,
entry_point: "main",
},
],
vertex_stage: wgpu::PipelineStageDescriptor {
module: &vs_module,
entry_point: "main",
},
fragment_stage: wgpu::PipelineStageDescriptor {
module: &fs_module,
entry_point: "main",
},
rasterization_state: wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Cw,
cull_mode: wgpu::CullMode::Back,
depth_bias: 0,
depth_bias_slope_scale: 0.0,
depth_bias_clamp: wgpu::MAX_DEPTH_BIAS_CLAMP,
},
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
attachments_state: wgpu::AttachmentsState {
color_attachments: &[wgpu::Attachment {
color_states: &[
wgpu::ColorStateDescriptor {
format: sc_desc.format,
samples: 1,
}],
depth_stencil_attachment: None,
},
blend_states: &[&blend_state0],
depth_stencil_state: &depth_stencil_state,
color: wgpu::BlendDescriptor::REPLACE,
alpha: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWriteFlags::ALL,
},
],
depth_stencil_state: None,
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[
wgpu::VertexBufferDescriptor {
Expand All @@ -284,6 +283,7 @@ impl framework::Example for Cube {
],
},
],
sample_count: 1,
});

// Done
Expand Down
15 changes: 11 additions & 4 deletions gfx-examples/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@ pub fn cast_slice<T>(data: &[T]) -> &[u8] {
}
}

pub fn load_glsl(name: &str, stage: wgpu::ShaderStage) -> Vec<u8> {
#[allow(dead_code)]
pub enum ShaderStage {
Vertex,
Fragment,
Compute,
}

pub fn load_glsl(name: &str, stage: ShaderStage) -> Vec<u8> {
use std::fs::read_to_string;
use std::io::Read;
use std::path::PathBuf;

let ty = match stage {
wgpu::ShaderStage::Vertex => glsl_to_spirv::ShaderType::Vertex,
wgpu::ShaderStage::Fragment => glsl_to_spirv::ShaderType::Fragment,
wgpu::ShaderStage::Compute => glsl_to_spirv::ShaderType::Compute,
ShaderStage::Vertex => glsl_to_spirv::ShaderType::Vertex,
ShaderStage::Fragment => glsl_to_spirv::ShaderType::Fragment,
ShaderStage::Compute => glsl_to_spirv::ShaderType::Compute,
};
let path = PathBuf::from("data").join(name);
let code = read_to_string(path).unwrap();
Expand Down
1 change: 1 addition & 0 deletions wgpu-bindings/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fn main() {
.with_crate(source_dir)
.with_config(config)
.with_parse_expand(&["wgpu-native"])
.with_parse_expand_features(&["local"])
.generate()
.unwrap()
.write_to_file(crate_dir.join("wgpu.h"));
Expand Down
Loading