Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
glslang
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
glslang
Commits
2f1ee452
Commit
2f1ee452
authored
May 17, 2016
by
Lei Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Run link tests in the GTest framework.
parent
fc697cc9
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
177 additions
and
48 deletions
+177
-48
CMakeLists.txt
gtests/CMakeLists.txt
+1
-0
Link.FromFile.cpp
gtests/Link.FromFile.cpp
+107
-0
TestFixture.h
gtests/TestFixture.h
+69
-48
No files found.
gtests/CMakeLists.txt
View file @
2f1ee452
...
@@ -14,6 +14,7 @@ if (TARGET gmock)
...
@@ -14,6 +14,7 @@ if (TARGET gmock)
${
CMAKE_CURRENT_SOURCE_DIR
}
/AST.FromFile.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/AST.FromFile.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/BuiltInResource.FromFile.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/BuiltInResource.FromFile.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/Hlsl.FromFile.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/Hlsl.FromFile.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/Link.FromFile.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/Pp.FromFile.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/Pp.FromFile.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/Spv.FromFile.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/Spv.FromFile.cpp
)
)
...
...
gtests/Link.FromFile.cpp
0 → 100644
View file @
2f1ee452
//
// 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.
#include <memory>
#include <gtest/gtest.h>
#include "TestFixture.h"
namespace
glslangtest
{
namespace
{
using
LinkTest
=
GlslangTest
<
::
testing
::
TestWithParam
<
std
::
vector
<
std
::
string
>>>
;
TEST_P
(
LinkTest
,
FromFile
)
{
const
auto
&
fileNames
=
GetParam
();
const
size_t
fileCount
=
fileNames
.
size
();
const
EShMessages
controls
=
DeriveOptions
(
Source
::
GLSL
,
Semantics
::
OpenGL
,
Target
::
AST
);
GlslangResult
result
;
// Compile each input shader file.
std
::
vector
<
std
::
unique_ptr
<
glslang
::
TShader
>>
shaders
;
for
(
size_t
i
=
0
;
i
<
fileCount
;
++
i
)
{
std
::
string
contents
;
tryLoadFile
(
GLSLANG_TEST_DIRECTORY
"/"
+
fileNames
[
i
],
"input"
,
&
contents
);
shaders
.
emplace_back
(
new
glslang
::
TShader
(
GetShaderStage
(
GetSuffix
(
fileNames
[
i
]))));
auto
*
shader
=
shaders
.
back
().
get
();
compile
(
shader
,
contents
,
""
,
controls
);
result
.
shaderResults
.
push_back
(
{
fileNames
[
i
],
shader
->
getInfoLog
(),
shader
->
getInfoDebugLog
()});
}
// Link all of them.
glslang
::
TProgram
program
;
for
(
const
auto
&
shader
:
shaders
)
program
.
addShader
(
shader
.
get
());
program
.
link
(
controls
);
result
.
linkingOutput
=
program
.
getInfoLog
();
result
.
linkingError
=
program
.
getInfoDebugLog
();
std
::
ostringstream
stream
;
outputResultToStream
(
&
stream
,
result
,
controls
);
// Check with expected results.
const
std
::
string
expectedOutputFname
=
GLSLANG_TEST_DIRECTORY
"/baseResults/"
+
fileNames
.
front
()
+
".out"
;
std
::
string
expectedOutput
;
tryLoadFile
(
expectedOutputFname
,
"expected output"
,
&
expectedOutput
);
checkEqAndUpdateIfRequested
(
expectedOutput
,
stream
.
str
(),
expectedOutputFname
);
}
// clang-format off
INSTANTIATE_TEST_CASE_P
(
Glsl
,
LinkTest
,
::
testing
::
ValuesIn
(
std
::
vector
<
std
::
vector
<
std
::
string
>>
({
{
"mains1.frag"
,
"mains2.frag"
,
"noMain1.geom"
,
"noMain2.geom"
},
{
"noMain.vert"
,
"mains.frag"
},
{
"link1.frag"
,
"link2.frag"
,
"link3.frag"
},
{
"recurse1.vert"
,
"recurse1.frag"
,
"recurse2.frag"
},
{
"300link.frag"
},
{
"300link2.frag"
},
{
"300link3.frag"
},
{
"empty.frag"
,
"empty2.frag"
,
"empty3.frag"
},
{
"150.tesc"
,
"150.tese"
,
"400.tesc"
,
"400.tese"
,
"410.tesc"
,
"420.tesc"
,
"420.tese"
},
{
"max_vertices_0.geom"
},
})),
);
// clang-format on
}
// anonymous namespace
}
// namespace glslangtest
gtests/TestFixture.h
View file @
2f1ee452
...
@@ -151,48 +151,61 @@ public:
...
@@ -151,48 +151,61 @@ public:
}
}
}
}
struct
ShaderResult
{
std
::
string
shaderName
;
std
::
string
output
;
std
::
string
error
;
};
// A struct for holding all the information returned by glslang compilation
// A struct for holding all the information returned by glslang compilation
// and linking.
// and linking.
struct
GlslangResult
{
struct
GlslangResult
{
const
std
::
string
compilationOutput
;
std
::
vector
<
ShaderResult
>
shaderResults
;
const
std
::
string
compilationError
;
std
::
string
linkingOutput
;
const
std
::
string
linkingOutput
;
std
::
string
linkingError
;
const
std
::
string
linkingError
;
std
::
string
spirvWarningsErrors
;
const
std
::
string
spirvWarningsErrors
;
std
::
string
spirv
;
// Optional SPIR-V disassembly text.
const
std
::
string
spirv
;
// Optional SPIR-V disassembly text.
};
};
// Compiles and links the given source |code| of the given shader
// Compiles and the given source |code| of the given shader |stage| into
// |stage| into the given |target| under the given |semantics|. Returns
// the target under the semantics conveyed via |controls|. Returns true
// a GlslangResult instance containing all the information generated
// and modifies |shader| on success.
// during the process. If |target| is Target::Spirv, also disassembles
bool
compile
(
glslang
::
TShader
*
shader
,
const
std
::
string
&
code
,
// the result and returns disassembly text.
const
std
::
string
&
entryPointName
,
EShMessages
controls
)
GlslangResult
compile
(
const
std
::
string
&
code
,
Source
source
,
const
std
::
string
&
stage
,
Semantics
semantics
,
Target
target
,
const
std
::
string
&
entryPointName
)
{
{
const
char
*
shaderStrings
=
code
.
data
();
const
char
*
shaderStrings
=
code
.
data
();
const
int
shaderLengths
=
static_cast
<
int
>
(
code
.
size
());
const
int
shaderLengths
=
static_cast
<
int
>
(
code
.
size
());
const
EShLanguage
kind
=
GetShaderStage
(
stage
);
glslang
::
TShader
shader
(
kind
);
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
());
const
EShMessages
messages
=
DeriveOptions
(
source
,
semantics
,
target
);
// Reinitialize glslang if the semantics change.
// Reinitialize glslang if the semantics change.
GlslangInitializer
::
InitializationToken
token
=
GlslangInitializer
::
InitializationToken
token
=
GlobalTestSettings
.
initializer
->
acquire
(
messages
);
GlobalTestSettings
.
initializer
->
acquire
(
controls
);
bool
success
=
return
shader
->
parse
(
&
glslang
::
DefaultTBuiltInResource
,
defaultVersion
,
shader
.
parse
(
&
glslang
::
DefaultTBuiltInResource
,
defaultVersion
,
isForwardCompatible
,
controls
);
isForwardCompatible
,
messages
);
}
// Compiles and links the given source |code| of the given shader
// |stage| into the target under the semantics specified via |controls|.
// Returns a GlslangResult instance containing all the information generated
// during the process. If the target includes SPIR-V, also disassembles
// the result and returns disassembly text.
GlslangResult
compileAndLink
(
const
std
::
string
shaderName
,
const
std
::
string
&
code
,
const
std
::
string
&
entryPointName
,
EShMessages
controls
)
{
const
EShLanguage
kind
=
GetShaderStage
(
GetSuffix
(
shaderName
));
glslang
::
TShader
shader
(
kind
);
bool
success
=
compile
(
&
shader
,
code
,
entryPointName
,
controls
);
glslang
::
TProgram
program
;
glslang
::
TProgram
program
;
program
.
addShader
(
&
shader
);
program
.
addShader
(
&
shader
);
success
&=
program
.
link
(
message
s
);
success
&=
program
.
link
(
control
s
);
spv
::
SpvBuildLogger
logger
;
spv
::
SpvBuildLogger
logger
;
if
(
success
&&
(
target
==
Target
::
Spv
||
target
==
Target
::
BothASTAndSpv
))
{
if
(
success
&&
(
controls
&
EShMsgSpvRules
))
{
std
::
vector
<
uint32_t
>
spirv_binary
;
std
::
vector
<
uint32_t
>
spirv_binary
;
glslang
::
GlslangToSpv
(
*
program
.
getIntermediate
(
kind
),
glslang
::
GlslangToSpv
(
*
program
.
getIntermediate
(
kind
),
spirv_binary
,
&
logger
);
spirv_binary
,
&
logger
);
...
@@ -200,13 +213,37 @@ public:
...
@@ -200,13 +213,37 @@ public:
std
::
ostringstream
disassembly_stream
;
std
::
ostringstream
disassembly_stream
;
spv
::
Parameterize
();
spv
::
Parameterize
();
spv
::
Disassemble
(
disassembly_stream
,
spirv_binary
);
spv
::
Disassemble
(
disassembly_stream
,
spirv_binary
);
return
{
shader
.
getInfoLog
(),
shader
.
getInfoDebugLog
()
,
return
{
{{
shaderName
,
shader
.
getInfoLog
(),
shader
.
getInfoDebugLog
()},}
,
program
.
getInfoLog
(),
program
.
getInfoDebugLog
(),
program
.
getInfoLog
(),
program
.
getInfoDebugLog
(),
logger
.
getAllMessages
(),
disassembly_stream
.
str
()};
logger
.
getAllMessages
(),
disassembly_stream
.
str
()};
}
else
{
}
else
{
return
{
shader
.
getInfoLog
(),
shader
.
getInfoDebugLog
(),
return
{{{
shaderName
,
shader
.
getInfoLog
(),
shader
.
getInfoDebugLog
()},},
program
.
getInfoLog
(),
program
.
getInfoDebugLog
(),
program
.
getInfoLog
(),
program
.
getInfoDebugLog
(),
""
,
""
};
""
,
""
};
}
}
void
outputResultToStream
(
std
::
ostringstream
*
stream
,
const
GlslangResult
&
result
,
EShMessages
controls
)
{
const
auto
outputIfNotEmpty
=
[
&
stream
](
const
std
::
string
&
str
)
{
if
(
!
str
.
empty
())
*
stream
<<
str
<<
"
\n
"
;
};
for
(
const
auto
&
shaderResult
:
result
.
shaderResults
)
{
*
stream
<<
shaderResult
.
shaderName
<<
"
\n
"
;
outputIfNotEmpty
(
shaderResult
.
output
);
outputIfNotEmpty
(
shaderResult
.
error
);
}
outputIfNotEmpty
(
result
.
linkingOutput
);
outputIfNotEmpty
(
result
.
linkingError
);
*
stream
<<
result
.
spirvWarningsErrors
;
if
(
controls
&
EShMsgSpvRules
)
{
*
stream
<<
(
result
.
spirv
.
empty
()
?
"SPIR-V is not generated for failed compile or link
\n
"
:
result
.
spirv
);
}
}
}
}
...
@@ -225,29 +262,13 @@ public:
...
@@ -225,29 +262,13 @@ public:
tryLoadFile
(
inputFname
,
"input"
,
&
input
);
tryLoadFile
(
inputFname
,
"input"
,
&
input
);
tryLoadFile
(
expectedOutputFname
,
"expected output"
,
&
expectedOutput
);
tryLoadFile
(
expectedOutputFname
,
"expected output"
,
&
expectedOutput
);
const
EShMessages
controls
=
DeriveOptions
(
source
,
semantics
,
target
);
GlslangResult
result
=
GlslangResult
result
=
compile
(
input
,
source
,
GetSuffix
(
testName
),
compileAndLink
(
testName
,
input
,
entryPointName
,
controls
);
semantics
,
target
,
entryPointName
);
// Generate the hybrid output in the way of glslangValidator.
// Generate the hybrid output in the way of glslangValidator.
std
::
ostringstream
stream
;
std
::
ostringstream
stream
;
outputResultToStream
(
&
stream
,
result
,
controls
);
const
auto
outputIfNotEmpty
=
[
&
stream
](
const
std
::
string
&
str
)
{
if
(
!
str
.
empty
())
stream
<<
str
<<
"
\n
"
;
};
stream
<<
testName
<<
"
\n
"
;
outputIfNotEmpty
(
result
.
compilationOutput
);
outputIfNotEmpty
(
result
.
compilationError
);
outputIfNotEmpty
(
result
.
linkingOutput
);
outputIfNotEmpty
(
result
.
linkingError
);
stream
<<
result
.
spirvWarningsErrors
;
if
(
target
==
Target
::
Spv
||
target
==
Target
::
BothASTAndSpv
)
{
stream
<<
(
result
.
spirv
.
empty
()
?
"SPIR-V is not generated for failed compile or link
\n
"
:
result
.
spirv
);
}
checkEqAndUpdateIfRequested
(
expectedOutput
,
stream
.
str
(),
checkEqAndUpdateIfRequested
(
expectedOutput
,
stream
.
str
(),
expectedOutputFname
);
expectedOutputFname
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment