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/. */
6 #ifndef WEBGL_SHADER_VALIDATOR_H_
7 #define WEBGL_SHADER_VALIDATOR_H_
11 #include <unordered_map>
14 #include "GLSLANG/ShaderLang.h"
17 namespace mozilla::webgl
{
19 class ShaderValidatorResults final
{
24 std::string mObjectCode
;
25 int mShaderVersion
= 0;
26 int mVertexShaderNumViews
= 0;
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
;
34 std::unordered_map
<std::string
, std::string
> mNameMap
;
36 int mMaxVaryingVectors
= 0;
38 bool mNeeds_webgl_gl_VertexID_Offset
= false;
40 bool CanLinkTo(const ShaderValidatorResults
& vert
,
41 nsCString
* const out_log
) const;
42 size_t SizeOfIncludingThis(MallocSizeOf
) const;
45 class ShaderValidator final
{
47 const ShHandle mHandle
;
50 const ShCompileOptions mCompileOptions
;
51 const int mMaxVaryingVectors
;
54 bool mIfNeeded_webgl_gl_VertexID_Offset
= false;
56 static std::unique_ptr
<ShaderValidator
> Create(
57 GLenum shaderType
, ShShaderSpec spec
, ShShaderOutput outputLanguage
,
58 const ShBuiltInResources
& resources
, ShCompileOptions compileOptions
);
61 ShaderValidator(ShHandle handle
, ShCompileOptions compileOptions
,
62 int maxVaryingVectors
)
64 mCompileOptions(compileOptions
),
65 mMaxVaryingVectors(maxVaryingVectors
) {}
70 std::unique_ptr
<const ShaderValidatorResults
> ValidateAndTranslate(
74 } // namespace mozilla::webgl
76 #endif // WEBGL_SHADER_VALIDATOR_H_