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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package render_ir_tests
import ir "../../render_ir"
import "core:testing"
@(test)
test_pass_render_targets_store_descriptors :: proc(t: ^testing.T) {
frame := ir.init_frame_ir()
defer ir.destroy_frame_ir(&frame)
color := ir.add_texture(
&frame,
"color",
800,
600,
.B8G8R8A8_SRGB,
{.Color_Attachment, .Sampled},
.Transient,
)
depth := ir.add_texture(
&frame,
"depth",
800,
600,
.D32_SFLOAT,
{.Depth_Stencil_Attachment, .Sampled},
.Transient,
)
pass := ir.Pass_Desc {
kind = .Render,
name = "offscreen",
}
testing.expect(
t,
ir.pass_add_color_target(
&pass,
ir.make_color_target(color, .B8G8R8A8_SRGB, .Clear, .Store, {0.1, 0.2, 0.3, 1}),
),
)
ir.pass_set_depth_target(&pass, ir.make_depth_target(depth, .D32_SFLOAT, .Clear, .Store, 1))
ir.pass_set_viewport(
&pass,
{x = 0, y = 0, width = 800, height = 600, min_depth = 0, max_depth = 1},
)
ir.pass_set_scissor(&pass, {x = 0, y = 0, width = 800, height = 600})
pass_handle := ir.add_pass(&frame, pass)
stored, ok := ir.get_pass(&frame, pass_handle)
testing.expect(t, ok)
testing.expect_value(t, stored.color_target_count, u8(1))
testing.expect(t, stored.color_targets[0].resource == color)
testing.expect(t, stored.color_targets[0].kind == .Color)
testing.expect(t, stored.depth_target.resource == depth)
testing.expect(t, stored.has_depth_target)
testing.expect(t, stored.has_viewport)
testing.expect(t, stored.has_scissor)
diagnostics := ir.init_diagnostics()
defer ir.destroy_diagnostics(&diagnostics)
ir.validate_pass_targets(&frame, &diagnostics)
testing.expect_value(t, len(diagnostics.items), 0)
}
@(test)
test_pass_render_targets_dump :: proc(t: ^testing.T) {
frame := ir.init_frame_ir()
defer ir.destroy_frame_ir(&frame)
color := ir.add_texture(
&frame,
"color",
800,
600,
.B8G8R8A8_SRGB,
{.Color_Attachment},
.Transient,
)
depth := ir.add_texture(
&frame,
"depth",
800,
600,
.D32_SFLOAT,
{.Depth_Stencil_Attachment},
.Transient,
)
pass := ir.Pass_Desc {
kind = .Render,
name = "offscreen",
}
_ = ir.pass_add_color_target(
&pass,
ir.make_color_target(color, .B8G8R8A8_SRGB, .Clear, .Store, {0.1, 0.2, 0.3, 1}),
)
ir.pass_set_depth_target(&pass, ir.make_depth_target(depth, .D32_SFLOAT, .Clear, .Store, 1))
ir.pass_set_viewport(
&pass,
{x = 0, y = 0, width = 800, height = 600, min_depth = 0, max_depth = 1},
)
ir.pass_set_scissor(&pass, {x = 0, y = 0, width = 800, height = 600})
_ = ir.add_pass(&frame, pass)
dump := ir.dump_frame_ir(&frame)
defer delete(dump)
expected :=
"Frame_IR\n" +
"resources 2\n" +
" #1 Texture name=\"color\" lifetime=Transient width=800 height=600 format=B8G8R8A8_SRGB usage=Color_Attachment\n" +
" #2 Texture name=\"depth\" lifetime=Transient width=800 height=600 format=D32_SFLOAT usage=Depth_Stencil_Attachment\n" +
"passes 1\n" +
" #1 Render name=\"offscreen\"\n" +
" color[0] resource=1 kind=Color format=B8G8R8A8_SRGB load=Clear store=Store clear=0.100000,0.200000,0.300000,1.000000\n" +
" depth resource=2 kind=Depth format=D32_SFLOAT load=Clear store=Store clear=1.000000\n" +
" viewport x=0.000000 y=0.000000 width=800.000000 height=600.000000 depth=0.000000,1.000000\n" +
" scissor x=0 y=0 width=800 height=600\n" +
"shaders 0\n" +
"descriptor_layouts 0\n" +
"descriptor_sets 0\n" +
"pipelines 0\n" +
"commands 0"
testing.expect_value(t, dump, expected)
}
@(test)
test_validate_pass_targets_rejects_wrong_usage :: proc(t: ^testing.T) {
frame := ir.init_frame_ir()
defer ir.destroy_frame_ir(&frame)
not_color := ir.add_texture(&frame, "sampled", 16, 16, .B8G8R8A8_SRGB, {.Sampled}, .Transient)
pass := ir.Pass_Desc {
kind = .Render,
name = "bad",
}
_ = ir.pass_add_color_target(&pass, ir.make_color_target(not_color, .B8G8R8A8_SRGB))
_ = ir.add_pass(&frame, pass)
diagnostics := ir.init_diagnostics()
defer ir.destroy_diagnostics(&diagnostics)
ir.validate_pass_targets(&frame, &diagnostics)
testing.expect_value(t, len(diagnostics.items), 1)
testing.expect(t, diagnostics.items[0].code == .Invalid_Resource)
}