yum-mirror/glslang
git clone https://git.yummers.dev/yum-mirror/glslang
5fc62e82
main-tot
1// 2// Copyright (C) 2016 Google, Inc. 3// 4// All rights reserved. 5// 6// Redistribution and use in source and binary forms, with or without 7// modification, are permitted provided that the following conditions 8// are met: 9// 10// Redistributions of source code must retain the above copyright 11// notice, this list of conditions and the following disclaimer. 12// 13// Redistributions in binary form must reproduce the above 14// copyright notice, this list of conditions and the following 15// disclaimer in the documentation and/or other materials provided 16// with the distribution. 17// 18// Neither the name of Google Inc. nor the names of its 19// contributors may be used to endorse or promote products derived 20// from this software without specific prior written permission. 21// 22// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33// POSSIBILITY OF SUCH DAMAGE. 34 35#include "TestFixture.h" 36 37namespace glslangtest { 38 39std :: string FileNameAsCustomTestSuffix ( 40const :: testing :: TestParamInfo < std :: string >& info ) 41{ 42std :: string name = info . param ; 43// A valid test case suffix cannot have '.' and '-' inside. 44std :: replace ( name . begin () , name . end () , '.' , '_' ) ; 45std :: replace ( name . begin () , name . end () , '-' , '_' ) ; 46return name ; 47} 48 49EShLanguage GetShaderStage ( const std :: string & stage ) 50{ 51if ( stage == "vert" ) { 52return EShLangVertex ; 53} else if ( stage == "tesc" ) { 54return EShLangTessControl ; 55} else if ( stage == "tese" ) { 56return EShLangTessEvaluation ; 57} else if ( stage == "geom" ) { 58return EShLangGeometry ; 59} else if ( stage == "frag" ) { 60return EShLangFragment ; 61} else if ( stage == "comp" ) { 62return EShLangCompute ; 63} else if ( stage == "rgen" ) { 64return EShLangRayGen ; 65} else if ( stage == "rint" ) { 66return EShLangIntersect ; 67} else if ( stage == "rahit" ) { 68return EShLangAnyHit ; 69} else if ( stage == "rchit" ) { 70return EShLangClosestHit ; 71} else if ( stage == "rmiss" ) { 72return EShLangMiss ; 73} else if ( stage == "rcall" ) { 74return EShLangCallable ; 75} else if ( stage == "task" ) { 76return EShLangTask ; 77} else if ( stage == "mesh" ) { 78return EShLangMesh ; 79} else { 80assert ( 0 && "Unknown shader stage" ) ; 81return EShLangCount ; 82} 83} 84 85EShMessages DeriveOptions ( Source source , Semantics semantics , Target target ) 86{ 87EShMessages result = EShMsgCascadingErrors ; 88 89switch ( source ) { 90case Source :: GLSL : 91break ; 92case Source :: HLSL : 93result = static_cast < EShMessages > ( result | EShMsgReadHlsl ) ; 94break ; 95} 96 97switch ( target ) { 98case Target :: AST : 99result = static_cast < EShMessages > ( result | EShMsgAST ) ; 100break ; 101case Target :: Spv : 102result = static_cast < EShMessages > ( result | EShMsgSpvRules ) ; 103result = static_cast < EShMessages > ( result | EShMsgKeepUncalled ) ; 104break ; 105case Target :: BothASTAndSpv : 106result = static_cast < EShMessages > ( result | EShMsgSpvRules | EShMsgAST ) ; 107result = static_cast < EShMessages > ( result | EShMsgKeepUncalled ) ; 108break ; 109} ; 110 111switch ( semantics ) { 112case Semantics :: OpenGL : 113break ; 114case Semantics :: Vulkan : 115result = static_cast < EShMessages > ( result | EShMsgVulkanRules | EShMsgSpvRules ) ; 116break ; 117} 118 119result = static_cast < EShMessages > ( result | EShMsgHlslLegalization | EShMsgValidateCrossStageIO ) ; 120 121return result ; 122} 123 124std :: pair < bool , std :: string > ReadFile ( const std :: string & path ) 125{ 126std :: ifstream fstream ( path , std :: ios :: in ) ; 127if ( fstream ) { 128std :: string contents ; 129fstream . seekg ( 0 , std :: ios :: end ) ; 130contents . reserve (( std :: string :: size_type ) fstream . tellg ()) ; 131fstream . seekg ( 0 , std :: ios :: beg ) ; 132contents . assign (( std :: istreambuf_iterator < char > ( fstream )) , 133std :: istreambuf_iterator < char > ()) ; 134return std :: make_pair ( true , contents ) ; 135} 136return std :: make_pair ( false , "" ) ; 137} 138 139std :: pair < bool , std :: vector < std :: uint32_t > > ReadSpvBinaryFile ( const std :: string & path ) 140{ 141std :: ifstream fstream ( path , std :: fstream :: in | std :: fstream :: binary ) ; 142 143if ( ! fstream ) 144return std :: make_pair ( false , std :: vector < std :: uint32_t > ()) ; 145 146std :: vector < std :: uint32_t > contents ; 147 148// Reserve space (for efficiency, not for correctness) 149fstream . seekg ( 0 , fstream . end ) ; 150contents . reserve ( size_t ( fstream . tellg ()) / sizeof ( std :: uint32_t )) ; 151fstream . seekg ( 0 , fstream . beg ) ; 152 153// There is no istream iterator traversing by uint32_t, so we must loop. 154while ( ! fstream . eof ()) { 155std :: uint32_t inWord ; 156fstream . read (( char * ) & inWord , sizeof ( inWord )) ; 157 158if ( ! fstream . eof ()) 159contents . push_back ( inWord ) ; 160} 161 162return std :: make_pair ( true , contents ) ; // hopefully, c++11 move semantics optimizes the copy away. 163} 164 165bool WriteFile ( const std :: string & path , const std :: string & contents ) 166{ 167std :: ofstream fstream ( path , std :: ios :: out ) ; 168if ( ! fstream ) return false ; 169fstream << contents ; 170fstream . flush () ; 171return true ; 172} 173 174std :: string GetSuffix ( const std :: string & name ) 175{ 176const size_t pos = name . rfind ( '.' ) ; 177return ( pos == std :: string :: npos ) ? "" : name . substr ( name . rfind ( '.' ) + 1 ) ; 178} 179 180} // namespace glslangtest