Skip to content

Commit b5cdb9f

Browse files
committed
binning + rasterization fixed, first disc rendered!
1 parent 7e06466 commit b5cdb9f

6 files changed

Lines changed: 20 additions & 28 deletions

File tree

‎lib/binning.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <stddef.h>
55

6-
static const size_t binning_shader_size = 26059;
6+
static const size_t binning_shader_size = 26020;
77
static const char binning_shader[] =
88
"// ---------------------------------------------------------------------------------------------------------------------------\n"
99
"// Structures\n"
@@ -773,8 +773,7 @@ static const char binning_shader[] =
773773
" }\n"
774774
"\n"
775775
" // 3. Fine-grained intersection test\n"
776-
" //let to_be_added = intersection_tile_command(tile_aabb, cmd, g_draw_args.aa_width + aabb_margin);\n"
777-
" let to_be_added:bool = true;\n"
776+
" let to_be_added = intersection_tile_command(tile_aabb, cmd, g_draw_args.aa_width + aabb_margin);\n"
778777
"\n"
779778
" // we traverse in reverse order, so the end comes first\n"
780779
" if (cmd_type == BEGIN_GROUP) \n"

‎lib/onedraw.c‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,8 @@ static inline gpu_draw_command gpu_draw_command_make(uint32_t data_index, uint8_
432432
enum primitive_fillmode fillmode, enum command_type type)
433433
{
434434
gpu_draw_command cmd;
435-
436435
cmd.data_index = data_index;
437-
cmd.flags =
438-
(uint32_t)extra
439-
| ((uint32_t)clip_index << 8)
440-
| ((uint32_t)fillmode << 16)
441-
| ((uint32_t)type << 24);
442-
436+
cmd.flags = (uint32_t)extra | ((uint32_t)clip_index << 8) | ((uint32_t)fillmode << 16) | ((uint32_t)type << 24);
443437
return cmd;
444438
}
445439

