tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WebGLShaderValidator.h (2079B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef WEBGL_SHADER_VALIDATOR_H_
      7 #define WEBGL_SHADER_VALIDATOR_H_
      8 
      9 #include <memory>
     10 #include <string>
     11 #include <unordered_map>
     12 
     13 #include "GLDefs.h"
     14 #include "GLSLANG/ShaderLang.h"
     15 #include "nsString.h"
     16 
     17 namespace mozilla::webgl {
     18 
     19 class ShaderValidatorResults final {
     20 public:
     21  std::string mInfoLog;
     22  bool mValid = false;
     23 
     24  std::string mObjectCode;
     25  int mShaderVersion = 0;
     26  int mVertexShaderNumViews = 0;
     27 
     28  std::vector<sh::Attribute> mAttributes;
     29  std::vector<sh::InterfaceBlock> mInterfaceBlocks;
     30  std::vector<sh::OutputVariable> mOutputVariables;
     31  std::vector<sh::Uniform> mUniforms;
     32  std::vector<sh::Varying> mVaryings;
     33 
     34  std::unordered_map<std::string, std::string> mNameMap;
     35 
     36  int mMaxVaryingVectors = 0;
     37 
     38  bool mNeeds_webgl_gl_VertexID_Offset = false;
     39 
     40  bool CanLinkTo(const ShaderValidatorResults& vert,
     41                 nsCString* const out_log) const;
     42  size_t SizeOfIncludingThis(mozilla::MallocSizeOf) const;
     43 };
     44 
     45 class ShaderValidator final {
     46 public:
     47  const ShHandle mHandle;
     48 
     49 private:
     50  const ShCompileOptions mCompileOptions;
     51  const int mMaxVaryingVectors;
     52 
     53 public:
     54  bool mIfNeeded_webgl_gl_VertexID_Offset = false;
     55 
     56  static std::unique_ptr<ShaderValidator> Create(
     57      GLenum shaderType, ShShaderSpec spec, ShShaderOutput outputLanguage,
     58      const ShBuiltInResources& resources, ShCompileOptions compileOptions);
     59 
     60 private:
     61  ShaderValidator(ShHandle handle, ShCompileOptions compileOptions,
     62                  int maxVaryingVectors)
     63      : mHandle(handle),
     64        mCompileOptions(compileOptions),
     65        mMaxVaryingVectors(maxVaryingVectors) {}
     66 
     67 public:
     68  ~ShaderValidator();
     69 
     70  std::unique_ptr<const ShaderValidatorResults> ValidateAndTranslate(
     71      const char*) const;
     72 };
     73 
     74 }  // namespace mozilla::webgl
     75 
     76 #endif  // WEBGL_SHADER_VALIDATOR_H_