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
6353d55e
Commit
6353d55e
authored
Jun 23, 2017
by
John Kessenich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Command-line: Add support for setting language's environment.
parent
c178f0a4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
114 additions
and
23 deletions
+114
-23
StandAlone.cpp
StandAlone/StandAlone.cpp
+86
-23
runtests
Test/runtests
+10
-0
spv.targetOpenGL.vert
Test/spv.targetOpenGL.vert
+9
-0
spv.targetVulkan.vert
Test/spv.targetVulkan.vert
+9
-0
No files found.
StandAlone/StandAlone.cpp
View file @
6353d55e
...
@@ -148,6 +148,10 @@ const char* sourceEntryPointName = nullptr;
...
@@ -148,6 +148,10 @@ const char* sourceEntryPointName = nullptr;
const
char
*
shaderStageName
=
nullptr
;
const
char
*
shaderStageName
=
nullptr
;
const
char
*
variableName
=
nullptr
;
const
char
*
variableName
=
nullptr
;
std
::
vector
<
std
::
string
>
IncludeDirectoryList
;
std
::
vector
<
std
::
string
>
IncludeDirectoryList
;
int
ClientInputSemanticsVersion
=
100
;
// maps to, say, #define VULKAN 100
int
VulkanClientVersion
=
100
;
// would map to, say, Vulkan 1.0
int
OpenGLClientVersion
=
450
;
// doesn't influence anything yet, but maps to OpenGL 4.50
unsigned
int
TargetVersion
=
0x00001000
;
// maps to, say, SPIR-V 1.0
std
::
array
<
unsigned
int
,
EShLangCount
>
baseSamplerBinding
;
std
::
array
<
unsigned
int
,
EShLangCount
>
baseSamplerBinding
;
std
::
array
<
unsigned
int
,
EShLangCount
>
baseTextureBinding
;
std
::
array
<
unsigned
int
,
EShLangCount
>
baseTextureBinding
;
...
@@ -294,15 +298,15 @@ void ProcessResourceSetBindingBase(int& argc, char**& argv, std::array<std::vect
...
@@ -294,15 +298,15 @@ void ProcessResourceSetBindingBase(int& argc, char**& argv, std::array<std::vect
base
[
lang
].
push_back
(
argv
[
2
]);
base
[
lang
].
push_back
(
argv
[
2
]);
base
[
lang
].
push_back
(
argv
[
3
]);
base
[
lang
].
push_back
(
argv
[
3
]);
base
[
lang
].
push_back
(
argv
[
4
]);
base
[
lang
].
push_back
(
argv
[
4
]);
argc
-=
4
;
argc
-=
4
;
argv
+=
4
;
argv
+=
4
;
while
(
argv
[
1
]
!=
NULL
)
{
while
(
argv
[
1
]
!=
NULL
)
{
if
(
argv
[
1
][
0
]
!=
'-'
)
{
if
(
argv
[
1
][
0
]
!=
'-'
)
{
base
[
lang
].
push_back
(
argv
[
1
]);
base
[
lang
].
push_back
(
argv
[
1
]);
base
[
lang
].
push_back
(
argv
[
2
]);
base
[
lang
].
push_back
(
argv
[
2
]);
base
[
lang
].
push_back
(
argv
[
3
]);
base
[
lang
].
push_back
(
argv
[
3
]);
argc
-=
3
;
argc
-=
3
;
argv
+=
3
;
argv
+=
3
;
}
}
else
{
else
{
break
;
break
;
...
@@ -352,6 +356,31 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
...
@@ -352,6 +356,31 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
return
argv
[
0
]
+
2
;
return
argv
[
0
]
+
2
;
};
};
// read a number attached to a single-letter option
const
auto
getAttachedNumber
=
[
&
](
const
char
*
desc
)
{
int
num
=
atoi
(
argv
[
0
]
+
2
);
if
(
num
==
0
)
{
printf
(
"%s: expected attached non-0 number
\n
"
,
desc
);
exit
(
EFailUsage
);
}
return
num
;
};
// minimum needed (without overriding something else) to target Vulkan SPIR-V
const
auto
setVulkanSpv
=
[]()
{
Options
|=
EOptionSpv
;
Options
|=
EOptionVulkanRules
;
Options
|=
EOptionLinkProgram
;
};
// minimum needed (without overriding something else) to target OpenGL SPIR-V
const
auto
setOpenGlSpv
=
[]()
{
Options
|=
EOptionSpv
;
Options
|=
EOptionLinkProgram
;
// undo a -H default to Vulkan
Options
&=
~
EOptionVulkanRules
;
};
for
(
bumpArg
();
argc
>=
1
;
bumpArg
())
{
for
(
bumpArg
();
argc
>=
1
;
bumpArg
())
{
if
(
argv
[
0
][
0
]
==
'-'
)
{
if
(
argv
[
0
][
0
]
==
'-'
)
{
switch
(
argv
[
0
][
1
])
{
switch
(
argv
[
0
][
1
])
{
...
@@ -368,6 +397,16 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
...
@@ -368,6 +397,16 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
}
else
if
(
lowerword
==
"auto-map-locations"
||
// synonyms
}
else
if
(
lowerword
==
"auto-map-locations"
||
// synonyms
lowerword
==
"aml"
)
{
lowerword
==
"aml"
)
{
Options
|=
EOptionAutoMapLocations
;
Options
|=
EOptionAutoMapLocations
;
}
else
if
(
lowerword
==
"client"
)
{
if
(
argc
>
1
)
{
if
(
strcmp
(
argv
[
1
],
"vulkan100"
)
==
0
)
setVulkanSpv
();
else
if
(
strcmp
(
argv
[
1
],
"opengl100"
)
==
0
)
setOpenGlSpv
();
else
Error
(
"--client expects vulkan100 or opengl100"
);
}
bumpArg
();
}
else
if
(
lowerword
==
"flatten-uniform-arrays"
||
// synonyms
}
else
if
(
lowerword
==
"flatten-uniform-arrays"
||
// synonyms
lowerword
==
"flatten-uniform-array"
||
lowerword
==
"flatten-uniform-array"
||
lowerword
==
"fua"
)
{
lowerword
==
"fua"
)
{
...
@@ -422,6 +461,18 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
...
@@ -422,6 +461,18 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
sourceEntryPointName
=
argv
[
1
];
sourceEntryPointName
=
argv
[
1
];
bumpArg
();
bumpArg
();
break
;
break
;
}
else
if
(
lowerword
==
"target-env"
)
{
if
(
argc
>
1
)
{
if
(
strcmp
(
argv
[
1
],
"vulkan1.0"
)
==
0
)
{
setVulkanSpv
();
VulkanClientVersion
=
100
;
}
else
if
(
strcmp
(
argv
[
1
],
"opengl"
)
==
0
)
{
setOpenGlSpv
();
OpenGLClientVersion
=
450
;
}
else
Error
(
"--target-env expected vulkan1.0 or opengl"
);
}
bumpArg
();
}
else
if
(
lowerword
==
"variable-name"
||
// synonyms
}
else
if
(
lowerword
==
"variable-name"
||
// synonyms
lowerword
==
"vn"
)
{
lowerword
==
"vn"
)
{
Options
|=
EOptionOutputHexadecimal
;
Options
|=
EOptionOutputHexadecimal
;
...
@@ -448,18 +499,16 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
...
@@ -448,18 +499,16 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
Options
|=
EOptionOutputPreprocessed
;
Options
|=
EOptionOutputPreprocessed
;
break
;
break
;
case
'G'
:
case
'G'
:
Options
|=
EOptionSpv
;
// OpenGL Client
Options
|=
EOptionLinkProgram
;
setOpenGlSpv
()
;
// undo a -H default to Vulkan
if
(
argv
[
0
][
2
]
!=
0
)
Options
&=
~
EOptionVulkanRules
;
ClientInputSemanticsVersion
=
getAttachedNumber
(
"-G<num> client input semantics"
)
;
break
;
break
;
case
'H'
:
case
'H'
:
Options
|=
EOptionHumanReadableSpv
;
Options
|=
EOptionHumanReadableSpv
;
if
((
Options
&
EOptionSpv
)
==
0
)
{
if
((
Options
&
EOptionSpv
)
==
0
)
{
// default to Vulkan
// default to Vulkan
Options
|=
EOptionSpv
;
setVulkanSpv
();
Options
|=
EOptionVulkanRules
;
Options
|=
EOptionLinkProgram
;
}
}
break
;
break
;
case
'I'
:
case
'I'
:
...
@@ -475,9 +524,9 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
...
@@ -475,9 +524,9 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
UserPreamble
.
addUndef
(
getStringOperand
(
"-U<macro>: macro name"
));
UserPreamble
.
addUndef
(
getStringOperand
(
"-U<macro>: macro name"
));
break
;
break
;
case
'V'
:
case
'V'
:
Options
|=
EOptionSpv
;
setVulkanSpv
()
;
Options
|=
EOptionVulkanRules
;
if
(
argv
[
0
][
2
]
!=
0
)
Options
|=
EOptionLinkProgram
;
ClientInputSemanticsVersion
=
getAttachedNumber
(
"-G<num> client input semantics"
)
;
break
;
break
;
case
'c'
:
case
'c'
:
Options
|=
EOptionDumpConfig
;
Options
|=
EOptionDumpConfig
;
...
@@ -716,15 +765,15 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
...
@@ -716,15 +765,15 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
if
(
Options
&
EOptionVulkanRules
)
{
if
(
Options
&
EOptionVulkanRules
)
{
shader
->
setEnvInput
((
Options
&
EOptionReadHlsl
)
?
glslang
::
EShSourceHlsl
shader
->
setEnvInput
((
Options
&
EOptionReadHlsl
)
?
glslang
::
EShSourceHlsl
:
glslang
::
EShSourceGlsl
,
:
glslang
::
EShSourceGlsl
,
compUnit
.
stage
,
glslang
::
EShClientVulkan
,
100
);
compUnit
.
stage
,
glslang
::
EShClientVulkan
,
ClientInputSemanticsVersion
);
shader
->
setEnvClient
(
glslang
::
EShClientVulkan
,
100
);
shader
->
setEnvClient
(
glslang
::
EShClientVulkan
,
VulkanClientVersion
);
shader
->
setEnvTarget
(
glslang
::
EshTargetSpv
,
0x00001000
);
shader
->
setEnvTarget
(
glslang
::
EshTargetSpv
,
TargetVersion
);
}
else
{
}
else
{
shader
->
setEnvInput
((
Options
&
EOptionReadHlsl
)
?
glslang
::
EShSourceHlsl
shader
->
setEnvInput
((
Options
&
EOptionReadHlsl
)
?
glslang
::
EShSourceHlsl
:
glslang
::
EShSourceGlsl
,
:
glslang
::
EShSourceGlsl
,
compUnit
.
stage
,
glslang
::
EShClientOpenGL
,
100
);
compUnit
.
stage
,
glslang
::
EShClientOpenGL
,
ClientInputSemanticsVersion
);
shader
->
setEnvClient
(
glslang
::
EShClientOpenGL
,
450
);
shader
->
setEnvClient
(
glslang
::
EShClientOpenGL
,
OpenGLClientVersion
);
shader
->
setEnvTarget
(
glslang
::
EshTargetSpv
,
0x00001000
);
shader
->
setEnvTarget
(
glslang
::
EshTargetSpv
,
TargetVersion
);
}
}
}
}
...
@@ -1085,16 +1134,24 @@ void usage()
...
@@ -1085,16 +1134,24 @@ void usage()
" -D<macro> define a pre-processor macro
\n
"
" -D<macro> define a pre-processor macro
\n
"
" -E print pre-processed GLSL; cannot be used with -l;
\n
"
" -E print pre-processed GLSL; cannot be used with -l;
\n
"
" errors will appear on stderr.
\n
"
" errors will appear on stderr.
\n
"
" -G
create SPIR-V binary, under OpenGL semantics; turns on -l;
\n
"
" -G
[ver]
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
"
" 'ver', when present, is the version of the input semantics,
\n
"
" which will appear in #define GL_SPIRV ver
\n
"
" '--client opengl100' is the same as -G100
\n
"
" a '--target-env' for OpenGL will also imply '-G'
\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
"
" -I<dir> add dir to the include search path; includer's directory
\n
"
" -I<dir> add dir to the include search path; includer's directory
\n
"
" is searched first, followed by left-to-right order of -I
\n
"
" is searched first, followed by left-to-right order of -I
\n
"
" -S <stage> uses specified stage rather than parsing the file extension
\n
"
" -S <stage> uses specified stage rather than parsing the file extension
\n
"
" choices for <stage> are vert, tesc, tese, geom, frag, or comp
\n
"
" choices for <stage> are vert, tesc, tese, geom, frag, or comp
\n
"
" -U<macro> undefine a pre-pr
eco
ssor macro
\n
"
" -U<macro> undefine a pre-pr
oce
ssor macro
\n
"
" -V
create SPIR-V binary, under Vulkan semantics; turns on -l;
\n
"
" -V
[ver]
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
"
" 'ver', when present, is the version of the input semantics,
\n
"
" which will appear in #define VULKAN ver
\n
"
" '--client vulkan100' is the same as -V100
\n
"
" a '--target-env' for Vulkan will also imply '-V'
\n
"
" -c configuration dump;
\n
"
" -c configuration dump;
\n
"
" creates the default configuration file (redirect to a .conf file)
\n
"
" creates the default configuration file (redirect to a .conf file)
\n
"
" -d default to desktop (#version 110) when there is no shader #version
\n
"
" -d default to desktop (#version 110) when there is no shader #version
\n
"
...
@@ -1119,6 +1176,7 @@ void usage()
...
@@ -1119,6 +1176,7 @@ void usage()
" --auto-map-locations automatically locate input/output lacking
\n
"
" --auto-map-locations automatically locate input/output lacking
\n
"
" 'location' (fragile, not cross stage)
\n
"
" 'location' (fragile, not cross stage)
\n
"
" --aml synonym for --auto-map-locations
\n
"
" --aml synonym for --auto-map-locations
\n
"
" --client {vulkan<ver>|opengl<ver>} see -V and -G
\n
"
" --flatten-uniform-arrays flatten uniform texture/sampler arrays to
\n
"
" --flatten-uniform-arrays flatten uniform texture/sampler arrays to
\n
"
" scalars
\n
"
" scalars
\n
"
" --fua synonym for --flatten-uniform-arrays
\n
"
" --fua synonym for --flatten-uniform-arrays
\n
"
...
@@ -1147,6 +1205,11 @@ void usage()
...
@@ -1147,6 +1205,11 @@ void usage()
" --source-entrypoint name the given shader source function is
\n
"
" --source-entrypoint name the given shader source function is
\n
"
" renamed to be the entry point given in -e
\n
"
" renamed to be the entry point given in -e
\n
"
" --sep synonym for --source-entrypoint
\n
"
" --sep synonym for --source-entrypoint
\n
"
" --target-env {vulkan1.0|opengl} set the execution environment the generated
\n
"
" code will execute in (as opposed to language
\n
"
" semantics selected by --client)
\n
"
" default is 'vulkan1.0' under '--client vulkan'
\n
"
" default is 'opengl' under '--client opengl'
\n
"
" --variable-name <name> Creates a C header file that contains a
\n
"
" --variable-name <name> Creates a C header file that contains a
\n
"
" uint32_t array named <name>
\n
"
" uint32_t array named <name>
\n
"
" initialized with the shader binary code.
\n
"
" initialized with the shader binary code.
\n
"
...
...
Test/runtests
View file @
6353d55e
...
@@ -128,6 +128,16 @@ $EXE -D -e main -V -i -DUNDEFED -UIN_SHADER -DFOO=200 -UUNDEFED hlsl.-D-U.frag >
...
@@ -128,6 +128,16 @@ $EXE -D -e main -V -i -DUNDEFED -UIN_SHADER -DFOO=200 -UUNDEFED hlsl.-D-U.frag >
diff
-b
$BASEDIR
/hlsl.-D-U.frag.out
$TARGETDIR
/hlsl.-D-U.frag.out
||
HASERROR
=
1
diff
-b
$BASEDIR
/hlsl.-D-U.frag.out
$TARGETDIR
/hlsl.-D-U.frag.out
||
HASERROR
=
1
#
#
# Test --client and --target-env
#
$EXE
--client
vulkan100 spv.targetVulkan.vert
||
HASERROR
=
1
$EXE
--client
opengl100 spv.targetOpenGL.vert
||
HASERROR
=
1
$EXE
--target-env
vulkan1.0 spv.targetVulkan.vert
||
HASERROR
=
1
$EXE
--target-env
opengl spv.targetOpenGL.vert
||
HASERROR
=
1
$EXE
-V100
spv.targetVulkan.vert
||
HASERROR
=
1
$EXE
-G100
spv.targetOpenGL.vert
||
HASERROR
=
1
#
# Final checking
# Final checking
#
#
if
[
$HASERROR
-eq
0
]
if
[
$HASERROR
-eq
0
]
...
...
Test/spv.targetOpenGL.vert
0 → 100755
View file @
6353d55e
#version 450
layout
(
constant_id
=
3
)
const
int
a
=
2
;
uniform
float
f
;
void
main
()
{
}
Test/spv.targetVulkan.vert
0 → 100755
View file @
6353d55e
#version 450
layout
(
constant_id
=
3
)
const
int
a
=
2
;
layout
(
push_constant
)
uniform
pc
{
float
f
;
};
void
main
()
{
}
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