mirror of
https://gitee.com/openharmony/third_party_vulkan-loader
synced 2025-01-13 02:34:09 +00:00
tests: Add utility function to compile GLSL to BIL
This requires glslang + BIL to be in a peer folder (glslang) to XGL.
This commit is contained in:
parent
00d36503b1
commit
35866804ae
@ -14,9 +14,26 @@ SET(COMMON_CPP
|
||||
xgltestframework.cpp
|
||||
)
|
||||
|
||||
link_directories(
|
||||
"${PROJECT_SOURCE_DIR}/../glslang/dbuild/install/lib"
|
||||
)
|
||||
|
||||
|
||||
set(TEST_LIBRARIES
|
||||
${OPENGL_gl_LIBRARY}
|
||||
${GLUT_glut_LIBRARY}
|
||||
glslang
|
||||
OGLCompiler
|
||||
OSDependent
|
||||
BIL
|
||||
)
|
||||
|
||||
include_directories(
|
||||
"${PROJECT_SOURCE_DIR}/tests/gtest-1.7.0/include"
|
||||
"${PROJECT_SOURCE_DIR}/icd/common"
|
||||
"${PROJECT_SOURCE_DIR}/../glslang/glslang/Include"
|
||||
"${PROJECT_SOURCE_DIR}/../glslang/glslang/Public"
|
||||
"${PROJECT_SOURCE_DIR}/../glslang/BIL"
|
||||
)
|
||||
|
||||
|
||||
@ -25,19 +42,19 @@ add_executable(xglbase init.cpp ${COMMON_CPP})
|
||||
set_target_properties(xglbase
|
||||
PROPERTIES
|
||||
COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
|
||||
target_link_libraries(xglbase XGL gtest gtest_main ${OPENGL_gl_LIBRARY} ${GLUT_glut_LIBRARY})
|
||||
target_link_libraries(xglbase XGL gtest gtest_main ${TEST_LIBRARIES})
|
||||
|
||||
add_executable(xgl_image_tests image_tests.cpp ${COMMON_CPP})
|
||||
set_target_properties(xgl_image_tests
|
||||
PROPERTIES
|
||||
COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
|
||||
target_link_libraries(xgl_image_tests XGL gtest gtest_main ${OPENGL_gl_LIBRARY} ${GLUT_glut_LIBRARY})
|
||||
target_link_libraries(xgl_image_tests XGL gtest gtest_main ${TEST_LIBRARIES})
|
||||
|
||||
add_executable(xgl_render_tests render_tests.cpp ${COMMON_CPP} displayengine.cpp)
|
||||
set_target_properties(xgl_render_tests
|
||||
PROPERTIES
|
||||
COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
|
||||
target_link_libraries(xgl_render_tests XGL gtest gtest_main ${OPENGL_gl_LIBRARY} ${GLUT_glut_LIBRARY})
|
||||
target_link_libraries(xgl_render_tests XGL gtest gtest_main ${TEST_LIBRARIES})
|
||||
|
||||
target_link_libraries(xglinfo XGL)
|
||||
|
||||
|
@ -205,7 +205,7 @@ public:
|
||||
void GenerateBindStateAndPipelineCmds(XGL_PIPELINE* pipeline);
|
||||
|
||||
XGL_DEVICE device() {return m_device->device();}
|
||||
void CreateShader(XGL_PIPELINE_SHADER_STAGE stage, XGL_SHADER *pshader);
|
||||
void CreateShader(XGL_PIPELINE_SHADER_STAGE stage, const char *shader_code, XGL_SHADER *pshader);
|
||||
void InitPipeline();
|
||||
void InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, const void* vertices );
|
||||
void InitConstantBuffer( int constantCount, int constantSize, const void* data );
|
||||
@ -317,52 +317,26 @@ void XglRenderTest::DestroyQueryPool(XGL_QUERY_POOL pool, XGL_GPU_MEMORY mem)
|
||||
ASSERT_XGL_SUCCESS(xglDestroyObject(pool));
|
||||
}
|
||||
|
||||
void XglRenderTest::CreateShader(XGL_PIPELINE_SHADER_STAGE stage, XGL_SHADER *pshader)
|
||||
void XglRenderTest::CreateShader(XGL_PIPELINE_SHADER_STAGE stage,
|
||||
const char *shader_code,
|
||||
XGL_SHADER *pshader)
|
||||
{
|
||||
struct icd_bil_header *pBIL;
|
||||
char * memblock;
|
||||
const char *kernel;
|
||||
size_t kernel_size;
|
||||
XGL_RESULT err;
|
||||
std::vector<unsigned int> bil;
|
||||
|
||||
const XGL_PHYSICAL_GPU_PROPERTIES *props = &m_device->props;
|
||||
const int gen = (strstr((const char *) props->gpuName, "Sandybridge")) ? 6 : 7;
|
||||
|
||||
if (stage == XGL_SHADER_STAGE_VERTEX) {
|
||||
if (gen == 6) {
|
||||
kernel = (const char *) gen6_vs;
|
||||
kernel_size = sizeof(gen6_vs);
|
||||
} else {
|
||||
kernel = (const char *) gen7_vs;
|
||||
kernel_size = sizeof(gen7_vs);
|
||||
}
|
||||
} else {
|
||||
if (gen == 6) {
|
||||
kernel = (const char *) gen6_fs;
|
||||
kernel_size = sizeof(gen6_fs);
|
||||
} else {
|
||||
kernel = (const char *) gen7_fs;
|
||||
kernel_size = sizeof(gen7_fs);
|
||||
}
|
||||
}
|
||||
|
||||
memblock = new char [sizeof(*pBIL) + kernel_size];
|
||||
ASSERT_TRUE(memblock != NULL) << "memory allocation failed";
|
||||
|
||||
pBIL = (struct icd_bil_header *) memblock;
|
||||
pBIL->magic = ICD_BIL_MAGIC;
|
||||
pBIL->version = ICD_BIL_VERSION;
|
||||
|
||||
pBIL->gen_magic = (stage == XGL_SHADER_STAGE_VERTEX) ? 'v' : 'w';
|
||||
memcpy(pBIL + 1, kernel, kernel_size);
|
||||
GLSLtoBIL(stage, shader_code, bil);
|
||||
|
||||
XGL_SHADER_CREATE_INFO createInfo;
|
||||
XGL_SHADER shader;
|
||||
|
||||
createInfo.sType = XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO;
|
||||
createInfo.pNext = NULL;
|
||||
createInfo.pCode = memblock;
|
||||
createInfo.codeSize = sizeof(*pBIL) + kernel_size;
|
||||
createInfo.pCode = bil.data();
|
||||
createInfo.codeSize = bil.size() * sizeof(unsigned int);
|
||||
createInfo.flags = 0;
|
||||
err = xglCreateShader(device(), &createInfo, &shader);
|
||||
ASSERT_XGL_SUCCESS(err);
|
||||
@ -592,7 +566,18 @@ void XglRenderTest::CreateDefaultPipeline(XGL_PIPELINE* pipeline, XGL_SHADER* vs
|
||||
xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView );
|
||||
xglEndDescriptorSetUpdate( m_rsrcDescSet );
|
||||
|
||||
ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX, vs));
|
||||
static const char *vertShaderText =
|
||||
"#version 130\n"
|
||||
"vec2 vertices[3];\n"
|
||||
"void main() {\n"
|
||||
" vertices[0] = vec2(-1.0, -1.0);\n"
|
||||
" vertices[1] = vec2( 1.0, -1.0);\n"
|
||||
" vertices[2] = vec2( 0.0, 1.0);\n"
|
||||
" gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
|
||||
vertShaderText, vs));
|
||||
|
||||
vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
vs_stage.pNext = XGL_NULL_HANDLE;
|
||||
@ -605,7 +590,15 @@ void XglRenderTest::CreateDefaultPipeline(XGL_PIPELINE* pipeline, XGL_SHADER* vs
|
||||
vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
|
||||
vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
|
||||
|
||||
ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT, ps));
|
||||
static const char *fragShaderText =
|
||||
"#version 130\n"
|
||||
"uniform vec4 foo;\n"
|
||||
"void main() {\n"
|
||||
" gl_FragColor = foo;\n"
|
||||
"}\n";
|
||||
|
||||
ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
|
||||
fragShaderText, ps));
|
||||
|
||||
ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
ps_stage.pNext = &vs_stage;
|
||||
|
@ -22,10 +22,70 @@
|
||||
|
||||
#include "xgltestframework.h"
|
||||
#include "GL/freeglut_std.h"
|
||||
//#include "ShaderLang.h"
|
||||
#include "GlslangToBil.h"
|
||||
#include <math.h>
|
||||
|
||||
// Command-line options
|
||||
enum TOptions {
|
||||
EOptionNone = 0x000,
|
||||
EOptionIntermediate = 0x001,
|
||||
EOptionSuppressInfolog = 0x002,
|
||||
EOptionMemoryLeakMode = 0x004,
|
||||
EOptionRelaxedErrors = 0x008,
|
||||
EOptionGiveWarnings = 0x010,
|
||||
EOptionLinkProgram = 0x020,
|
||||
EOptionMultiThreaded = 0x040,
|
||||
EOptionDumpConfig = 0x080,
|
||||
EOptionDumpReflection = 0x100,
|
||||
EOptionSuppressWarnings = 0x200,
|
||||
EOptionDumpVersions = 0x400,
|
||||
EOptionBil = 0x800,
|
||||
EOptionDefaultDesktop = 0x1000,
|
||||
};
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
int fopen_s(
|
||||
FILE** pFile,
|
||||
const char* filename,
|
||||
const char* mode
|
||||
)
|
||||
{
|
||||
if (!pFile || !filename || !mode) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
FILE* f = fopen(filename, mode);
|
||||
if (! f) {
|
||||
if (errno != 0) {
|
||||
return errno;
|
||||
} else {
|
||||
return ENOENT;
|
||||
}
|
||||
}
|
||||
*pFile = f;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
XglTestFramework::XglTestFramework() :
|
||||
m_glut_initialized( false )
|
||||
m_glut_initialized( false ),
|
||||
m_compile_options( 0 ),
|
||||
m_num_shader_strings( 0 )
|
||||
{
|
||||
// Initialize GLSL to BIL compiler utility
|
||||
// ShInitialize();
|
||||
glslang::InitializeProcess();
|
||||
}
|
||||
|
||||
XglTestFramework::~XglTestFramework()
|
||||
{
|
||||
glslang::FinalizeProcess();
|
||||
}
|
||||
|
||||
// Define all the static elements
|
||||
@ -280,6 +340,572 @@ void XglTestFramework::Finish()
|
||||
glutMainLoop();
|
||||
}
|
||||
|
||||
//
|
||||
// ShInitialize() should be called exactly once per process, not per thread.
|
||||
//
|
||||
//int XglTestFramework::ShInitialize()
|
||||
//{
|
||||
// glslang::InitGlobalLock();
|
||||
|
||||
// if (! InitProcess())
|
||||
// return 0;
|
||||
|
||||
// if (! PerProcessGPA)
|
||||
// PerProcessGPA = new TPoolAllocator();
|
||||
|
||||
// glslang::TScanContext::fillInKeywordMap();
|
||||
|
||||
// return 1;
|
||||
//}
|
||||
|
||||
//
|
||||
// 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
|
||||
//
|
||||
static const char* DefaultConfig =
|
||||
"MaxLights 32\n"
|
||||
"MaxClipPlanes 6\n"
|
||||
"MaxTextureUnits 32\n"
|
||||
"MaxTextureCoords 32\n"
|
||||
"MaxVertexAttribs 64\n"
|
||||
"MaxVertexUniformComponents 4096\n"
|
||||
"MaxVaryingFloats 64\n"
|
||||
"MaxVertexTextureImageUnits 32\n"
|
||||
"MaxCombinedTextureImageUnits 80\n"
|
||||
"MaxTextureImageUnits 32\n"
|
||||
"MaxFragmentUniformComponents 4096\n"
|
||||
"MaxDrawBuffers 32\n"
|
||||
"MaxVertexUniformVectors 128\n"
|
||||
"MaxVaryingVectors 8\n"
|
||||
"MaxFragmentUniformVectors 16\n"
|
||||
"MaxVertexOutputVectors 16\n"
|
||||
"MaxFragmentInputVectors 15\n"
|
||||
"MinProgramTexelOffset -8\n"
|
||||
"MaxProgramTexelOffset 7\n"
|
||||
"MaxClipDistances 8\n"
|
||||
"MaxComputeWorkGroupCountX 65535\n"
|
||||
"MaxComputeWorkGroupCountY 65535\n"
|
||||
"MaxComputeWorkGroupCountZ 65535\n"
|
||||
"MaxComputeWorkGroupSizeX 1024\n"
|
||||
"MaxComputeWorkGroupSizeY 1024\n"
|
||||
"MaxComputeWorkGroupSizeZ 64\n"
|
||||
"MaxComputeUniformComponents 1024\n"
|
||||
"MaxComputeTextureImageUnits 16\n"
|
||||
"MaxComputeImageUniforms 8\n"
|
||||
"MaxComputeAtomicCounters 8\n"
|
||||
"MaxComputeAtomicCounterBuffers 1\n"
|
||||
"MaxVaryingComponents 60\n"
|
||||
"MaxVertexOutputComponents 64\n"
|
||||
"MaxGeometryInputComponents 64\n"
|
||||
"MaxGeometryOutputComponents 128\n"
|
||||
"MaxFragmentInputComponents 128\n"
|
||||
"MaxImageUnits 8\n"
|
||||
"MaxCombinedImageUnitsAndFragmentOutputs 8\n"
|
||||
"MaxCombinedShaderOutputResources 8\n"
|
||||
"MaxImageSamples 0\n"
|
||||
"MaxVertexImageUniforms 0\n"
|
||||
"MaxTessControlImageUniforms 0\n"
|
||||
"MaxTessEvaluationImageUniforms 0\n"
|
||||
"MaxGeometryImageUniforms 0\n"
|
||||
"MaxFragmentImageUniforms 8\n"
|
||||
"MaxCombinedImageUniforms 8\n"
|
||||
"MaxGeometryTextureImageUnits 16\n"
|
||||
"MaxGeometryOutputVertices 256\n"
|
||||
"MaxGeometryTotalOutputComponents 1024\n"
|
||||
"MaxGeometryUniformComponents 1024\n"
|
||||
"MaxGeometryVaryingComponents 64\n"
|
||||
"MaxTessControlInputComponents 128\n"
|
||||
"MaxTessControlOutputComponents 128\n"
|
||||
"MaxTessControlTextureImageUnits 16\n"
|
||||
"MaxTessControlUniformComponents 1024\n"
|
||||
"MaxTessControlTotalOutputComponents 4096\n"
|
||||
"MaxTessEvaluationInputComponents 128\n"
|
||||
"MaxTessEvaluationOutputComponents 128\n"
|
||||
"MaxTessEvaluationTextureImageUnits 16\n"
|
||||
"MaxTessEvaluationUniformComponents 1024\n"
|
||||
"MaxTessPatchComponents 120\n"
|
||||
"MaxPatchVertices 32\n"
|
||||
"MaxTessGenLevel 64\n"
|
||||
"MaxViewports 16\n"
|
||||
"MaxVertexAtomicCounters 0\n"
|
||||
"MaxTessControlAtomicCounters 0\n"
|
||||
"MaxTessEvaluationAtomicCounters 0\n"
|
||||
"MaxGeometryAtomicCounters 0\n"
|
||||
"MaxFragmentAtomicCounters 8\n"
|
||||
"MaxCombinedAtomicCounters 8\n"
|
||||
"MaxAtomicCounterBindings 1\n"
|
||||
"MaxVertexAtomicCounterBuffers 0\n"
|
||||
"MaxTessControlAtomicCounterBuffers 0\n"
|
||||
"MaxTessEvaluationAtomicCounterBuffers 0\n"
|
||||
"MaxGeometryAtomicCounterBuffers 0\n"
|
||||
"MaxFragmentAtomicCounterBuffers 1\n"
|
||||
"MaxCombinedAtomicCounterBuffers 1\n"
|
||||
"MaxAtomicCounterBufferSize 16384\n"
|
||||
"MaxTransformFeedbackBuffers 4\n"
|
||||
"MaxTransformFeedbackInterleavedComponents 64\n"
|
||||
"MaxCullDistances 8\n"
|
||||
"MaxCombinedClipAndCullDistances 8\n"
|
||||
"MaxSamples 4\n"
|
||||
|
||||
"nonInductiveForLoops 1\n"
|
||||
"whileLoops 1\n"
|
||||
"doWhileLoops 1\n"
|
||||
"generalUniformIndexing 1\n"
|
||||
"generalAttributeMatrixVectorIndexing 1\n"
|
||||
"generalVaryingIndexing 1\n"
|
||||
"generalSamplerIndexing 1\n"
|
||||
"generalVariableIndexing 1\n"
|
||||
"generalConstantMatrixVectorIndexing 1\n"
|
||||
;
|
||||
|
||||
//
|
||||
// *.conf => this is a config file that can set limits/resources
|
||||
//
|
||||
bool XglTestFramework::SetConfigFile(const std::string& name)
|
||||
{
|
||||
if (name.size() < 5)
|
||||
return false;
|
||||
|
||||
if (name.compare(name.size() - 5, 5, ".conf") == 0) {
|
||||
ConfigFile = name;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Parse either a .conf file provided by the user or the default string above.
|
||||
//
|
||||
void XglTestFramework::ProcessConfigFile()
|
||||
{
|
||||
char** configStrings = 0;
|
||||
char* config = 0;
|
||||
if (ConfigFile.size() > 0) {
|
||||
configStrings = ReadFileData(ConfigFile.c_str());
|
||||
if (configStrings)
|
||||
config = *configStrings;
|
||||
else {
|
||||
printf("Error opening configuration file; will instead use the default configuration\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (config == 0) {
|
||||
config = new char[strlen(DefaultConfig) + 1];
|
||||
strcpy(config, DefaultConfig);
|
||||
}
|
||||
|
||||
const char* delims = " \t\n\r";
|
||||
const char* token = strtok(config, delims);
|
||||
while (token) {
|
||||
const char* valueStr = strtok(0, delims);
|
||||
if (valueStr == 0 || ! (valueStr[0] == '-' || (valueStr[0] >= '0' && valueStr[0] <= '9'))) {
|
||||
printf("Error: '%s' bad .conf file. Each name must be followed by one number.\n", valueStr ? valueStr : "");
|
||||
return;
|
||||
}
|
||||
int value = atoi(valueStr);
|
||||
|
||||
if (strcmp(token, "MaxLights") == 0)
|
||||
Resources.maxLights = value;
|
||||
else if (strcmp(token, "MaxClipPlanes") == 0)
|
||||
Resources.maxClipPlanes = value;
|
||||
else if (strcmp(token, "MaxTextureUnits") == 0)
|
||||
Resources.maxTextureUnits = value;
|
||||
else if (strcmp(token, "MaxTextureCoords") == 0)
|
||||
Resources.maxTextureCoords = value;
|
||||
else if (strcmp(token, "MaxVertexAttribs") == 0)
|
||||
Resources.maxVertexAttribs = value;
|
||||
else if (strcmp(token, "MaxVertexUniformComponents") == 0)
|
||||
Resources.maxVertexUniformComponents = value;
|
||||
else if (strcmp(token, "MaxVaryingFloats") == 0)
|
||||
Resources.maxVaryingFloats = value;
|
||||
else if (strcmp(token, "MaxVertexTextureImageUnits") == 0)
|
||||
Resources.maxVertexTextureImageUnits = value;
|
||||
else if (strcmp(token, "MaxCombinedTextureImageUnits") == 0)
|
||||
Resources.maxCombinedTextureImageUnits = value;
|
||||
else if (strcmp(token, "MaxTextureImageUnits") == 0)
|
||||
Resources.maxTextureImageUnits = value;
|
||||
else if (strcmp(token, "MaxFragmentUniformComponents") == 0)
|
||||
Resources.maxFragmentUniformComponents = value;
|
||||
else if (strcmp(token, "MaxDrawBuffers") == 0)
|
||||
Resources.maxDrawBuffers = value;
|
||||
else if (strcmp(token, "MaxVertexUniformVectors") == 0)
|
||||
Resources.maxVertexUniformVectors = value;
|
||||
else if (strcmp(token, "MaxVaryingVectors") == 0)
|
||||
Resources.maxVaryingVectors = value;
|
||||
else if (strcmp(token, "MaxFragmentUniformVectors") == 0)
|
||||
Resources.maxFragmentUniformVectors = value;
|
||||
else if (strcmp(token, "MaxVertexOutputVectors") == 0)
|
||||
Resources.maxVertexOutputVectors = value;
|
||||
else if (strcmp(token, "MaxFragmentInputVectors") == 0)
|
||||
Resources.maxFragmentInputVectors = value;
|
||||
else if (strcmp(token, "MinProgramTexelOffset") == 0)
|
||||
Resources.minProgramTexelOffset = value;
|
||||
else if (strcmp(token, "MaxProgramTexelOffset") == 0)
|
||||
Resources.maxProgramTexelOffset = value;
|
||||
else if (strcmp(token, "MaxClipDistances") == 0)
|
||||
Resources.maxClipDistances = value;
|
||||
else if (strcmp(token, "MaxComputeWorkGroupCountX") == 0)
|
||||
Resources.maxComputeWorkGroupCountX = value;
|
||||
else if (strcmp(token, "MaxComputeWorkGroupCountY") == 0)
|
||||
Resources.maxComputeWorkGroupCountY = value;
|
||||
else if (strcmp(token, "MaxComputeWorkGroupCountZ") == 0)
|
||||
Resources.maxComputeWorkGroupCountZ = value;
|
||||
else if (strcmp(token, "MaxComputeWorkGroupSizeX") == 0)
|
||||
Resources.maxComputeWorkGroupSizeX = value;
|
||||
else if (strcmp(token, "MaxComputeWorkGroupSizeY") == 0)
|
||||
Resources.maxComputeWorkGroupSizeY = value;
|
||||
else if (strcmp(token, "MaxComputeWorkGroupSizeZ") == 0)
|
||||
Resources.maxComputeWorkGroupSizeZ = value;
|
||||
else if (strcmp(token, "MaxComputeUniformComponents") == 0)
|
||||
Resources.maxComputeUniformComponents = value;
|
||||
else if (strcmp(token, "MaxComputeTextureImageUnits") == 0)
|
||||
Resources.maxComputeTextureImageUnits = value;
|
||||
else if (strcmp(token, "MaxComputeImageUniforms") == 0)
|
||||
Resources.maxComputeImageUniforms = value;
|
||||
else if (strcmp(token, "MaxComputeAtomicCounters") == 0)
|
||||
Resources.maxComputeAtomicCounters = value;
|
||||
else if (strcmp(token, "MaxComputeAtomicCounterBuffers") == 0)
|
||||
Resources.maxComputeAtomicCounterBuffers = value;
|
||||
else if (strcmp(token, "MaxVaryingComponents") == 0)
|
||||
Resources.maxVaryingComponents = value;
|
||||
else if (strcmp(token, "MaxVertexOutputComponents") == 0)
|
||||
Resources.maxVertexOutputComponents = value;
|
||||
else if (strcmp(token, "MaxGeometryInputComponents") == 0)
|
||||
Resources.maxGeometryInputComponents = value;
|
||||
else if (strcmp(token, "MaxGeometryOutputComponents") == 0)
|
||||
Resources.maxGeometryOutputComponents = value;
|
||||
else if (strcmp(token, "MaxFragmentInputComponents") == 0)
|
||||
Resources.maxFragmentInputComponents = value;
|
||||
else if (strcmp(token, "MaxImageUnits") == 0)
|
||||
Resources.maxImageUnits = value;
|
||||
else if (strcmp(token, "MaxCombinedImageUnitsAndFragmentOutputs") == 0)
|
||||
Resources.maxCombinedImageUnitsAndFragmentOutputs = value;
|
||||
else if (strcmp(token, "MaxCombinedShaderOutputResources") == 0)
|
||||
Resources.maxCombinedShaderOutputResources = value;
|
||||
else if (strcmp(token, "MaxImageSamples") == 0)
|
||||
Resources.maxImageSamples = value;
|
||||
else if (strcmp(token, "MaxVertexImageUniforms") == 0)
|
||||
Resources.maxVertexImageUniforms = value;
|
||||
else if (strcmp(token, "MaxTessControlImageUniforms") == 0)
|
||||
Resources.maxTessControlImageUniforms = value;
|
||||
else if (strcmp(token, "MaxTessEvaluationImageUniforms") == 0)
|
||||
Resources.maxTessEvaluationImageUniforms = value;
|
||||
else if (strcmp(token, "MaxGeometryImageUniforms") == 0)
|
||||
Resources.maxGeometryImageUniforms = value;
|
||||
else if (strcmp(token, "MaxFragmentImageUniforms") == 0)
|
||||
Resources.maxFragmentImageUniforms = value;
|
||||
else if (strcmp(token, "MaxCombinedImageUniforms") == 0)
|
||||
Resources.maxCombinedImageUniforms = value;
|
||||
else if (strcmp(token, "MaxGeometryTextureImageUnits") == 0)
|
||||
Resources.maxGeometryTextureImageUnits = value;
|
||||
else if (strcmp(token, "MaxGeometryOutputVertices") == 0)
|
||||
Resources.maxGeometryOutputVertices = value;
|
||||
else if (strcmp(token, "MaxGeometryTotalOutputComponents") == 0)
|
||||
Resources.maxGeometryTotalOutputComponents = value;
|
||||
else if (strcmp(token, "MaxGeometryUniformComponents") == 0)
|
||||
Resources.maxGeometryUniformComponents = value;
|
||||
else if (strcmp(token, "MaxGeometryVaryingComponents") == 0)
|
||||
Resources.maxGeometryVaryingComponents = value;
|
||||
else if (strcmp(token, "MaxTessControlInputComponents") == 0)
|
||||
Resources.maxTessControlInputComponents = value;
|
||||
else if (strcmp(token, "MaxTessControlOutputComponents") == 0)
|
||||
Resources.maxTessControlOutputComponents = value;
|
||||
else if (strcmp(token, "MaxTessControlTextureImageUnits") == 0)
|
||||
Resources.maxTessControlTextureImageUnits = value;
|
||||
else if (strcmp(token, "MaxTessControlUniformComponents") == 0)
|
||||
Resources.maxTessControlUniformComponents = value;
|
||||
else if (strcmp(token, "MaxTessControlTotalOutputComponents") == 0)
|
||||
Resources.maxTessControlTotalOutputComponents = value;
|
||||
else if (strcmp(token, "MaxTessEvaluationInputComponents") == 0)
|
||||
Resources.maxTessEvaluationInputComponents = value;
|
||||
else if (strcmp(token, "MaxTessEvaluationOutputComponents") == 0)
|
||||
Resources.maxTessEvaluationOutputComponents = value;
|
||||
else if (strcmp(token, "MaxTessEvaluationTextureImageUnits") == 0)
|
||||
Resources.maxTessEvaluationTextureImageUnits = value;
|
||||
else if (strcmp(token, "MaxTessEvaluationUniformComponents") == 0)
|
||||
Resources.maxTessEvaluationUniformComponents = value;
|
||||
else if (strcmp(token, "MaxTessPatchComponents") == 0)
|
||||
Resources.maxTessPatchComponents = value;
|
||||
else if (strcmp(token, "MaxPatchVertices") == 0)
|
||||
Resources.maxPatchVertices = value;
|
||||
else if (strcmp(token, "MaxTessGenLevel") == 0)
|
||||
Resources.maxTessGenLevel = value;
|
||||
else if (strcmp(token, "MaxViewports") == 0)
|
||||
Resources.maxViewports = value;
|
||||
else if (strcmp(token, "MaxVertexAtomicCounters") == 0)
|
||||
Resources.maxVertexAtomicCounters = value;
|
||||
else if (strcmp(token, "MaxTessControlAtomicCounters") == 0)
|
||||
Resources.maxTessControlAtomicCounters = value;
|
||||
else if (strcmp(token, "MaxTessEvaluationAtomicCounters") == 0)
|
||||
Resources.maxTessEvaluationAtomicCounters = value;
|
||||
else if (strcmp(token, "MaxGeometryAtomicCounters") == 0)
|
||||
Resources.maxGeometryAtomicCounters = value;
|
||||
else if (strcmp(token, "MaxFragmentAtomicCounters") == 0)
|
||||
Resources.maxFragmentAtomicCounters = value;
|
||||
else if (strcmp(token, "MaxCombinedAtomicCounters") == 0)
|
||||
Resources.maxCombinedAtomicCounters = value;
|
||||
else if (strcmp(token, "MaxAtomicCounterBindings") == 0)
|
||||
Resources.maxAtomicCounterBindings = value;
|
||||
else if (strcmp(token, "MaxVertexAtomicCounterBuffers") == 0)
|
||||
Resources.maxVertexAtomicCounterBuffers = value;
|
||||
else if (strcmp(token, "MaxTessControlAtomicCounterBuffers") == 0)
|
||||
Resources.maxTessControlAtomicCounterBuffers = value;
|
||||
else if (strcmp(token, "MaxTessEvaluationAtomicCounterBuffers") == 0)
|
||||
Resources.maxTessEvaluationAtomicCounterBuffers = value;
|
||||
else if (strcmp(token, "MaxGeometryAtomicCounterBuffers") == 0)
|
||||
Resources.maxGeometryAtomicCounterBuffers = value;
|
||||
else if (strcmp(token, "MaxFragmentAtomicCounterBuffers") == 0)
|
||||
Resources.maxFragmentAtomicCounterBuffers = value;
|
||||
else if (strcmp(token, "MaxCombinedAtomicCounterBuffers") == 0)
|
||||
Resources.maxCombinedAtomicCounterBuffers = value;
|
||||
else if (strcmp(token, "MaxAtomicCounterBufferSize") == 0)
|
||||
Resources.maxAtomicCounterBufferSize = value;
|
||||
else if (strcmp(token, "MaxTransformFeedbackBuffers") == 0)
|
||||
Resources.maxTransformFeedbackBuffers = value;
|
||||
else if (strcmp(token, "MaxTransformFeedbackInterleavedComponents") == 0)
|
||||
Resources.maxTransformFeedbackInterleavedComponents = value;
|
||||
else if (strcmp(token, "MaxCullDistances") == 0)
|
||||
Resources.maxCullDistances = value;
|
||||
else if (strcmp(token, "MaxCombinedClipAndCullDistances") == 0)
|
||||
Resources.maxCombinedClipAndCullDistances = value;
|
||||
else if (strcmp(token, "MaxSamples") == 0)
|
||||
Resources.maxSamples = value;
|
||||
|
||||
else if (strcmp(token, "nonInductiveForLoops") == 0)
|
||||
Resources.limits.nonInductiveForLoops = (value != 0);
|
||||
else if (strcmp(token, "whileLoops") == 0)
|
||||
Resources.limits.whileLoops = (value != 0);
|
||||
else if (strcmp(token, "doWhileLoops") == 0)
|
||||
Resources.limits.doWhileLoops = (value != 0);
|
||||
else if (strcmp(token, "generalUniformIndexing") == 0)
|
||||
Resources.limits.generalUniformIndexing = (value != 0);
|
||||
else if (strcmp(token, "generalAttributeMatrixVectorIndexing") == 0)
|
||||
Resources.limits.generalAttributeMatrixVectorIndexing = (value != 0);
|
||||
else if (strcmp(token, "generalVaryingIndexing") == 0)
|
||||
Resources.limits.generalVaryingIndexing = (value != 0);
|
||||
else if (strcmp(token, "generalSamplerIndexing") == 0)
|
||||
Resources.limits.generalSamplerIndexing = (value != 0);
|
||||
else if (strcmp(token, "generalVariableIndexing") == 0)
|
||||
Resources.limits.generalVariableIndexing = (value != 0);
|
||||
else if (strcmp(token, "generalConstantMatrixVectorIndexing") == 0)
|
||||
Resources.limits.generalConstantMatrixVectorIndexing = (value != 0);
|
||||
else
|
||||
printf("Warning: unrecognized limit (%s) in configuration file.\n", token);
|
||||
|
||||
token = strtok(0, delims);
|
||||
}
|
||||
if (configStrings)
|
||||
FreeFileData(configStrings);
|
||||
}
|
||||
|
||||
void XglTestFramework::SetMessageOptions(EShMessages& messages)
|
||||
{
|
||||
if (m_compile_options & EOptionRelaxedErrors)
|
||||
messages = (EShMessages)(messages | EShMsgRelaxedErrors);
|
||||
if (m_compile_options & EOptionIntermediate)
|
||||
messages = (EShMessages)(messages | EShMsgAST);
|
||||
if (m_compile_options & EOptionSuppressWarnings)
|
||||
messages = (EShMessages)(messages | EShMsgSuppressWarnings);
|
||||
}
|
||||
|
||||
//
|
||||
// Malloc a string of sufficient size and read a string into it.
|
||||
//
|
||||
char** XglTestFramework::ReadFileData(const char* fileName)
|
||||
{
|
||||
FILE *in;
|
||||
#if defined(_WIN32) && defined(__GNUC__)
|
||||
in = fopen(fileName, "r");
|
||||
int errorCode = in ? 0 : 1;
|
||||
#else
|
||||
int errorCode = fopen_s(&in, fileName, "r");
|
||||
#endif
|
||||
|
||||
char *fdata;
|
||||
int count = 0;
|
||||
const int maxSourceStrings = 5;
|
||||
char** return_data = (char**)malloc(sizeof(char *) * (maxSourceStrings+1));
|
||||
|
||||
if (errorCode) {
|
||||
printf("Error: unable to open input file: %s\n", fileName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (fgetc(in) != EOF)
|
||||
count++;
|
||||
|
||||
fseek(in, 0, SEEK_SET);
|
||||
|
||||
if (!(fdata = (char*)malloc(count+2))) {
|
||||
printf("Error allocating memory\n");
|
||||
return 0;
|
||||
}
|
||||
if (fread(fdata,1,count, in)!=count) {
|
||||
printf("Error reading input file: %s\n", fileName);
|
||||
return 0;
|
||||
}
|
||||
fdata[count] = '\0';
|
||||
fclose(in);
|
||||
if (count == 0) {
|
||||
return_data[0]=(char*)malloc(count+2);
|
||||
return_data[0][0]='\0';
|
||||
m_num_shader_strings = 0;
|
||||
return return_data;
|
||||
} else
|
||||
m_num_shader_strings = 1;
|
||||
|
||||
int len = (int)(ceil)((float)count/(float)m_num_shader_strings);
|
||||
int ptr_len=0,i=0;
|
||||
while(count>0){
|
||||
return_data[i]=(char*)malloc(len+2);
|
||||
memcpy(return_data[i],fdata+ptr_len,len);
|
||||
return_data[i][len]='\0';
|
||||
count-=(len);
|
||||
ptr_len+=(len);
|
||||
if(count<len){
|
||||
if(count==0){
|
||||
m_num_shader_strings=(i+1);
|
||||
break;
|
||||
}
|
||||
len = count;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return return_data;
|
||||
}
|
||||
|
||||
void XglTestFramework::FreeFileData(char** data)
|
||||
{
|
||||
for(int i=0;i<m_num_shader_strings;i++)
|
||||
free(data[i]);
|
||||
}
|
||||
|
||||
//
|
||||
// Deduce the language from the filename. Files must end in one of the
|
||||
// following extensions:
|
||||
//
|
||||
// .vert = vertex
|
||||
// .tesc = tessellation control
|
||||
// .tese = tessellation evaluation
|
||||
// .geom = geometry
|
||||
// .frag = fragment
|
||||
// .comp = compute
|
||||
//
|
||||
EShLanguage XglTestFramework::FindLanguage(const std::string& name)
|
||||
{
|
||||
size_t ext = name.rfind('.');
|
||||
if (ext == std::string::npos) {
|
||||
return EShLangVertex;
|
||||
}
|
||||
|
||||
std::string suffix = name.substr(ext + 1, std::string::npos);
|
||||
if (suffix == "vert")
|
||||
return EShLangVertex;
|
||||
else if (suffix == "tesc")
|
||||
return EShLangTessControl;
|
||||
else if (suffix == "tese")
|
||||
return EShLangTessEvaluation;
|
||||
else if (suffix == "geom")
|
||||
return EShLangGeometry;
|
||||
else if (suffix == "frag")
|
||||
return EShLangFragment;
|
||||
else if (suffix == "comp")
|
||||
return EShLangCompute;
|
||||
|
||||
return EShLangVertex;
|
||||
}
|
||||
|
||||
//
|
||||
// Convert XGL shader type to compiler's
|
||||
//
|
||||
EShLanguage XglTestFramework::FindLanguage(const XGL_PIPELINE_SHADER_STAGE shader_type)
|
||||
{
|
||||
switch (shader_type) {
|
||||
case XGL_SHADER_STAGE_VERTEX:
|
||||
return EShLangVertex;
|
||||
|
||||
case XGL_SHADER_STAGE_TESS_CONTROL:
|
||||
return EShLangTessControl;
|
||||
|
||||
case XGL_SHADER_STAGE_TESS_EVALUATION:
|
||||
return EShLangTessEvaluation;
|
||||
|
||||
case XGL_SHADER_STAGE_GEOMETRY:
|
||||
return EShLangGeometry;
|
||||
|
||||
case XGL_SHADER_STAGE_FRAGMENT:
|
||||
return EShLangFragment;
|
||||
|
||||
case XGL_SHADER_STAGE_COMPUTE:
|
||||
return EShLangCompute;
|
||||
}
|
||||
|
||||
return EShLangVertex;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Compile a given string containing GLSL into BIL for use by XGL
|
||||
// Return value of false means an error was encountered.
|
||||
//
|
||||
bool XglTestFramework::GLSLtoBIL(const XGL_PIPELINE_SHADER_STAGE shader_type,
|
||||
const char *pshader,
|
||||
std::vector<unsigned int> &bil)
|
||||
{
|
||||
glslang::TProgram& program = *new glslang::TProgram;
|
||||
const char *shaderStrings[1];
|
||||
|
||||
// TODO: Do we want to load a special config file depending on the
|
||||
// shader source? Optional name maybe?
|
||||
// SetConfigFile(fileName);
|
||||
|
||||
ProcessConfigFile();
|
||||
|
||||
EShMessages messages = EShMsgDefault;
|
||||
SetMessageOptions(messages);
|
||||
|
||||
EShLanguage stage = FindLanguage(shader_type);
|
||||
glslang::TShader* shader = new glslang::TShader(stage);
|
||||
|
||||
shaderStrings[0] = pshader;
|
||||
shader->setStrings(shaderStrings, 1);
|
||||
|
||||
if (! shader->parse(&Resources, (m_compile_options & EOptionDefaultDesktop) ? 110 : 100, false, messages)) {
|
||||
|
||||
return false; // something didn't work
|
||||
}
|
||||
|
||||
program.addShader(shader);
|
||||
|
||||
if (! (m_compile_options & EOptionSuppressInfolog)) {
|
||||
puts(shader->getInfoLog());
|
||||
puts(shader->getInfoDebugLog());
|
||||
}
|
||||
|
||||
//
|
||||
// Program-level processing...
|
||||
//
|
||||
|
||||
if (! program.link(messages))
|
||||
return false;
|
||||
|
||||
if (! (m_compile_options & EOptionSuppressInfolog)) {
|
||||
puts(program.getInfoLog());
|
||||
puts(program.getInfoDebugLog());
|
||||
}
|
||||
|
||||
if (m_compile_options & EOptionDumpReflection) {
|
||||
program.buildReflection();
|
||||
program.dumpReflection();
|
||||
}
|
||||
|
||||
glslang::GlslangToBil(*program.getIntermediate(stage), bil);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
XglTestImageRecord::XglTestImageRecord() : // Constructor
|
||||
|
@ -25,6 +25,8 @@
|
||||
|
||||
#include "gtest-1.7.0/include/gtest/gtest.h"
|
||||
#include "xglimage.h"
|
||||
#include "ShaderLang.h"
|
||||
#include "GLSL450Lib.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@ -56,6 +58,7 @@ class XglTestFramework : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
XglTestFramework();
|
||||
~XglTestFramework();
|
||||
|
||||
static void InitArgs(int *argc, char *argv[]);
|
||||
static void Finish();
|
||||
@ -63,8 +66,23 @@ public:
|
||||
void WritePPM( const char *basename, XglImage *image );
|
||||
void Show(const char *comment, XglImage *image);
|
||||
void RecordImage(XglImage *image);
|
||||
bool GLSLtoBIL(const XGL_PIPELINE_SHADER_STAGE shader_type,
|
||||
const char *pshader,
|
||||
std::vector<unsigned int> &bil);
|
||||
|
||||
private:
|
||||
int m_compile_options;
|
||||
int m_num_shader_strings;
|
||||
TBuiltInResource Resources;
|
||||
int ShInitialize();
|
||||
void SetMessageOptions(EShMessages& messages);
|
||||
void ProcessConfigFile();
|
||||
char** ReadFileData(const char* fileName);
|
||||
void FreeFileData(char** data);
|
||||
EShLanguage FindLanguage(const std::string& name);
|
||||
EShLanguage FindLanguage(const XGL_PIPELINE_SHADER_STAGE shader_type);
|
||||
std::string ConfigFile;
|
||||
bool SetConfigFile(const std::string& name);
|
||||
static void Reshape( int w, int h );
|
||||
static void Display();
|
||||
static void Key(unsigned char key, int x, int y);
|
||||
|
Loading…
x
Reference in New Issue
Block a user