зеркало из https://github.com/AvaloniaUI/angle.git
Change ShaderLang APIs from c style to c++ style.
BUG=angle:816 TEST=gpu_unittests,angle_unittests,webgl_conformance Change-Id: I0b46c11f6055a82511bb946a6dc491360835526e Reviewed-on: https://chromium-review.googlesource.com/226410 Reviewed-by: Zhenyao Mo <zmo@chromium.org> Tested-by: Zhenyao Mo <zmo@chromium.org>
This commit is contained in:
Родитель
f108df2494
Коммит
4de44cb67e
|
@ -27,6 +27,10 @@
|
|||
|
||||
#include "KHR/khrplatform.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
//
|
||||
// This is the platform independent interface between an OGL driver
|
||||
// and the shading language compiler.
|
||||
|
@ -42,13 +46,9 @@ typedef unsigned int GLenum;
|
|||
// Note: make sure to increment ANGLE_SH_VERSION when changing ShaderVars.h
|
||||
#include "ShaderVars.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Version number for shader translation API.
|
||||
// It is incremented every time the API changes.
|
||||
#define ANGLE_SH_VERSION 131
|
||||
#define ANGLE_SH_VERSION 132
|
||||
|
||||
typedef enum {
|
||||
SH_GLES2_SPEC = 0x8B40,
|
||||
|
@ -88,18 +88,6 @@ typedef enum {
|
|||
SH_HLSL11_OUTPUT = 0x8B48
|
||||
} ShShaderOutput;
|
||||
|
||||
typedef enum {
|
||||
SH_INFO_LOG_LENGTH = 0x8B84,
|
||||
SH_OBJECT_CODE_LENGTH = 0x8B88, // GL_SHADER_SOURCE_LENGTH
|
||||
SH_MAPPED_NAME_MAX_LENGTH = 0x6000,
|
||||
SH_NAME_MAX_LENGTH = 0x6001,
|
||||
SH_HASHED_NAME_MAX_LENGTH = 0x6002,
|
||||
SH_HASHED_NAMES_COUNT = 0x6003,
|
||||
SH_SHADER_VERSION = 0x6004,
|
||||
SH_RESOURCES_STRING_LENGTH = 0x6005,
|
||||
SH_OUTPUT_TYPE = 0x6006
|
||||
} ShShaderInfo;
|
||||
|
||||
// Compile options.
|
||||
typedef enum {
|
||||
SH_VALIDATE = 0,
|
||||
|
@ -198,14 +186,14 @@ typedef enum {
|
|||
//
|
||||
// Driver must call this first, once, before doing any other
|
||||
// compiler operations.
|
||||
// If the function succeeds, the return value is nonzero, else zero.
|
||||
// If the function succeeds, the return value is true, else false.
|
||||
//
|
||||
COMPILER_EXPORT int ShInitialize();
|
||||
COMPILER_EXPORT bool ShInitialize();
|
||||
//
|
||||
// Driver should call this at shutdown.
|
||||
// If the function succeeds, the return value is nonzero, else zero.
|
||||
// If the function succeeds, the return value is true, else false.
|
||||
//
|
||||
COMPILER_EXPORT int ShFinalize();
|
||||
COMPILER_EXPORT bool ShFinalize();
|
||||
|
||||
// The 64 bits hash function. The first parameter is the input string; the
|
||||
// second parameter is the string length.
|
||||
|
@ -273,7 +261,7 @@ typedef struct
|
|||
// Parameters:
|
||||
// resources: The object to initialize. Will be comparable with memcmp.
|
||||
//
|
||||
COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources* resources);
|
||||
COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources *resources);
|
||||
|
||||
//
|
||||
// ShHandle held by but opaque to the driver. It is allocated,
|
||||
|
@ -282,18 +270,15 @@ COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources* resources);
|
|||
//
|
||||
// If handle creation fails, 0 will be returned.
|
||||
//
|
||||
typedef void* ShHandle;
|
||||
typedef void *ShHandle;
|
||||
|
||||
//
|
||||
// Returns the a concatenated list of the items in ShBuiltInResources as a string.
|
||||
// Returns the a concatenated list of the items in ShBuiltInResources as a
|
||||
// null-terminated string.
|
||||
// This function must be updated whenever ShBuiltInResources is changed.
|
||||
// Parameters:
|
||||
// handle: Specifies the handle of the compiler to be used.
|
||||
// outStringLen: Specifies the size of the buffer, in number of characters. The size
|
||||
// of the buffer required to store the resources string can be obtained
|
||||
// by calling ShGetInfo with SH_RESOURCES_STRING_LENGTH.
|
||||
// outStr: Returns a null-terminated string representing all the built-in resources.
|
||||
COMPILER_EXPORT void ShGetBuiltInResourcesString(const ShHandle handle, size_t outStringLen, char *outStr);
|
||||
COMPILER_EXPORT const std::string &ShGetBuiltInResourcesString(const ShHandle handle);
|
||||
|
||||
//
|
||||
// Driver calls these to create and destroy compiler objects.
|
||||
|
@ -311,12 +296,12 @@ COMPILER_EXPORT ShHandle ShConstructCompiler(
|
|||
sh::GLenum type,
|
||||
ShShaderSpec spec,
|
||||
ShShaderOutput output,
|
||||
const ShBuiltInResources* resources);
|
||||
const ShBuiltInResources *resources);
|
||||
COMPILER_EXPORT void ShDestruct(ShHandle handle);
|
||||
|
||||
//
|
||||
// Compiles the given shader source.
|
||||
// If the function succeeds, the return value is nonzero, else zero.
|
||||
// If the function succeeds, the return value is true, else false.
|
||||
// Parameters:
|
||||
// handle: Specifies the handle of compiler to be used.
|
||||
// shaderStrings: Specifies an array of pointers to null-terminated strings
|
||||
|
@ -338,74 +323,36 @@ COMPILER_EXPORT void ShDestruct(ShHandle handle);
|
|||
// SH_VARIABLES: Extracts attributes, uniforms, and varyings.
|
||||
// Can be queried by calling ShGetVariableInfo().
|
||||
//
|
||||
COMPILER_EXPORT int ShCompile(
|
||||
COMPILER_EXPORT bool ShCompile(
|
||||
const ShHandle handle,
|
||||
const char* const shaderStrings[],
|
||||
const char * const shaderStrings[],
|
||||
size_t numStrings,
|
||||
int compileOptions
|
||||
);
|
||||
int compileOptions);
|
||||
|
||||
// Returns a parameter from a compiled shader.
|
||||
// Return the version of the shader language.
|
||||
COMPILER_EXPORT int ShGetShaderVersion(const ShHandle handle);
|
||||
|
||||
// Return the currently set language output type.
|
||||
COMPILER_EXPORT ShShaderOutput ShGetShaderOutputType(
|
||||
const ShHandle handle);
|
||||
|
||||
// Returns null-terminated information log for a compiled shader.
|
||||
// Parameters:
|
||||
// handle: Specifies the compiler
|
||||
// pname: Specifies the parameter to query.
|
||||
// The following parameters are defined:
|
||||
// SH_INFO_LOG_LENGTH: the number of characters in the information log
|
||||
// including the null termination character.
|
||||
// SH_OBJECT_CODE_LENGTH: the number of characters in the object code
|
||||
// including the null termination character.
|
||||
// SH_MAPPED_NAME_MAX_LENGTH: the length of the mapped variable name including
|
||||
// the null termination character.
|
||||
// SH_NAME_MAX_LENGTH: the max length of a user-defined name including the
|
||||
// null termination character.
|
||||
// SH_HASHED_NAME_MAX_LENGTH: the max length of a hashed name including the
|
||||
// null termination character.
|
||||
// SH_HASHED_NAMES_COUNT: the number of hashed names from the latest compile.
|
||||
// SH_SHADER_VERSION: the version of the shader language
|
||||
// SH_OUTPUT_TYPE: the currently set language output type
|
||||
//
|
||||
// params: Requested parameter
|
||||
COMPILER_EXPORT void ShGetInfo(const ShHandle handle,
|
||||
ShShaderInfo pname,
|
||||
size_t* params);
|
||||
|
||||
// Returns nul-terminated information log for a compiled shader.
|
||||
// Parameters:
|
||||
// handle: Specifies the compiler
|
||||
// infoLog: Specifies an array of characters that is used to return
|
||||
// the information log. It is assumed that infoLog has enough memory
|
||||
// to accomodate the information log. The size of the buffer required
|
||||
// to store the returned information log can be obtained by calling
|
||||
// ShGetInfo with SH_INFO_LOG_LENGTH.
|
||||
COMPILER_EXPORT void ShGetInfoLog(const ShHandle handle, char* infoLog);
|
||||
COMPILER_EXPORT const std::string &ShGetInfoLog(const ShHandle handle);
|
||||
|
||||
// Returns null-terminated object code for a compiled shader.
|
||||
// Parameters:
|
||||
// handle: Specifies the compiler
|
||||
// infoLog: Specifies an array of characters that is used to return
|
||||
// the object code. It is assumed that infoLog has enough memory to
|
||||
// accomodate the object code. The size of the buffer required to
|
||||
// store the returned object code can be obtained by calling
|
||||
// ShGetInfo with SH_OBJECT_CODE_LENGTH.
|
||||
COMPILER_EXPORT void ShGetObjectCode(const ShHandle handle, char* objCode);
|
||||
COMPILER_EXPORT const std::string &ShGetObjectCode(const ShHandle handle);
|
||||
|
||||
// Returns information about a name hashing entry from the latest compile.
|
||||
// Returns a (original_name, hash) map containing all the user defined
|
||||
// names in the shader, including variable names, function names, struct
|
||||
// names, and struct field names.
|
||||
// Parameters:
|
||||
// handle: Specifies the compiler
|
||||
// index: Specifies the index of the name hashing entry to be queried.
|
||||
// name: Returns a null terminated string containing the user defined name.
|
||||
// It is assumed that name has enough memory to accomodate the name.
|
||||
// The size of the buffer required to store the user defined name can
|
||||
// be obtained by calling ShGetInfo with SH_NAME_MAX_LENGTH.
|
||||
// hashedName: Returns a null terminated string containing the hashed name of
|
||||
// the uniform variable, It is assumed that hashedName has enough
|
||||
// memory to accomodate the name. The size of the buffer required
|
||||
// to store the name can be obtained by calling ShGetInfo with
|
||||
// SH_HASHED_NAME_MAX_LENGTH.
|
||||
COMPILER_EXPORT void ShGetNameHashingEntry(const ShHandle handle,
|
||||
int index,
|
||||
char* name,
|
||||
char* hashedName);
|
||||
COMPILER_EXPORT const std::map<std::string, std::string> *ShGetNameHashingMap(
|
||||
const ShHandle handle);
|
||||
|
||||
// Shader variable inspection.
|
||||
// Returns a pointer to a list of variables of the designated type.
|
||||
|
@ -425,17 +372,17 @@ typedef struct
|
|||
int size;
|
||||
} ShVariableInfo;
|
||||
|
||||
// Returns 1 if the passed in variables pack in maxVectors following
|
||||
// Returns true if the passed in variables pack in maxVectors following
|
||||
// the packing rules from the GLSL 1.017 spec, Appendix A, section 7.
|
||||
// Returns 0 otherwise. Also look at the SH_ENFORCE_PACKING_RESTRICTIONS
|
||||
// Returns false otherwise. Also look at the SH_ENFORCE_PACKING_RESTRICTIONS
|
||||
// flag above.
|
||||
// Parameters:
|
||||
// maxVectors: the available rows of registers.
|
||||
// varInfoArray: an array of variable info (types and sizes).
|
||||
// varInfoArraySize: the size of the variable array.
|
||||
COMPILER_EXPORT int ShCheckVariablesWithinPackingLimits(
|
||||
COMPILER_EXPORT bool ShCheckVariablesWithinPackingLimits(
|
||||
int maxVectors,
|
||||
ShVariableInfo* varInfoArray,
|
||||
ShVariableInfo *varInfoArray,
|
||||
size_t varInfoArraySize);
|
||||
|
||||
// Gives the compiler-assigned register for an interface block.
|
||||
|
@ -446,7 +393,7 @@ COMPILER_EXPORT int ShCheckVariablesWithinPackingLimits(
|
|||
// interfaceBlockName: Specifies the interface block
|
||||
// indexOut: output variable that stores the assigned register
|
||||
COMPILER_EXPORT bool ShGetInterfaceBlockRegister(const ShHandle handle,
|
||||
const char *interfaceBlockName,
|
||||
const std::string &interfaceBlockName,
|
||||
unsigned int *indexOut);
|
||||
|
||||
// Gives the compiler-assigned register for uniforms in the default
|
||||
|
@ -458,11 +405,7 @@ COMPILER_EXPORT bool ShGetInterfaceBlockRegister(const ShHandle handle,
|
|||
// interfaceBlockName: Specifies the uniform
|
||||
// indexOut: output variable that stores the assigned register
|
||||
COMPILER_EXPORT bool ShGetUniformRegister(const ShHandle handle,
|
||||
const char *uniformName,
|
||||
const std::string &uniformName,
|
||||
unsigned int *indexOut);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _COMPILER_INTERFACE_INCLUDED_
|
||||
|
|
|
@ -80,7 +80,7 @@ class TCompiler : public TShHandleBase
|
|||
TSymbolTable& getSymbolTable() { return symbolTable; }
|
||||
ShShaderSpec getShaderSpec() const { return shaderSpec; }
|
||||
ShShaderOutput getOutputType() const { return outputType; }
|
||||
std::string getBuiltInResourcesString() const { return builtInResourcesString; }
|
||||
const std::string &getBuiltInResourcesString() const { return builtInResourcesString; }
|
||||
|
||||
// Get the resources set by InitBuiltInSymbolTable
|
||||
const ShBuiltInResources& getResources() const;
|
||||
|
|
|
@ -84,32 +84,48 @@ const std::vector<VarT> *GetShaderVariables(const ShHandle handle, ShaderVariabl
|
|||
return GetVariableList<VarT>(compiler, variableType);
|
||||
}
|
||||
|
||||
TCompiler *GetCompilerFromHandle(ShHandle handle)
|
||||
{
|
||||
if (!handle)
|
||||
return NULL;
|
||||
TShHandleBase *base = static_cast<TShHandleBase *>(handle);
|
||||
return base->getAsCompiler();
|
||||
}
|
||||
|
||||
TranslatorHLSL *GetTranslatorHLSLFromHandle(ShHandle handle)
|
||||
{
|
||||
if (!handle)
|
||||
return NULL;
|
||||
TShHandleBase *base = static_cast<TShHandleBase *>(handle);
|
||||
return base->getAsTranslatorHLSL();
|
||||
}
|
||||
|
||||
} // namespace anonymous
|
||||
|
||||
//
|
||||
// Driver must call this first, once, before doing any other compiler operations.
|
||||
// Subsequent calls to this function are no-op.
|
||||
//
|
||||
int ShInitialize()
|
||||
bool ShInitialize()
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
isInitialized = InitProcess();
|
||||
}
|
||||
return isInitialized ? 1 : 0;
|
||||
return isInitialized;
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup symbol tables
|
||||
//
|
||||
int ShFinalize()
|
||||
bool ShFinalize()
|
||||
{
|
||||
if (isInitialized)
|
||||
{
|
||||
DetachProcess();
|
||||
isInitialized = false;
|
||||
}
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -190,23 +206,13 @@ void ShDestruct(ShHandle handle)
|
|||
DeleteCompiler(base->getAsCompiler());
|
||||
}
|
||||
|
||||
void ShGetBuiltInResourcesString(const ShHandle handle, size_t outStringLen, char *outString)
|
||||
const std::string &ShGetBuiltInResourcesString(const ShHandle handle)
|
||||
{
|
||||
if (!handle || !outString)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TShHandleBase *base = static_cast<TShHandleBase*>(handle);
|
||||
TCompiler *compiler = base->getAsCompiler();
|
||||
if (!compiler)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
strncpy(outString, compiler->getBuiltInResourcesString().c_str(), outStringLen);
|
||||
outString[outStringLen - 1] = '\0';
|
||||
TCompiler *compiler = GetCompilerFromHandle(handle);
|
||||
ASSERT(compiler);
|
||||
return compiler->getBuiltInResourcesString();
|
||||
}
|
||||
|
||||
//
|
||||
// Do an actual compile on the given strings. The result is left
|
||||
// in the given compile object.
|
||||
|
@ -214,149 +220,62 @@ void ShGetBuiltInResourcesString(const ShHandle handle, size_t outStringLen, cha
|
|||
// Return: The return value of ShCompile is really boolean, indicating
|
||||
// success or failure.
|
||||
//
|
||||
int ShCompile(
|
||||
bool ShCompile(
|
||||
const ShHandle handle,
|
||||
const char* const shaderStrings[],
|
||||
const char *const shaderStrings[],
|
||||
size_t numStrings,
|
||||
int compileOptions)
|
||||
{
|
||||
if (handle == 0)
|
||||
return 0;
|
||||
TCompiler *compiler = GetCompilerFromHandle(handle);
|
||||
ASSERT(compiler);
|
||||
|
||||
TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);
|
||||
TCompiler* compiler = base->getAsCompiler();
|
||||
if (compiler == 0)
|
||||
return 0;
|
||||
|
||||
bool success = compiler->compile(shaderStrings, numStrings, compileOptions);
|
||||
return success ? 1 : 0;
|
||||
return compiler->compile(shaderStrings, numStrings, compileOptions);
|
||||
}
|
||||
|
||||
void ShGetInfo(const ShHandle handle, ShShaderInfo pname, size_t* params)
|
||||
int ShGetShaderVersion(const ShHandle handle)
|
||||
{
|
||||
if (!handle || !params)
|
||||
return;
|
||||
TCompiler* compiler = GetCompilerFromHandle(handle);
|
||||
ASSERT(compiler);
|
||||
return compiler->getShaderVersion();
|
||||
}
|
||||
|
||||
TShHandleBase* base = static_cast<TShHandleBase*>(handle);
|
||||
TCompiler* compiler = base->getAsCompiler();
|
||||
if (!compiler) return;
|
||||
|
||||
switch(pname)
|
||||
{
|
||||
case SH_INFO_LOG_LENGTH:
|
||||
*params = compiler->getInfoSink().info.size() + 1;
|
||||
break;
|
||||
case SH_OBJECT_CODE_LENGTH:
|
||||
*params = compiler->getInfoSink().obj.size() + 1;
|
||||
break;
|
||||
case SH_MAPPED_NAME_MAX_LENGTH:
|
||||
// Use longer length than MAX_SHORTENED_IDENTIFIER_SIZE to
|
||||
// handle array and struct dereferences.
|
||||
*params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
|
||||
break;
|
||||
case SH_NAME_MAX_LENGTH:
|
||||
*params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
|
||||
break;
|
||||
case SH_HASHED_NAME_MAX_LENGTH:
|
||||
if (compiler->getHashFunction() == NULL) {
|
||||
*params = 0;
|
||||
} else {
|
||||
// 64 bits hashing output requires 16 bytes for hex
|
||||
// representation.
|
||||
const char HashedNamePrefix[] = HASHED_NAME_PREFIX;
|
||||
(void)HashedNamePrefix;
|
||||
*params = 16 + sizeof(HashedNamePrefix);
|
||||
}
|
||||
break;
|
||||
case SH_HASHED_NAMES_COUNT:
|
||||
*params = compiler->getNameMap().size();
|
||||
break;
|
||||
case SH_SHADER_VERSION:
|
||||
*params = compiler->getShaderVersion();
|
||||
break;
|
||||
case SH_RESOURCES_STRING_LENGTH:
|
||||
*params = compiler->getBuiltInResourcesString().length() + 1;
|
||||
break;
|
||||
case SH_OUTPUT_TYPE:
|
||||
*params = compiler->getOutputType();
|
||||
break;
|
||||
default: UNREACHABLE();
|
||||
}
|
||||
ShShaderOutput ShGetShaderOutputType(const ShHandle handle)
|
||||
{
|
||||
TCompiler* compiler = GetCompilerFromHandle(handle);
|
||||
ASSERT(compiler);
|
||||
return compiler->getOutputType();
|
||||
}
|
||||
|
||||
//
|
||||
// Return any compiler log of messages for the application.
|
||||
//
|
||||
void ShGetInfoLog(const ShHandle handle, char* infoLog)
|
||||
const std::string &ShGetInfoLog(const ShHandle handle)
|
||||
{
|
||||
if (!handle || !infoLog)
|
||||
return;
|
||||
TCompiler *compiler = GetCompilerFromHandle(handle);
|
||||
ASSERT(compiler);
|
||||
|
||||
TShHandleBase* base = static_cast<TShHandleBase*>(handle);
|
||||
TCompiler* compiler = base->getAsCompiler();
|
||||
if (!compiler) return;
|
||||
|
||||
TInfoSink& infoSink = compiler->getInfoSink();
|
||||
strcpy(infoLog, infoSink.info.c_str());
|
||||
TInfoSink &infoSink = compiler->getInfoSink();
|
||||
return infoSink.info.str();
|
||||
}
|
||||
|
||||
//
|
||||
// Return any object code.
|
||||
//
|
||||
void ShGetObjectCode(const ShHandle handle, char* objCode)
|
||||
const std::string &ShGetObjectCode(const ShHandle handle)
|
||||
{
|
||||
if (!handle || !objCode)
|
||||
return;
|
||||
TCompiler *compiler = GetCompilerFromHandle(handle);
|
||||
ASSERT(compiler);
|
||||
|
||||
TShHandleBase* base = static_cast<TShHandleBase*>(handle);
|
||||
TCompiler* compiler = base->getAsCompiler();
|
||||
if (!compiler) return;
|
||||
|
||||
TInfoSink& infoSink = compiler->getInfoSink();
|
||||
strcpy(objCode, infoSink.obj.c_str());
|
||||
TInfoSink &infoSink = compiler->getInfoSink();
|
||||
return infoSink.obj.str();
|
||||
}
|
||||
|
||||
void ShGetNameHashingEntry(const ShHandle handle,
|
||||
int index,
|
||||
char* name,
|
||||
char* hashedName)
|
||||
const std::map<std::string, std::string> *ShGetNameHashingMap(
|
||||
const ShHandle handle)
|
||||
{
|
||||
if (!handle || !name || !hashedName || index < 0)
|
||||
return;
|
||||
|
||||
TShHandleBase* base = static_cast<TShHandleBase*>(handle);
|
||||
TCompiler* compiler = base->getAsCompiler();
|
||||
if (!compiler) return;
|
||||
|
||||
const NameMap& nameMap = compiler->getNameMap();
|
||||
if (index >= static_cast<int>(nameMap.size()))
|
||||
return;
|
||||
|
||||
NameMap::const_iterator it = nameMap.begin();
|
||||
for (int i = 0; i < index; ++i)
|
||||
++it;
|
||||
|
||||
size_t len = it->first.length() + 1;
|
||||
size_t max_len = 0;
|
||||
ShGetInfo(handle, SH_NAME_MAX_LENGTH, &max_len);
|
||||
if (len > max_len) {
|
||||
ASSERT(false);
|
||||
len = max_len;
|
||||
}
|
||||
strncpy(name, it->first.c_str(), len);
|
||||
// To be on the safe side in case the source is longer than expected.
|
||||
name[len - 1] = '\0';
|
||||
|
||||
len = it->second.length() + 1;
|
||||
max_len = 0;
|
||||
ShGetInfo(handle, SH_HASHED_NAME_MAX_LENGTH, &max_len);
|
||||
if (len > max_len) {
|
||||
ASSERT(false);
|
||||
len = max_len;
|
||||
}
|
||||
strncpy(hashedName, it->second.c_str(), len);
|
||||
// To be on the safe side in case the source is longer than expected.
|
||||
hashedName[len - 1] = '\0';
|
||||
TCompiler *compiler = GetCompilerFromHandle(handle);
|
||||
ASSERT(compiler);
|
||||
return &(compiler->getNameMap());
|
||||
}
|
||||
|
||||
const std::vector<sh::Uniform> *ShGetUniforms(const ShHandle handle)
|
||||
|
@ -384,11 +303,11 @@ const std::vector<sh::InterfaceBlock> *ShGetInterfaceBlocks(const ShHandle handl
|
|||
return GetShaderVariables<sh::InterfaceBlock>(handle, SHADERVAR_INTERFACEBLOCK);
|
||||
}
|
||||
|
||||
int ShCheckVariablesWithinPackingLimits(
|
||||
int maxVectors, ShVariableInfo* varInfoArray, size_t varInfoArraySize)
|
||||
bool ShCheckVariablesWithinPackingLimits(
|
||||
int maxVectors, ShVariableInfo *varInfoArray, size_t varInfoArraySize)
|
||||
{
|
||||
if (varInfoArraySize == 0)
|
||||
return 1;
|
||||
return true;
|
||||
ASSERT(varInfoArray);
|
||||
std::vector<sh::ShaderVariable> variables;
|
||||
for (size_t ii = 0; ii < varInfoArraySize; ++ii)
|
||||
|
@ -397,24 +316,17 @@ int ShCheckVariablesWithinPackingLimits(
|
|||
variables.push_back(var);
|
||||
}
|
||||
VariablePacker packer;
|
||||
return packer.CheckVariablesWithinPackingLimits(maxVectors, variables) ? 1 : 0;
|
||||
return packer.CheckVariablesWithinPackingLimits(maxVectors, variables);
|
||||
}
|
||||
|
||||
bool ShGetInterfaceBlockRegister(const ShHandle handle,
|
||||
const char *interfaceBlockName,
|
||||
const std::string &interfaceBlockName,
|
||||
unsigned int *indexOut)
|
||||
{
|
||||
if (!handle || !interfaceBlockName || !indexOut)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ASSERT(indexOut);
|
||||
|
||||
TShHandleBase* base = static_cast<TShHandleBase*>(handle);
|
||||
TranslatorHLSL* translator = base->getAsTranslatorHLSL();
|
||||
if (!translator)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
|
||||
ASSERT(translator);
|
||||
|
||||
if (!translator->hasInterfaceBlock(interfaceBlockName))
|
||||
{
|
||||
|
@ -426,20 +338,12 @@ bool ShGetInterfaceBlockRegister(const ShHandle handle,
|
|||
}
|
||||
|
||||
bool ShGetUniformRegister(const ShHandle handle,
|
||||
const char *uniformName,
|
||||
const std::string &uniformName,
|
||||
unsigned int *indexOut)
|
||||
{
|
||||
if (!handle || !uniformName || !indexOut)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TShHandleBase* base = static_cast<TShHandleBase*>(handle);
|
||||
TranslatorHLSL* translator = base->getAsTranslatorHLSL();
|
||||
if (!translator)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ASSERT(indexOut);
|
||||
TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
|
||||
ASSERT(translator);
|
||||
|
||||
if (!translator->hasUniform(uniformName))
|
||||
{
|
||||
|
|
|
@ -102,7 +102,7 @@ void ShaderD3D::initializeCompiler()
|
|||
{
|
||||
if (!mFragmentCompiler)
|
||||
{
|
||||
int result = ShInitialize();
|
||||
bool result = ShInitialize();
|
||||
|
||||
if (result)
|
||||
{
|
||||
|
@ -252,23 +252,16 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
|
|||
result = ShCompile(compiler, sourceStrings, ArraySize(sourceStrings), compileOptions | SH_SOURCE_PATH);
|
||||
}
|
||||
|
||||
size_t shaderVersion = 100;
|
||||
ShGetInfo(compiler, SH_SHADER_VERSION, &shaderVersion);
|
||||
mShaderVersion = ShGetShaderVersion(compiler);
|
||||
|
||||
mShaderVersion = static_cast<int>(shaderVersion);
|
||||
|
||||
if (shaderVersion == 300 && mRenderer->getCurrentClientVersion() < 3)
|
||||
if (mShaderVersion == 300 && mRenderer->getCurrentClientVersion() < 3)
|
||||
{
|
||||
mInfoLog = "GLSL ES 3.00 is not supported by OpenGL ES 2.0 contexts";
|
||||
TRACE("\n%s", mInfoLog.c_str());
|
||||
}
|
||||
else if (result)
|
||||
{
|
||||
size_t objCodeLen = 0;
|
||||
ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &objCodeLen);
|
||||
|
||||
std::vector<char> outputHLSL(objCodeLen);
|
||||
ShGetObjectCode(compiler, outputHLSL.data());
|
||||
mHlsl = ShGetObjectCode(compiler);
|
||||
|
||||
#ifdef _DEBUG
|
||||
// Prefix hlsl shader with commented out glsl shader
|
||||
|
@ -288,10 +281,8 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
|
|||
curPos = (nextLine == std::string::npos) ? std::string::npos : (nextLine + 1);
|
||||
}
|
||||
hlslStream << "\n\n";
|
||||
hlslStream << outputHLSL.data();
|
||||
hlslStream << mHlsl;
|
||||
mHlsl = hlslStream.str();
|
||||
#else
|
||||
mHlsl = outputHLSL.data();
|
||||
#endif
|
||||
|
||||
mUniforms = *GetShaderVariables(ShGetUniforms(compiler));
|
||||
|
@ -303,7 +294,7 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
|
|||
if (uniform.staticUse)
|
||||
{
|
||||
unsigned int index = -1;
|
||||
bool result = ShGetUniformRegister(compiler, uniform.name.c_str(), &index);
|
||||
bool result = ShGetUniformRegister(compiler, uniform.name, &index);
|
||||
UNUSED_ASSERTION_VARIABLE(result);
|
||||
ASSERT(result);
|
||||
|
||||
|
@ -320,7 +311,7 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
|
|||
if (interfaceBlock.staticUse)
|
||||
{
|
||||
unsigned int index = -1;
|
||||
bool result = ShGetInterfaceBlockRegister(compiler, interfaceBlock.name.c_str(), &index);
|
||||
bool result = ShGetInterfaceBlockRegister(compiler, interfaceBlock.name, &index);
|
||||
UNUSED_ASSERTION_VARIABLE(result);
|
||||
ASSERT(result);
|
||||
|
||||
|
@ -330,14 +321,9 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
|
|||
}
|
||||
else
|
||||
{
|
||||
size_t infoLogLen = 0;
|
||||
ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &infoLogLen);
|
||||
mInfoLog = ShGetInfoLog(compiler);
|
||||
|
||||
std::vector<char> infoLog(infoLogLen);
|
||||
ShGetInfoLog(compiler, infoLog.data());
|
||||
mInfoLog = infoLog.data();
|
||||
|
||||
TRACE("\n%s", infoLog.data());
|
||||
TRACE("\n%s", mInfoLog.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -419,10 +405,7 @@ ShShaderOutput ShaderD3D::getCompilerOutputType(GLenum shader)
|
|||
default: UNREACHABLE(); return SH_HLSL9_OUTPUT;
|
||||
}
|
||||
|
||||
size_t outputType = 0;
|
||||
ShGetInfo(compiler, SH_OUTPUT_TYPE, &outputType);
|
||||
|
||||
return static_cast<ShShaderOutput>(outputType);
|
||||
return ShGetShaderOutputType(compiler);
|
||||
}
|
||||
|
||||
bool ShaderD3D::compile(const std::string &source)
|
||||
|
|
|
@ -144,19 +144,18 @@ protected:
|
|||
// substring in the error log. This way we know the error is specific
|
||||
// to the issue we are testing.
|
||||
bool CheckShaderCompilation(ShHandle compiler,
|
||||
const char* source,
|
||||
const char *source,
|
||||
int compileOptions,
|
||||
const char* expected_error) {
|
||||
const char *expected_error)
|
||||
{
|
||||
bool success = ShCompile(compiler, &source, 1, compileOptions) != 0;
|
||||
if (success) {
|
||||
if (success)
|
||||
{
|
||||
success = !expected_error;
|
||||
} else {
|
||||
size_t bufferLen = 0;
|
||||
ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &bufferLen);
|
||||
char* buffer(new char [bufferLen]);
|
||||
ShGetInfoLog(compiler, buffer);
|
||||
std::string log(buffer, buffer + bufferLen);
|
||||
delete [] buffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string log = ShGetInfoLog(compiler);
|
||||
if (expected_error)
|
||||
success = log.find(expected_error) != std::string::npos;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче