yum-mirror/glslang
git clone https://git.yummers.dev/yum-mirror/glslang
e70645c4
main
1#!/bin/bash 2 3# This script validates shaders (if successfully compiled) using spirv-val. 4# It is not meant to preclude the possible addition of the validator to 5# glslang. 6 7declare -rEXE ='../build/install/bin/glslang' 8 9# search common locations for spirv-tools: keep first one 10for toolsdir in '../External/spirv-tools/build/tools' '../../SPIRV-Tools/build/tools/bin' '/usr/local/bin' ;do 11 [[ -z" $ VAL " && -x" ${ toolsdir } /spirv-val" ]]&& declare -rVAL =" ${ toolsdir } /spirv-val" 12 [[ -z" $ DIS " && -x" ${ toolsdir } /spirv-dis" ]]&& declare -rDIS =" ${ toolsdir } /spirv-dis" 13done 14 15declare -rgtests ='../gtests/Hlsl.FromFile.cpp ../gtests/Spv.FromFile.cpp' 16 17declare -rtargetenv ='vulkan1.0' 18 19function fatal () {echo "ERROR: $ @" ;exit 5; } 20 21function usage 22{ 23echo 24echo "Usage: $( basename $ 0) [options...] shaders..." 25echo 26echo " Validates shaders (if successfully compiled) through spirv-val." 27echo 28echo "General options:" 29echo " --help prints this text" 30echo " --no-color disables output colorization" 31echo " --dump-asm dumps all successfully compiled shader assemblies" 32echo " --dump-val dumps all validation results" 33echo " --dump-comp dumps all compilation logs" 34echo "Spam reduction options:" 35echo " --no-summary disables result summaries" 36echo " --skip-ok do not print successful validations" 37echo " --skip-comperr do not print compilation errors" 38echo " --skip-valerr do not print validation errors" 39echo " --quiet synonym for --skip-ok --skip-comperr --skip-valerr --no-summary" 40echo " --terse print terse single line progress summary" 41echo "Disassembly options:" 42echo " --raw-id uses raw ids for disassembly" 43echo 44echo "Usage examples. Note most non-hlsl tests fail to compile for expected reasons." 45echo " Exercise all hlsl.* files:" 46echo " $( basename $ 0) hlsl.*" 47echo " Exercise all hlsl.* files, tersely:" 48echo " $( basename $ 0) --terse hlsl.*" 49echo " Print validator output for myfile.frag:" 50echo " $( basename $ 0) --quiet --dump-val myfile.frag" 51echo " Exercise hlsl.* files, only printing validation errors:" 52echo " $( basename $ 0) --skip-ok --skip-comperr hlsl.*" 53 54exit 5 55} 56 57function status () 58{ 59printf "%-40s: %b\n" " $ 1 " " $ 2 " 60} 61 62# make sure we can find glslang 63[[ -x" $ EXE " ]] ||fatal "Unable to locate $( basename " $ EXE " ) executable" 64[[ -x" $ VAL " ]] ||fatal "Unable to locate spirv-val executable" 65[[ -x" $ DIS " ]] ||fatal "Unable to locate spirv-dis executable" 66 67for gtest in $ gtests ;do 68 [[ -r" $ gtest " ]] ||fatal "Unable to locate source file: $( basename $ gtest ) " 69done 70 71# temp files 72declare -rspvfile ='out.spv' \ 73complog ='comp.out' \ 74vallog ='val.out' \ 75dislog ='dis.out' \ 76 77# options 78declareopt_vallog =false \ 79opt_complog =false \ 80opt_dislog =false \ 81opt_summary =true \ 82opt_stat_comperr =true \ 83opt_stat_ok =true \ 84opt_stat_valerr =true \ 85opt_color =true \ 86opt_raw_id =false \ 87opt_quiet =false \ 88opt_terse =false 89 90# clean up on exit 91trap "rm -f ${ spvfile } ${ complog } ${ vallog } ${ dislog } " EXIT 92 93# Language guesser: there is no fixed mapping from filenames to language, 94# so this examines the file and return one of: 95# hlsl 96# glsl 97# bin 98# unknown 99# This is easier WRT future expansion than a big explicit list. 100function FindLanguage () 101{ 102 localtest =" $ 1 " 103 104# If it starts with hlsl, assume it's hlsl. 105if [[" $ test " == *hlsl.* ]];then 106echo hlsl 107return 108fi 109 110if [[" $ test " == *.spv ]];then 111echo bin 112return ; 113fi 114 115# If it doesn't start with spv., assume it's GLSL. 116if [[ !" $ test " == spv.* ]];then 117echo glsl 118return 119fi 120 121# Otherwise, attempt to guess from shader contents, since there's no 122# fixed mapping of filenames to languages. 123 localcontents =" $( cat " $ test " ) " 124 125if [[" $ contents " == *#version* ]];then 126echo glsl 127return 128fi 129 130if [[" $ contents " == *SamplerState* || 131" $ contents " == *cbuffer* || 132" $ contents " == *SV_* ]];then 133echo hlsl 134return 135fi 136 137echo unknown 138} 139 140# Attempt to discover entry point 141function FindEntryPoint () 142{ 143 localtest =" $ 1 " 144 145# if it's not hlsl, always use main 146if [[" $ language " !='hlsl' ]];then 147echo 'main' 148return 149fi 150 151# Try to find it in test sources 152awk -F '[ (){",]+' -e "\$2 == \" ${ test } \" { print \$3; found=1; } END { if (found==0) print \"main\"; } " $ gtests 153} 154 155# command line options 156while [$ # -gt 0 ] 157do 158case " $ 1 " in 159# -c) glslang="$2"; shift 2;; 160 --help| -?)usage ;; 161 --no-color)opt_color =false;shift ;; 162 --no-summary)opt_summary =false;shift ;; 163 --skip-ok)opt_stat_ok =false;shift ;; 164 --skip-comperr)opt_stat_comperr =false;shift ;; 165 --skip-valerr)opt_stat_valerr =false;shift ;; 166 --dump-asm)opt_dislog =true;shift ;; 167 --dump-val)opt_vallog =true;shift ;; 168 --dump-comp)opt_complog =true;shift ;; 169 --raw-id)opt_raw_id =true;shift ;; 170 --quiet)opt_quiet =true;shift ;; 171 --terse)opt_quiet =true 172opt_terse =true 173shift ;; 174 --*)fatal "Unknown command line option: $ 1 " ;; 175 *)break ;; 176esac 177done 178 179# this is what quiet means 180if $ opt_quiet ;then 181opt_stat_ok =false 182opt_stat_comperr =false 183opt_stat_valerr =false 184$ opt_terse ||opt_summary =false 185fi 186 187if $ opt_color ;then 188 declare -rwhite ="\e[1;37m" cyan ="\e[1;36m" red ="\e[0;31m" no_color ="\e[0m" 189else 190 declare -rwhite ="" cyan ="" red ="" no_color ="" 191fi 192 193# stats 194declare -icount_ok =0count_err =0count_nocomp =0count_total =0 195 196declare -rdashsep ='------------------------------------------------------------------------' 197 198testfiles =(${@} ) 199# if no shaders given, look for everything in current directory 200[[${# testfiles [*]} == 0 ]]&& testfiles =(*.frag *.vert *.tesc *.tese *.geom *.comp) 201 202$ opt_summary && printf "\nValidating: ${# testfiles [*]} shaders\n\n" 203 204# Loop through the shaders we were given, compiling them if we can. 205for test in ${ testfiles [*]} 206do 207if [[ ! -r" $ test " ]];then 208$ opt_quiet ||status " $ test " " ${ red } FILE NOT FOUND ${ no_color } " 209continue 210fi 211 212((++ count_total )) 213 214$ opt_terse && printf "\r[%-3d/%-3d : ${ white } comperr=%-3d ${ red } valerr=%-3d ${ cyan } ok=%-3d ${ no_color } ]" \ 215${ count_total } ${# testfiles [*]} ${ count_nocomp } ${ count_err } ${ count_ok } 216 217language =" $( FindLanguage $ test ) " 218entry =" $( FindEntryPoint $ test ) " 219langops ='' 220 221case " $ language " in 222 hlsl)langops ='-D --hlsl-iomap --hlsl-offsets' ;; 223 glsl) ;; 224 bin)continue ;;# skip binaries 225 *)$ opt_quiet ||status " $ test " " ${ red } UNKNOWN LANGUAGE ${ no_color } " ;continue ;; 226esac 227 228# compile the test file 229if compout =$( " $ EXE " -e " $ entry " $ langops -V -o " $ spvfile " " $ test " 2 >&1) 230then 231# successful compilation: validate 232if valout =$( " $ VAL " --target-env ${ targetenv } " $ spvfile " 2 >&1) 233then 234# validated OK 235$ opt_stat_ok && status " $ test " " ${ cyan } OK ${ no_color } " 236((++ count_ok )) 237else 238# validation failure 239$ opt_stat_valerr && status " $ test " " ${ red } VAL ERROR ${ no_color } " 240printf "%s\n%s:\n%s\n" " $ dashsep " " $ test " " $ valout " >> " $ vallog " 241((++ count_err )) 242fi 243 244if $ opt_dislog ;then 245printf "%s\n%s:\n" " $ dashsep " " $ test " >> " $ dislog " 246$ opt_raw_id && id_opt =--raw-id 247" $ DIS " ${ id_opt } " $ spvfile " >> " $ dislog " 248fi 249else 250# compile failure 251$ opt_stat_comperr && status " $ test " " ${ white } COMP ERROR ${ no_color } " 252printf "%s\n%s\n" " $ dashsep " " $ compout " >> " $ complog " 253((++ count_nocomp )) 254fi 255done 256 257$ opt_terse && echo 258 259# summarize 260$ opt_summary && printf "\nSummary: ${ white }${ count_nocomp } compile errors ${ no_color } , ${ red }${ count_err } validation errors ${ no_color } , ${ cyan }${ count_ok } successes ${ no_color } \n" 261 262# dump logs 263$ opt_vallog && [[ -r$ vallog ]]&& cat " $ vallog " 264$ opt_complog && [[ -r$ complog ]]&& cat " $ complog " 265$ opt_dislog && [[ -r$ dislog ]]&& cat " $ dislog " 266 267# exit code 268[[${ count_err } -gt 0 ]]&& exit 1 269exit 0