package render_ir_tests import ir "../../render_ir" import "core:testing" @(test) test_dump_empty_frame_ir :: proc(t: ^testing.T) { frame := ir.init_frame_ir() defer ir.destroy_frame_ir(&frame) dump := ir.dump_frame_ir(&frame) defer delete(dump) expected := "Frame_IR\nresources 0\npasses 0\nshaders 0\ndescriptor_layouts 0\ndescriptor_sets 0\npipelines 0\ncommands 0" testing.expect_value(t, dump, expected) } @(test) test_dump_populated_frame_ir :: proc(t: ^testing.T) { frame := ir.init_frame_ir() defer ir.destroy_frame_ir(&frame) _ = ir.add_buffer(&frame, "vertices", 128, {.Vertex, .Transfer_Dst}, {.Device_Local}) _ = ir.add_texture( &frame, "color", 16, 8, .R8G8B8A8_UNORM, {.Sampled, .Color_Attachment}, .Transient, ) _ = ir.add_sampler( &frame, "linear", { mag_filter = .Linear, min_filter = .Linear, address_mode_u = .Repeat, address_mode_v = .Clamp_To_Edge, mipmap_mode = .Linear, }, ) render_pass := ir.add_pass(&frame, {kind = .Render, name = "main"}) compute_pass := ir.add_pass(&frame, {kind = .Compute, name = "compute"}) _ = ir.add_shader_source(&frame, "rect.vert", .Vertex, "vertex main() {}") _ = ir.add_shader_file(&frame, "rect.frag", .Fragment, "shaders/rect.frag.luma") layout := ir.make_descriptor_set_layout("set0") _ = ir.descriptor_layout_add_binding(&layout, 0, .Combined_Image_Sampler, 1, {.Fragment}) layout_handle := ir.add_descriptor_set_layout(&frame, layout) set := ir.make_descriptor_set("material", layout_handle) _ = ir.descriptor_set_bind_texture_sampler( &set, 0, ir.Resource_Handle(2), ir.Resource_Handle(3), ) _ = ir.add_descriptor_set(&frame, set) gfx_state := ir.default_graphics_pipeline_state() gfx_state.vertex_shader = ir.Shader_Handle(1) gfx_state.fragment_shader = ir.Shader_Handle(2) gfx_desc := ir.Pipeline_Desc { kind = .Graphics, name = "rect", graphics = gfx_state, } _ = ir.pipeline_add_descriptor_layout(&gfx_desc, layout_handle) gfx := ir.add_pipeline(&frame, gfx_desc) compute_state := ir.default_compute_pipeline_state(ir.Shader_Handle(0)) compute := ir.add_compute_pipeline(&frame, "particles", compute_state) _ = ir.add_draw( &frame, {pass = render_pass, pipeline = gfx, vertex_count = 6, instance_count = 1}, ) _ = ir.add_dispatch(&frame, {pass = compute_pass, pipeline = compute, groups = {8, 1, 1}}) dump := ir.dump_frame_ir(&frame) defer delete(dump) expected := "Frame_IR\n" + "resources 3\n" + " #1 Buffer name=\"vertices\" lifetime=Persistent size=128 usage=Vertex|Transfer_Dst memory=Device_Local\n" + " #2 Texture name=\"color\" lifetime=Transient width=16 height=8 format=R8G8B8A8_UNORM usage=Sampled|Color_Attachment\n" + " #3 Sampler name=\"linear\" lifetime=Persistent mag=Linear min=Linear address=Repeat,Clamp_To_Edge aniso=false compare=false compare_op=Never mipmap=Linear\n" + "passes 2\n" + " #1 Render name=\"main\"\n" + " #2 Compute name=\"compute\"\n" + "shaders 2\n" + " #1 Vertex Source language=Luma name=\"rect.vert\" source_len=16\n" + " #2 Fragment File language=Luma name=\"rect.frag\" path=\"shaders/rect.frag.luma\"\n" + "descriptor_layouts 1\n" + " #1 name=\"set0\" bindings=1\n" + " binding=0 type=Combined_Image_Sampler count=1 stages=Fragment\n" + "descriptor_sets 1\n" + " #1 name=\"material\" layout=1 bindings=1\n" + " binding=0 type=Combined_Image_Sampler resource=2 sampler=3 size=0\n" + "pipelines 2\n" + " #1 Graphics name=\"rect\" key=\"gfx:vs=1;fs=2;layouts=1;layout=PNU;instance_layout=false/PNU;topology=Triangle_List;cull=Back;front=Counter_Clockwise;blend=true/Alpha;depth=false/false;color=B8G8R8A8_SRGB;depth_format=Undefined;pc=0;pc_stages=None\"\n" + " #2 Compute name=\"particles\" key=\"compute:shader=0;layouts=None;pc=0;pc_stages=None\"\n" + "commands 2\n" + " #1 Draw pass=1 pipeline=1 vertex_count=6 instance_count=1\n" + " #2 Dispatch pass=2 pipeline=2 groups=8,1,1 shader_id=0 buffers=None push_constants_size=0 barrier_after=false" testing.expect_value(t, dump, expected) }