package render_ir_tests import ir "../../render_ir" import "core:testing" @(test) test_handles_start_at_one :: proc(t: ^testing.T) { frame := ir.init_frame_ir() defer ir.destroy_frame_ir(&frame) res := ir.add_resource(&frame, {kind = .Buffer, name = "vertices", buffer = {size = 128}}) pass := ir.add_pass(&frame, {kind = .Render, name = "main"}) pipeline := ir.add_pipeline(&frame, {kind = .Graphics, name = "rect"}) cmd := ir.add_draw( &frame, {pass = pass, pipeline = pipeline, vertex_count = 6, instance_count = 1}, ) testing.expect(t, ir.INVALID_RESOURCE == ir.Resource_Handle(0)) testing.expect(t, res == ir.Resource_Handle(1)) testing.expect(t, pass == ir.Pass_Handle(1)) testing.expect(t, pipeline == ir.Pipeline_Handle(1)) testing.expect(t, cmd == ir.Command_Handle(1)) } @(test) test_get_rejects_invalid_handles :: proc(t: ^testing.T) { frame := ir.init_frame_ir() defer ir.destroy_frame_ir(&frame) res := ir.add_resource(&frame, {kind = .Buffer, name = "vertices", buffer = {size = 128}}) _, invalid_ok := ir.get_resource(&frame, ir.INVALID_RESOURCE) testing.expect(t, !invalid_ok) last, last_ok := ir.get_resource(&frame, res) testing.expect(t, last_ok) testing.expect(t, last.buffer.size == 128) _, past_ok := ir.get_resource(&frame, ir.Resource_Handle(2)) testing.expect(t, !past_ok) _, wrong_cmd_ok := ir.get_draw(&frame, ir.INVALID_COMMAND) testing.expect(t, !wrong_cmd_ok) } @(test) test_command_stream_preserves_order :: proc(t: ^testing.T) { frame := ir.init_frame_ir() defer ir.destroy_frame_ir(&frame) pass := ir.add_pass(&frame, {kind = .Render, name = "main"}) compute_pass := ir.add_pass(&frame, {kind = .Compute, name = "compute"}) gfx := ir.add_pipeline(&frame, {kind = .Graphics, name = "rect"}) compute := ir.add_pipeline(&frame, {kind = .Compute, name = "particles"}) draw := ir.add_draw( &frame, {pass = pass, pipeline = gfx, vertex_count = 6, instance_count = 1}, ) dispatch := ir.add_dispatch( &frame, {pass = compute_pass, pipeline = compute, groups = {8, 1, 1}}, ) testing.expect_value(t, ir.command_count(&frame), 2) first, first_ok := ir.get_command_record(&frame, draw) testing.expect(t, first_ok) testing.expect(t, first.kind == .Draw) testing.expect_value(t, first.index, u32(0)) second, second_ok := ir.get_command_record(&frame, dispatch) testing.expect(t, second_ok) testing.expect(t, second.kind == .Dispatch) testing.expect_value(t, second.index, u32(0)) draw_payload, draw_ok := ir.get_draw(&frame, draw) testing.expect(t, draw_ok) testing.expect_value(t, draw_payload.vertex_count, u32(6)) dispatch_payload, dispatch_ok := ir.get_dispatch(&frame, dispatch) testing.expect(t, dispatch_ok) testing.expect_value(t, dispatch_payload.groups, [3]u32{8, 1, 1}) _, draw_as_dispatch_ok := ir.get_dispatch(&frame, draw) testing.expect(t, !draw_as_dispatch_ok) } @(test) test_reset_clears_counts_and_reuses_handles :: proc(t: ^testing.T) { frame := ir.init_frame_ir() defer ir.destroy_frame_ir(&frame) _ = ir.add_resource(&frame, {kind = .Buffer, name = "vertices", buffer = {size = 128}}) pass := ir.add_pass(&frame, {kind = .Render, name = "main"}) pipeline := ir.add_pipeline(&frame, {kind = .Graphics, name = "rect"}) _ = ir.add_draw( &frame, {pass = pass, pipeline = pipeline, vertex_count = 6, instance_count = 1}, ) ir.reset_frame_ir(&frame) testing.expect_value(t, ir.resource_count(&frame), 0) testing.expect_value(t, ir.pass_count(&frame), 0) testing.expect_value(t, ir.pipeline_count(&frame), 0) testing.expect_value(t, ir.command_count(&frame), 0) res := ir.add_resource( &frame, {kind = .Texture, name = "color", texture = {width = 16, height = 16}}, ) testing.expect(t, res == ir.Resource_Handle(1)) } @(test) test_destroy_zeroes_counts :: proc(t: ^testing.T) { frame := ir.init_frame_ir() _ = ir.add_resource(&frame, {kind = .Buffer, name = "vertices", buffer = {size = 128}}) ir.destroy_frame_ir(&frame) testing.expect_value(t, ir.resource_count(&frame), 0) testing.expect_value(t, ir.pass_count(&frame), 0) testing.expect_value(t, ir.pipeline_count(&frame), 0) testing.expect_value(t, ir.command_count(&frame), 0) }