1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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)
}