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. 8 // The shaders are then fed into glslang to spit out SPIR-V (libANGLE-side). 9 // See: https://www.khronos.org/registry/vulkan/specs/misc/GL_KHR_vulkan_glsl.txt 10 // 11 12 #include "compiler/translator/OutputGLSL.h" 13 14 namespace sh 15 { 16 17 class TOutputVulkanGLSL : public TOutputGLSL 18 { 19 public: 20 TOutputVulkanGLSL(TInfoSinkBase &objSink, 21 ShArrayIndexClampingStrategy clampingStrategy, 22 ShHashFunction64 hashFunction, 23 NameMap &nameMap, 24 TSymbolTable *symbolTable, 25 sh::GLenum shaderType, 26 int shaderVersion, 27 ShShaderOutput output, 28 bool forceHighp, 29 bool enablePrecision, 30 ShCompileOptions compileOptions); 31 32 void writeStructType(const TStructure *structure); 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(TIntermTyped *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