Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 1 | # Copyright 2015 The Shaderc Authors. All rights reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | import expect |
| 16 | import os.path |
| 17 | from glslc_test_framework import inside_glslc_testsuite |
| 18 | from placeholder import FileShader, StdinShader, TempFileName |
| 19 | |
| 20 | |
| 21 | @inside_glslc_testsuite('File') |
| 22 | class SimpleFileCompiled(expect.ValidObjectFile): |
| 23 | """Tests whether or not a simple glsl file compiles.""" |
| 24 | |
| 25 | shader = FileShader('#version 310 es\nvoid main() {}', '.frag') |
| 26 | glslc_args = ['-c', shader] |
| 27 | |
| 28 | |
| 29 | @inside_glslc_testsuite('File') |
| 30 | class NotSpecifyingOutputName(expect.SuccessfulReturn, |
| 31 | expect.CorrectObjectFilePreamble): |
| 32 | """Tests that when there is no -o and -E/-S/-c specified, output as a.spv.""" |
| 33 | |
David Neto | fab6411 | 2016-02-02 16:24:06 -0500 | [diff] [blame] | 34 | shader = FileShader('#version 140\nvoid main() {}', '.frag') |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 35 | glslc_args = [shader] |
| 36 | |
| 37 | def check_output_a_spv(self, status): |
| 38 | output_name = os.path.join(status.directory, 'a.spv') |
| 39 | return self.verify_object_file_preamble(output_name) |
| 40 | |
| 41 | |
| 42 | @inside_glslc_testsuite('Parameters') |
| 43 | class HelpParameters( |
| 44 | expect.ReturnCodeIsZero, expect.StdoutMatch, expect.StderrMatch): |
| 45 | """Tests the --help flag outputs correctly and does not produce and error.""" |
| 46 | |
| 47 | glslc_args = ['--help'] |
| 48 | |
David Neto | 91bfb4c | 2016-02-23 22:26:18 -0500 | [diff] [blame] | 49 | expected_stdout = '''glslc - Compile shaders into SPIR-V |
| 50 | |
| 51 | Usage: glslc [options] file... |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 52 | |
| 53 | An input file of - represents standard input. |
| 54 | |
| 55 | Options: |
| 56 | -c Only run preprocess, compile, and assemble steps. |
| 57 | -Dmacro[=defn] Add an implicit macro definition. |
| 58 | -E Outputs only the results of the preprocessing step. |
Lei Zhang | 1ccede1 | 2016-02-24 09:30:32 -0500 | [diff] [blame] | 59 | Output defaults to standard output. |
David Neto | 7ae44a1 | 2017-01-23 17:24:33 -0500 | [diff] [blame] | 60 | -fauto-bind-uniforms |
| 61 | Automatically assign bindings to uniform variables that |
| 62 | don't have an explicit 'binding' layout in the shader |
| 63 | source. |
Benjamin Chrétien | d1f763c | 2018-02-09 18:08:58 +0100 | [diff] [blame] | 64 | -fauto-map-locations |
| 65 | Automatically assign locations to uniform variables that |
| 66 | don't have an explicit 'location' layout in the shader |
| 67 | source. |
Lei Zhang | 9340ae5 | 2018-09-20 11:05:50 -0400 | [diff] [blame] | 68 | -fentry-point=<name> |
| 69 | Specify the entry point name for HLSL compilation, for |
| 70 | all subsequent source files. Default is "main". |
David Neto | 5fd1b25 | 2018-04-13 16:27:04 -0400 | [diff] [blame] | 71 | -fhlsl_functionality1, -fhlsl-functionality1 |
| 72 | Enable extension SPV_GOOGLE_hlsl_functionality1 for HLSL |
| 73 | compilation. |
David Neto | c21dd10 | 2019-06-13 17:44:25 -0400 | [diff] [blame] | 74 | -finvert-y Invert position.Y output in vertex shader. |
Lei Zhang | 9340ae5 | 2018-09-20 11:05:50 -0400 | [diff] [blame] | 75 | -fhlsl-iomap Use HLSL IO mappings for bindings. |
| 76 | -fhlsl-offsets Use HLSL offset rules for packing members of blocks. |
| 77 | Affects only GLSL. HLSL rules are always used for HLSL. |
| 78 | -flimit=<settings> |
| 79 | Specify resource limits. Each limit is specified by a limit |
| 80 | name followed by an integer value. Tokens should be |
| 81 | separated by whitespace. If the same limit is specified |
| 82 | several times, only the last setting takes effect. |
| 83 | -flimit-file <file> |
| 84 | Set limits as specified in the given file. |
David Neto | 2cbf790 | 2019-06-19 00:23:21 -0400 | [diff] [blame] | 85 | -fnan-clamp Generate code for max and min builtins so that, when given |
| 86 | a NaN operand, the other operand is returned. Similarly, |
| 87 | the clamp builtin will favour the non-NaN operands, as if |
| 88 | clamp were implemented as a composition of max and min. |
Lei Zhang | 9340ae5 | 2018-09-20 11:05:50 -0400 | [diff] [blame] | 89 | -fresource-set-binding [stage] <reg0> <set0> <binding0> |
| 90 | [<reg1> <set1> <binding1>...] |
| 91 | Explicitly sets the descriptor set and binding for |
| 92 | HLSL resources, by register name. Optionally restrict |
| 93 | it to a single stage. |
| 94 | -fcbuffer-binding-base [stage] <value> |
| 95 | Same as -fubo-binding-base. |
David Neto | 357d24b | 2017-06-04 18:27:12 -0400 | [diff] [blame] | 96 | -fimage-binding-base [stage] <value> |
David Neto | a290067 | 2017-01-28 13:03:24 -0800 | [diff] [blame] | 97 | Sets the lowest automatically assigned binding number for |
David Neto | 357d24b | 2017-06-04 18:27:12 -0400 | [diff] [blame] | 98 | images. Optionally only set it for a single shader stage. |
David Neto | 63313f9 | 2017-06-07 09:15:34 -0700 | [diff] [blame] | 99 | For HLSL, the resource register number is added to this |
| 100 | base. |
David Neto | 357d24b | 2017-06-04 18:27:12 -0400 | [diff] [blame] | 101 | -fsampler-binding-base [stage] <value> |
David Neto | a290067 | 2017-01-28 13:03:24 -0800 | [diff] [blame] | 102 | Sets the lowest automatically assigned binding number for |
David Neto | 357d24b | 2017-06-04 18:27:12 -0400 | [diff] [blame] | 103 | samplers Optionally only set it for a single shader stage. |
David Neto | 63313f9 | 2017-06-07 09:15:34 -0700 | [diff] [blame] | 104 | For HLSL, the resource register number is added to this |
| 105 | base. |
Lei Zhang | 9340ae5 | 2018-09-20 11:05:50 -0400 | [diff] [blame] | 106 | -fssbo-binding-base [stage] <value> |
| 107 | Sets the lowest automatically assigned binding number for |
| 108 | shader storage buffer objects (SSBO). Optionally only set |
| 109 | it for a single shader stage. Only affects GLSL. |
| 110 | -ftexture-binding-base [stage] <value> |
| 111 | Sets the lowest automatically assigned binding number for |
| 112 | textures. Optionally only set it for a single shader stage. |
| 113 | For HLSL, the resource register number is added to this |
| 114 | base. |
| 115 | -fuav-binding-base [stage] <value> |
| 116 | For automatically assigned bindings for unordered access |
| 117 | views (UAV), the register number is added to this base to |
| 118 | determine the binding number. Optionally only set it for |
| 119 | a single shader stage. Only affects HLSL. |
David Neto | 357d24b | 2017-06-04 18:27:12 -0400 | [diff] [blame] | 120 | -fubo-binding-base [stage] <value> |
David Neto | a290067 | 2017-01-28 13:03:24 -0800 | [diff] [blame] | 121 | Sets the lowest automatically assigned binding number for |
David Neto | 357d24b | 2017-06-04 18:27:12 -0400 | [diff] [blame] | 122 | uniform buffer objects (UBO). Optionally only set it for |
| 123 | a single shader stage. |
David Neto | 63313f9 | 2017-06-07 09:15:34 -0700 | [diff] [blame] | 124 | For HLSL, the resource register number is added to this |
| 125 | base. |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 126 | -fshader-stage=<stage> |
| 127 | Treat subsequent input files as having stage <stage>. |
David Neto | 357d24b | 2017-06-04 18:27:12 -0400 | [diff] [blame] | 128 | Valid stages are vertex, vert, fragment, frag, tesscontrol, |
| 129 | tesc, tesseval, tese, geometry, geom, compute, and comp. |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 130 | -g Generate source-level debug information. |
| 131 | Currently this option has no effect. |
| 132 | --help Display available options. |
| 133 | -I <value> Add directory to include search path. |
qining | b3cfde4 | 2016-05-14 01:43:31 -0400 | [diff] [blame] | 134 | -mfmt=<format> Output SPIR-V binary code using the selected format. This |
| 135 | option may be specified only when the compilation output is |
| 136 | in SPIR-V binary code form. Available options include bin, c |
| 137 | and num. By default the binary output format is bin. |
qining | bde33a9 | 2016-02-01 14:30:07 -0500 | [diff] [blame] | 138 | -M Generate make dependencies. Implies -E and -w. |
| 139 | -MM An alias for -M. |
| 140 | -MD Generate make dependencies and compile. |
| 141 | -MF <file> Write dependency output to the given file. |
| 142 | -MT <target> Specify the target of the rule emitted by dependency |
| 143 | generation. |
Lei Zhang | 9340ae5 | 2018-09-20 11:05:50 -0400 | [diff] [blame] | 144 | -O Optimize the generated SPIR-V code for better performance. |
| 145 | -Os Optimize the generated SPIR-V code for smaller size. |
| 146 | -O0 Disable optimization. |
| 147 | -o <file> Write output to <file>. |
| 148 | A file name of '-' represents standard output. |
| 149 | -std=<value> Version and profile for GLSL input files. Possible values |
| 150 | are concatenations of version and profile, e.g. 310es, |
| 151 | 450core, etc. Ignored for HLSL files. |
David Neto | 9f95ca9 | 2020-01-30 09:19:24 -0500 | [diff] [blame^] | 152 | -S Emit SPIR-V assembly instead of binary. |
Lei Zhang | 9340ae5 | 2018-09-20 11:05:50 -0400 | [diff] [blame] | 153 | --show-limits Display available limit names and their default values. |
qining | f6d8374 | 2016-01-28 16:05:11 -0500 | [diff] [blame] | 154 | --target-env=<environment> |
David Neto | c993158 | 2018-03-22 07:32:14 -0700 | [diff] [blame] | 155 | Set the target client environment, and the semantics |
| 156 | of warnings and errors. An optional suffix can specify |
| 157 | the client version. Values are: |
| 158 | vulkan1.0 # The default |
| 159 | vulkan1.1 |
David Neto | cdac124 | 2020-01-15 12:51:13 -0800 | [diff] [blame] | 160 | vulkan1.2 |
David Neto | c993158 | 2018-03-22 07:32:14 -0700 | [diff] [blame] | 161 | vulkan # Same as vulkan1.0 |
| 162 | opengl4.5 |
| 163 | opengl # Same as opengl4.5 |
David Neto | 23bbb32 | 2019-07-02 10:17:31 -0400 | [diff] [blame] | 164 | --target-spv=<spirv-version> |
| 165 | Set the SPIR-V version to be used for the generated SPIR-V |
| 166 | module. The default is the highest version of SPIR-V |
| 167 | required to be supported for the target environment. |
| 168 | For example, default for vulkan1.0 is spv1.0, and |
David Neto | cdac124 | 2020-01-15 12:51:13 -0800 | [diff] [blame] | 169 | the default for vulkan1.1 is spv1.3, |
| 170 | the default for vulkan1.2 is spv1.5. |
David Neto | 23bbb32 | 2019-07-02 10:17:31 -0400 | [diff] [blame] | 171 | Values are: |
David Neto | 0d8908a | 2019-10-04 15:31:15 -0400 | [diff] [blame] | 172 | spv1.0, spv1.1, spv1.2, spv1.3, spv1.4, spv1.5 |
Lei Zhang | 9340ae5 | 2018-09-20 11:05:50 -0400 | [diff] [blame] | 173 | --version Display compiler version information. |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 174 | -w Suppresses all warning messages. |
| 175 | -Werror Treat all warnings as errors. |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 176 | -x <language> Treat subsequent input files as having type <language>. |
David Neto | cdefe18 | 2016-10-21 01:12:53 -0400 | [diff] [blame] | 177 | Valid languages are: glsl, hlsl. |
| 178 | For files ending in .hlsl the default is hlsl. |
| 179 | Otherwise the default is glsl. |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 180 | ''' |
| 181 | |
| 182 | expected_stderr = '' |
| 183 | |
| 184 | |
| 185 | @inside_glslc_testsuite('Parameters') |
| 186 | class HelpIsNotTooWide(expect.StdoutNoWiderThan80Columns): |
| 187 | """Tests that --help output is not too wide.""" |
| 188 | |
| 189 | glslc_args = ['--help'] |
| 190 | |
| 191 | |
| 192 | @inside_glslc_testsuite('Parameters') |
| 193 | class UnknownSingleLetterArgument(expect.ErrorMessage): |
| 194 | """Tests that an unknown argument triggers an error message.""" |
| 195 | |
| 196 | glslc_args = ['-a'] |
| 197 | expected_error = ["glslc: error: unknown argument: '-a'\n"] |
| 198 | |
| 199 | |
| 200 | @inside_glslc_testsuite('Parameters') |
| 201 | class UnknownMultiLetterArgument(expect.ErrorMessage): |
| 202 | """Tests that an unknown argument triggers an error message.""" |
| 203 | |
| 204 | glslc_args = ['-zzz'] |
| 205 | expected_error = ["glslc: error: unknown argument: '-zzz'\n"] |
| 206 | |
| 207 | |
| 208 | @inside_glslc_testsuite('Parameters') |
| 209 | class UnsupportedOption(expect.ErrorMessage): |
| 210 | """Tests that an unsupported option triggers an error message.""" |
| 211 | |
| 212 | glslc_args = ['--unsupported-option'] |
| 213 | expected_error = [ |
| 214 | "glslc: error: unsupported option: '--unsupported-option'\n"] |
| 215 | |
| 216 | |
| 217 | @inside_glslc_testsuite('File') |
| 218 | class FileNotFound(expect.ErrorMessage): |
| 219 | """Tests the error message if a file cannot be found.""" |
| 220 | |
| 221 | blabla_file = TempFileName('blabla.frag') |
| 222 | glslc_args = [blabla_file] |
| 223 | expected_error = [ |
| 224 | "glslc: error: cannot open input file: '", blabla_file, |
| 225 | "': No such file or directory\n"] |
| 226 | |
| 227 | |
| 228 | @inside_glslc_testsuite('Unsupported') |
| 229 | class LinkingNotSupported(expect.ErrorMessage): |
| 230 | """Tests the error message generated by linking not supported yet.""" |
| 231 | |
David Neto | fab6411 | 2016-02-02 16:24:06 -0500 | [diff] [blame] | 232 | shader1 = FileShader('#version 140\nvoid main() {}', '.vert') |
| 233 | shader2 = FileShader('#version 140\nvoid main() {}', '.frag') |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 234 | glslc_args = [shader1, shader2] |
| 235 | expected_error = [ |
| 236 | 'glslc: error: linking multiple files is not supported yet. ', |
| 237 | 'Use -c to compile files individually.\n'] |
| 238 | |
| 239 | |
| 240 | @inside_glslc_testsuite('Unsupported') |
| 241 | class MultipleStdinUnsupported(expect.ErrorMessage): |
| 242 | """Tests the error message generated by having more than one - input.""" |
| 243 | |
| 244 | glslc_args = ['-c', '-fshader-stage=vertex', '-', '-'] |
| 245 | expected_error = [ |
| 246 | 'glslc: error: specifying standard input "-" as input more' |
| 247 | ' than once is not allowed.\n'] |
| 248 | |
| 249 | |
| 250 | @inside_glslc_testsuite('Parameters') |
| 251 | class StdinWithoutShaderStage(expect.StdoutMatch, expect.StderrMatch): |
| 252 | """Tests that you must use -fshader-stage when specifying - as input.""" |
| 253 | shader = StdinShader( |
David Neto | fab6411 | 2016-02-02 16:24:06 -0500 | [diff] [blame] | 254 | """#version 140 |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 255 | int a() { |
| 256 | } |
| 257 | void main() { |
| 258 | int x = a(); |
| 259 | } |
| 260 | """) |
| 261 | glslc_args = [shader] |
| 262 | |
| 263 | expected_stdout = '' |
| 264 | expected_stderr = [ |
| 265 | "glslc: error: '-': -fshader-stage required when input is from " |
| 266 | 'standard input "-"\n'] |
David Neto | 2df47b5 | 2016-11-12 13:55:21 -0800 | [diff] [blame] | 267 | |
| 268 | |
| 269 | @inside_glslc_testsuite('Parameters') |
| 270 | class LimitsHelp(expect.StdoutMatch, expect.StderrMatch): |
| 271 | """Tests --show-limits shows correct output.""" |
| 272 | |
| 273 | glslc_args = ['--show-limits'] |
| 274 | |
| 275 | expected_stderr = '' |
| 276 | expected_stdout = """MaxLights 8 |
| 277 | MaxClipPlanes 6 |
| 278 | MaxTextureUnits 2 |
| 279 | MaxTextureCoords 8 |
| 280 | MaxVertexAttribs 16 |
| 281 | MaxVertexUniformComponents 4096 |
| 282 | MaxVaryingFloats 60 |
| 283 | MaxVertexTextureImageUnits 16 |
| 284 | MaxCombinedTextureImageUnits 80 |
| 285 | MaxTextureImageUnits 16 |
| 286 | MaxFragmentUniformComponents 1024 |
David Neto | ef03acd | 2017-06-30 10:30:17 -0400 | [diff] [blame] | 287 | MaxDrawBuffers 8 |
David Neto | 2df47b5 | 2016-11-12 13:55:21 -0800 | [diff] [blame] | 288 | MaxVertexUniformVectors 256 |
| 289 | MaxVaryingVectors 15 |
| 290 | MaxFragmentUniformVectors 256 |
| 291 | MaxVertexOutputVectors 16 |
| 292 | MaxFragmentInputVectors 15 |
| 293 | MinProgramTexelOffset -8 |
| 294 | MaxProgramTexelOffset 7 |
| 295 | MaxClipDistances 8 |
| 296 | MaxComputeWorkGroupCountX 65535 |
| 297 | MaxComputeWorkGroupCountY 65535 |
| 298 | MaxComputeWorkGroupCountZ 65535 |
| 299 | MaxComputeWorkGroupSizeX 1024 |
| 300 | MaxComputeWorkGroupSizeY 1024 |
| 301 | MaxComputeWorkGroupSizeZ 64 |
| 302 | MaxComputeUniformComponents 512 |
| 303 | MaxComputeTextureImageUnits 16 |
| 304 | MaxComputeImageUniforms 8 |
| 305 | MaxComputeAtomicCounters 8 |
| 306 | MaxComputeAtomicCounterBuffers 1 |
| 307 | MaxVaryingComponents 60 |
| 308 | MaxVertexOutputComponents 64 |
| 309 | MaxGeometryInputComponents 64 |
| 310 | MaxGeometryOutputComponents 128 |
| 311 | MaxFragmentInputComponents 128 |
| 312 | MaxImageUnits 8 |
| 313 | MaxCombinedImageUnitsAndFragmentOutputs 8 |
| 314 | MaxCombinedShaderOutputResources 8 |
| 315 | MaxImageSamples 0 |
| 316 | MaxVertexImageUniforms 0 |
| 317 | MaxTessControlImageUniforms 0 |
| 318 | MaxTessEvaluationImageUniforms 0 |
| 319 | MaxGeometryImageUniforms 0 |
| 320 | MaxFragmentImageUniforms 8 |
| 321 | MaxCombinedImageUniforms 8 |
| 322 | MaxGeometryTextureImageUnits 16 |
| 323 | MaxGeometryOutputVertices 256 |
| 324 | MaxGeometryTotalOutputComponents 1024 |
| 325 | MaxGeometryUniformComponents 512 |
| 326 | MaxGeometryVaryingComponents 60 |
| 327 | MaxTessControlInputComponents 128 |
| 328 | MaxTessControlOutputComponents 128 |
| 329 | MaxTessControlTextureImageUnits 16 |
| 330 | MaxTessControlUniformComponents 1024 |
| 331 | MaxTessControlTotalOutputComponents 4096 |
| 332 | MaxTessEvaluationInputComponents 128 |
| 333 | MaxTessEvaluationOutputComponents 128 |
| 334 | MaxTessEvaluationTextureImageUnits 16 |
| 335 | MaxTessEvaluationUniformComponents 1024 |
| 336 | MaxTessPatchComponents 120 |
| 337 | MaxPatchVertices 32 |
| 338 | MaxTessGenLevel 64 |
| 339 | MaxViewports 16 |
| 340 | MaxVertexAtomicCounters 0 |
| 341 | MaxTessControlAtomicCounters 0 |
| 342 | MaxTessEvaluationAtomicCounters 0 |
| 343 | MaxGeometryAtomicCounters 0 |
| 344 | MaxFragmentAtomicCounters 8 |
| 345 | MaxCombinedAtomicCounters 8 |
| 346 | MaxAtomicCounterBindings 1 |
| 347 | MaxVertexAtomicCounterBuffers 0 |
| 348 | MaxTessControlAtomicCounterBuffers 0 |
| 349 | MaxTessEvaluationAtomicCounterBuffers 0 |
| 350 | MaxGeometryAtomicCounterBuffers 0 |
| 351 | MaxFragmentAtomicCounterBuffers 0 |
| 352 | MaxCombinedAtomicCounterBuffers 1 |
| 353 | MaxAtomicCounterBufferSize 32 |
| 354 | MaxTransformFeedbackBuffers 4 |
| 355 | MaxTransformFeedbackInterleavedComponents 64 |
| 356 | MaxCullDistances 8 |
| 357 | MaxCombinedClipAndCullDistances 8 |
| 358 | MaxSamples 4 |
| 359 | """ |