Improve ResourceLimits interface to be more forward compatible
New interface allows users to generate ResourceLimits for interface so that additions to TBuiltInResource do not break the ABI. Users should use the glslang-default-resource-limits library and the Public/ResourceLimits.h header. Similar changes have been made to the C interface. Use Public/resource_limits_c.h. Fixes #2822
This commit is contained in:
parent
980ac50813
commit
90c5214344
11 changed files with 47 additions and 30 deletions
|
|
@ -37,9 +37,9 @@
|
|||
#include <sstream>
|
||||
#include <cctype>
|
||||
|
||||
#include "ResourceLimits.h"
|
||||
#include "glslang/Public/ResourceLimits.h"
|
||||
|
||||
namespace glslang {
|
||||
TBuiltInResource Resources;
|
||||
|
||||
const TBuiltInResource DefaultTBuiltInResource = {
|
||||
/* .MaxLights = */ 32,
|
||||
|
|
@ -529,4 +529,12 @@ void DecodeResourceLimits(TBuiltInResource* resources, char* config)
|
|||
}
|
||||
}
|
||||
|
||||
} // end namespace glslang
|
||||
TBuiltInResource* GetResources()
|
||||
{
|
||||
return &Resources;
|
||||
}
|
||||
|
||||
const TBuiltInResource* GetDefaultResources()
|
||||
{
|
||||
return &DefaultTBuiltInResource;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,57 +0,0 @@
|
|||
//
|
||||
// Copyright (C) 2016 Google, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_
|
||||
#define _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../glslang/Include/ResourceLimits.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
// These are the default resources for TBuiltInResources, used for both
|
||||
// - parsing this string for the case where the user didn't supply one,
|
||||
// - dumping out a template for user construction of a config file.
|
||||
extern const TBuiltInResource DefaultTBuiltInResource;
|
||||
|
||||
// Returns the DefaultTBuiltInResource as a human-readable string.
|
||||
std::string GetDefaultTBuiltInResourceString();
|
||||
|
||||
// Decodes the resource limits from |config| to |resources|.
|
||||
void DecodeResourceLimits(TBuiltInResource* resources, char* config);
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_
|
||||
|
|
@ -41,7 +41,7 @@
|
|||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include "ResourceLimits.h"
|
||||
#include "glslang/Public/ResourceLimits.h"
|
||||
#include "Worklist.h"
|
||||
#include "DirStackFileIncluder.h"
|
||||
#include "./../glslang/Include/ShHandle.h"
|
||||
|
|
@ -149,7 +149,6 @@ bool LinkFailed = false;
|
|||
// array of unique places to leave the shader names and infologs for the asynchronous compiles
|
||||
std::vector<std::unique_ptr<glslang::TWorkItem>> WorkItems;
|
||||
|
||||
TBuiltInResource Resources;
|
||||
std::string ConfigFile;
|
||||
|
||||
//
|
||||
|
|
@ -158,11 +157,11 @@ std::string ConfigFile;
|
|||
void ProcessConfigFile()
|
||||
{
|
||||
if (ConfigFile.size() == 0)
|
||||
Resources = glslang::DefaultTBuiltInResource;
|
||||
*GetResources() = *GetDefaultResources();
|
||||
#ifndef GLSLANG_WEB
|
||||
else {
|
||||
char* configString = ReadFileData(ConfigFile.c_str());
|
||||
glslang::DecodeResourceLimits(&Resources, configString);
|
||||
DecodeResourceLimits(GetResources(), configString);
|
||||
FreeFileData(configString);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1417,7 +1416,7 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
|||
#ifndef GLSLANG_WEB
|
||||
if (Options & EOptionOutputPreprocessed) {
|
||||
std::string str;
|
||||
if (shader->preprocess(&Resources, defaultVersion, ENoProfile, false, false, messages, &str, includer)) {
|
||||
if (shader->preprocess(GetResources(), defaultVersion, ENoProfile, false, false, messages, &str, includer)) {
|
||||
PutsIfNonEmpty(str.c_str());
|
||||
} else {
|
||||
CompileFailed = true;
|
||||
|
|
@ -1428,7 +1427,7 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
|||
}
|
||||
#endif
|
||||
|
||||
if (! shader->parse(&Resources, defaultVersion, false, messages, includer))
|
||||
if (! shader->parse(GetResources(), defaultVersion, false, messages, includer))
|
||||
CompileFailed = true;
|
||||
|
||||
program.addShader(shader);
|
||||
|
|
@ -1612,7 +1611,7 @@ int singleMain()
|
|||
|
||||
#ifndef GLSLANG_WEB
|
||||
if (Options & EOptionDumpConfig) {
|
||||
printf("%s", glslang::GetDefaultTBuiltInResourceString().c_str());
|
||||
printf("%s", GetDefaultTBuiltInResourceString().c_str());
|
||||
if (workList.empty())
|
||||
return ESuccess;
|
||||
}
|
||||
|
|
@ -1838,7 +1837,7 @@ void CompileFile(const char* fileName, ShHandle compiler)
|
|||
for (int i = 0; i < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++i) {
|
||||
for (int j = 0; j < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++j) {
|
||||
// ret = ShCompile(compiler, shaderStrings, NumShaderStrings, lengths, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages);
|
||||
ret = ShCompile(compiler, &shaderString, 1, nullptr, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages);
|
||||
ret = ShCompile(compiler, &shaderString, 1, nullptr, EShOptNone, GetResources(), Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages);
|
||||
// const char* multi[12] = { "# ve", "rsion", " 300 e", "s", "\n#err",
|
||||
// "or should be l", "ine 1", "string 5\n", "float glo", "bal",
|
||||
// ";\n#error should be line 2\n void main() {", "global = 2.3;}" };
|
||||
|
|
|
|||
|
|
@ -26,15 +26,20 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**/
|
||||
|
||||
#include "resource_limits_c.h"
|
||||
#include "ResourceLimits.h"
|
||||
#include "glslang/Public/resource_limits_c.h"
|
||||
#include "glslang/Public/ResourceLimits.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
glslang_resource_t* glslang_resource(void)
|
||||
{
|
||||
return reinterpret_cast<glslang_resource_t*>(GetResources());
|
||||
}
|
||||
|
||||
const glslang_resource_t* glslang_default_resource(void)
|
||||
{
|
||||
return reinterpret_cast<const glslang_resource_t*>(&glslang::DefaultTBuiltInResource);
|
||||
return reinterpret_cast<const glslang_resource_t*>(GetDefaultResources());
|
||||
}
|
||||
|
||||
#if defined(__clang__) || defined(__GNUC__)
|
||||
|
|
@ -47,7 +52,7 @@ const glslang_resource_t* glslang_default_resource(void)
|
|||
|
||||
const char* glslang_default_resource_string()
|
||||
{
|
||||
std::string cpp_str = glslang::GetDefaultTBuiltInResourceString();
|
||||
std::string cpp_str = GetDefaultTBuiltInResourceString();
|
||||
char* c_str = (char*)malloc(cpp_str.length() + 1);
|
||||
strcpy(c_str, cpp_str.c_str());
|
||||
return c_str;
|
||||
|
|
@ -61,5 +66,5 @@ const char* glslang_default_resource_string()
|
|||
|
||||
void glslang_decode_resource_limits(glslang_resource_t* resources, char* config)
|
||||
{
|
||||
glslang::DecodeResourceLimits(reinterpret_cast<TBuiltInResource*>(resources), config);
|
||||
DecodeResourceLimits(reinterpret_cast<TBuiltInResource*>(resources), config);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
/**
|
||||
BSD 2-Clause License
|
||||
|
||||
Copyright (c) 2020, Travis Fort
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**/
|
||||
|
||||
#ifndef _STAND_ALONE_RESOURCE_LIMITS_C_INCLUDED_
|
||||
#define _STAND_ALONE_RESOURCE_LIMITS_C_INCLUDED_
|
||||
|
||||
#include "../glslang/Include/glslang_c_interface.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// These are the default resources for TBuiltInResources, used for both
|
||||
// - parsing this string for the case where the user didn't supply one,
|
||||
// - dumping out a template for user construction of a config file.
|
||||
const glslang_resource_t* glslang_default_resource(void);
|
||||
|
||||
// Returns the DefaultTBuiltInResource as a human-readable string.
|
||||
// NOTE: User is responsible for freeing this string.
|
||||
const char* glslang_default_resource_string();
|
||||
|
||||
// Decodes the resource limits from |config| to |resources|.
|
||||
void glslang_decode_resource_limits(glslang_resource_t* resources, char* config);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _STAND_ALONE_RESOURCE_LIMITS_C_INCLUDED_
|
||||
Loading…
Add table
Add a link
Reference in a new issue