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) }