Upgrade to wgpu 0.7 (#134)
Co-authored-by: Jay Oster <jay@kodewerx.org>
This commit is contained in:
parent
0709161e02
commit
f2d4a4f084
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
@ -13,7 +13,7 @@ jobs:
|
||||||
rust:
|
rust:
|
||||||
- stable
|
- stable
|
||||||
- beta
|
- beta
|
||||||
- 1.46.0
|
- 1.48.0
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
@ -40,7 +40,7 @@ jobs:
|
||||||
rust:
|
rust:
|
||||||
- stable
|
- stable
|
||||||
- beta
|
- beta
|
||||||
- 1.46.0
|
- 1.48.0
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
|
@ -23,7 +23,7 @@ pollster = "0.2"
|
||||||
raw-window-handle = "0.3"
|
raw-window-handle = "0.3"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
ultraviolet = "0.7"
|
ultraviolet = "0.7"
|
||||||
wgpu = "0.6"
|
wgpu = "0.7"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
pixels-mocks = { path = "internals/pixels-mocks" }
|
pixels-mocks = { path = "internals/pixels-mocks" }
|
||||||
|
|
|
@ -153,7 +153,7 @@ fn create_noise_renderer(pixels: &Pixels) -> (wgpu::TextureView, NoiseRenderer)
|
||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
dimension: wgpu::TextureDimension::D2,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
||||||
usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::RENDER_ATTACHMENT,
|
||||||
};
|
};
|
||||||
let scaled_texture = device
|
let scaled_texture = device
|
||||||
.create_texture(&texture_descriptor)
|
.create_texture(&texture_descriptor)
|
||||||
|
|
|
@ -8,8 +8,8 @@ pub(crate) struct NoiseRenderer {
|
||||||
|
|
||||||
impl NoiseRenderer {
|
impl NoiseRenderer {
|
||||||
pub(crate) fn new(device: &wgpu::Device, texture_view: &wgpu::TextureView) -> Self {
|
pub(crate) fn new(device: &wgpu::Device, texture_view: &wgpu::TextureView) -> Self {
|
||||||
let vs_module = device.create_shader_module(wgpu::include_spirv!("../shaders/vert.spv"));
|
let vs_module = device.create_shader_module(&wgpu::include_spirv!("../shaders/vert.spv"));
|
||||||
let fs_module = device.create_shader_module(wgpu::include_spirv!("../shaders/frag.spv"));
|
let fs_module = device.create_shader_module(&wgpu::include_spirv!("../shaders/frag.spv"));
|
||||||
|
|
||||||
// Create a texture sampler with nearest neighbor
|
// Create a texture sampler with nearest neighbor
|
||||||
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||||
|
@ -24,6 +24,7 @@ impl NoiseRenderer {
|
||||||
lod_max_clamp: 1.0,
|
lod_max_clamp: 1.0,
|
||||||
compare: None,
|
compare: None,
|
||||||
anisotropy_clamp: None,
|
anisotropy_clamp: None,
|
||||||
|
border_color: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create uniform buffer
|
// Create uniform buffer
|
||||||
|
@ -40,24 +41,28 @@ impl NoiseRenderer {
|
||||||
wgpu::BindGroupLayoutEntry {
|
wgpu::BindGroupLayoutEntry {
|
||||||
binding: 0,
|
binding: 0,
|
||||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
visibility: wgpu::ShaderStage::FRAGMENT,
|
||||||
ty: wgpu::BindingType::SampledTexture {
|
ty: wgpu::BindingType::Texture {
|
||||||
component_type: wgpu::TextureComponentType::Uint,
|
sample_type: wgpu::TextureSampleType::Float { filterable: true },
|
||||||
multisampled: false,
|
multisampled: false,
|
||||||
dimension: wgpu::TextureViewDimension::D2,
|
view_dimension: wgpu::TextureViewDimension::D2,
|
||||||
},
|
},
|
||||||
count: None,
|
count: None,
|
||||||
},
|
},
|
||||||
wgpu::BindGroupLayoutEntry {
|
wgpu::BindGroupLayoutEntry {
|
||||||
binding: 1,
|
binding: 1,
|
||||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
visibility: wgpu::ShaderStage::FRAGMENT,
|
||||||
ty: wgpu::BindingType::Sampler { comparison: false },
|
ty: wgpu::BindingType::Sampler {
|
||||||
|
filtering: true,
|
||||||
|
comparison: false,
|
||||||
|
},
|
||||||
count: None,
|
count: None,
|
||||||
},
|
},
|
||||||
wgpu::BindGroupLayoutEntry {
|
wgpu::BindGroupLayoutEntry {
|
||||||
binding: 2,
|
binding: 2,
|
||||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
visibility: wgpu::ShaderStage::FRAGMENT,
|
||||||
ty: wgpu::BindingType::UniformBuffer {
|
ty: wgpu::BindingType::Buffer {
|
||||||
dynamic: false,
|
ty: wgpu::BufferBindingType::Uniform,
|
||||||
|
has_dynamic_offset: false,
|
||||||
min_binding_size: None,
|
min_binding_size: None,
|
||||||
},
|
},
|
||||||
count: None,
|
count: None,
|
||||||
|
@ -78,7 +83,11 @@ impl NoiseRenderer {
|
||||||
},
|
},
|
||||||
wgpu::BindGroupEntry {
|
wgpu::BindGroupEntry {
|
||||||
binding: 2,
|
binding: 2,
|
||||||
resource: wgpu::BindingResource::Buffer(time_buffer.slice(..)),
|
resource: wgpu::BindingResource::Buffer {
|
||||||
|
buffer: &time_buffer,
|
||||||
|
offset: 0,
|
||||||
|
size: None,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
@ -92,37 +101,34 @@ impl NoiseRenderer {
|
||||||
let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||||
label: Some("NoiseRenderer pipeline"),
|
label: Some("NoiseRenderer pipeline"),
|
||||||
layout: Some(&pipeline_layout),
|
layout: Some(&pipeline_layout),
|
||||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
vertex: wgpu::VertexState {
|
||||||
module: &vs_module,
|
module: &vs_module,
|
||||||
entry_point: "main",
|
entry_point: "main",
|
||||||
|
buffers: &[],
|
||||||
},
|
},
|
||||||
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
|
primitive: wgpu::PrimitiveState {
|
||||||
module: &fs_module,
|
topology: wgpu::PrimitiveTopology::TriangleList,
|
||||||
entry_point: "main",
|
strip_index_format: None,
|
||||||
}),
|
|
||||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
|
||||||
front_face: wgpu::FrontFace::Ccw,
|
front_face: wgpu::FrontFace::Ccw,
|
||||||
cull_mode: wgpu::CullMode::None,
|
cull_mode: wgpu::CullMode::None,
|
||||||
clamp_depth: false,
|
polygon_mode: wgpu::PolygonMode::Fill,
|
||||||
depth_bias: 0,
|
|
||||||
depth_bias_slope_scale: 0.0,
|
|
||||||
depth_bias_clamp: 0.0,
|
|
||||||
}),
|
|
||||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
|
||||||
color_states: &[wgpu::ColorStateDescriptor {
|
|
||||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
|
||||||
color_blend: wgpu::BlendDescriptor::REPLACE,
|
|
||||||
alpha_blend: wgpu::BlendDescriptor::REPLACE,
|
|
||||||
write_mask: wgpu::ColorWrite::ALL,
|
|
||||||
}],
|
|
||||||
depth_stencil_state: None,
|
|
||||||
vertex_state: wgpu::VertexStateDescriptor {
|
|
||||||
index_format: wgpu::IndexFormat::Uint16,
|
|
||||||
vertex_buffers: &[],
|
|
||||||
},
|
},
|
||||||
sample_count: 1,
|
depth_stencil: None,
|
||||||
sample_mask: !0,
|
multisample: wgpu::MultisampleState {
|
||||||
alpha_to_coverage_enabled: false,
|
count: 1,
|
||||||
|
mask: !0,
|
||||||
|
alpha_to_coverage_enabled: false,
|
||||||
|
},
|
||||||
|
fragment: Some(wgpu::FragmentState {
|
||||||
|
module: &fs_module,
|
||||||
|
entry_point: "main",
|
||||||
|
targets: &[wgpu::ColorTargetState {
|
||||||
|
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
||||||
|
color_blend: wgpu::BlendState::REPLACE,
|
||||||
|
alpha_blend: wgpu::BlendState::REPLACE,
|
||||||
|
write_mask: wgpu::ColorWrite::ALL,
|
||||||
|
}],
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
@ -142,6 +148,7 @@ impl NoiseRenderer {
|
||||||
render_target: &wgpu::TextureView,
|
render_target: &wgpu::TextureView,
|
||||||
) {
|
) {
|
||||||
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||||
|
label: Some("NoiseRenderer render pass"),
|
||||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||||
attachment: render_target,
|
attachment: render_target,
|
||||||
resolve_target: None,
|
resolve_target: None,
|
||||||
|
|
|
@ -12,7 +12,7 @@ default = ["optimize"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
env_logger = "0.8"
|
env_logger = "0.8"
|
||||||
imgui = "0.7"
|
imgui = "0.7"
|
||||||
imgui-wgpu = { git = "https://github.com/parasyte/imgui-wgpu-rs.git", rev = "8da89b3ad1ef54384b7ff4bd550adf9f808df1f8" }
|
imgui-wgpu = "0.14"
|
||||||
imgui-winit-support = "0.7"
|
imgui-winit-support = "0.7"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
pixels = { path = "../.." }
|
pixels = { path = "../.." }
|
||||||
|
|
|
@ -114,6 +114,7 @@ impl Gui {
|
||||||
|
|
||||||
// Render Dear ImGui with WGPU
|
// Render Dear ImGui with WGPU
|
||||||
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||||
|
label: Some("imgui"),
|
||||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||||
attachment: render_target,
|
attachment: render_target,
|
||||||
resolve_target: None,
|
resolve_target: None,
|
||||||
|
|
222
src/builder.rs
222
src/builder.rs
|
@ -5,9 +5,9 @@ use raw_window_handle::HasRawWindowHandle;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
/// A builder to help create customized pixel buffers.
|
/// A builder to help create customized pixel buffers.
|
||||||
pub struct PixelsBuilder<'req, 'win, W: HasRawWindowHandle> {
|
pub struct PixelsBuilder<'req, 'dev, 'win, W: HasRawWindowHandle> {
|
||||||
request_adapter_options: Option<wgpu::RequestAdapterOptions<'req>>,
|
request_adapter_options: Option<wgpu::RequestAdapterOptions<'req>>,
|
||||||
device_descriptor: wgpu::DeviceDescriptor,
|
device_descriptor: wgpu::DeviceDescriptor<'dev>,
|
||||||
backend: wgpu::BackendBit,
|
backend: wgpu::BackendBit,
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
|
@ -18,7 +18,7 @@ pub struct PixelsBuilder<'req, 'win, W: HasRawWindowHandle> {
|
||||||
render_texture_format: wgpu::TextureFormat,
|
render_texture_format: wgpu::TextureFormat,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'req, 'win, W: HasRawWindowHandle> PixelsBuilder<'req, 'win, W> {
|
impl<'req, 'dev, 'win, W: HasRawWindowHandle> PixelsBuilder<'req, 'dev, 'win, W> {
|
||||||
/// Create a builder that can be finalized into a [`Pixels`] pixel buffer.
|
/// Create a builder that can be finalized into a [`Pixels`] pixel buffer.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
|
@ -44,7 +44,7 @@ impl<'req, 'win, W: HasRawWindowHandle> PixelsBuilder<'req, 'win, W> {
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
surface_texture: SurfaceTexture<'win, W>,
|
surface_texture: SurfaceTexture<'win, W>,
|
||||||
) -> PixelsBuilder<'req, 'win, W> {
|
) -> PixelsBuilder<'req, 'dev, 'win, W> {
|
||||||
assert!(width > 0);
|
assert!(width > 0);
|
||||||
assert!(height > 0);
|
assert!(height > 0);
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ impl<'req, 'win, W: HasRawWindowHandle> PixelsBuilder<'req, 'win, W> {
|
||||||
pub fn request_adapter_options(
|
pub fn request_adapter_options(
|
||||||
mut self,
|
mut self,
|
||||||
request_adapter_options: wgpu::RequestAdapterOptions<'req>,
|
request_adapter_options: wgpu::RequestAdapterOptions<'req>,
|
||||||
) -> PixelsBuilder<'req, 'win, W> {
|
) -> PixelsBuilder<'req, 'dev, 'win, W> {
|
||||||
self.request_adapter_options = Some(request_adapter_options);
|
self.request_adapter_options = Some(request_adapter_options);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -74,8 +74,8 @@ impl<'req, 'win, W: HasRawWindowHandle> PixelsBuilder<'req, 'win, W> {
|
||||||
/// Add options for requesting a [`wgpu::Device`].
|
/// Add options for requesting a [`wgpu::Device`].
|
||||||
pub fn device_descriptor(
|
pub fn device_descriptor(
|
||||||
mut self,
|
mut self,
|
||||||
device_descriptor: wgpu::DeviceDescriptor,
|
device_descriptor: wgpu::DeviceDescriptor<'dev>,
|
||||||
) -> PixelsBuilder<'req, 'win, W> {
|
) -> PixelsBuilder<'req, 'dev, 'win, W> {
|
||||||
self.device_descriptor = device_descriptor;
|
self.device_descriptor = device_descriptor;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ impl<'req, 'win, W: HasRawWindowHandle> PixelsBuilder<'req, 'win, W> {
|
||||||
///
|
///
|
||||||
/// The default value of this is [`wgpu::BackendBit::PRIMARY`], which enables
|
/// The default value of this is [`wgpu::BackendBit::PRIMARY`], which enables
|
||||||
/// the well supported backends for wgpu.
|
/// the well supported backends for wgpu.
|
||||||
pub fn wgpu_backend(mut self, backend: wgpu::BackendBit) -> PixelsBuilder<'req, 'win, W> {
|
pub fn wgpu_backend(mut self, backend: wgpu::BackendBit) -> PixelsBuilder<'req, 'dev, 'win, W> {
|
||||||
self.backend = backend;
|
self.backend = backend;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,10 @@ impl<'req, 'win, W: HasRawWindowHandle> PixelsBuilder<'req, 'win, W> {
|
||||||
///
|
///
|
||||||
/// This documentation is hidden because support for pixel aspect ratio is incomplete.
|
/// This documentation is hidden because support for pixel aspect ratio is incomplete.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn pixel_aspect_ratio(mut self, pixel_aspect_ratio: f64) -> PixelsBuilder<'req, 'win, W> {
|
pub fn pixel_aspect_ratio(
|
||||||
|
mut self,
|
||||||
|
pixel_aspect_ratio: f64,
|
||||||
|
) -> PixelsBuilder<'req, 'dev, 'win, W> {
|
||||||
assert!(pixel_aspect_ratio > 0.0);
|
assert!(pixel_aspect_ratio > 0.0);
|
||||||
|
|
||||||
self.pixel_aspect_ratio = pixel_aspect_ratio;
|
self.pixel_aspect_ratio = pixel_aspect_ratio;
|
||||||
|
@ -118,7 +121,7 @@ impl<'req, 'win, W: HasRawWindowHandle> PixelsBuilder<'req, 'win, W> {
|
||||||
/// The `wgpu` present mode will be set to `Fifo` when Vsync is enabled, or `Immediate` when
|
/// The `wgpu` present mode will be set to `Fifo` when Vsync is enabled, or `Immediate` when
|
||||||
/// Vsync is disabled. To set the present mode to `Mailbox` or another value, use the
|
/// Vsync is disabled. To set the present mode to `Mailbox` or another value, use the
|
||||||
/// [`PixelsBuilder::present_mode`] method.
|
/// [`PixelsBuilder::present_mode`] method.
|
||||||
pub fn enable_vsync(mut self, enable_vsync: bool) -> PixelsBuilder<'req, 'win, W> {
|
pub fn enable_vsync(mut self, enable_vsync: bool) -> PixelsBuilder<'req, 'dev, 'win, W> {
|
||||||
self.present_mode = if enable_vsync {
|
self.present_mode = if enable_vsync {
|
||||||
wgpu::PresentMode::Fifo
|
wgpu::PresentMode::Fifo
|
||||||
} else {
|
} else {
|
||||||
|
@ -131,7 +134,10 @@ impl<'req, 'win, W: HasRawWindowHandle> PixelsBuilder<'req, 'win, W> {
|
||||||
///
|
///
|
||||||
/// This differs from [`PixelsBuilder::enable_vsync`] by allowing the present mode to be set to
|
/// This differs from [`PixelsBuilder::enable_vsync`] by allowing the present mode to be set to
|
||||||
/// any value.
|
/// any value.
|
||||||
pub fn present_mode(mut self, present_mode: wgpu::PresentMode) -> PixelsBuilder<'req, 'win, W> {
|
pub fn present_mode(
|
||||||
|
mut self,
|
||||||
|
present_mode: wgpu::PresentMode,
|
||||||
|
) -> PixelsBuilder<'req, 'dev, 'win, W> {
|
||||||
self.present_mode = present_mode;
|
self.present_mode = present_mode;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -144,7 +150,7 @@ impl<'req, 'win, W: HasRawWindowHandle> PixelsBuilder<'req, 'win, W> {
|
||||||
pub fn texture_format(
|
pub fn texture_format(
|
||||||
mut self,
|
mut self,
|
||||||
texture_format: wgpu::TextureFormat,
|
texture_format: wgpu::TextureFormat,
|
||||||
) -> PixelsBuilder<'req, 'win, W> {
|
) -> PixelsBuilder<'req, 'dev, 'win, W> {
|
||||||
self.texture_format = texture_format;
|
self.texture_format = texture_format;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -157,7 +163,7 @@ impl<'req, 'win, W: HasRawWindowHandle> PixelsBuilder<'req, 'win, W> {
|
||||||
pub fn render_texture_format(
|
pub fn render_texture_format(
|
||||||
mut self,
|
mut self,
|
||||||
texture_format: wgpu::TextureFormat,
|
texture_format: wgpu::TextureFormat,
|
||||||
) -> PixelsBuilder<'req, 'win, W> {
|
) -> PixelsBuilder<'req, 'dev, 'win, W> {
|
||||||
self.render_texture_format = texture_format;
|
self.render_texture_format = texture_format;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -252,7 +258,7 @@ pub(crate) fn create_swap_chain(
|
||||||
device.create_swap_chain(
|
device.create_swap_chain(
|
||||||
&surface,
|
&surface,
|
||||||
&wgpu::SwapChainDescriptor {
|
&wgpu::SwapChainDescriptor {
|
||||||
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
|
||||||
format,
|
format,
|
||||||
width: surface_size.width,
|
width: surface_size.width,
|
||||||
height: surface_size.height,
|
height: surface_size.height,
|
||||||
|
@ -318,80 +324,152 @@ pub(crate) fn create_backing_texture(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
#[inline]
|
#[inline]
|
||||||
const fn get_texture_format_size(texture_format: wgpu::TextureFormat) -> f32 {
|
const fn get_texture_format_size(texture_format: wgpu::TextureFormat) -> f32 {
|
||||||
|
use wgpu::TextureFormat::*;
|
||||||
|
|
||||||
|
// TODO: Use constant arithmetic when supported.
|
||||||
|
// See: https://github.com/rust-lang/rust/issues/57241
|
||||||
match texture_format {
|
match texture_format {
|
||||||
// 8-bit formats
|
// 8-bit formats, 8 bits per component
|
||||||
wgpu::TextureFormat::R8Unorm
|
R8Unorm
|
||||||
| wgpu::TextureFormat::R8Snorm
|
| R8Snorm
|
||||||
| wgpu::TextureFormat::R8Uint
|
| R8Uint
|
||||||
| wgpu::TextureFormat::R8Sint => 1.0,
|
| R8Sint => 1.0, // 8.0 / 8.0
|
||||||
|
|
||||||
// 16-bit formats
|
// 16-bit formats, 8 bits per component
|
||||||
wgpu::TextureFormat::R16Uint
|
R16Uint
|
||||||
| wgpu::TextureFormat::R16Sint
|
| R16Sint
|
||||||
| wgpu::TextureFormat::R16Float
|
| R16Float
|
||||||
| wgpu::TextureFormat::Rg8Unorm
|
| Rg8Unorm
|
||||||
| wgpu::TextureFormat::Rg8Snorm
|
| Rg8Snorm
|
||||||
| wgpu::TextureFormat::Rg8Uint
|
| Rg8Uint
|
||||||
| wgpu::TextureFormat::Rg8Sint => 2.0,
|
| Rg8Sint => 2.0, // 16.0 / 8.0
|
||||||
|
|
||||||
// 32-bit formats
|
// 32-bit formats, 8 bits per component
|
||||||
wgpu::TextureFormat::R32Uint
|
R32Uint
|
||||||
| wgpu::TextureFormat::R32Sint
|
| R32Sint
|
||||||
| wgpu::TextureFormat::R32Float
|
| R32Float
|
||||||
| wgpu::TextureFormat::Rg16Uint
|
| Rg16Uint
|
||||||
| wgpu::TextureFormat::Rg16Sint
|
| Rg16Sint
|
||||||
| wgpu::TextureFormat::Rg16Float
|
| Rg16Float
|
||||||
| wgpu::TextureFormat::Rgba8Unorm
|
| Rgba8Unorm
|
||||||
| wgpu::TextureFormat::Rgba8UnormSrgb
|
| Rgba8UnormSrgb
|
||||||
| wgpu::TextureFormat::Rgba8Snorm
|
| Rgba8Snorm
|
||||||
| wgpu::TextureFormat::Rgba8Uint
|
| Rgba8Uint
|
||||||
| wgpu::TextureFormat::Rgba8Sint
|
| Rgba8Sint
|
||||||
| wgpu::TextureFormat::Bgra8Unorm
|
| Bgra8Unorm
|
||||||
| wgpu::TextureFormat::Bgra8UnormSrgb
|
| Bgra8UnormSrgb
|
||||||
| wgpu::TextureFormat::Rgb10a2Unorm
|
| Rgb10a2Unorm
|
||||||
| wgpu::TextureFormat::Rg11b10Float
|
| Rg11b10Float
|
||||||
| wgpu::TextureFormat::Depth32Float
|
| Depth32Float
|
||||||
| wgpu::TextureFormat::Depth24Plus
|
| Depth24Plus
|
||||||
| wgpu::TextureFormat::Depth24PlusStencil8 => 4.0,
|
| Depth24PlusStencil8 => 4.0, // 32.0 / 8.0
|
||||||
|
|
||||||
// 64-bit formats
|
// 64-bit formats, 8 bits per component
|
||||||
wgpu::TextureFormat::Rg32Uint
|
Rg32Uint
|
||||||
| wgpu::TextureFormat::Rg32Sint
|
| Rg32Sint
|
||||||
| wgpu::TextureFormat::Rg32Float
|
| Rg32Float
|
||||||
| wgpu::TextureFormat::Rgba16Uint
|
| Rgba16Uint
|
||||||
| wgpu::TextureFormat::Rgba16Sint
|
| Rgba16Sint
|
||||||
| wgpu::TextureFormat::Rgba16Float => 8.0,
|
| Rgba16Float => 8.0, // 64.0 / 8.0
|
||||||
|
|
||||||
// 128-bit formats
|
// 128-bit formats, 8 bits per component
|
||||||
wgpu::TextureFormat::Rgba32Uint
|
Rgba32Uint
|
||||||
| wgpu::TextureFormat::Rgba32Sint
|
| Rgba32Sint
|
||||||
| wgpu::TextureFormat::Rgba32Float => 16.0,
|
| Rgba32Float => 16.0, // 128.0 / 8.0
|
||||||
|
|
||||||
// Compressed formats
|
// Compressed formats
|
||||||
wgpu::TextureFormat::Bc1RgbaUnorm
|
|
||||||
| wgpu::TextureFormat::Bc1RgbaUnormSrgb
|
|
||||||
| wgpu::TextureFormat::Bc4RUnorm
|
|
||||||
| wgpu::TextureFormat::Bc4RSnorm => 0.5,
|
|
||||||
|
|
||||||
wgpu::TextureFormat::Bc2RgbaUnorm
|
// 4x4 blocks, 8 bytes per block
|
||||||
| wgpu::TextureFormat::Bc2RgbaUnormSrgb
|
Bc1RgbaUnorm
|
||||||
| wgpu::TextureFormat::Bc3RgbaUnorm
|
| Bc1RgbaUnormSrgb
|
||||||
| wgpu::TextureFormat::Bc3RgbaUnormSrgb
|
| Bc4RUnorm
|
||||||
| wgpu::TextureFormat::Bc5RgUnorm
|
| Bc4RSnorm
|
||||||
| wgpu::TextureFormat::Bc5RgSnorm
|
| Etc2RgbUnorm
|
||||||
| wgpu::TextureFormat::Bc6hRgbUfloat
|
| Etc2RgbUnormSrgb
|
||||||
| wgpu::TextureFormat::Bc6hRgbSfloat
|
| Etc2RgbA1Unorm
|
||||||
| wgpu::TextureFormat::Bc7RgbaUnorm
|
| Etc2RgbA1UnormSrgb
|
||||||
| wgpu::TextureFormat::Bc7RgbaUnormSrgb => 1.0,
|
| EacRUnorm
|
||||||
|
| EacRSnorm => 0.5, // 4.0 * 4.0 / 8.0
|
||||||
|
|
||||||
|
// 4x4 blocks, 16 bytes per block
|
||||||
|
Bc2RgbaUnorm
|
||||||
|
| Bc2RgbaUnormSrgb
|
||||||
|
| Bc3RgbaUnorm
|
||||||
|
| Bc3RgbaUnormSrgb
|
||||||
|
| Bc5RgUnorm
|
||||||
|
| Bc5RgSnorm
|
||||||
|
| Bc6hRgbUfloat
|
||||||
|
| Bc6hRgbSfloat
|
||||||
|
| Bc7RgbaUnorm
|
||||||
|
| Bc7RgbaUnormSrgb
|
||||||
|
| Etc2RgbA8Unorm
|
||||||
|
| Etc2RgbA8UnormSrgb
|
||||||
|
| EtcRgUnorm
|
||||||
|
| EtcRgSnorm
|
||||||
|
| Astc4x4RgbaUnorm
|
||||||
|
| Astc4x4RgbaUnormSrgb => 1.0, // 4.0 * 4.0 / 16.0
|
||||||
|
|
||||||
|
// 5x4 blocks, 16 bytes per block
|
||||||
|
Astc5x4RgbaUnorm
|
||||||
|
| Astc5x4RgbaUnormSrgb => 1.25, // 5.0 * 4.0 / 16.0
|
||||||
|
|
||||||
|
// 5x5 blocks, 16 bytes per block
|
||||||
|
Astc5x5RgbaUnorm
|
||||||
|
| Astc5x5RgbaUnormSrgb => 1.5625, // 5.0 * 5.0 / 16.0
|
||||||
|
|
||||||
|
// 6x5 blocks, 16 bytes per block
|
||||||
|
Astc6x5RgbaUnorm
|
||||||
|
| Astc6x5RgbaUnormSrgb => 1.875, // 6.0 * 5.0 / 16.0
|
||||||
|
|
||||||
|
// 6x6 blocks, 16 bytes per block
|
||||||
|
Astc6x6RgbaUnorm
|
||||||
|
| Astc6x6RgbaUnormSrgb => 2.25, // 6.0 * 6.0 / 16.0
|
||||||
|
|
||||||
|
// 8x5 blocks, 16 bytes per block
|
||||||
|
Astc8x5RgbaUnorm
|
||||||
|
| Astc8x5RgbaUnormSrgb => 2.5, // 8.0 * 5.0 / 16.0
|
||||||
|
|
||||||
|
// 8x6 blocks, 16 bytes per block
|
||||||
|
Astc8x6RgbaUnorm
|
||||||
|
| Astc8x6RgbaUnormSrgb => 3.0, // 8.0 * 6.0 / 16.0
|
||||||
|
|
||||||
|
// 8x8 blocks, 16 bytes per block
|
||||||
|
Astc8x8RgbaUnorm
|
||||||
|
| Astc8x8RgbaUnormSrgb => 4.0, // 8.0 * 8.0 / 16.0
|
||||||
|
|
||||||
|
// 10x5 blocks, 16 bytes per block
|
||||||
|
Astc10x5RgbaUnorm
|
||||||
|
| Astc10x5RgbaUnormSrgb => 3.125, // 10.0 * 5.0 / 16.0
|
||||||
|
|
||||||
|
// 10x6 blocks, 16 bytes per block
|
||||||
|
Astc10x6RgbaUnorm
|
||||||
|
| Astc10x6RgbaUnormSrgb => 3.75, // 10.0 * 6.0 / 16.0
|
||||||
|
|
||||||
|
// 10x8 blocks, 16 bytes per block
|
||||||
|
Astc10x8RgbaUnorm
|
||||||
|
| Astc10x8RgbaUnormSrgb => 5.0, // 10.0 * 8.0 / 16.0
|
||||||
|
|
||||||
|
// 10x10 blocks, 16 bytes per block
|
||||||
|
Astc10x10RgbaUnorm
|
||||||
|
| Astc10x10RgbaUnormSrgb => 6.25, // 10.0 * 10.0 / 16.0
|
||||||
|
|
||||||
|
// 12x10 blocks, 16 bytes per block
|
||||||
|
Astc12x10RgbaUnorm
|
||||||
|
| Astc12x10RgbaUnormSrgb => 7.5, // 12.0 * 10.0 / 16.0
|
||||||
|
|
||||||
|
// 12x12 blocks, 16 bytes per block
|
||||||
|
Astc12x12RgbaUnorm
|
||||||
|
| Astc12x12RgbaUnormSrgb => 9.0, // 12.0 * 12.0 / 16.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_default_power_preference() -> wgpu::PowerPreference {
|
fn get_default_power_preference() -> wgpu::PowerPreference {
|
||||||
env::var("PIXELS_HIGH_PERF").map_or_else(
|
env::var("PIXELS_HIGH_PERF").map_or_else(
|
||||||
|_| {
|
|_| {
|
||||||
env::var("PIXELS_LOW_POWER").map_or(wgpu::PowerPreference::Default, |_| {
|
env::var("PIXELS_LOW_POWER").map_or(wgpu::PowerPreference::default(), |_| {
|
||||||
wgpu::PowerPreference::LowPower
|
wgpu::PowerPreference::LowPower
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
@ -19,8 +19,8 @@ impl ScalingRenderer {
|
||||||
texture_size: &wgpu::Extent3d,
|
texture_size: &wgpu::Extent3d,
|
||||||
render_texture_format: wgpu::TextureFormat,
|
render_texture_format: wgpu::TextureFormat,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let vs_module = device.create_shader_module(wgpu::include_spirv!("../shaders/vert.spv"));
|
let vs_module = device.create_shader_module(&wgpu::include_spirv!("../shaders/vert.spv"));
|
||||||
let fs_module = device.create_shader_module(wgpu::include_spirv!("../shaders/frag.spv"));
|
let fs_module = device.create_shader_module(&wgpu::include_spirv!("../shaders/frag.spv"));
|
||||||
|
|
||||||
// Create a texture sampler with nearest neighbor
|
// Create a texture sampler with nearest neighbor
|
||||||
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||||
|
@ -35,6 +35,7 @@ impl ScalingRenderer {
|
||||||
lod_max_clamp: 1.0,
|
lod_max_clamp: 1.0,
|
||||||
compare: None,
|
compare: None,
|
||||||
anisotropy_clamp: None,
|
anisotropy_clamp: None,
|
||||||
|
border_color: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create uniform buffer
|
// Create uniform buffer
|
||||||
|
@ -58,24 +59,28 @@ impl ScalingRenderer {
|
||||||
wgpu::BindGroupLayoutEntry {
|
wgpu::BindGroupLayoutEntry {
|
||||||
binding: 0,
|
binding: 0,
|
||||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
visibility: wgpu::ShaderStage::FRAGMENT,
|
||||||
ty: wgpu::BindingType::SampledTexture {
|
ty: wgpu::BindingType::Texture {
|
||||||
component_type: wgpu::TextureComponentType::Uint,
|
sample_type: wgpu::TextureSampleType::Float { filterable: true },
|
||||||
multisampled: false,
|
multisampled: false,
|
||||||
dimension: wgpu::TextureViewDimension::D2,
|
view_dimension: wgpu::TextureViewDimension::D2,
|
||||||
},
|
},
|
||||||
count: None,
|
count: None,
|
||||||
},
|
},
|
||||||
wgpu::BindGroupLayoutEntry {
|
wgpu::BindGroupLayoutEntry {
|
||||||
binding: 1,
|
binding: 1,
|
||||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
visibility: wgpu::ShaderStage::FRAGMENT,
|
||||||
ty: wgpu::BindingType::Sampler { comparison: false },
|
ty: wgpu::BindingType::Sampler {
|
||||||
|
filtering: true,
|
||||||
|
comparison: false,
|
||||||
|
},
|
||||||
count: None,
|
count: None,
|
||||||
},
|
},
|
||||||
wgpu::BindGroupLayoutEntry {
|
wgpu::BindGroupLayoutEntry {
|
||||||
binding: 2,
|
binding: 2,
|
||||||
visibility: wgpu::ShaderStage::VERTEX,
|
visibility: wgpu::ShaderStage::VERTEX,
|
||||||
ty: wgpu::BindingType::UniformBuffer {
|
ty: wgpu::BindingType::Buffer {
|
||||||
dynamic: false,
|
ty: wgpu::BufferBindingType::Uniform,
|
||||||
|
has_dynamic_offset: false,
|
||||||
min_binding_size: None,
|
min_binding_size: None,
|
||||||
},
|
},
|
||||||
count: None,
|
count: None,
|
||||||
|
@ -96,7 +101,11 @@ impl ScalingRenderer {
|
||||||
},
|
},
|
||||||
wgpu::BindGroupEntry {
|
wgpu::BindGroupEntry {
|
||||||
binding: 2,
|
binding: 2,
|
||||||
resource: wgpu::BindingResource::Buffer(uniform_buffer.slice(..)),
|
resource: wgpu::BindingResource::Buffer {
|
||||||
|
buffer: &uniform_buffer,
|
||||||
|
offset: 0,
|
||||||
|
size: None,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
@ -110,37 +119,34 @@ impl ScalingRenderer {
|
||||||
let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||||
label: Some("pixels_scaling_renderer_pipeline"),
|
label: Some("pixels_scaling_renderer_pipeline"),
|
||||||
layout: Some(&pipeline_layout),
|
layout: Some(&pipeline_layout),
|
||||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
vertex: wgpu::VertexState {
|
||||||
module: &vs_module,
|
module: &vs_module,
|
||||||
entry_point: "main",
|
entry_point: "main",
|
||||||
|
buffers: &[],
|
||||||
},
|
},
|
||||||
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
|
primitive: wgpu::PrimitiveState {
|
||||||
module: &fs_module,
|
topology: wgpu::PrimitiveTopology::TriangleList,
|
||||||
entry_point: "main",
|
strip_index_format: None,
|
||||||
}),
|
|
||||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
|
||||||
front_face: wgpu::FrontFace::Ccw,
|
front_face: wgpu::FrontFace::Ccw,
|
||||||
cull_mode: wgpu::CullMode::None,
|
cull_mode: wgpu::CullMode::None,
|
||||||
clamp_depth: false,
|
polygon_mode: wgpu::PolygonMode::Fill,
|
||||||
depth_bias: 0,
|
|
||||||
depth_bias_slope_scale: 0.0,
|
|
||||||
depth_bias_clamp: 0.0,
|
|
||||||
}),
|
|
||||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
|
||||||
color_states: &[wgpu::ColorStateDescriptor {
|
|
||||||
format: render_texture_format,
|
|
||||||
color_blend: wgpu::BlendDescriptor::REPLACE,
|
|
||||||
alpha_blend: wgpu::BlendDescriptor::REPLACE,
|
|
||||||
write_mask: wgpu::ColorWrite::ALL,
|
|
||||||
}],
|
|
||||||
depth_stencil_state: None,
|
|
||||||
vertex_state: wgpu::VertexStateDescriptor {
|
|
||||||
index_format: wgpu::IndexFormat::Uint16,
|
|
||||||
vertex_buffers: &[],
|
|
||||||
},
|
},
|
||||||
sample_count: 1,
|
depth_stencil: None,
|
||||||
sample_mask: !0,
|
multisample: wgpu::MultisampleState {
|
||||||
alpha_to_coverage_enabled: false,
|
count: 1,
|
||||||
|
mask: !0,
|
||||||
|
alpha_to_coverage_enabled: false,
|
||||||
|
},
|
||||||
|
fragment: Some(wgpu::FragmentState {
|
||||||
|
module: &fs_module,
|
||||||
|
entry_point: "main",
|
||||||
|
targets: &[wgpu::ColorTargetState {
|
||||||
|
format: render_texture_format,
|
||||||
|
color_blend: wgpu::BlendState::REPLACE,
|
||||||
|
alpha_blend: wgpu::BlendState::REPLACE,
|
||||||
|
write_mask: wgpu::ColorWrite::ALL,
|
||||||
|
}],
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
@ -156,6 +162,7 @@ impl ScalingRenderer {
|
||||||
pub fn render(&self, encoder: &mut wgpu::CommandEncoder, render_target: &wgpu::TextureView) {
|
pub fn render(&self, encoder: &mut wgpu::CommandEncoder, render_target: &wgpu::TextureView) {
|
||||||
// Draw the updated texture to the render target
|
// Draw the updated texture to the render target
|
||||||
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||||
|
label: Some("pixels_scaling_renderer_render_pass"),
|
||||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||||
attachment: render_target,
|
attachment: render_target,
|
||||||
resolve_target: None,
|
resolve_target: None,
|
||||||
|
|
Loading…
Reference in a new issue