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: Implement blend modes #8262

Merged
merged 54 commits into from
Jan 3, 2023
Merged
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
ebf7f3d
render: Replace PushBlendMode/PopBlendMode with Blend
Dinnerbone Sep 20, 2022
0d8047a
wgpu: Removed blendmode stuff
Dinnerbone Sep 20, 2022
7504dae
wgpu: Separated srgb out of Surface
Dinnerbone Sep 20, 2022
e43446b
wgpu: Frame no longer owns UniformBuffer
Dinnerbone Sep 20, 2022
a2a586c
wgpu: Simplify Surface to no longer be an enum as there's not really …
Dinnerbone Sep 20, 2022
616229b
wgpu: Globals should now belong to the Surface and doesn't need to be…
Dinnerbone Sep 20, 2022
85d71e5
wgpu: Perform command rendering recursively and chunk up blends. Blen…
Dinnerbone Sep 21, 2022
dc9c4cc
wgpu: Implement all blend modes
Dinnerbone Dec 18, 2022
2337ef5
wgpu: Always clear the first texture buffer to the desired color
Dinnerbone Dec 18, 2022
aa07f60
wgpu: Allow for different sized subcommand list targets, but don't us…
Dinnerbone Dec 18, 2022
32cb327
wgpu: For trivial blends (ie Normal), just draw them as bitmaps with …
Dinnerbone Dec 20, 2022
33c3924
wgpu: Workaround naga-vulkan bug with default position in switch stat…
Dinnerbone Dec 20, 2022
ae4409b
wgpu: Don't create blend buffers until they're needed
Dinnerbone Dec 20, 2022
a597e6a
tests: Added new output of bitmapdata_draw tests for github agents. S…
Dinnerbone Dec 20, 2022
d846f53
core: Remove blend mode unsupported message
Dinnerbone Dec 20, 2022
4b91528
tests: Add blendmode visual tests
Dinnerbone Dec 20, 2022
df74206
wgpu: Handle alpha correctly for add or subtract blendmodes
Dinnerbone Dec 21, 2022
7d34741
wgpu: Appease beta clippy
Dinnerbone Dec 21, 2022
1720d26
wgpu: Don't create depth buffers, or use any depth testing, if we are…
Dinnerbone Dec 21, 2022
b3ef530
wgpu: Optimise rendering blendables by queueing everything up in the …
Dinnerbone Dec 22, 2022
6a136fc
wgpu: Don't require VERTEX_WRITABLE_STORAGE which is unavailable on web
Dinnerbone Dec 22, 2022
1a8b87f
wgpu: Pool textures during the same frame, and drop whatever we don't…
Dinnerbone Dec 22, 2022
1613623
wgpu: Cache Globals for a total draw frame, don't remake it if it's g…
Dinnerbone Dec 22, 2022
e8b692a
wgpu: Made Multiply, Add and Subtract blend modes use bitmap+blend
Dinnerbone Dec 23, 2022
ffe9b5f
wgpu: Share the buffer pool throughout the entire frame
Dinnerbone Dec 23, 2022
13023e5
wgpu: Don't wait for the entire frame to be drawn if we're just captu…
Dinnerbone Dec 23, 2022
a6a88af
wgpu: Default msaa on mobiles to 2x, same as webgl backend
Dinnerbone Dec 23, 2022
1a834b1
wgpu: Removed some needless copies in command iteration
Dinnerbone Dec 23, 2022
a6f3c7c
tests: New multiply blend mode image
Dinnerbone Dec 23, 2022
aaa1c5c
wgpu: Multiply can't be trivial blend mode because of 0 alpha
Dinnerbone Dec 23, 2022
92ab825
wgpu: Try harder to find render passes where we don't need depth
Dinnerbone Dec 23, 2022
fd26461
wgpu: Simplify blend_buffers map creation
Dinnerbone Dec 23, 2022
4679e11
wgpu: Revert using same pool for whole frame - breaks bitmapdata.draw…
Dinnerbone Dec 23, 2022
1f07803
wgpu: Temporarily disable msaa on phones until wgpu upgrade
Dinnerbone Dec 23, 2022
4b2a7b0
wgpu: Add some more debug labels
Dinnerbone Dec 23, 2022
ef12363
wgpu: Add more debug labels within render passes
Dinnerbone Dec 23, 2022
55bd8af
wgpu: Split up blend modes into their own shaders for performance
Dinnerbone Dec 23, 2022
31c447a
wgpu: Share texture pool across all frames, and ensure targets are cl…
Dinnerbone Dec 23, 2022
a5975ac
wgpu: Reduce gradient.colors uniform memory by 4x
Dinnerbone Dec 24, 2022
c998888
wgpu: Reduce gradient.ratios uniform memory by 4x
Dinnerbone Dec 24, 2022
2b0d2d8
wgpu: Appease beta clippy. again.
Dinnerbone Dec 24, 2022
dba9cf2
wgpu: Clean up gradient shaders by bringing out common shared source …
Dinnerbone Dec 24, 2022
2753094
wgpu: Split up gradient shader based on type and repeat
Dinnerbone Dec 25, 2022
754c814
wgpu: Clear out texture pool when resized
Dinnerbone Dec 27, 2022
2eca4f6
wgpu: Refactor surface command target to its own file
Dinnerbone Dec 27, 2022
dcce43a
wgpu: Move command renderer to surface/commands.rs
Dinnerbone Dec 27, 2022
63915ae
wgpu: Inlined CommandRenderer::execute into Surface::draw_commands
Dinnerbone Dec 27, 2022
39c1d95
wgpu: Moved DrawCommand handling to CommandRenderer::execute
Dinnerbone Dec 27, 2022
02f8435
wgpu: Define the sizes of uniforms upfront instead of at each call
Dinnerbone Dec 27, 2022
7552c83
wgpu: Moved ColorAdjustments into its own bind group, and reuse Color…
Dinnerbone Dec 27, 2022
0703f5f
render: Make CommandList a struct instead of a tuple
Dinnerbone Dec 27, 2022
48d3ffa
wgpu: Cleaned up some buffer binding api
Dinnerbone Dec 28, 2022
7bece49
wgpu: Don't load or store the depth side of the depth buffer, we only…
Dinnerbone Dec 28, 2022
5619304
wgpu: Use frame-temporary buffer for offscreen rendering
Dinnerbone Jan 2, 2023
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
Prev Previous commit
Next Next commit
wgpu: Reduce gradient.ratios uniform memory by 4x
  • Loading branch information
