mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-02-16 17:02:32 +00:00
[rs] Update to latest wgpu native
This commit is contained in:
parent
ad5aab2e55
commit
a77904f3ff
@ -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" }
|
||||
|
@ -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,
|
||||
});
|
||||
|
||||
|
@ -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();
|
||||
|
@ -23,7 +23,7 @@ pub enum ShaderStage {
|
||||
Compute,
|
||||
}
|
||||
|
||||
pub fn load_glsl(code: &str, stage: ShaderStage) -> Vec<u8> {
|
||||
pub fn load_glsl(code: &str, stage: ShaderStage) -> Vec<u32> {
|
||||
use std::io::Read;
|
||||
|
||||
let ty = match stage {
|
||||
@ -33,9 +33,14 @@ pub fn load_glsl(code: &str, stage: ShaderStage) -> Vec<u8> {
|
||||
};
|
||||
|
||||
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<E: Example>(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<E: Example>(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<E: Example>(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,
|
||||
|
@ -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(
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -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<wgn::glutin::PossiblyCurrent>) -> 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(),
|
||||
},
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user