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

wgpu: Yeet the copy_srgb shader and pipeline #12720

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
33 changes: 0 additions & 33 deletions render/wgpu/shaders/copy_srgb.wgsl

This file was deleted.

1 change: 0 additions & 1 deletion render/wgpu/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,6 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
run_copy_pipeline(
&self.descriptors,
target.color_texture().format(),
texture.texture.format(),
target.color_texture().size(),
&texture.texture.create_view(&Default::default()),
target.color_view(),
Expand Down
81 changes: 0 additions & 81 deletions render/wgpu/src/descriptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub struct Descriptors {
pub bind_layouts: BindLayouts,
pub quad: Quad,
copy_pipeline: Mutex<FnvHashMap<(u32, wgpu::TextureFormat), Arc<wgpu::RenderPipeline>>>,
copy_srgb_pipeline: Mutex<FnvHashMap<(u32, wgpu::TextureFormat), Arc<wgpu::RenderPipeline>>>,
pub shaders: Shaders,
pipelines: Mutex<FnvHashMap<(u32, wgpu::TextureFormat), Arc<Pipelines>>>,
pub default_color_bind_group: wgpu::BindGroup,
Expand Down Expand Up @@ -72,93 +71,13 @@ impl Descriptors {
bind_layouts,
quad,
copy_pipeline: Default::default(),
copy_srgb_pipeline: Default::default(),
shaders,
pipelines: Default::default(),
default_color_bind_group,
filters,
}
}

pub fn copy_srgb_pipeline(
&self,
format: wgpu::TextureFormat,
msaa_sample_count: u32,
) -> Arc<wgpu::RenderPipeline> {
let mut pipelines = self
.copy_srgb_pipeline
.lock()
.expect("Pipelines should not be already locked");
pipelines
.entry((msaa_sample_count, format))
.or_insert_with(|| {
let copy_texture_pipeline_layout =
&self
.device
.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: create_debug_label!("Copy sRGB pipeline layout").as_deref(),
bind_group_layouts: &if self.limits.max_push_constant_size > 0 {
vec![&self.bind_layouts.globals, &self.bind_layouts.bitmap]
} else {
vec![
&self.bind_layouts.globals,
&self.bind_layouts.transforms,
&self.bind_layouts.bitmap,
]
},
push_constant_ranges: if self.device.limits().max_push_constant_size > 0
{
&[wgpu::PushConstantRange {
stages: wgpu::ShaderStages::VERTEX,
range: 0..(mem::size_of::<Transforms>() as u32),
}]
} else {
&[]
},
});
Arc::new(
self.device
.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: create_debug_label!("Copy sRGB pipeline").as_deref(),
layout: Some(copy_texture_pipeline_layout),
vertex: wgpu::VertexState {
module: &self.shaders.copy_srgb_shader,
entry_point: "main_vertex",
buffers: &VERTEX_BUFFERS_DESCRIPTION_POS,
},
fragment: Some(wgpu::FragmentState {
module: &self.shaders.copy_srgb_shader,
entry_point: "main_fragment",
targets: &[Some(wgpu::ColorTargetState {
format,
// All of our blending has been done by now, so we want
// to overwrite the target pixels without any blending
blend: Some(wgpu::BlendState::REPLACE),
write_mask: Default::default(),
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
strip_index_format: None,
front_face: wgpu::FrontFace::Ccw,
cull_mode: None,
polygon_mode: wgpu::PolygonMode::default(),
unclipped_depth: false,
conservative: false,
},
depth_stencil: None,
multisample: wgpu::MultisampleState {
count: msaa_sample_count,
mask: !0,
alpha_to_coverage_enabled: false,
},
multiview: None,
}),
)
})
.clone()
}

pub fn copy_pipeline(
&self,
format: wgpu::TextureFormat,
Expand Down
9 changes: 0 additions & 9 deletions render/wgpu/src/shaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub struct Shaders {
/// an out-of-range value).
pub bitmap_late_saturate_shader: wgpu::ShaderModule,
pub gradient_shader: wgpu::ShaderModule,
pub copy_srgb_shader: wgpu::ShaderModule,
pub copy_shader: wgpu::ShaderModule,
pub blend_shaders: EnumMap<ComplexBlend, wgpu::ShaderModule>,
pub color_matrix_filter: wgpu::ShaderModule,
Expand Down Expand Up @@ -62,13 +61,6 @@ impl Shaders {
"bitmap.wgsl",
include_str!("../shaders/bitmap.wgsl"),
);
let copy_srgb_shader = make_shader(
device,
&mut composer,
&shader_defs,
"copy_srgb.wgsl",
include_str!("../shaders/copy_srgb.wgsl"),
);
let copy_shader = make_shader(
device,
&mut composer,
Expand Down Expand Up @@ -136,7 +128,6 @@ impl Shaders {
bitmap_shader,
bitmap_late_saturate_shader,
gradient_shader,
copy_srgb_shader,
copy_shader,
blend_shaders,
color_matrix_filter,
Expand Down
3 changes: 0 additions & 3 deletions render/wgpu/src/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub struct Surface {
sample_count: u32,
pipelines: Arc<Pipelines>,
format: wgpu::TextureFormat,
actual_surface_format: wgpu::TextureFormat,
}

impl Surface {
Expand All @@ -57,7 +56,6 @@ impl Surface {
sample_count,
pipelines,
format: frame_buffer_format,
actual_surface_format: surface_format,
}
}

Expand Down Expand Up @@ -93,7 +91,6 @@ impl Surface {
run_copy_pipeline(
descriptors,
self.format,
self.actual_surface_format,
self.size,
frame_view,
target.color_view(),
Expand Down
1 change: 0 additions & 1 deletion render/wgpu/src/surface/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ impl CommandTarget {
run_copy_pipeline(
descriptors,
format,
format,
size,
frame_buffer.texture.view(),
&texture.create_view(&Default::default()),
Expand Down
7 changes: 1 addition & 6 deletions render/wgpu/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ pub fn supported_sample_count(
pub fn run_copy_pipeline(
descriptors: &Descriptors,
format: wgpu::TextureFormat,
actual_surface_format: wgpu::TextureFormat,
size: wgpu::Extent3d,
frame_view: &wgpu::TextureView,
input: &wgpu::TextureView,
Expand Down Expand Up @@ -237,11 +236,7 @@ pub fn run_copy_pipeline(
label: create_debug_label!("Copy sRGB bind group").as_deref(),
});

let pipeline = if actual_surface_format == format {
descriptors.copy_pipeline(format, sample_count)
} else {
descriptors.copy_srgb_pipeline(actual_surface_format, sample_count)
};
let pipeline = descriptors.copy_pipeline(format, sample_count);

// We overwrite the pixels in the target texture (no blending at all),
// so this doesn't matter.
Expand Down