Dinnerbone committed Jan 2, 2023
commit c9988886347ed43e1c3b0006f6923f2f9b6bbed0
19 changes: 8 additions & 11 deletions render/wgpu/shaders/gradient_uniform.wgsl
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
/// Shader used for drawing all flavors of gradients.

struct wrapped_f32 {
elem: f32,
_padding1: f32,
_padding2: f32,
_padding3: f32,
}

struct Gradient {
colors: array<vec4<f32>, 16>,
ratios: array<wrapped_f32,16u>,
ratios: array<vec4<f32>, 4u>, // secretly array<f32; 16> but this let's us squeeze it into alignment
gradient_type: i32,
num_colors: u32,
repeat_mode: i32,
@@ -33,6 +26,10 @@ fn main_vertex(in: VertexInput) -> VertexOutput {
return VertexOutput(pos, uv);
}

fn ratio(i: u32) -> f32 {
return gradient.ratios[i / 4u][i % 4u];
}

@fragment
fn main_fragment(in: VertexOutput) -> @location(0) vec4<f32> {
let last = gradient.num_colors - 1u;
@@ -91,17 +88,17 @@ fn main_fragment(in: VertexOutput) -> @location(0) vec4<f32> {
break;
}
}
t = clamp(t, gradient.ratios[0].elem, gradient.ratios[last].elem);
t = clamp(t, ratio(0u), ratio(last));

// Find the two gradient colors bordering our position.
var j: u32;
for( j = 1u; t > gradient.ratios[j].elem; j = j + 1u) {
for( j = 1u; t > ratio(j); j = j + 1u) {
// Noop
}
let i = j - 1u;

// Lerp between the two colors.
let a = (t - gradient.ratios[i].elem) / (gradient.ratios[j].elem - gradient.ratios[i].elem);
let a = (t - ratio(i)) / (ratio(j) - ratio(i));
var color: vec4<f32> = mix(gradient.colors[i], gradient.colors[j], a);
if( gradient.interpolation != 0 ) {
color = linear_to_srgb(color);
6 changes: 3 additions & 3 deletions render/wgpu/src/lib.rs
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ impl From<TessVertex> for Vertex {
#[derive(Copy, Clone, Debug, Pod, Zeroable)]
struct GradientUniforms {
colors: [[f32; 4]; 16],
ratios: [[f32; 4]; 16],
ratios: [f32; 16],
gradient_type: i32,
num_colors: u32,
repeat_mode: i32,
@@ -119,11 +119,11 @@ struct GradientUniforms {

impl From<TessGradient> for GradientUniforms {
fn from(gradient: TessGradient) -> Self {
let mut ratios = [[0.0; 4]; 16];
let mut ratios = [0.0; 16];
let mut colors = [[0.0; 4]; 16];

for i in 0..gradient.num_colors {
ratios[i] = [gradient.ratios[i], 0.0, 0.0, 0.0];
ratios[i] = gradient.ratios[i];
colors[i].copy_from_slice(&gradient.colors[i]);
}