wgpu: Remove push constant support - simplifies code significantly, and it should be same perf now

This commit is contained in:
Nathan Adams 2024-01-23 21:28:12 +01:00
parent fd604b3a18
commit befce41e11
25 changed files with 136 additions and 471 deletions

View File

@ -7,24 +7,14 @@ struct VertexOutput {
@location(0) uv: vec2<f32>,
};
#if use_push_constants == true
var<push_constant> pc: common::PushConstants;
@group(1) @binding(0) var<uniform> textureTransforms: common::TextureTransforms;
@group(1) @binding(1) var texture: texture_2d<f32>;
@group(1) @binding(2) var texture_sampler: sampler;
#else
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var<uniform> colorTransforms: common::ColorTransforms;
@group(3) @binding(0) var<uniform> textureTransforms: common::TextureTransforms;
@group(3) @binding(1) var texture: texture_2d<f32>;
@group(3) @binding(2) var texture_sampler: sampler;
#endif
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var<uniform> colorTransforms: common::ColorTransforms;
@group(3) @binding(0) var<uniform> textureTransforms: common::TextureTransforms;
@group(3) @binding(1) var texture: texture_2d<f32>;
@group(3) @binding(2) var texture_sampler: sampler;
@vertex
fn main_vertex(in: common::VertexInput) -> VertexOutput {
#if use_push_constants == true
var transforms = pc.transforms;
#endif
let matrix_ = textureTransforms.texture_matrix;
let uv = (mat3x3<f32>(matrix_[0].xyz, matrix_[1].xyz, matrix_[2].xyz) * vec3<f32>(in.position, 1.0)).xy;
let pos = common::globals.view_matrix * transforms.world_matrix * vec4<f32>(in.position.x, in.position.y, 0.0, 1.0);
@ -34,9 +24,6 @@ fn main_vertex(in: common::VertexInput) -> VertexOutput {
@fragment
fn main_fragment(in: VertexOutput) -> @location(0) vec4<f32> {
var color: vec4<f32> = textureSample(texture, texture_sampler, in.uv);
#if use_push_constants == true
var colorTransforms = pc.colorTransforms;
#endif
// Texture is premultiplied by alpha.
// Unmultiply alpha, apply color transform, remultiply alpha.
if( color.a > 0.0 ) {

View File

@ -5,17 +5,10 @@ struct VertexOutput {
@location(0) uv: vec2<f32>,
};
#if use_push_constants == true
var<push_constant> transforms: common::Transforms;
@group(1) @binding(0) var parent_texture: texture_2d<f32>;
@group(1) @binding(1) var current_texture: texture_2d<f32>;
@group(1) @binding(2) var texture_sampler: sampler;
#else
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
@group(2) @binding(1) var current_texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
#endif
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
@group(2) @binding(1) var current_texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
@vertex
fn main_vertex(in: common::VertexInput) -> VertexOutput {

View File

@ -5,17 +5,10 @@ struct VertexOutput {
@location(0) uv: vec2<f32>,
};
#if use_push_constants == true
var<push_constant> transforms: common::Transforms;
@group(1) @binding(0) var parent_texture: texture_2d<f32>;
@group(1) @binding(1) var current_texture: texture_2d<f32>;
@group(1) @binding(2) var texture_sampler: sampler;
#else
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
@group(2) @binding(1) var current_texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
#endif
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
@group(2) @binding(1) var current_texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
@vertex
fn main_vertex(in: common::VertexInput) -> VertexOutput {

View File

@ -5,17 +5,10 @@ struct VertexOutput {
@location(0) uv: vec2<f32>,
};
#if use_push_constants == true
var<push_constant> transforms: common::Transforms;
@group(1) @binding(0) var parent_texture: texture_2d<f32>;
@group(1) @binding(1) var current_texture: texture_2d<f32>;
@group(1) @binding(2) var texture_sampler: sampler;
#else
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
@group(2) @binding(1) var current_texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
#endif
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
@group(2) @binding(1) var current_texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
@vertex
fn main_vertex(in: common::VertexInput) -> VertexOutput {

View File

@ -5,17 +5,10 @@ struct VertexOutput {
@location(0) uv: vec2<f32>,
};
#if use_push_constants == true
var<push_constant> transforms: common::Transforms;
@group(1) @binding(0) var parent_texture: texture_2d<f32>;
@group(1) @binding(1) var current_texture: texture_2d<f32>;
@group(1) @binding(2) var texture_sampler: sampler;
#else
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
@group(2) @binding(1) var current_texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
#endif
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
@group(2) @binding(1) var current_texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
@vertex
fn main_vertex(in: common::VertexInput) -> VertexOutput {

View File

@ -5,17 +5,10 @@ struct VertexOutput {
@location(0) uv: vec2<f32>,
};
#if use_push_constants == true
var<push_constant> transforms: common::Transforms;
@group(1) @binding(0) var parent_texture: texture_2d<f32>;
@group(1) @binding(1) var current_texture: texture_2d<f32>;
@group(1) @binding(2) var texture_sampler: sampler;
#else
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
@group(2) @binding(1) var current_texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
#endif
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
@group(2) @binding(1) var current_texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
@vertex
fn main_vertex(in: common::VertexInput) -> VertexOutput {

View File

@ -5,17 +5,10 @@ struct VertexOutput {
@location(0) uv: vec2<f32>,
};
#if use_push_constants == true
var<push_constant> transforms: common::Transforms;
@group(1) @binding(0) var parent_texture: texture_2d<f32>;
@group(1) @binding(1) var current_texture: texture_2d<f32>;
@group(1) @binding(2) var texture_sampler: sampler;
#else
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
@group(2) @binding(1) var current_texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
#endif
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
@group(2) @binding(1) var current_texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
@vertex
fn main_vertex(in: common::VertexInput) -> VertexOutput {

View File

@ -5,17 +5,10 @@ struct VertexOutput {
@location(0) uv: vec2<f32>,
};
#if use_push_constants == true
var<push_constant> transforms: common::Transforms;
@group(1) @binding(0) var parent_texture: texture_2d<f32>;
@group(1) @binding(1) var current_texture: texture_2d<f32>;
@group(1) @binding(2) var texture_sampler: sampler;
#else
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
@group(2) @binding(1) var current_texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
#endif
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
@group(2) @binding(1) var current_texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
@vertex
fn main_vertex(in: common::VertexInput) -> VertexOutput {

View File

@ -5,17 +5,10 @@ struct VertexOutput {
@location(0) uv: vec2<f32>,
};
#if use_push_constants == true
var<push_constant> transforms: common::Transforms;
@group(1) @binding(0) var parent_texture: texture_2d<f32>;
@group(1) @binding(1) var current_texture: texture_2d<f32>;
@group(1) @binding(2) var texture_sampler: sampler;
#else
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
@group(2) @binding(1) var current_texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
#endif
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
@group(2) @binding(1) var current_texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
@vertex
fn main_vertex(in: common::VertexInput) -> VertexOutput {

View File

@ -5,17 +5,10 @@ struct VertexOutput {
@location(0) uv: vec2<f32>,
};
#if use_push_constants == true
var<push_constant> transforms: common::Transforms;
@group(1) @binding(0) var parent_texture: texture_2d<f32>;
@group(1) @binding(1) var current_texture: texture_2d<f32>;
@group(1) @binding(2) var texture_sampler: sampler;
#else
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
@group(2) @binding(1) var current_texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
#endif
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
@group(2) @binding(1) var current_texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
@vertex
fn main_vertex(in: common::VertexInput) -> VertexOutput {

View File

@ -12,19 +12,11 @@ struct VertexOutput {
@location(0) color: vec4<f32>,
};
#if use_push_constants == true
var<push_constant> pc: common::PushConstants;
#else
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var<uniform> colorTransforms: common::ColorTransforms;
#endif
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var<uniform> colorTransforms: common::ColorTransforms;
@vertex
fn main_vertex(in: VertexInput) -> VertexOutput {
#if use_push_constants == true
var transforms = pc.transforms;
var colorTransforms = pc.colorTransforms;
#endif
let pos = common::globals.view_matrix * transforms.world_matrix * vec4<f32>(in.position.x, in.position.y, 0.0, 1.0);
let color = saturate(in.color * colorTransforms.mult_color + colorTransforms.add_color);
return VertexOutput(pos, vec4<f32>(color.rgb * color.a, color.a));

View File

@ -7,17 +7,10 @@ struct VertexOutput {
@location(0) uv: vec2<f32>,
};
#if use_push_constants == true
var<push_constant> transforms: common::Transforms;
@group(1) @binding(0) var<uniform> textureTransforms: common::TextureTransforms;
@group(1) @binding(1) var texture: texture_2d<f32>;
@group(1) @binding(2) var texture_sampler: sampler;
#else
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var<uniform> textureTransforms: common::TextureTransforms;
@group(2) @binding(1) var texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
#endif
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var<uniform> textureTransforms: common::TextureTransforms;
@group(2) @binding(1) var texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
@vertex
fn main_vertex(in: common::VertexInput) -> VertexOutput {

View File

@ -7,17 +7,10 @@ struct VertexOutput {
@location(0) uv: vec2<f32>,
};
#if use_push_constants == true
var<push_constant> transforms: common::Transforms;
@group(1) @binding(0) var<uniform> textureTransforms: common::TextureTransforms;
@group(1) @binding(1) var texture: texture_2d<f32>;
@group(1) @binding(2) var texture_sampler: sampler;
#else
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var<uniform> textureTransforms: common::TextureTransforms;
@group(2) @binding(1) var texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
#endif
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var<uniform> textureTransforms: common::TextureTransforms;
@group(2) @binding(1) var texture: texture_2d<f32>;
@group(2) @binding(2) var texture_sampler: sampler;
@vertex
fn main_vertex(in: common::VertexInput) -> VertexOutput {

View File

@ -26,11 +26,7 @@ struct Filter {
@group(0) @binding(0) var texture: texture_2d<f32>;
@group(0) @binding(1) var texture_sampler: sampler;
#if use_push_constants == true
var<push_constant> filter_args: Filter;
#else
@group(0) @binding(2) var<uniform> filter_args: Filter;
#endif
@group(0) @binding(2) var<uniform> filter_args: Filter;
@vertex
fn main_vertex(in: filter::VertexInput) -> filter::VertexOutput {

View File

@ -6,14 +6,9 @@ struct VertexOutput {
@location(0) uv: vec2<f32>,
};
#if use_push_constants == true
var<push_constant> pc: common::PushConstants;
@group(1) @binding(0) var<uniform> textureTransforms: common::TextureTransforms;
#else
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var<uniform> colorTransforms: common::ColorTransforms;
@group(3) @binding(0) var<uniform> textureTransforms: common::TextureTransforms;
#endif
@group(1) @binding(0) var<uniform> transforms: common::Transforms;
@group(2) @binding(0) var<uniform> colorTransforms: common::ColorTransforms;
@group(3) @binding(0) var<uniform> textureTransforms: common::TextureTransforms;
struct Gradient {
focal_point: f32,
@ -22,15 +17,9 @@ struct Gradient {
repeat: i32,
};
#if use_push_constants == true
@group(1) @binding(1) var<uniform> gradient: Gradient;
@group(1) @binding(2) var texture: texture_2d<f32>;
@group(1) @binding(3) var texture_sampler: sampler;
#else
@group(3) @binding(1) var<uniform> gradient: Gradient;
@group(3) @binding(2) var texture: texture_2d<f32>;
@group(3) @binding(3) var texture_sampler: sampler;
#endif
@group(3) @binding(1) var<uniform> gradient: Gradient;
@group(3) @binding(2) var texture: texture_2d<f32>;
@group(3) @binding(3) var texture_sampler: sampler;
struct GradientVertexInput {
/// The position of the vertex in object space.
@ -39,9 +28,6 @@ struct GradientVertexInput {
@vertex
fn main_vertex(in: GradientVertexInput) -> VertexOutput {
#if use_push_constants == true
var transforms = pc.transforms;
#endif
let matrix_ = textureTransforms.texture_matrix;
let uv = (mat3x3<f32>(matrix_[0].xyz, matrix_[1].xyz, matrix_[2].xyz) * vec3<f32>(in.position, 1.0)).xy;
let pos = common::globals.view_matrix * transforms.world_matrix * vec4<f32>(in.position.x, in.position.y, 0.0, 1.0);
@ -67,9 +53,6 @@ fn find_t(uv: vec2<f32>) -> f32 {
@fragment
fn main_fragment(in: VertexOutput) -> @location(0) vec4<f32> {
#if use_push_constants == true
var colorTransforms = pc.colorTransforms;
#endif
// Calculate normalized `t` position in gradient, [0.0, 1.0] being the bounds of the ratios.
var t: f32 = find_t(in.uv);

View File

@ -10,8 +10,8 @@ use crate::target::{MaybeOwnedBuffer, TextureTarget};
use crate::target::{RenderTargetFrame, TextureBufferInfo};
use crate::utils::{run_copy_pipeline, BufferDimensions};
use crate::{
as_texture, format_list, get_backend_names, ColorAdjustments, Descriptors, Error,
QueueSyncHandle, RenderTarget, SwapChainTarget, Texture, Transforms,
as_texture, format_list, get_backend_names, Descriptors, Error, QueueSyncHandle, RenderTarget,
SwapChainTarget, Texture,
};
use image::imageops::FilterType;
use ruffle_render::backend::{
@ -33,7 +33,6 @@ use ruffle_render::shape_utils::DistilledShape;
use ruffle_render::tessellator::ShapeTessellator;
use std::borrow::Cow;
use std::cell::Cell;
use std::mem;
use std::path::Path;
use std::sync::Arc;
use swf::Color;
@ -608,7 +607,6 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
&self.descriptors,
target.color_texture().format(),
texture.texture.format(),
target.color_texture().size(),
&texture.texture.create_view(&Default::default()),
target.color_view(),
target.whole_frame_bind_group(&self.descriptors),
@ -1194,14 +1192,6 @@ async fn request_device(
let mut features = Default::default();
let needed_size = (mem::size_of::<Transforms>() + mem::size_of::<ColorAdjustments>()) as u32;
if adapter.features().contains(wgpu::Features::PUSH_CONSTANTS)
&& adapter.limits().max_push_constant_size >= needed_size
{
// limits.max_push_constant_size = needed_size;
// features |= wgpu::Features::PUSH_CONSTANTS;
}
let try_features = [
wgpu::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES,
wgpu::Features::SHADER_UNUSED_VERTEX_OUTPUT,

View File

@ -4,11 +4,10 @@ use crate::pipelines::VERTEX_BUFFERS_DESCRIPTION_POS;
use crate::shaders::Shaders;
use crate::{
create_buffer_with_data, BitmapSamplers, Pipelines, PosColorVertex, PosVertex,
TextureTransforms, Transforms, DEFAULT_COLOR_ADJUSTMENTS,
TextureTransforms, DEFAULT_COLOR_ADJUSTMENTS,
};
use fnv::FnvHashMap;
use std::fmt::Debug;
use std::mem;
use std::sync::{Arc, Mutex};
pub struct Descriptors {
@ -97,24 +96,12 @@ impl Descriptors {
.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 {
&[]
},
bind_group_layouts: &[
&self.bind_layouts.globals,
&self.bind_layouts.transforms,
&self.bind_layouts.bitmap,
],
push_constant_ranges: &[],
});
Arc::new(
self.device
@ -176,24 +163,12 @@ impl Descriptors {
.device
.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: create_debug_label!("Copy 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 {
&[]
},
bind_group_layouts: &[
&self.bind_layouts.globals,
&self.bind_layouts.transforms,
&self.bind_layouts.bitmap,
],
push_constant_ranges: &[],
});
Arc::new(
self.device

View File

@ -50,44 +50,30 @@ impl BlurFilter {
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
count: None,
};
let bind_group_layout = if device.limits().max_push_constant_size > 0 {
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[texture, sampling],
label: create_debug_label!("Blur filter binds").as_deref(),
})
} else {
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[
texture,
sampling,
wgpu::BindGroupLayoutEntry {
binding: 2,
visibility: wgpu::ShaderStages::FRAGMENT | wgpu::ShaderStages::VERTEX,
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: wgpu::BufferSize::new(
std::mem::size_of::<BlurUniform>() as u64,
),
},
count: None,
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[
texture,
sampling,
wgpu::BindGroupLayoutEntry {
binding: 2,
visibility: wgpu::ShaderStages::FRAGMENT | wgpu::ShaderStages::VERTEX,
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: wgpu::BufferSize::new(
std::mem::size_of::<BlurUniform>() as u64
),
},
],
label: create_debug_label!("Blur filter binds (with buffer)").as_deref(),
})
};
count: None,
},
],
label: create_debug_label!("Blur filter binds (with buffer)").as_deref(),
});
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: None,
bind_group_layouts: &[&bind_group_layout],
push_constant_ranges: if device.limits().max_push_constant_size > 0 {
&[wgpu::PushConstantRange {
stages: wgpu::ShaderStages::VERTEX_FRAGMENT,
range: 0..(std::mem::size_of::<BlurUniform>() as u32),
}]
} else {
&[]
},
push_constant_ranges: &[],
});
Self {
@ -250,27 +236,15 @@ impl BlurFilter {
last_weight,
};
if descriptors.limits.max_push_constant_size > 0 {
self.render_with_push_constants(
descriptors,
draw_encoder,
pipeline,
&mut flop,
previous_view,
previous_vertices,
uniform,
);
} else {
self.render_with_uniform_buffers(
descriptors,
draw_encoder,
pipeline,
&mut flop,
previous_view,
previous_vertices,
uniform,
);
}
self.render_with_uniform_buffers(
descriptors,
draw_encoder,
pipeline,
&mut flop,
previous_view,
previous_vertices,
uniform,
);
std::mem::swap(&mut flip, &mut flop);
}
@ -284,59 +258,6 @@ impl BlurFilter {
}
}
#[allow(clippy::too_many_arguments)]
fn render_with_push_constants(
&self,
descriptors: &Descriptors,
draw_encoder: &mut CommandEncoder,
pipeline: &RenderPipeline,
destination: &mut CommandTarget,
source: &TextureView,
vertices: BufferSlice,
uniform: BlurUniform,
) {
let filter_group = descriptors
.device
.create_bind_group(&wgpu::BindGroupDescriptor {
label: create_debug_label!("Filter group").as_deref(),
layout: &self.bind_group_layout,
entries: &[
wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::TextureView(source),
},
wgpu::BindGroupEntry {
binding: 1,
resource: wgpu::BindingResource::Sampler(
descriptors.bitmap_samplers.get_sampler(false, true),
),
},
],
});
let mut render_pass = draw_encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: create_debug_label!("Blur filter").as_deref(),
color_attachments: &[destination.color_attachments()],
..Default::default()
});
render_pass.set_pipeline(pipeline);
render_pass.set_push_constants(
wgpu::ShaderStages::FRAGMENT | wgpu::ShaderStages::VERTEX,
0,
bytemuck::cast_slice(&[uniform]),
);
render_pass.set_bind_group(0, &filter_group, &[]);
render_pass.set_vertex_buffer(0, vertices);
render_pass.set_index_buffer(
descriptors.quad.indices.slice(..),
wgpu::IndexFormat::Uint32,
);
render_pass.draw_indexed(0..6, 0, 0..1);
}
#[allow(clippy::too_many_arguments)]
fn render_with_uniform_buffers(
&self,

View File

@ -69,13 +69,6 @@ pub enum MaskState {
ClearMaskStencil,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Pod, Zeroable)]
pub struct PushConstants {
transforms: Transforms,
colors: ColorAdjustments,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Pod, Zeroable)]
pub struct Transforms {

View File

@ -1,9 +1,8 @@
use crate::blend::{ComplexBlend, TrivialBlend};
use crate::layouts::BindLayouts;
use crate::shaders::Shaders;
use crate::{MaskState, PosColorVertex, PosVertex, PushConstants, Transforms};
use crate::{MaskState, PosColorVertex, PosVertex};
use enum_map::{enum_map, Enum, EnumMap};
use std::mem;
use wgpu::{vertex_attr_array, BlendState};
pub const VERTEX_BUFFERS_DESCRIPTION_POS: [wgpu::VertexBufferLayout; 1] =
@ -87,33 +86,11 @@ impl Pipelines {
msaa_sample_count: u32,
bind_layouts: &BindLayouts,
) -> Self {
let colort_bindings = if device.limits().max_push_constant_size > 0 {
vec![&bind_layouts.globals]
} else {
vec![
&bind_layouts.globals,
&bind_layouts.transforms,
&bind_layouts.color_transforms,
]
};
let full_push_constants = &if device.limits().max_push_constant_size > 0 {
vec![wgpu::PushConstantRange {
stages: wgpu::ShaderStages::VERTEX_FRAGMENT,
range: 0..mem::size_of::<PushConstants>() as u32,
}]
} else {
vec![]
};
let partial_push_constants = &if device.limits().max_push_constant_size > 0 {
vec![wgpu::PushConstantRange {
stages: wgpu::ShaderStages::VERTEX,
range: 0..(mem::size_of::<Transforms>() as u32),
}]
} else {
vec![]
};
let colort_bindings = vec![
&bind_layouts.globals,
&bind_layouts.transforms,
&bind_layouts.color_transforms,
];
let color_pipelines = create_shape_pipeline(
"Color",
@ -124,19 +101,15 @@ impl Pipelines {
&VERTEX_BUFFERS_DESCRIPTION_COLOR,
&colort_bindings,
wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING,
full_push_constants,
&[],
);
let gradient_bindings = if device.limits().max_push_constant_size > 0 {
vec![&bind_layouts.globals, &bind_layouts.gradient]
} else {
vec![
&bind_layouts.globals,
&bind_layouts.transforms,
&bind_layouts.color_transforms,
&bind_layouts.gradient,
]
};
let gradient_bindings = vec![
&bind_layouts.globals,
&bind_layouts.transforms,
&bind_layouts.color_transforms,
&bind_layouts.gradient,
];
let gradient_pipeline = create_shape_pipeline(
"Gradient",
@ -147,18 +120,14 @@ impl Pipelines {
&VERTEX_BUFFERS_DESCRIPTION_POS,
&gradient_bindings,
wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING,
full_push_constants,
&[],
);
let complex_blend_bindings = if device.limits().max_push_constant_size > 0 {
vec![&bind_layouts.globals, &bind_layouts.blend]
} else {
vec![
&bind_layouts.globals,
&bind_layouts.transforms,
&bind_layouts.blend,
]
};
let complex_blend_bindings = vec![
&bind_layouts.globals,
&bind_layouts.transforms,
&bind_layouts.blend,
];
let complex_blend_pipelines = enum_map! {
blend => create_shape_pipeline(
@ -170,20 +139,16 @@ impl Pipelines {
&VERTEX_BUFFERS_DESCRIPTION_POS,
&complex_blend_bindings,
wgpu::BlendState::REPLACE,
partial_push_constants,
&[],
)
};
let bitmap_blend_bindings = if device.limits().max_push_constant_size > 0 {
vec![&bind_layouts.globals, &bind_layouts.bitmap]
} else {
vec![
&bind_layouts.globals,
&bind_layouts.transforms,
&bind_layouts.color_transforms,
&bind_layouts.bitmap,
]
};
let bitmap_blend_bindings = vec![
&bind_layouts.globals,
&bind_layouts.transforms,
&bind_layouts.color_transforms,
&bind_layouts.bitmap,
];
let bitmap_pipelines: [ShapePipeline; TrivialBlend::LENGTH] = (0..TrivialBlend::LENGTH)
.map(|blend| {
@ -198,7 +163,7 @@ impl Pipelines {
&VERTEX_BUFFERS_DESCRIPTION_POS,
&bitmap_blend_bindings,
blend.blend_state(),
full_push_constants,
&[],
)
})
.collect::<Vec<_>>()
@ -211,7 +176,7 @@ impl Pipelines {
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: bitmap_opaque_pipeline_layout_label.as_deref(),
bind_group_layouts: &bitmap_blend_bindings,
push_constant_ranges: full_push_constants,
push_constant_ranges: &[],
});
let bitmap_opaque = device.create_render_pipeline(&create_pipeline_descriptor(

View File

@ -32,10 +32,6 @@ impl Shaders {
pub fn new(device: &wgpu::Device) -> Self {
let mut composer = composer().expect("Couldn't create shader composer");
let mut shader_defs = HashMap::new();
shader_defs.insert(
"use_push_constants".to_owned(),
ShaderDefValue::Bool(device.limits().max_push_constant_size > 0),
);
shader_defs.insert("early_saturate".to_owned(), ShaderDefValue::Bool(true));
let mut late_saturate_shader_defs = shader_defs.clone();

View File

@ -10,7 +10,7 @@ use crate::mesh::Mesh;
use crate::pixel_bender::{run_pixelbender_shader_impl, ShaderMode};
use crate::surface::commands::{chunk_blends, Chunk, CommandRenderer};
use crate::utils::{remove_srgb, supported_sample_count};
use crate::{Descriptors, MaskState, Pipelines, Transforms};
use crate::{Descriptors, MaskState, Pipelines};
use ruffle_render::commands::CommandList;
use ruffle_render::pixel_bender::{ImageInputTexture, PixelBenderShaderArgument};
use ruffle_render::quality::StageQuality;
@ -98,7 +98,6 @@ impl Surface {
descriptors,
self.format,
self.actual_surface_format,
self.size,
frame_view,
target.color_view(),
target.whole_frame_bind_group(descriptors),
@ -339,28 +338,8 @@ impl Surface {
);
}
if descriptors.limits.max_push_constant_size > 0 {
render_pass.set_push_constants(
wgpu::ShaderStages::VERTEX,
0,
bytemuck::cast_slice(&[Transforms {
world_matrix: [
[self.size.width as f32, 0.0, 0.0, 0.0],
[0.0, self.size.height as f32, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 1.0],
],
}]),
);
render_pass.set_bind_group(1, &blend_bind_group, &[]);
} else {
render_pass.set_bind_group(
1,
target.whole_frame_bind_group(descriptors),
&[0],
);
render_pass.set_bind_group(2, &blend_bind_group, &[]);
}
render_pass.set_bind_group(1, target.whole_frame_bind_group(descriptors), &[0]);
render_pass.set_bind_group(2, &blend_bind_group, &[]);
render_pass.set_vertex_buffer(0, descriptors.quad.vertices_pos.slice(..));
render_pass.set_index_buffer(

View File

@ -125,15 +125,7 @@ impl<'pass, 'frame: 'pass, 'global: 'frame> CommandRenderer<'pass, 'frame, 'glob
.set_pipeline(self.pipelines.gradients.stencilless_pipeline());
}
self.render_pass.set_bind_group(
if self.descriptors.limits.max_push_constant_size > 0 {
1
} else {
3
},
bind_group,
&[],
);
self.render_pass.set_bind_group(3, bind_group, &[]);
}
pub fn prep_bitmap(
@ -160,15 +152,7 @@ impl<'pass, 'frame: 'pass, 'global: 'frame> CommandRenderer<'pass, 'frame, 'glob
}
}
self.render_pass.set_bind_group(
if self.descriptors.limits.max_push_constant_size > 0 {
1
} else {
3
},
bind_group,
&[],
);
self.render_pass.set_bind_group(3, bind_group, &[]);
}
pub fn draw(

View File

@ -288,7 +288,6 @@ impl CommandTarget {
descriptors,
format,
format,
size,
frame_buffer.texture.view(),
&texture.create_view(&Default::default()),
get_whole_frame_bind_group(&whole_frame_bind_group, descriptors, size),

View File

@ -1,7 +1,6 @@
use crate::buffer_pool::BufferDescription;
use crate::descriptors::Descriptors;
use crate::globals::Globals;
use crate::Transforms;
use std::borrow::Cow;
use wgpu::util::DeviceExt;
use wgpu::{CommandEncoder, TextureFormat};
@ -200,7 +199,6 @@ 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,
whole_frame_bind_group: &wgpu::BindGroup,
@ -257,24 +255,8 @@ pub fn run_copy_pipeline(
render_pass.set_pipeline(&pipeline);
render_pass.set_bind_group(0, globals.bind_group(), &[]);
if descriptors.limits.max_push_constant_size > 0 {
render_pass.set_push_constants(
wgpu::ShaderStages::VERTEX,
0,
bytemuck::cast_slice(&[Transforms {
world_matrix: [
[size.width as f32, 0.0, 0.0, 0.0],
[0.0, size.height as f32, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 1.0],
],
}]),
);
render_pass.set_bind_group(1, &copy_bind_group, &[]);
} else {
render_pass.set_bind_group(1, whole_frame_bind_group, &[0]);
render_pass.set_bind_group(2, &copy_bind_group, &[]);
}
render_pass.set_bind_group(1, whole_frame_bind_group, &[0]);
render_pass.set_bind_group(2, &copy_bind_group, &[]);
render_pass.set_vertex_buffer(0, descriptors.quad.vertices_pos.slice(..));
render_pass.set_index_buffer(