mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-09 20:31:29 +11:00
Add draft kernel 4
Render from ptcl rather than original scene.
This commit is contained in:
parent
6976f877e0
commit
8d51ccbc74
|
@ -12,3 +12,5 @@ build image.spv: glsl image.comp | scene.h
|
|||
build kernel1.spv: glsl kernel1.comp | scene.h tilegroup.h
|
||||
|
||||
build kernel3.spv: glsl kernel3.comp | scene.h tilegroup.h ptcl.h
|
||||
|
||||
build kernel4.spv: glsl kernel4.comp | ptcl.h
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// This is "kernel 3" in a 4-kernel pipeline. It walks the active items
|
||||
// for the tilegroup and produces a per-tile command list for each tile.
|
||||
|
||||
#version 450
|
||||
#extension GL_GOOGLE_include_directive : enable
|
||||
|
||||
|
|
61
piet-gpu/shader/kernel4.comp
Normal file
61
piet-gpu/shader/kernel4.comp
Normal file
|
@ -0,0 +1,61 @@
|
|||
// This is "kernel 4" in a 4-kernel pipeline. It renders the commands
|
||||
// in the per-tile command list to an image.
|
||||
|
||||
// Right now, this kernel stores the image in a buffer, but a better
|
||||
// plan is to use a texture. This is because of limited support.
|
||||
|
||||
#version 450
|
||||
#extension GL_GOOGLE_include_directive : enable
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16) in;
|
||||
|
||||
// Same concern that this should be readonly as in kernel 3.
|
||||
layout(set = 0, binding = 0) buffer PtclBuf {
|
||||
uint[] ptcl;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 1) buffer ImageBuf {
|
||||
uint[] image;
|
||||
};
|
||||
|
||||
#include "ptcl.h"
|
||||
|
||||
// TODO: make the image size dynamic.
|
||||
#define IMAGE_WIDTH 2048
|
||||
#define IMAGE_HEIGHT 1535
|
||||
|
||||
#define WIDTH_IN_TILES 128
|
||||
|
||||
#define PTCL_INITIAL_ALLOC 4096
|
||||
|
||||
void main() {
|
||||
uint tile_ix = gl_WorkGroupID.y * WIDTH_IN_TILES + gl_WorkGroupID.x;
|
||||
CmdRef cmd_ref = CmdRef(tile_ix * PTCL_INITIAL_ALLOC);
|
||||
|
||||
uvec2 xy_uint = gl_GlobalInvocationID.xy;
|
||||
vec2 xy = vec2(xy_uint);
|
||||
vec2 uv = xy * vec2(1.0 / IMAGE_WIDTH, 1.0 / IMAGE_HEIGHT);
|
||||
vec3 rgb = uv.xyy;
|
||||
|
||||
while (true) {
|
||||
uint tag = Cmd_tag(cmd_ref);
|
||||
if (tag == Cmd_End) {
|
||||
break;
|
||||
}
|
||||
switch (tag) {
|
||||
case Cmd_Circle:
|
||||
CmdCircle circle = Cmd_Circle_read(cmd_ref);
|
||||
float r = length(xy + vec2(0.5, 0.5) - circle.center.xy);
|
||||
float alpha = clamp(0.5 + circle.radius - r, 0.0, 1.0);
|
||||
vec4 fg_rgba = unpackUnorm4x8(circle.rgba_color);
|
||||
// TODO: sRGB
|
||||
rgb = mix(rgb, fg_rgba.rgb, alpha * fg_rgba.a);
|
||||
}
|
||||
cmd_ref.offset += Cmd_size;
|
||||
}
|
||||
|
||||
// TODO: sRGB
|
||||
uvec4 s = uvec4(round(vec4(rgb, 1.0) * 255.0));
|
||||
uint rgba_packed = s.r | (s.g << 8) | (s.b << 16) | (s.a << 24);
|
||||
image[xy_uint.y * IMAGE_WIDTH + xy_uint.x] = rgba_packed;
|
||||
}
|
BIN
piet-gpu/shader/kernel4.spv
Normal file
BIN
piet-gpu/shader/kernel4.spv
Normal file
Binary file not shown.
|
@ -16,7 +16,7 @@ const HEIGHT: usize = 1536;
|
|||
const TILE_W: usize = 16;
|
||||
const TILE_H: usize = 16;
|
||||
|
||||
const N_CIRCLES: usize = 100;
|
||||
const N_CIRCLES: usize = 3000;
|
||||
|
||||
fn make_scene() -> Vec<u8> {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
@ -119,10 +119,10 @@ fn main() {
|
|||
.create_descriptor_set(&k3_pipeline, &[&scene_dev, &tilegroup_buf, &ptcl_buf])
|
||||
.unwrap();
|
||||
|
||||
let code = include_bytes!("../shader/image.spv");
|
||||
let pipeline = device.create_simple_compute_pipeline(code, 2).unwrap();
|
||||
let k4_code = include_bytes!("../shader/kernel4.spv");
|
||||
let pipeline = device.create_simple_compute_pipeline(k4_code, 2).unwrap();
|
||||
let descriptor_set = device
|
||||
.create_descriptor_set(&pipeline, &[&scene_dev, &image_dev])
|
||||
.create_descriptor_set(&pipeline, &[&ptcl_buf, &image_dev])
|
||||
.unwrap();
|
||||
let query_pool = device.create_query_pool(4).unwrap();
|
||||
let mut cmd_buf = device.create_cmd_buf().unwrap();
|
||||
|
@ -167,9 +167,11 @@ fn main() {
|
|||
(timestamps[2] - timestamps[1]) * 1e3
|
||||
);
|
||||
|
||||
/*
|
||||
let mut k1_data: Vec<u32> = Default::default();
|
||||
device.read_buffer(&ptcl_buf, &mut k1_data).unwrap();
|
||||
dump_k1_data(&k1_data);
|
||||
*/
|
||||
|
||||
let mut img_data: Vec<u8> = Default::default();
|
||||
// Note: because png can use a `&[u8]` slice, we could avoid an extra copy
|
||||
|
|
Loading…
Reference in a new issue