2022-09-07 02:45:33 +00:00
|
|
|
use crate::layouts::BindLayouts;
|
2022-09-07 01:41:23 +00:00
|
|
|
use crate::shaders::Shaders;
|
2022-09-03 00:14:24 +00:00
|
|
|
use crate::{BitmapSamplers, Pipelines};
|
|
|
|
|
|
|
|
/// Contains data specific to a `RenderTarget`.
|
|
|
|
/// We cannot re-use this data in `with_offscreen_backend`
|
|
|
|
pub struct DescriptorsTargetData {
|
|
|
|
// These fields are specific to our `RenderTarget`, and
|
|
|
|
// cannot be re-used
|
|
|
|
pub pipelines: Pipelines,
|
|
|
|
pub msaa_sample_count: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DescriptorsTargetData {
|
|
|
|
fn new(
|
|
|
|
device: &wgpu::Device,
|
2022-09-07 01:41:23 +00:00
|
|
|
shaders: &Shaders,
|
2022-09-03 00:14:24 +00:00
|
|
|
surface_format: wgpu::TextureFormat,
|
|
|
|
msaa_sample_count: u32,
|
2022-09-07 02:45:33 +00:00
|
|
|
bind_layouts: &BindLayouts,
|
2022-09-03 00:14:24 +00:00
|
|
|
) -> Self {
|
|
|
|
// We want to render directly onto a linear render target to avoid any gamma correction.
|
|
|
|
// If our surface is sRGB, render to a linear texture and than copy over to the surface.
|
|
|
|
// Remove Srgb from texture format.
|
|
|
|
let frame_buffer_format = match surface_format {
|
|
|
|
wgpu::TextureFormat::Rgba8UnormSrgb => wgpu::TextureFormat::Rgba8Unorm,
|
|
|
|
wgpu::TextureFormat::Bgra8UnormSrgb => wgpu::TextureFormat::Bgra8Unorm,
|
|
|
|
wgpu::TextureFormat::Bc1RgbaUnormSrgb => wgpu::TextureFormat::Bc1RgbaUnorm,
|
|
|
|
wgpu::TextureFormat::Bc2RgbaUnormSrgb => wgpu::TextureFormat::Bc2RgbaUnorm,
|
|
|
|
wgpu::TextureFormat::Bc3RgbaUnormSrgb => wgpu::TextureFormat::Bc3RgbaUnorm,
|
|
|
|
wgpu::TextureFormat::Bc7RgbaUnormSrgb => wgpu::TextureFormat::Bc7RgbaUnorm,
|
|
|
|
wgpu::TextureFormat::Etc2Rgb8UnormSrgb => wgpu::TextureFormat::Etc2Rgb8Unorm,
|
|
|
|
wgpu::TextureFormat::Etc2Rgb8A1UnormSrgb => wgpu::TextureFormat::Etc2Rgb8A1Unorm,
|
|
|
|
wgpu::TextureFormat::Etc2Rgba8UnormSrgb => wgpu::TextureFormat::Etc2Rgba8Unorm,
|
|
|
|
wgpu::TextureFormat::Astc {
|
|
|
|
block,
|
|
|
|
channel: wgpu::AstcChannel::UnormSrgb,
|
|
|
|
} => wgpu::TextureFormat::Astc {
|
|
|
|
block,
|
|
|
|
channel: wgpu::AstcChannel::Unorm,
|
|
|
|
},
|
|
|
|
_ => surface_format,
|
|
|
|
};
|
|
|
|
|
|
|
|
let pipelines = Pipelines::new(
|
2022-09-07 01:41:23 +00:00
|
|
|
device,
|
|
|
|
shaders,
|
2022-09-03 00:14:24 +00:00
|
|
|
surface_format,
|
|
|
|
frame_buffer_format,
|
|
|
|
msaa_sample_count,
|
2022-09-07 02:45:33 +00:00
|
|
|
bind_layouts,
|
2022-09-03 00:14:24 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
DescriptorsTargetData {
|
|
|
|
pipelines,
|
|
|
|
msaa_sample_count,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Descriptors {
|
|
|
|
pub device: wgpu::Device,
|
|
|
|
pub info: wgpu::AdapterInfo,
|
|
|
|
pub limits: wgpu::Limits,
|
|
|
|
pub surface_format: wgpu::TextureFormat,
|
|
|
|
pub frame_buffer_format: wgpu::TextureFormat,
|
|
|
|
pub queue: wgpu::Queue,
|
|
|
|
pub bitmap_samplers: BitmapSamplers,
|
|
|
|
pub msaa_sample_count: u32,
|
|
|
|
pub onscreen: DescriptorsTargetData,
|
|
|
|
pub offscreen: DescriptorsTargetData,
|
2022-09-07 02:45:33 +00:00
|
|
|
pub bind_layouts: BindLayouts,
|
2022-09-03 00:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Descriptors {
|
|
|
|
pub fn new(
|
|
|
|
device: wgpu::Device,
|
|
|
|
queue: wgpu::Queue,
|
|
|
|
info: wgpu::AdapterInfo,
|
|
|
|
surface_format: wgpu::TextureFormat,
|
|
|
|
msaa_sample_count: u32,
|
|
|
|
) -> Self {
|
|
|
|
let limits = device.limits();
|
2022-09-07 02:45:33 +00:00
|
|
|
let bind_layouts = BindLayouts::new(&device);
|
|
|
|
let bitmap_samplers = BitmapSamplers::new(&device, &bind_layouts);
|
2022-09-07 01:41:23 +00:00
|
|
|
let shaders = Shaders::new(&device);
|
2022-09-03 00:14:24 +00:00
|
|
|
|
|
|
|
// We want to render directly onto a linear render target to avoid any gamma correction.
|
|
|
|
// If our surface is sRGB, render to a linear texture and than copy over to the surface.
|
|
|
|
// Remove Srgb from texture format.
|
|
|
|
let frame_buffer_format = match surface_format {
|
|
|
|
wgpu::TextureFormat::Rgba8UnormSrgb => wgpu::TextureFormat::Rgba8Unorm,
|
|
|
|
wgpu::TextureFormat::Bgra8UnormSrgb => wgpu::TextureFormat::Bgra8Unorm,
|
|
|
|
wgpu::TextureFormat::Bc1RgbaUnormSrgb => wgpu::TextureFormat::Bc1RgbaUnorm,
|
|
|
|
wgpu::TextureFormat::Bc2RgbaUnormSrgb => wgpu::TextureFormat::Bc2RgbaUnorm,
|
|
|
|
wgpu::TextureFormat::Bc3RgbaUnormSrgb => wgpu::TextureFormat::Bc3RgbaUnorm,
|
|
|
|
wgpu::TextureFormat::Bc7RgbaUnormSrgb => wgpu::TextureFormat::Bc7RgbaUnorm,
|
|
|
|
wgpu::TextureFormat::Etc2Rgb8UnormSrgb => wgpu::TextureFormat::Etc2Rgb8Unorm,
|
|
|
|
wgpu::TextureFormat::Etc2Rgb8A1UnormSrgb => wgpu::TextureFormat::Etc2Rgb8A1Unorm,
|
|
|
|
wgpu::TextureFormat::Etc2Rgba8UnormSrgb => wgpu::TextureFormat::Etc2Rgba8Unorm,
|
|
|
|
wgpu::TextureFormat::Astc {
|
|
|
|
block,
|
|
|
|
channel: wgpu::AstcChannel::UnormSrgb,
|
|
|
|
} => wgpu::TextureFormat::Astc {
|
|
|
|
block,
|
|
|
|
channel: wgpu::AstcChannel::Unorm,
|
|
|
|
},
|
|
|
|
_ => surface_format,
|
|
|
|
};
|
|
|
|
|
|
|
|
let onscreen = DescriptorsTargetData::new(
|
|
|
|
&device,
|
2022-09-07 01:41:23 +00:00
|
|
|
&shaders,
|
2022-09-03 00:14:24 +00:00
|
|
|
surface_format,
|
|
|
|
msaa_sample_count,
|
2022-09-07 02:45:33 +00:00
|
|
|
&bind_layouts,
|
2022-09-03 00:14:24 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// FIXME - get MSAA working for `TextureTarget`
|
|
|
|
let offscreen = DescriptorsTargetData::new(
|
|
|
|
&device,
|
2022-09-07 01:41:23 +00:00
|
|
|
&shaders,
|
2022-09-03 00:14:24 +00:00
|
|
|
wgpu::TextureFormat::Rgba8Unorm,
|
|
|
|
1,
|
2022-09-07 02:45:33 +00:00
|
|
|
&bind_layouts,
|
2022-09-03 00:14:24 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
Self {
|
|
|
|
device,
|
|
|
|
info,
|
|
|
|
limits,
|
|
|
|
surface_format,
|
|
|
|
frame_buffer_format,
|
|
|
|
queue,
|
|
|
|
bitmap_samplers,
|
|
|
|
msaa_sample_count,
|
|
|
|
onscreen,
|
|
|
|
offscreen,
|
2022-09-07 02:45:33 +00:00
|
|
|
bind_layouts,
|
2022-09-03 00:14:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|