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