1 // 2 // Copyright 2019 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 // mtl_msl_utils.h: Utilities to manipulate MSL. 7 // 8 9 #ifndef mtl_msl_utils_h 10 #define mtl_msl_utils_h 11 12 #include <memory> 13 14 #include "compiler/translator/msl/TranslatorMSL.h" 15 #include "libANGLE/Context.h" 16 #include "libANGLE/renderer/ProgramImpl.h" 17 #include "libANGLE/renderer/metal/mtl_common.h" 18 19 namespace rx 20 { 21 struct CompiledShaderStateMtl : angle::NonCopyable 22 { 23 sh::TranslatorMetalReflection translatorMetalReflection = {}; 24 }; 25 using SharedCompiledShaderStateMtl = std::shared_ptr<CompiledShaderStateMtl>; 26 27 namespace mtl 28 { 29 struct SamplerBinding 30 { 31 uint32_t textureBinding = 0; 32 uint32_t samplerBinding = 0; 33 }; 34 35 struct TranslatedShaderInfo 36 { 37 void reset(); 38 // Translated Metal source code 39 std::shared_ptr<const std::string> metalShaderSource; 40 // Metal library compiled from source code above. Used by ProgramMtl. 41 AutoObjCPtr<id<MTLLibrary>> metalLibrary; 42 std::array<SamplerBinding, kMaxGLSamplerBindings> actualSamplerBindings; 43 std::array<int, kMaxShaderImages> actualImageBindings; 44 std::array<uint32_t, kMaxGLUBOBindings> actualUBOBindings; 45 std::array<uint32_t, kMaxShaderXFBs> actualXFBBindings; 46 bool hasUBOArgumentBuffer; 47 bool hasIsnanOrIsinf; 48 bool hasInvariant; 49 }; 50 51 void MSLGetShaderSource(const gl::ProgramState &programState, 52 const gl::ProgramLinkedResources &resources, 53 gl::ShaderMap<std::string> *shaderSourcesOut); 54 55 angle::Result MTLGetMSL(const angle::FeaturesMtl &features, 56 const gl::ProgramExecutable &executable, 57 const gl::ShaderMap<std::string> &shaderSources, 58 const gl::ShaderMap<SharedCompiledShaderStateMtl> &shadersState, 59 gl::ShaderMap<TranslatedShaderInfo> *mslShaderInfoOut); 60 61 // Get equivalent shadow compare mode that is used in translated msl shader. 62 uint MslGetShaderShadowCompareMode(GLenum mode, GLenum func); 63 } // namespace mtl 64 } // namespace rx 65 66 #endif /* mtl_msl_utils_h */ 67