Branch data Line data Source code
1 : : /* 2 : : * This file is part of libplacebo. 3 : : * 4 : : * libplacebo is free software; you can redistribute it and/or 5 : : * modify it under the terms of the GNU Lesser General Public 6 : : * License as published by the Free Software Foundation; either 7 : : * version 2.1 of the License, or (at your option) any later version. 8 : : * 9 : : * libplacebo is distributed in the hope that it will be useful, 10 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : : * GNU Lesser General Public License for more details. 13 : : * 14 : : * You should have received a copy of the GNU Lesser General Public 15 : : * License along with libplacebo. If not, see <http://www.gnu.org/licenses/>. 16 : : */ 17 : : 18 : : #include "shaders.h" 19 : : 20 : : #include <libplacebo/shaders/custom.h> 21 : : 22 : 4 : bool pl_shader_custom(pl_shader sh, const struct pl_custom_shader *params) 23 : : { 24 [ - + ]: 4 : if (params->compute) { 25 [ # # ]: 0 : int bw = PL_DEF(params->compute_group_size[0], 16); 26 [ # # ]: 0 : int bh = PL_DEF(params->compute_group_size[1], 16); 27 [ # # # # ]: 0 : bool flex = !params->compute_group_size[0] || 28 : : !params->compute_group_size[1]; 29 [ # # ]: 0 : if (!sh_try_compute(sh, bw, bh, flex, params->compute_shmem)) 30 : : return false; 31 : : } 32 : : 33 [ - + ]: 4 : if (!sh_require(sh, params->input, params->output_w, params->output_h)) 34 : : return false; 35 : : 36 : 4 : sh->output = params->output; 37 : : 38 [ + + ]: 6 : for (int i = 0; i < params->num_variables; i++) { 39 : 2 : struct pl_shader_var sv = params->variables[i]; 40 : 2 : GLSLP("#define %s "$"\n", sv.var.name, sh_var(sh, sv)); 41 : : } 42 : : 43 [ - + ]: 4 : for (int i = 0; i < params->num_descriptors; i++) { 44 : 0 : struct pl_shader_desc sd = params->descriptors[i]; 45 : 0 : GLSLP("#define %s "$"\n", sd.desc.name, sh_desc(sh, sd)); 46 : : } 47 : : 48 [ - + ]: 4 : for (int i = 0; i < params->num_vertex_attribs; i++) { 49 : 0 : struct pl_shader_va sva = params->vertex_attribs[i]; 50 : 0 : GLSLP("#define %s "$"\n", sva.attr.name, sh_attr(sh, sva)); 51 : : } 52 : : 53 [ - + ]: 4 : for (int i = 0; i < params->num_constants; i++) { 54 : 0 : struct pl_shader_const sc = params->constants[i]; 55 : 0 : GLSLP("#define %s "$"\n", sc.name, sh_const(sh, sc)); 56 : : } 57 : : 58 [ - + ]: 4 : if (params->prelude) 59 : 0 : GLSLP("// pl_shader_custom prelude: \n%s\n", params->prelude); 60 [ + + ]: 4 : if (params->header) 61 : 2 : GLSLH("// pl_shader_custom header: \n%s\n", params->header); 62 : : 63 [ - + ]: 4 : if (params->description) 64 : 0 : sh_describef(sh, "%s", params->description); 65 : : 66 [ + - ]: 4 : if (params->body) { 67 : : const char *output_decl = ""; 68 [ + - ]: 4 : if (params->output != params->input) { 69 [ - - + ]: 4 : switch (params->output) { 70 : : case PL_SHADER_SIG_NONE: break; 71 : : case PL_SHADER_SIG_COLOR: 72 : : output_decl = "vec4 color = vec4(0.0);"; 73 : : break; 74 : : 75 : : case PL_SHADER_SIG_SAMPLER: 76 : 0 : pl_unreachable(); 77 : : } 78 : : } 79 : : 80 : 4 : GLSL("// pl_shader_custom \n" 81 : : "%s \n" 82 : : "{ \n" 83 : : "%s \n" 84 : : "} \n", 85 : : output_decl, params->body); 86 : : } 87 : : 88 : : return true; 89 : : }