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
ecb0f3b7
Commit
ecb0f3b7
authored
May 27, 2016
by
Johannes van Waveren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added -x option to save SPIR-V as 32-bit hexadecimal numbers to a text file.
parent
5a7f0eff
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
7 deletions
+45
-7
GlslangToSpv.cpp
SPIRV/GlslangToSpv.cpp
+24
-1
GlslangToSpv.h
SPIRV/GlslangToSpv.h
+2
-1
StandAlone.cpp
StandAlone/StandAlone.cpp
+19
-5
No files found.
SPIRV/GlslangToSpv.cpp
View file @
ecb0f3b7
...
@@ -49,8 +49,10 @@ namespace spv {
...
@@ -49,8 +49,10 @@ namespace spv {
#include "../glslang/MachineIndependent/localintermediate.h"
#include "../glslang/MachineIndependent/localintermediate.h"
#include "../glslang/MachineIndependent/SymbolTable.h"
#include "../glslang/MachineIndependent/SymbolTable.h"
#include "../glslang/Include/Common.h"
#include "../glslang/Include/Common.h"
#include "../glslang/Include/revision.h"
#include <fstream>
#include <fstream>
#include <iomanip>
#include <list>
#include <list>
#include <map>
#include <map>
#include <stack>
#include <stack>
...
@@ -4311,7 +4313,7 @@ void GetSpirvVersion(std::string& version)
...
@@ -4311,7 +4313,7 @@ void GetSpirvVersion(std::string& version)
}
}
// Write SPIR-V out to a binary file
// Write SPIR-V out to a binary file
void
OutputSpv
(
const
std
::
vector
<
unsigned
int
>&
spirv
,
const
char
*
baseName
)
void
OutputSpv
Bin
(
const
std
::
vector
<
unsigned
int
>&
spirv
,
const
char
*
baseName
)
{
{
std
::
ofstream
out
;
std
::
ofstream
out
;
out
.
open
(
baseName
,
std
::
ios
::
binary
|
std
::
ios
::
out
);
out
.
open
(
baseName
,
std
::
ios
::
binary
|
std
::
ios
::
out
);
...
@@ -4322,6 +4324,27 @@ void OutputSpv(const std::vector<unsigned int>& spirv, const char* baseName)
...
@@ -4322,6 +4324,27 @@ void OutputSpv(const std::vector<unsigned int>& spirv, const char* baseName)
out
.
close
();
out
.
close
();
}
}
// Write SPIR-V out to a text file with 32-bit hexadecimal words
void
OutputSpvHex
(
const
std
::
vector
<
unsigned
int
>&
spirv
,
const
char
*
baseName
)
{
std
::
ofstream
out
;
out
.
open
(
baseName
,
std
::
ios
::
binary
|
std
::
ios
::
out
);
out
<<
"
\t
// "
GLSLANG_REVISION
" "
GLSLANG_DATE
<<
std
::
endl
;
const
int
WORDS_PER_LINE
=
8
;
for
(
int
i
=
0
;
i
<
(
int
)
spirv
.
size
();
i
+=
WORDS_PER_LINE
)
{
out
<<
"
\t
"
;
for
(
int
j
=
0
;
j
<
WORDS_PER_LINE
&&
i
+
j
<
(
int
)
spirv
.
size
();
++
j
)
{
const
unsigned
int
word
=
spirv
[
i
+
j
];
out
<<
"0x"
<<
std
::
hex
<<
std
::
setw
(
8
)
<<
std
::
setfill
(
'0'
)
<<
word
;
if
(
i
+
j
+
1
<
(
int
)
spirv
.
size
())
{
out
<<
","
;
}
}
out
<<
std
::
endl
;
}
out
.
close
();
}
//
//
// Set up the glslang traversal
// Set up the glslang traversal
//
//
...
...
SPIRV/GlslangToSpv.h
View file @
ecb0f3b7
...
@@ -44,6 +44,7 @@ namespace glslang {
...
@@ -44,6 +44,7 @@ namespace glslang {
void
GetSpirvVersion
(
std
::
string
&
);
void
GetSpirvVersion
(
std
::
string
&
);
void
GlslangToSpv
(
const
glslang
::
TIntermediate
&
intermediate
,
std
::
vector
<
unsigned
int
>&
spirv
);
void
GlslangToSpv
(
const
glslang
::
TIntermediate
&
intermediate
,
std
::
vector
<
unsigned
int
>&
spirv
);
void
GlslangToSpv
(
const
glslang
::
TIntermediate
&
intermediate
,
std
::
vector
<
unsigned
int
>&
spirv
,
spv
::
SpvBuildLogger
*
logger
);
void
GlslangToSpv
(
const
glslang
::
TIntermediate
&
intermediate
,
std
::
vector
<
unsigned
int
>&
spirv
,
spv
::
SpvBuildLogger
*
logger
);
void
OutputSpv
(
const
std
::
vector
<
unsigned
int
>&
spirv
,
const
char
*
baseName
);
void
OutputSpvBin
(
const
std
::
vector
<
unsigned
int
>&
spirv
,
const
char
*
baseName
);
void
OutputSpvHex
(
const
std
::
vector
<
unsigned
int
>&
spirv
,
const
char
*
baseName
);
}
}
StandAlone/StandAlone.cpp
View file @
ecb0f3b7
...
@@ -75,7 +75,8 @@ enum TOptions {
...
@@ -75,7 +75,8 @@ enum TOptions {
EOptionVulkanRules
=
0x2000
,
EOptionVulkanRules
=
0x2000
,
EOptionDefaultDesktop
=
0x4000
,
EOptionDefaultDesktop
=
0x4000
,
EOptionOutputPreprocessed
=
0x8000
,
EOptionOutputPreprocessed
=
0x8000
,
EOptionReadHlsl
=
0x10000
,
EOptionOutputHexadecimal
=
0x10000
,
EOptionReadHlsl
=
0x20000
,
};
};
//
//
...
@@ -294,6 +295,15 @@ void ProcessArguments(int argc, char* argv[])
...
@@ -294,6 +295,15 @@ void ProcessArguments(int argc, char* argv[])
case
'w'
:
case
'w'
:
Options
|=
EOptionSuppressWarnings
;
Options
|=
EOptionSuppressWarnings
;
break
;
break
;
case
'x'
:
Options
|=
EOptionOutputHexadecimal
;
binaryFileName
=
argv
[
1
];
if
(
argc
>
0
)
{
argc
--
;
argv
++
;
}
else
Error
(
"no <file> provided for -x"
);
break
;
default:
default:
usage
();
usage
();
break
;
break
;
...
@@ -311,7 +321,7 @@ void ProcessArguments(int argc, char* argv[])
...
@@ -311,7 +321,7 @@ void ProcessArguments(int argc, char* argv[])
if
((
Options
&
EOptionOutputPreprocessed
)
&&
(
Options
&
EOptionLinkProgram
))
if
((
Options
&
EOptionOutputPreprocessed
)
&&
(
Options
&
EOptionLinkProgram
))
Error
(
"can't use -E when linking is selected"
);
Error
(
"can't use -E when linking is selected"
);
// -o makes no sense if there is no target binary
// -o
or -x
makes no sense if there is no target binary
if
(
binaryFileName
&&
(
Options
&
EOptionSpv
)
==
0
)
if
(
binaryFileName
&&
(
Options
&
EOptionSpv
)
==
0
)
Error
(
"no binary generation requested (e.g., -V)"
);
Error
(
"no binary generation requested (e.g., -V)"
);
}
}
...
@@ -481,7 +491,11 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
...
@@ -481,7 +491,11 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
// memory/perf testing, as it's not internal to programmatic use.
// memory/perf testing, as it's not internal to programmatic use.
if
(
!
(
Options
&
EOptionMemoryLeakMode
))
{
if
(
!
(
Options
&
EOptionMemoryLeakMode
))
{
printf
(
"%s"
,
logger
.
getAllMessages
().
c_str
());
printf
(
"%s"
,
logger
.
getAllMessages
().
c_str
());
glslang
::
OutputSpv
(
spirv
,
GetBinaryName
((
EShLanguage
)
stage
));
if
(
Options
&
EOptionOutputHexadecimal
)
{
glslang
::
OutputSpvHex
(
spirv
,
GetBinaryName
((
EShLanguage
)
stage
));
}
else
{
glslang
::
OutputSpvBin
(
spirv
,
GetBinaryName
((
EShLanguage
)
stage
));
}
if
(
Options
&
EOptionHumanReadableSpv
)
{
if
(
Options
&
EOptionHumanReadableSpv
)
{
spv
::
Disassemble
(
std
::
cout
,
spirv
);
spv
::
Disassemble
(
std
::
cout
,
spirv
);
}
}
...
@@ -749,7 +763,6 @@ void usage()
...
@@ -749,7 +763,6 @@ void usage()
"Each option must be specified separately.
\n
"
"Each option must be specified separately.
\n
"
" -V create SPIR-V binary, under Vulkan semantics; turns on -l;
\n
"
" -V create SPIR-V binary, under Vulkan semantics; turns on -l;
\n
"
" default file name is <stage>.spv (-o overrides this)
\n
"
" default file name is <stage>.spv (-o overrides this)
\n
"
" (unless -o is specified, which overrides the default file name)
\n
"
" -G create SPIR-V binary, under OpenGL semantics; turns on -l;
\n
"
" -G create SPIR-V binary, under OpenGL semantics; turns on -l;
\n
"
" default file name is <stage>.spv (-o overrides this)
\n
"
" default file name is <stage>.spv (-o overrides this)
\n
"
" -H print human readable form of SPIR-V; turns on -V
\n
"
" -H print human readable form of SPIR-V; turns on -V
\n
"
...
@@ -765,13 +778,14 @@ void usage()
...
@@ -765,13 +778,14 @@ void usage()
" -i intermediate tree (glslang AST) is printed out
\n
"
" -i intermediate tree (glslang AST) is printed out
\n
"
" -l link all input files together to form a single module
\n
"
" -l link all input files together to form a single module
\n
"
" -m memory leak mode
\n
"
" -m memory leak mode
\n
"
" -o <file> save binary
in
to <file>, requires a binary option (e.g., -V)
\n
"
" -o <file> save binary to <file>, requires a binary option (e.g., -V)
\n
"
" -q dump reflection query database
\n
"
" -q dump reflection query database
\n
"
" -r relaxed semantic error-checking mode
\n
"
" -r relaxed semantic error-checking mode
\n
"
" -s silent mode
\n
"
" -s silent mode
\n
"
" -t multi-threaded mode
\n
"
" -t multi-threaded mode
\n
"
" -v print version strings
\n
"
" -v print version strings
\n
"
" -w suppress warnings (except as required by #extension : warn)
\n
"
" -w suppress warnings (except as required by #extension : warn)
\n
"
" -x <file> save 32-bit hex numbers as text to <file>, requires a binary option (e.g., -V)
\n
"
);
);
exit
(
EFailUsage
);
exit
(
EFailUsage
);
...
...
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