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(TCompiler *compiler, 24 TInfoSinkBase &objSink, 25 bool enablePrecision, 26 ShCompileOptions compileOptions); 27 nextUnusedBinding()28 uint32_t nextUnusedBinding() { return mNextUnusedBinding++; } nextUnusedInputLocation(uint32_t consumedCount)29 uint32_t nextUnusedInputLocation(uint32_t consumedCount) 30 { 31 uint32_t nextUnused = mNextUnusedInputLocation; 32 mNextUnusedInputLocation += consumedCount; 33 return nextUnused; 34 } nextUnusedOutputLocation(uint32_t consumedCount)35 uint32_t nextUnusedOutputLocation(uint32_t consumedCount) 36 { 37 uint32_t nextUnused = mNextUnusedOutputLocation; 38 mNextUnusedOutputLocation += consumedCount; 39 return nextUnused; 40 } 41 42 protected: 43 void writeLayoutQualifier(TIntermSymbol *variable) override; 44 void writeVariableType(const TType &type, 45 const TSymbol *symbol, 46 bool isFunctionArgument) override; 47 bool writeVariablePrecision(TPrecision) override; 48 49 // Every resource that requires set & binding layout qualifiers is assigned set 0 and an 50 // arbitrary binding when outputting GLSL. Every input/output that requires a location 51 // layout qualifiers is assigned an arbitrary location as well. 52 // 53 // Glslang wrapper modifies set, binding and location decorations in SPIR-V directly. 54 uint32_t mNextUnusedBinding; 55 uint32_t mNextUnusedInputLocation; 56 uint32_t mNextUnusedOutputLocation; 57 58 private: 59 bool mEnablePrecision; 60 }; 61 62 } // namespace sh 63 64 #endif // COMPILER_TRANSLATOR_OUTPUTVULKANGLSL_H_ 65