diff --git a/Cargo.toml b/Cargo.toml index 096b7b488d..68f6dd6d78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ gl = ["wgn/gfx-backend-gl"] [dependencies] #TODO: only depend on the published version -wgn = { package = "wgpu-native", version = "0.2.6", features = ["local", "window-winit"], git = "https://github.com/gfx-rs/wgpu", rev = "5224bb812420e420485ee08ad8cb820695a3e6eb" } +wgn = { package = "wgpu-native", version = "0.2.6", features = ["local", "window-winit"], git = "https://github.com/gfx-rs/wgpu", rev = "f72dfc9cbbcf752ea5905ff9b038f8ca3f1d3691"} arrayvec = "0.4" zerocopy = "0.2" @@ -34,7 +34,3 @@ env_logger = "0.6" glsl-to-spirv = "0.1" log = "0.4" png = "0.15" - -[patch.crates-io] -#gfx-hal = { path = "../gfx/src/hal" } -#gfx-backend-dx12 = { path = "../gfx/src/backend/dx12" } diff --git a/examples/capture/main.rs b/examples/capture/main.rs index e40179bca8..dde9cadd95 100644 --- a/examples/capture/main.rs +++ b/examples/capture/main.rs @@ -42,7 +42,7 @@ fn main() { mip_level_count: 1, sample_count: 1, dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8Unorm, + format: wgpu::TextureFormat::Rgba8UnormSrgb, usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT | wgpu::TextureUsage::TRANSFER_SRC, }); diff --git a/examples/cube/main.rs b/examples/cube/main.rs index b5544deb73..d53604940c 100644 --- a/examples/cube/main.rs +++ b/examples/cube/main.rs @@ -161,7 +161,7 @@ impl framework::Example for Example { mip_level_count: 1, sample_count: 1, dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8Unorm, + format: wgpu::TextureFormat::Rgba8UnormSrgb, usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::TRANSFER_DST, }); let texture_view = texture.create_default_view(); diff --git a/examples/framework.rs b/examples/framework.rs index 74495acca6..78f2dfed2d 100644 --- a/examples/framework.rs +++ b/examples/framework.rs @@ -23,7 +23,7 @@ pub enum ShaderStage { Compute, } -pub fn load_glsl(code: &str, stage: ShaderStage) -> Vec { +pub fn load_glsl(code: &str, stage: ShaderStage) -> Vec { use std::io::Read; let ty = match stage { @@ -33,9 +33,14 @@ pub fn load_glsl(code: &str, stage: ShaderStage) -> Vec { }; let mut output = glsl_to_spirv::compile(&code, ty).unwrap(); - let mut spv = Vec::new(); - output.read_to_end(&mut spv).unwrap(); - spv + let mut spv_bytes = Vec::new(); + output.read_to_end(&mut spv_bytes).unwrap(); + + let mut spv_words = Vec::new(); + for bytes4 in spv_bytes.chunks(4) { + spv_words.push(u32::from_le_bytes([bytes4[0], bytes4[1], bytes4[2], bytes4[3]])); + } + spv_words } pub trait Example { @@ -78,10 +83,10 @@ pub fn run(title: &str) { }; #[cfg(feature = "gl")] - let (instance, hidpi_factor, size, surface) = { + let (_window, instance, hidpi_factor, size, surface) = { let wb = wgpu::winit::WindowBuilder::new(); let cb = wgpu::glutin::ContextBuilder::new().with_vsync(true); - let context = wgpu::glutin::WindowedContext::new_windowed(wb, cb, &events_loop).unwrap(); + let context = cb.build_windowed(wb, &events_loop).unwrap(); context.window().set_title(title); let hidpi_factor = context.window().get_hidpi_factor(); @@ -91,10 +96,12 @@ pub fn run(title: &str) { .unwrap() .to_physical(hidpi_factor); + let (context, window) = unsafe { context.make_current().unwrap().split() }; + let instance = wgpu::Instance::new(context); let surface = instance.get_surface(); - (instance, hidpi_factor, size, surface) + (window, instance, hidpi_factor, size, surface) }; let adapter = instance.get_adapter(&wgpu::AdapterDescriptor { @@ -110,7 +117,7 @@ pub fn run(title: &str) { let mut sc_desc = wgpu::SwapChainDescriptor { usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, - format: wgpu::TextureFormat::Bgra8Unorm, + format: wgpu::TextureFormat::Bgra8UnormSrgb, width: size.width.round() as u32, height: size.height.round() as u32, present_mode: wgpu::PresentMode::Vsync, diff --git a/examples/hello-compute/main.rs b/examples/hello-compute/main.rs index a56c557ae9..733b276aa8 100644 --- a/examples/hello-compute/main.rs +++ b/examples/hello-compute/main.rs @@ -26,7 +26,11 @@ fn main() { }); let cs_bytes = include_bytes!("shader.comp.spv"); - let cs_module = device.create_shader_module(cs_bytes); + let mut cs_words = vec!(); + for bytes4 in cs_bytes.chunks(4) { + cs_words.push(u32::from_le_bytes([bytes4[0], bytes4[1], bytes4[2], bytes4[3]])); + } + let cs_module = device.create_shader_module(&cs_words); let staging_buffer = device .create_buffer_mapped( diff --git a/examples/hello-triangle/main.rs b/examples/hello-triangle/main.rs index cf5172b0ec..328f02ef99 100644 --- a/examples/hello-triangle/main.rs +++ b/examples/hello-triangle/main.rs @@ -30,10 +30,10 @@ fn main() { }; #[cfg(feature = "gl")] - let (instance, size, surface) = { + let (_window, instance, size, surface) = { let wb = wgpu::winit::WindowBuilder::new(); let cb = wgpu::glutin::ContextBuilder::new().with_vsync(true); - let context = wgpu::glutin::WindowedContext::new_windowed(wb, cb, &events_loop).unwrap(); + let context = cb.build_windowed(wb, &events_loop).unwrap(); let size = context .window() @@ -41,10 +41,12 @@ fn main() { .unwrap() .to_physical(context.window().get_hidpi_factor()); + let (context, window) = unsafe { context.make_current().unwrap().split() }; + let instance = wgpu::Instance::new(context); let surface = instance.get_surface(); - (instance, size, surface) + (window, instance, size, surface) }; let adapter = instance.get_adapter(&wgpu::AdapterDescriptor { @@ -59,9 +61,18 @@ fn main() { }); let vs_bytes = include_bytes!("shader.vert.spv"); - let vs_module = device.create_shader_module(vs_bytes); + let mut vs_words = vec!(); + for bytes4 in vs_bytes.chunks(4) { + vs_words.push(u32::from_le_bytes([bytes4[0], bytes4[1], bytes4[2], bytes4[3]])); + } + let vs_module = device.create_shader_module(&vs_words); + let fs_bytes = include_bytes!("shader.frag.spv"); - let fs_module = device.create_shader_module(fs_bytes); + let mut fs_words = vec!(); + for bytes4 in fs_bytes.chunks(4) { + fs_words.push(u32::from_le_bytes([bytes4[0], bytes4[1], bytes4[2], bytes4[3]])); + } + let fs_module = device.create_shader_module(&fs_words); let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { bindings: &[] }); @@ -92,7 +103,7 @@ fn main() { }, primitive_topology: wgpu::PrimitiveTopology::TriangleList, color_states: &[wgpu::ColorStateDescriptor { - format: wgpu::TextureFormat::Bgra8Unorm, + format: wgpu::TextureFormat::Bgra8UnormSrgb, color_blend: wgpu::BlendDescriptor::REPLACE, alpha_blend: wgpu::BlendDescriptor::REPLACE, write_mask: wgpu::ColorWrite::ALL, @@ -107,7 +118,7 @@ fn main() { &surface, &wgpu::SwapChainDescriptor { usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, - format: wgpu::TextureFormat::Bgra8Unorm, + format: wgpu::TextureFormat::Bgra8UnormSrgb, width: size.width.round() as u32, height: size.height.round() as u32, present_mode: wgpu::PresentMode::Vsync, diff --git a/examples/mipmap/main.rs b/examples/mipmap/main.rs index d457942d86..b77e048822 100644 --- a/examples/mipmap/main.rs +++ b/examples/mipmap/main.rs @@ -1,7 +1,7 @@ #[path = "../framework.rs"] mod framework; -const TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8Unorm; +const TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb; #[derive(Clone, Copy)] struct Vertex { diff --git a/src/lib.rs b/src/lib.rs index bdad80d05e..ff4a22a640 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -469,7 +469,7 @@ impl Instance { } #[cfg(feature = "gl")] - pub fn new(windowed_context: wgn::glutin::WindowedContext) -> Self { + pub fn new(windowed_context: wgn::glutin::RawContext) -> Self { Instance { id: wgn::wgpu_create_gl_instance(windowed_context), } @@ -556,9 +556,9 @@ impl Device { } /// Creates a shader module from SPIR-V source code. - pub fn create_shader_module(&self, spv: &[u8]) -> ShaderModule { + pub fn create_shader_module(&self, spv: &[u32]) -> ShaderModule { let desc = wgn::ShaderModuleDescriptor { - code: wgn::ByteArray { + code: wgn::U32Array { bytes: spv.as_ptr(), length: spv.len(), }, diff --git a/tests/multithreaded_compute.rs b/tests/multithreaded_compute.rs index d09bc21ea9..b28d1d2f16 100644 --- a/tests/multithreaded_compute.rs +++ b/tests/multithreaded_compute.rs @@ -27,7 +27,11 @@ fn multithreaded_compute() { }); let cs_bytes = include_bytes!("../examples/hello-compute/shader.comp.spv"); - let cs_module = device.create_shader_module(cs_bytes); + let mut cs_words = vec!(); + for bytes4 in cs_bytes.chunks(4) { + cs_words.push(u32::from_le_bytes([bytes4[0], bytes4[1], bytes4[2], bytes4[3]])); + } + let cs_module = device.create_shader_module(&cs_words); let staging_buffer = device .create_buffer_mapped(