1 #include "gpu_tests.h"
2
main()3 int main()
4 {
5 pl_log log = pl_test_logger();
6 pl_gpu gpu = pl_gpu_dummy_create(log, NULL);
7 pl_buffer_tests(gpu);
8 pl_texture_tests(gpu);
9
10 // Attempt creating a shader and accessing the resulting LUT
11 pl_tex dummy = pl_tex_dummy_create(gpu, &(struct pl_tex_dummy_params) {
12 .w = 100,
13 .h = 100,
14 .format = pl_find_named_fmt(gpu, "rgba8"),
15 });
16
17 struct pl_sample_src src = {
18 .tex = dummy,
19 .new_w = 1000,
20 .new_h = 1000,
21 };
22
23 pl_shader_obj lut = NULL;
24 struct pl_sample_filter_params filter_params = {
25 .filter = pl_filter_ewa_lanczos,
26 .lut = &lut,
27 };
28
29 pl_shader sh = pl_shader_alloc(log, &(struct pl_shader_params) { .gpu = gpu });
30 REQUIRE(pl_shader_sample_polar(sh, &src, &filter_params));
31 const struct pl_shader_res *res = pl_shader_finalize(sh);
32 REQUIRE(res);
33
34 for (int n = 0; n < res->num_descriptors; n++) {
35 const struct pl_shader_desc *sd = &res->descriptors[n];
36 if (sd->desc.type != PL_DESC_SAMPLED_TEX)
37 continue;
38
39 pl_tex tex = sd->binding.object;
40 const float *data = (float *) pl_tex_dummy_data(tex);
41 if (!data)
42 continue; // means this was the `dummy` texture
43
44 for (int i = 0; i < tex->params.w; i++)
45 printf("lut[%d] = %f\n", i, data[i]);
46 }
47
48 // Try out generation of the sampler2D interface
49 src.tex = NULL;
50 src.tex_w = 100;
51 src.tex_h = 100;
52 src.format = PL_FMT_UNORM;
53 src.sampler = PL_SAMPLER_NORMAL;
54 src.mode = PL_TEX_SAMPLE_LINEAR;
55
56 pl_shader_reset(sh, &(struct pl_shader_params) { .gpu = gpu });
57 REQUIRE(pl_shader_sample_polar(sh, &src, &filter_params));
58 REQUIRE((res = pl_shader_finalize(sh)));
59 REQUIRE(res->input == PL_SHADER_SIG_SAMPLER);
60 printf("generated sampler2D shader:\n\n%s\n", res->glsl);
61
62 pl_shader_free(&sh);
63 pl_shader_obj_destroy(&lut);
64 pl_tex_destroy(gpu, &dummy);
65 pl_gpu_dummy_destroy(&gpu);
66 pl_log_destroy(&log);
67 }
68