Merge pull request #3055 from greg-lunarg/limit2
Improve ResourceLimits interface to be more forward compatible
This commit is contained in:
commit
8da6495058
11 changed files with 47 additions and 30 deletions
|
|
@ -210,7 +210,7 @@ cc_library(
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "glslang-default-resource-limits",
|
name = "glslang-default-resource-limits",
|
||||||
srcs = ["StandAlone/ResourceLimits.cpp"],
|
srcs = ["StandAlone/ResourceLimits.cpp"],
|
||||||
hdrs = ["StandAlone/ResourceLimits.h"],
|
hdrs = ["glslang/Public/ResourceLimits.h"],
|
||||||
copts = COMMON_COPTS,
|
copts = COMMON_COPTS,
|
||||||
linkstatic = 1,
|
linkstatic = 1,
|
||||||
deps = [":glslang"],
|
deps = [":glslang"],
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,9 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
|
||||||
#include "ResourceLimits.h"
|
#include "glslang/Public/ResourceLimits.h"
|
||||||
|
|
||||||
namespace glslang {
|
TBuiltInResource Resources;
|
||||||
|
|
||||||
const TBuiltInResource DefaultTBuiltInResource = {
|
const TBuiltInResource DefaultTBuiltInResource = {
|
||||||
/* .MaxLights = */ 32,
|
/* .MaxLights = */ 32,
|
||||||
|
|
@ -529,4 +529,12 @@ void DecodeResourceLimits(TBuiltInResource* resources, char* config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace glslang
|
TBuiltInResource* GetResources()
|
||||||
|
{
|
||||||
|
return &Resources;
|
||||||
|
}
|
||||||
|
|
||||||
|
const TBuiltInResource* GetDefaultResources()
|
||||||
|
{
|
||||||
|
return &DefaultTBuiltInResource;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@
|
||||||
#define _CRT_SECURE_NO_WARNINGS
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "ResourceLimits.h"
|
#include "glslang/Public/ResourceLimits.h"
|
||||||
#include "Worklist.h"
|
#include "Worklist.h"
|
||||||
#include "DirStackFileIncluder.h"
|
#include "DirStackFileIncluder.h"
|
||||||
#include "./../glslang/Include/ShHandle.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
|
// array of unique places to leave the shader names and infologs for the asynchronous compiles
|
||||||
std::vector<std::unique_ptr<glslang::TWorkItem>> WorkItems;
|
std::vector<std::unique_ptr<glslang::TWorkItem>> WorkItems;
|
||||||
|
|
||||||
TBuiltInResource Resources;
|
|
||||||
std::string ConfigFile;
|
std::string ConfigFile;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
@ -158,11 +157,11 @@ std::string ConfigFile;
|
||||||
void ProcessConfigFile()
|
void ProcessConfigFile()
|
||||||
{
|
{
|
||||||
if (ConfigFile.size() == 0)
|
if (ConfigFile.size() == 0)
|
||||||
Resources = glslang::DefaultTBuiltInResource;
|
*GetResources() = *GetDefaultResources();
|
||||||
#ifndef GLSLANG_WEB
|
#ifndef GLSLANG_WEB
|
||||||
else {
|
else {
|
||||||
char* configString = ReadFileData(ConfigFile.c_str());
|
char* configString = ReadFileData(ConfigFile.c_str());
|
||||||
glslang::DecodeResourceLimits(&Resources, configString);
|
DecodeResourceLimits(GetResources(), configString);
|
||||||
FreeFileData(configString);
|
FreeFileData(configString);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -1417,7 +1416,7 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
||||||
#ifndef GLSLANG_WEB
|
#ifndef GLSLANG_WEB
|
||||||
if (Options & EOptionOutputPreprocessed) {
|
if (Options & EOptionOutputPreprocessed) {
|
||||||
std::string str;
|
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());
|
PutsIfNonEmpty(str.c_str());
|
||||||
} else {
|
} else {
|
||||||
CompileFailed = true;
|
CompileFailed = true;
|
||||||
|
|
@ -1428,7 +1427,7 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (! shader->parse(&Resources, defaultVersion, false, messages, includer))
|
if (! shader->parse(GetResources(), defaultVersion, false, messages, includer))
|
||||||
CompileFailed = true;
|
CompileFailed = true;
|
||||||
|
|
||||||
program.addShader(shader);
|
program.addShader(shader);
|
||||||
|
|
@ -1612,7 +1611,7 @@ int singleMain()
|
||||||
|
|
||||||
#ifndef GLSLANG_WEB
|
#ifndef GLSLANG_WEB
|
||||||
if (Options & EOptionDumpConfig) {
|
if (Options & EOptionDumpConfig) {
|
||||||
printf("%s", glslang::GetDefaultTBuiltInResourceString().c_str());
|
printf("%s", GetDefaultTBuiltInResourceString().c_str());
|
||||||
if (workList.empty())
|
if (workList.empty())
|
||||||
return ESuccess;
|
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 i = 0; i < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++i) {
|
||||||
for (int j = 0; j < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++j) {
|
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, 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",
|
// const char* multi[12] = { "# ve", "rsion", " 300 e", "s", "\n#err",
|
||||||
// "or should be l", "ine 1", "string 5\n", "float glo", "bal",
|
// "or should be l", "ine 1", "string 5\n", "float glo", "bal",
|
||||||
// ";\n#error should be line 2\n void main() {", "global = 2.3;}" };
|
// ";\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.
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include "resource_limits_c.h"
|
#include "glslang/Public/resource_limits_c.h"
|
||||||
#include "ResourceLimits.h"
|
#include "glslang/Public/ResourceLimits.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
glslang_resource_t* glslang_resource(void)
|
||||||
|
{
|
||||||
|
return reinterpret_cast<glslang_resource_t*>(GetResources());
|
||||||
|
}
|
||||||
|
|
||||||
const glslang_resource_t* glslang_default_resource(void)
|
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__)
|
#if defined(__clang__) || defined(__GNUC__)
|
||||||
|
|
@ -47,7 +52,7 @@ const glslang_resource_t* glslang_default_resource(void)
|
||||||
|
|
||||||
const char* glslang_default_resource_string()
|
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);
|
char* c_str = (char*)malloc(cpp_str.length() + 1);
|
||||||
strcpy(c_str, cpp_str.c_str());
|
strcpy(c_str, cpp_str.c_str());
|
||||||
return 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)
|
void glslang_decode_resource_limits(glslang_resource_t* resources, char* config)
|
||||||
{
|
{
|
||||||
glslang::DecodeResourceLimits(reinterpret_cast<TBuiltInResource*>(resources), config);
|
DecodeResourceLimits(reinterpret_cast<TBuiltInResource*>(resources), config);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "glslang/Include/glslang_c_interface.h"
|
#include "glslang/Include/glslang_c_interface.h"
|
||||||
|
|
||||||
#include "StandAlone/DirStackFileIncluder.h"
|
#include "StandAlone/DirStackFileIncluder.h"
|
||||||
#include "StandAlone/ResourceLimits.h"
|
#include "glslang/Public/ResourceLimits.h"
|
||||||
#include "glslang/Include/ShHandle.h"
|
#include "glslang/Include/ShHandle.h"
|
||||||
|
|
||||||
#include "glslang/Include/ResourceLimits.h"
|
#include "glslang/Include/ResourceLimits.h"
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,8 @@ set(GLSLANG_SOURCES
|
||||||
|
|
||||||
set(GLSLANG_HEADERS
|
set(GLSLANG_HEADERS
|
||||||
Public/ShaderLang.h
|
Public/ShaderLang.h
|
||||||
|
Public/ResourceLimits.h
|
||||||
|
Public/resource_limits_c.h
|
||||||
Include/arrays.h
|
Include/arrays.h
|
||||||
Include/BaseTypes.h
|
Include/BaseTypes.h
|
||||||
Include/Common.h
|
Include/Common.h
|
||||||
|
|
|
||||||
|
|
@ -37,14 +37,16 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "../glslang/Include/ResourceLimits.h"
|
#include "../Include/ResourceLimits.h"
|
||||||
|
|
||||||
namespace glslang {
|
// Return pointer to user-writable Resource to pass through API in
|
||||||
|
// future-proof way.
|
||||||
|
extern TBuiltInResource* GetResources();
|
||||||
|
|
||||||
// These are the default resources for TBuiltInResources, used for both
|
// These are the default resources for TBuiltInResources, used for both
|
||||||
// - parsing this string for the case where the user didn't supply one,
|
// - parsing this string for the case where the user didn't supply one,
|
||||||
// - dumping out a template for user construction of a config file.
|
// - dumping out a template for user construction of a config file.
|
||||||
extern const TBuiltInResource DefaultTBuiltInResource;
|
extern const TBuiltInResource* GetDefaultResources();
|
||||||
|
|
||||||
// Returns the DefaultTBuiltInResource as a human-readable string.
|
// Returns the DefaultTBuiltInResource as a human-readable string.
|
||||||
std::string GetDefaultTBuiltInResourceString();
|
std::string GetDefaultTBuiltInResourceString();
|
||||||
|
|
@ -52,6 +54,4 @@ std::string GetDefaultTBuiltInResourceString();
|
||||||
// Decodes the resource limits from |config| to |resources|.
|
// Decodes the resource limits from |config| to |resources|.
|
||||||
void DecodeResourceLimits(TBuiltInResource* resources, char* config);
|
void DecodeResourceLimits(TBuiltInResource* resources, char* config);
|
||||||
|
|
||||||
} // end namespace glslang
|
|
||||||
|
|
||||||
#endif // _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_
|
#endif // _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_
|
||||||
|
|
@ -35,6 +35,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Returns a struct that can be use to create custom resource values.
|
||||||
|
glslang_resource_t* glslang_resource(void);
|
||||||
|
|
||||||
// These are the default resources for TBuiltInResources, used for both
|
// These are the default resources for TBuiltInResources, used for both
|
||||||
// - parsing this string for the case where the user didn't supply one,
|
// - parsing this string for the case where the user didn't supply one,
|
||||||
// - dumping out a template for user construction of a config file.
|
// - dumping out a template for user construction of a config file.
|
||||||
|
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include "StandAlone/ResourceLimits.h"
|
#include "glslang/Public/ResourceLimits.h"
|
||||||
#include "TestFixture.h"
|
#include "TestFixture.h"
|
||||||
|
|
||||||
namespace glslangtest {
|
namespace glslangtest {
|
||||||
|
|
@ -49,7 +49,7 @@ TEST_F(DefaultResourceTest, FromFile)
|
||||||
const std::string path = GlobalTestSettings.testRoot + "/baseResults/test.conf";
|
const std::string path = GlobalTestSettings.testRoot + "/baseResults/test.conf";
|
||||||
std::string expectedConfig;
|
std::string expectedConfig;
|
||||||
tryLoadFile(path, "expected resource limit", &expectedConfig);
|
tryLoadFile(path, "expected resource limit", &expectedConfig);
|
||||||
const std::string realConfig = glslang::GetDefaultTBuiltInResourceString();
|
const std::string realConfig = GetDefaultTBuiltInResourceString();
|
||||||
ASSERT_EQ(expectedConfig, realConfig);
|
ASSERT_EQ(expectedConfig, realConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
// POSSIBILITY OF SUCH DAMAGE.
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include "StandAlone/ResourceLimits.h"
|
#include "glslang/Public/ResourceLimits.h"
|
||||||
#include "TestFixture.h"
|
#include "TestFixture.h"
|
||||||
|
|
||||||
namespace glslangtest {
|
namespace glslangtest {
|
||||||
|
|
@ -65,7 +65,7 @@ TEST_P(ConfigTest, FromFile)
|
||||||
char* configChars = new char[len + 1];
|
char* configChars = new char[len + 1];
|
||||||
memcpy(configChars, configContents.data(), len);
|
memcpy(configChars, configContents.data(), len);
|
||||||
configChars[len] = 0;
|
configChars[len] = 0;
|
||||||
glslang::DecodeResourceLimits(&resources, configChars);
|
DecodeResourceLimits(&resources, configChars);
|
||||||
delete[] configChars;
|
delete[] configChars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@
|
||||||
#include "SPIRV/disassemble.h"
|
#include "SPIRV/disassemble.h"
|
||||||
#include "SPIRV/doc.h"
|
#include "SPIRV/doc.h"
|
||||||
#include "SPIRV/SPVRemapper.h"
|
#include "SPIRV/SPVRemapper.h"
|
||||||
#include "StandAlone/ResourceLimits.h"
|
#include "glslang/Public/ResourceLimits.h"
|
||||||
#include "glslang/Public/ShaderLang.h"
|
#include "glslang/Public/ShaderLang.h"
|
||||||
|
|
||||||
#include "Initializer.h"
|
#include "Initializer.h"
|
||||||
|
|
@ -199,7 +199,7 @@ public:
|
||||||
shader->setStringsWithLengths(&shaderStrings, &shaderLengths, 1);
|
shader->setStringsWithLengths(&shaderStrings, &shaderLengths, 1);
|
||||||
if (!entryPointName.empty()) shader->setEntryPoint(entryPointName.c_str());
|
if (!entryPointName.empty()) shader->setEntryPoint(entryPointName.c_str());
|
||||||
return shader->parse(
|
return shader->parse(
|
||||||
(resources ? resources : &glslang::DefaultTBuiltInResource),
|
(resources ? resources : GetDefaultResources()),
|
||||||
defaultVersion, isForwardCompatible, controls);
|
defaultVersion, isForwardCompatible, controls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -640,7 +640,7 @@ public:
|
||||||
std::string ppShader;
|
std::string ppShader;
|
||||||
glslang::TShader::ForbidIncluder includer;
|
glslang::TShader::ForbidIncluder includer;
|
||||||
const bool success = shader.preprocess(
|
const bool success = shader.preprocess(
|
||||||
&glslang::DefaultTBuiltInResource, defaultVersion, defaultProfile,
|
GetDefaultResources(), defaultVersion, defaultProfile,
|
||||||
forceVersionProfile, isForwardCompatible, (EShMessages)(EShMsgOnlyPreprocessor | EShMsgCascadingErrors),
|
forceVersionProfile, isForwardCompatible, (EShMessages)(EShMsgOnlyPreprocessor | EShMsgCascadingErrors),
|
||||||
&ppShader, includer);
|
&ppShader, includer);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue