LCOV - code coverage report
Current view: top level - src/glsl - spirv.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 13 15 86.7 %
Date: 2025-03-29 09:04:10 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 6 50.0 %

           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 "spirv.h"
      19                 :            : 
      20                 :            : extern const struct spirv_compiler pl_spirv_shaderc;
      21                 :            : extern const struct spirv_compiler pl_spirv_glslang;
      22                 :            : 
      23                 :            : static const struct spirv_compiler *compilers[] = {
      24                 :            : #ifdef PL_HAVE_SHADERC
      25                 :            :     &pl_spirv_shaderc,
      26                 :            : #endif
      27                 :            : #ifdef PL_HAVE_GLSLANG
      28                 :            :     &pl_spirv_glslang,
      29                 :            : #endif
      30                 :            : };
      31                 :            : 
      32                 :          3 : pl_spirv pl_spirv_create(pl_log log, struct pl_spirv_version spirv_ver)
      33                 :            : {
      34         [ +  - ]:          3 :     for (int i = 0; i < PL_ARRAY_SIZE(compilers); i++) {
      35                 :          3 :         pl_spirv spirv = compilers[i]->create(log, spirv_ver);
      36         [ -  + ]:          3 :         if (!spirv)
      37                 :            :             continue;
      38                 :            : 
      39                 :          3 :         pl_info(log, "Initialized SPIR-V compiler '%s'", compilers[i]->name);
      40                 :          3 :         return spirv;
      41                 :            :     }
      42                 :            : 
      43                 :          0 :     pl_fatal(log, "Failed initializing any SPIR-V compiler! Maybe libplacebo "
      44                 :            :              "was built without support for either libshaderc or glslang?");
      45                 :          0 :     return NULL;
      46                 :            : }
      47                 :            : 
      48                 :          3 : void pl_spirv_destroy(pl_spirv *pspirv)
      49                 :            : {
      50                 :          3 :     pl_spirv spirv = *pspirv;
      51         [ +  - ]:          3 :     if (!spirv)
      52                 :            :         return;
      53                 :            : 
      54                 :          3 :     spirv->impl->destroy(spirv);
      55                 :          3 :     *pspirv = NULL;
      56                 :            : }
      57                 :            : 
      58                 :        266 : pl_str pl_spirv_compile_glsl(pl_spirv spirv, void *alloc,
      59                 :            :                              struct pl_glsl_version glsl,
      60                 :            :                              enum glsl_shader_stage stage,
      61                 :            :                              const char *shader)
      62                 :            : {
      63                 :        266 :     return spirv->impl->compile(spirv, alloc, glsl, stage, shader);
      64                 :            : }

Generated by: LCOV version 1.16