@@ -478,7 +472,7 @@ static inline void merge_quantized_aabb(quantized_aabb* merge, const quantized_a
478472
uint32_t m = *merge;
479473
uint32_t o = *other;
480474

481-
uint32_t min_x = OD_MIN(m & 0xFFu, o & 0xFFu);
475+
uint32_t min_x = OD_MIN(m & 0xFFu, o & 0xFFu);
482476
uint32_t min_y = OD_MIN((m >> 8) & 0xFFu, (o >> 8) & 0xFFu);
483477
uint32_t max_x = OD_MAX((m >> 16) & 0xFFu, (o >> 16) & 0xFFu);
484478
uint32_t max_y = OD_MAX((m >> 24) & 0xFFu, (o >> 24) & 0xFFu);
@@ -1308,6 +1302,7 @@ void od_end_frame(struct onedraw* r, WGPUTextureView target_view)
13081302
dynamic_buffer_upload(r->queue, &r->commands.colors, buffer_index);
13091303
dynamic_buffer_upload(r->queue, &r->commands.float_data, buffer_index);
13101304
dynamic_buffer_upload(r->queue, &r->commands.draw_args, buffer_index);
1305+
dynamic_buffer_upload(r->queue, &r->commands.list, buffer_index);
13111306

13121307
WGPUCommandEncoderDescriptor encoder_desc = {0};
13131308
WGPUCommandEncoder encoder = wgpuDeviceCreateCommandEncoder(r->device, &encoder_desc);
@@ -1317,7 +1312,8 @@ void od_end_frame(struct onedraw* r, WGPUTextureView target_view)
13171312

13181313
// clear heads pass
13191314
{
1320-
WGPUComputePassEncoder pass = wgpuCommandEncoderBeginComputePass(encoder, NULL);
1315+
WGPUComputePassDescriptor desc = {.label = WGPU_STRING_VIEW("clear_heads pass")};
1316+
WGPUComputePassEncoder pass = wgpuCommandEncoderBeginComputePass(encoder, &desc);
13211317
wgpuComputePassEncoderSetPipeline(pass, r->tiles.clear_pso);
13221318
wgpuComputePassEncoderSetBindGroup(pass, 0, r->binding.binning_bindgroup, 0, NULL);
13231319
wgpuComputePassEncoderSetBindGroup(pass, 1, r->binding.frame_bindgroup[buffer_index], 0, NULL);
@@ -1328,7 +1324,8 @@ void od_end_frame(struct onedraw* r, WGPUTextureView target_view)
13281324

13291325
// binning pass
13301326
{
1331-
WGPUComputePassEncoder pass = wgpuCommandEncoderBeginComputePass(encoder, NULL);
1327+
WGPUComputePassDescriptor desc = {.label = WGPU_STRING_VIEW("binning pass")};
1328+
WGPUComputePassEncoder pass = wgpuCommandEncoderBeginComputePass(encoder, &desc);
13321329
wgpuComputePassEncoderSetPipeline(pass, r->tiles.binning_pso);
13331330
wgpuComputePassEncoderSetBindGroup(pass, 0, r->binding.binning_bindgroup, 0, NULL);
13341331
wgpuComputePassEncoderSetBindGroup(pass, 1, r->binding.frame_bindgroup[buffer_index], 0, NULL);
@@ -1339,7 +1336,8 @@ void od_end_frame(struct onedraw* r, WGPUTextureView target_view)
13391336

13401337
// write indirect params pass
13411338
{
1342-
WGPUComputePassEncoder pass = wgpuCommandEncoderBeginComputePass(encoder, NULL);
1339+
WGPUComputePassDescriptor desc = {.label = WGPU_STRING_VIEW("write_indirect_params pass")};
1340+
WGPUComputePassEncoder pass = wgpuCommandEncoderBeginComputePass(encoder, &desc);
13431341
wgpuComputePassEncoderSetPipeline(pass, r->tiles.write_indirect_buffer_pso);
13441342
wgpuComputePassEncoderSetBindGroup(pass, 0, r->binding.binning_bindgroup, 0, NULL);
13451343
wgpuComputePassEncoderSetBindGroup(pass, 1, r->binding.frame_bindgroup[buffer_index], 0, NULL);
@@ -1364,7 +1362,7 @@ void od_end_frame(struct onedraw* r, WGPUTextureView target_view)
13641362
.colorAttachmentCount = 1,
13651363
.colorAttachments = &color_attachment,
13661364
.depthStencilAttachment = NULL,
1367-
.label = WGPU_STRING_VIEW("rasterization_pass")
1365+
.label = WGPU_STRING_VIEW("rasterization pass")
13681366
};
13691367

13701368

‎lib/rasterizer.h‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <stddef.h>
55

6-
static const size_t rasterizer_shader_size = 24175;
6+
static const size_t rasterizer_shader_size = 24121;
77
static const char rasterizer_shader[] =
88
"// ---------------------------------------------------------------------------------------------------------------------------\n"
99
"// Structures\n"
@@ -471,8 +471,7 @@ static const char rasterizer_shader[] =
471471
"fn tile_fs(in: vs_out) -> @location(0) vec4<f32> \n"
472472
"{\n"
473473
" var output:vec4<f32> = g_draw_args.clear_color;\n"
474-
"\n"
475-
" /* \n"
474+
" \n"
476475
" var node_idx:u32 = g_tile_heads[in.tile_index];\n"
477476
" if (node_idx == INVALID_INDEX)\n"
478477
" {\n"
@@ -706,8 +705,7 @@ static const char rasterizer_shader[] =
706705
" output = linear_to_srgb(output);\n"
707706
" }\n"
708707
"\n"
709-
" //return output; */\n"
710-
" return vec4<f32>(1.0, 0.0, 0.0, 1.0);\n"
708+
" return output;\n"
711709
"}\n"
712710
;
713711

‎src/shaders/binning.wgsl‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,7 @@ fn tile_bin(@builtin(global_invocation_id) global_id: vec3<u32>)
572572
}
573573

574574
// 3. Fine-grained intersection test
575-
//let to_be_added = intersection_tile_command(tile_aabb, cmd, g_draw_args.aa_width + aabb_margin);
576-
let to_be_added:bool = true;
575+
let to_be_added = intersection_tile_command(tile_aabb, cmd, g_draw_args.aa_width + aabb_margin);
577576

578577
// we traverse in reverse order, so the end comes first
579578
if (cmd_type == BEGIN_GROUP)

‎src/shaders/rasterizer.wgsl‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,7 @@ fn tile_vs(@builtin(instance_index) instance_id: u32, @builtin(vertex_index) ver
270270
fn tile_fs(in: vs_out) -> @location(0) vec4<f32>
271271
{
272272
var output:vec4<f32> = g_draw_args.clear_color;
273-
274-
/*
273+
275274
var node_idx:u32 = g_tile_heads[in.tile_index];
276275
if (node_idx == INVALID_INDEX)
277276
{
@@ -505,6 +504,5 @@ fn tile_fs(in: vs_out) -> @location(0) vec4<f32>
505504
output = linear_to_srgb(output);
506505
}
507506

508-
//return output; */
509-
return vec4<f32>(1.0, 0.0, 0.0, 1.0);
507+
return output;
510508
}

‎tests/minimal.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ void frame(void)
4444
WGPUTextureView frame = wgpuTextureCreateView(surfaceTexture.texture, NULL);
4545

4646
od_begin_frame(renderer);
47-
od_draw_disc(renderer, 50.f, 50.f, 25.f, 0xffffffff);
48-
// od_draw_text(renderer, 0, 0, "Hello world!", 0xffffffff);
47+
od_draw_disc(renderer, 500.f, 500.f, 250.f, 0xffffffff);
48+
//od_draw_text(renderer, 0, 0, "Hello world!", 0xffffffff);
4949
od_end_frame(renderer, frame);
5050

5151
wgpuSurfacePresent(wgpu.surface);

0 commit comments

Comments
 (0)