2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-01-16 02:40:39 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef WEBGL_SHADER_VALIDATOR_H_
|
|
|
|
#define WEBGL_SHADER_VALIDATOR_H_
|
|
|
|
|
2020-10-20 16:14:51 +03:00
|
|
|
#include <memory>
|
2019-01-25 02:38:15 +03:00
|
|
|
#include <string>
|
2020-01-09 01:19:16 +03:00
|
|
|
#include <unordered_map>
|
2019-01-25 02:38:15 +03:00
|
|
|
|
2019-02-01 06:58:38 +03:00
|
|
|
#include "GLDefs.h"
|
2019-01-25 02:38:15 +03:00
|
|
|
#include "GLSLANG/ShaderLang.h"
|
2015-01-16 02:40:39 +03:00
|
|
|
#include "nsString.h"
|
|
|
|
|
2022-05-09 23:41:05 +03:00
|
|
|
namespace mozilla::webgl {
|
2015-01-16 02:40:39 +03:00
|
|
|
|
2019-06-21 19:52:50 +03:00
|
|
|
class ShaderValidatorResults final {
|
|
|
|
public:
|
|
|
|
std::string mInfoLog;
|
|
|
|
bool mValid = false;
|
|
|
|
|
|
|
|
std::string mObjectCode;
|
|
|
|
int mShaderVersion = 0;
|
|
|
|
int mVertexShaderNumViews = 0;
|
|
|
|
|
|
|
|
std::vector<sh::Attribute> mAttributes;
|
|
|
|
std::vector<sh::InterfaceBlock> mInterfaceBlocks;
|
|
|
|
std::vector<sh::OutputVariable> mOutputVariables;
|
|
|
|
std::vector<sh::Uniform> mUniforms;
|
|
|
|
std::vector<sh::Varying> mVaryings;
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
std::unordered_map<std::string, std::string> mNameMap;
|
|
|
|
|
2019-06-21 19:52:50 +03:00
|
|
|
int mMaxVaryingVectors = 0;
|
|
|
|
|
2022-09-15 03:47:03 +03:00
|
|
|
bool mNeeds_webgl_gl_VertexID_Offset = false;
|
|
|
|
|
2019-06-21 19:52:50 +03:00
|
|
|
bool CanLinkTo(const ShaderValidatorResults& vert,
|
|
|
|
nsCString* const out_log) const;
|
2024-03-11 20:37:24 +03:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf) const;
|
2019-06-21 19:52:50 +03:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class ShaderValidator final {
|
2019-05-24 14:26:01 +03:00
|
|
|
public:
|
2015-01-16 02:40:39 +03:00
|
|
|
const ShHandle mHandle;
|
2019-05-25 20:46:15 +03:00
|
|
|
|
2019-05-24 14:26:01 +03:00
|
|
|
private:
|
2016-12-22 03:37:25 +03:00
|
|
|
const ShCompileOptions mCompileOptions;
|
2015-03-12 06:12:43 +03:00
|
|
|
const int mMaxVaryingVectors;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-01-16 02:40:39 +03:00
|
|
|
public:
|
2022-09-15 03:47:03 +03:00
|
|
|
bool mIfNeeded_webgl_gl_VertexID_Offset = false;
|
|
|
|
|
2019-06-21 19:52:50 +03:00
|
|
|
static std::unique_ptr<ShaderValidator> Create(
|
|
|
|
GLenum shaderType, ShShaderSpec spec, ShShaderOutput outputLanguage,
|
|
|
|
const ShBuiltInResources& resources, ShCompileOptions compileOptions);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-01-16 02:40:39 +03:00
|
|
|
private:
|
2016-12-22 03:37:25 +03:00
|
|
|
ShaderValidator(ShHandle handle, ShCompileOptions compileOptions,
|
|
|
|
int maxVaryingVectors)
|
2015-01-16 02:40:39 +03:00
|
|
|
: mHandle(handle),
|
|
|
|
mCompileOptions(compileOptions),
|
2019-06-21 19:52:50 +03:00
|
|
|
mMaxVaryingVectors(maxVaryingVectors) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-01-16 02:40:39 +03:00
|
|
|
public:
|
|
|
|
~ShaderValidator();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-06-21 19:52:50 +03:00
|
|
|
std::unique_ptr<const ShaderValidatorResults> ValidateAndTranslate(
|
|
|
|
const char*) const;
|
2015-01-16 02:40:39 +03:00
|
|
|
};
|
|
|
|
|
2022-05-09 23:41:05 +03:00
|
|
|
} // namespace mozilla::webgl
|
2015-01-16 02:40:39 +03:00
|
|
|
|
|
|
|
#endif // WEBGL_SHADER_VALIDATOR_H_
|