1 // 2 // Copyright 2016 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 // OutputVulkanGLSL: 7 // Code that outputs shaders that fit GL_KHR_vulkan_glsl, to be fed to glslang to generate 8 // SPIR-V. 9 // See: https://www.khronos.org/registry/vulkan/specs/misc/GL_KHR_vulkan_glsl.txt 10 // 11 12 #ifndef COMPILER_TRANSLATOR_OUTPUTVULKANGLSL_H_ 13 #define COMPILER_TRANSLATOR_OUTPUTVULKANGLSL_H_ 14 15 #include "compiler/translator/OutputGLSL.h" 16 17 namespace sh 18 { 19 20 class TOutputVulkanGLSL : public TOutputGLSL 21 { 22 public: 23 TOutputVulkanGLSL(TInfoSinkBase &objSink, 24 ShHashFunction64 hashFunction, 25 NameMap &nameMap, 26 TSymbolTable *symbolTable, 27 sh::GLenum shaderType, 28 int shaderVersion, 29 ShShaderOutput output, 30 bool forceHighp, 31 bool enablePrecision, 32 ShCompileOptions compileOptions); 33 nextUnusedBinding()34 uint32_t nextUnusedBinding() { return mNextUnusedBinding++; } nextUnusedInputLocation(uint32_t consumedCount)35 uint32_t nextUnusedInputLocation(uint32_t consumedCount) 36 { 37 uint32_t nextUnused = mNextUnusedInputLocation; 38 mNextUnusedInputLocation += consumedCount; 39 return nextUnused; 40 } nextUnusedOutputLocation(uint32_t consumedCount)41 uint32_t nextUnusedOutputLocation(uint32_t consumedCount) 42 { 43 uint32_t nextUnused = mNextUnusedOutputLocation; 44 mNextUnusedOutputLocation += consumedCount; 45 return nextUnused; 46 } 47 48 protected: 49 void writeLayoutQualifier(TIntermSymbol *variable) override; 50 void writeVariableType(const TType &type, 51 const TSymbol *symbol, 52 bool isFunctionArgument) override; 53 bool writeVariablePrecision(TPrecision) override; 54 55 // Every resource that requires set & binding layout qualifiers is assigned set 0 and an 56 // arbitrary binding when outputting GLSL. Every input/output that requires a location 57 // layout qualifiers is assigned an arbitrary location as well. 58 // 59 // Glslang wrapper modifies set, binding and location decorations in SPIR-V directly. 60 uint32_t mNextUnusedBinding; 61 uint32_t mNextUnusedInputLocation; 62 uint32_t mNextUnusedOutputLocation; 63 64 private: 65 bool mForceHighp; 66 bool mEnablePrecision; 67 }; 68 69 } // namespace sh 70 71 #endif // COMPILER_TRANSLATOR_OUTPUTVULKANGLSL_H_ 72