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. |
David Neto | 63313f9 | 2017-06-07 09:15:34 -0700 | [diff] [blame] | 68 | -fhlsl-iomap Use HLSL IO mappings for bindings. |
David Neto | 5fd1b25 | 2018-04-13 16:27:04 -0400 | [diff] [blame^] | 69 | -fhlsl_functionality1, -fhlsl-functionality1 |
| 70 | Enable extension SPV_GOOGLE_hlsl_functionality1 for HLSL |
| 71 | compilation. |
David Neto | 357d24b | 2017-06-04 18:27:12 -0400 | [diff] [blame] | 72 | -fimage-binding-base [stage] <value> |
David Neto | a290067 | 2017-01-28 13:03:24 -0800 | [diff] [blame] | 73 | Sets the lowest automatically assigned binding number for |
David Neto | 357d24b | 2017-06-04 18:27:12 -0400 | [diff] [blame] | 74 | images. Optionally only set it for a single shader stage. |
David Neto | 63313f9 | 2017-06-07 09:15:34 -0700 | [diff] [blame] | 75 | For HLSL, the resource register number is added to this |
| 76 | base. |
David Neto | 357d24b | 2017-06-04 18:27:12 -0400 | [diff] [blame] | 77 | -ftexture-binding-base [stage] <value> |
David Neto | a290067 | 2017-01-28 13:03:24 -0800 | [diff] [blame] | 78 | Sets the lowest automatically assigned binding number for |
David Neto | 357d24b | 2017-06-04 18:27:12 -0400 | [diff] [blame] | 79 | textures. Optionally only set it for a single shader stage. |
David Neto | 63313f9 | 2017-06-07 09:15:34 -0700 | [diff] [blame] | 80 | For HLSL, the resource register number is added to this |
| 81 | base. |
David Neto | 357d24b | 2017-06-04 18:27:12 -0400 | [diff] [blame] | 82 | -fsampler-binding-base [stage] <value> |
David Neto | a290067 | 2017-01-28 13:03:24 -0800 | [diff] [blame] | 83 | Sets the lowest automatically assigned binding number for |
David Neto | 357d24b | 2017-06-04 18:27:12 -0400 | [diff] [blame] | 84 | samplers Optionally only set it for a single shader stage. |
David Neto | 63313f9 | 2017-06-07 09:15:34 -0700 | [diff] [blame] | 85 | For HLSL, the resource register number is added to this |
| 86 | base. |
David Neto | 357d24b | 2017-06-04 18:27:12 -0400 | [diff] [blame] | 87 | -fubo-binding-base [stage] <value> |
David Neto | a290067 | 2017-01-28 13:03:24 -0800 | [diff] [blame] | 88 | Sets the lowest automatically assigned binding number for |
David Neto | 357d24b | 2017-06-04 18:27:12 -0400 | [diff] [blame] | 89 | uniform buffer objects (UBO). Optionally only set it for |
| 90 | a single shader stage. |
David Neto | 63313f9 | 2017-06-07 09:15:34 -0700 | [diff] [blame] | 91 | For HLSL, the resource register number is added to this |
| 92 | base. |
David Neto | cdcc015 | 2017-06-04 19:53:34 -0400 | [diff] [blame] | 93 | -fcbuffer-binding-base [stage] <value> |
| 94 | Same as -fubo-binding-base. |
| 95 | -fssbo-binding-base [stage] <value> |
| 96 | Sets the lowest automatically assigned binding number for |
| 97 | shader storage buffer objects (SSBO). Optionally only set |
| 98 | it for a single shader stage. Only affects GLSL. |
David Neto | 63313f9 | 2017-06-07 09:15:34 -0700 | [diff] [blame] | 99 | -fuav-binding-base [stage] <value> |
| 100 | For automatically assigned bindings for unordered access |
| 101 | views (UAV), the register number is added to this base to |
| 102 | determine the binding number. Optionally only set it for |
| 103 | a single shader stage. Only affects HLSL. |
David Neto | 63d0f82 | 2017-06-10 01:11:51 -0700 | [diff] [blame] | 104 | -fresource-set-binding [stage] <reg0> <set0> <binding0> |
| 105 | [<reg1> <set1> <binding1>...] |
| 106 | Explicitly sets the descriptor set and binding for |
| 107 | HLSL resources, by register name. Optionally restrict |
| 108 | it to a single stage. |
David Neto | 2df47b5 | 2016-11-12 13:55:21 -0800 | [diff] [blame] | 109 | -fentry-point=<name> |
| 110 | Specify the entry point name for HLSL compilation, for |
| 111 | all subsequent source files. Default is "main". |
| 112 | -flimit=<settings> |
| 113 | Specify resource limits. Each limit is specified by a limit |
| 114 | name followed by an integer value. Tokens should be |
| 115 | separated by whitespace. If the same limit is specified |
| 116 | several times, only the last setting takes effect. |
| 117 | --show-limits Display available limit names and their default values. |
| 118 | -flimit-file <file> |
| 119 | Set limits as specified in the given file. |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 120 | -fshader-stage=<stage> |
| 121 | Treat subsequent input files as having stage <stage>. |
David Neto | 357d24b | 2017-06-04 18:27:12 -0400 | [diff] [blame] | 122 | Valid stages are vertex, vert, fragment, frag, tesscontrol, |
| 123 | tesc, tesseval, tese, geometry, geom, compute, and comp. |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 124 | -g Generate source-level debug information. |
| 125 | Currently this option has no effect. |
| 126 | --help Display available options. |
Dejan Mircevski | 2917445 | 2016-02-18 18:11:57 -0500 | [diff] [blame] | 127 | --version Display compiler version information. |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 128 | -I <value> Add directory to include search path. |
| 129 | -o <file> Write output to <file>. |
| 130 | A file name of '-' represents standard output. |
David Neto | cdefe18 | 2016-10-21 01:12:53 -0400 | [diff] [blame] | 131 | -std=<value> Version and profile for GLSL input files. Possible values |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 132 | are concatenations of version and profile, e.g. 310es, |
David Neto | cdefe18 | 2016-10-21 01:12:53 -0400 | [diff] [blame] | 133 | 450core, etc. Ignored for HLSL files. |
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. |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 144 | -S Only run preprocess and compilation steps. |
qining | f6d8374 | 2016-01-28 16:05:11 -0500 | [diff] [blame] | 145 | --target-env=<environment> |
David Neto | c993158 | 2018-03-22 07:32:14 -0700 | [diff] [blame] | 146 | Set the target client environment, and the semantics |
| 147 | of warnings and errors. An optional suffix can specify |
| 148 | the client version. Values are: |
| 149 | vulkan1.0 # The default |
| 150 | vulkan1.1 |
| 151 | vulkan # Same as vulkan1.0 |
| 152 | opengl4.5 |
| 153 | opengl # Same as opengl4.5 |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 154 | -w Suppresses all warning messages. |
| 155 | -Werror Treat all warnings as errors. |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 156 | -x <language> Treat subsequent input files as having type <language>. |
David Neto | cdefe18 | 2016-10-21 01:12:53 -0400 | [diff] [blame] | 157 | Valid languages are: glsl, hlsl. |
| 158 | For files ending in .hlsl the default is hlsl. |
| 159 | Otherwise the default is glsl. |
David Neto | 44dff89 | 2017-06-08 00:15:58 -0700 | [diff] [blame] | 160 | -fhlsl-offsets Use HLSL offset rules for packing members of blocks. |
| 161 | Affects only GLSL. HLSL rules are always used for HLSL. |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 162 | ''' |
| 163 | |
| 164 | expected_stderr = '' |
| 165 | |
| 166 | |
| 167 | @inside_glslc_testsuite('Parameters') |
| 168 | class HelpIsNotTooWide(expect.StdoutNoWiderThan80Columns): |
| 169 | """Tests that --help output is not too wide.""" |
| 170 | |
| 171 | glslc_args = ['--help'] |
| 172 | |
| 173 | |
| 174 | @inside_glslc_testsuite('Parameters') |
| 175 | class UnknownSingleLetterArgument(expect.ErrorMessage): |
| 176 | """Tests that an unknown argument triggers an error message.""" |
| 177 | |
| 178 | glslc_args = ['-a'] |
| 179 | expected_error = ["glslc: error: unknown argument: '-a'\n"] |
| 180 | |
| 181 | |
| 182 | @inside_glslc_testsuite('Parameters') |
| 183 | class UnknownMultiLetterArgument(expect.ErrorMessage): |
| 184 | """Tests that an unknown argument triggers an error message.""" |
| 185 | |
| 186 | glslc_args = ['-zzz'] |
| 187 | expected_error = ["glslc: error: unknown argument: '-zzz'\n"] |
| 188 | |
| 189 | |
| 190 | @inside_glslc_testsuite('Parameters') |
| 191 | class UnsupportedOption(expect.ErrorMessage): |
| 192 | """Tests that an unsupported option triggers an error message.""" |
| 193 | |
| 194 | glslc_args = ['--unsupported-option'] |
| 195 | expected_error = [ |
| 196 | "glslc: error: unsupported option: '--unsupported-option'\n"] |
| 197 | |
| 198 | |
| 199 | @inside_glslc_testsuite('File') |
| 200 | class FileNotFound(expect.ErrorMessage): |
| 201 | """Tests the error message if a file cannot be found.""" |
| 202 | |
| 203 | blabla_file = TempFileName('blabla.frag') |
| 204 | glslc_args = [blabla_file] |
| 205 | expected_error = [ |
| 206 | "glslc: error: cannot open input file: '", blabla_file, |
| 207 | "': No such file or directory\n"] |
| 208 | |
| 209 | |
| 210 | @inside_glslc_testsuite('Unsupported') |
| 211 | class LinkingNotSupported(expect.ErrorMessage): |
| 212 | """Tests the error message generated by linking not supported yet.""" |
| 213 | |
David Neto | fab6411 | 2016-02-02 16:24:06 -0500 | [diff] [blame] | 214 | shader1 = FileShader('#version 140\nvoid main() {}', '.vert') |
| 215 | shader2 = FileShader('#version 140\nvoid main() {}', '.frag') |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 216 | glslc_args = [shader1, shader2] |
| 217 | expected_error = [ |
| 218 | 'glslc: error: linking multiple files is not supported yet. ', |
| 219 | 'Use -c to compile files individually.\n'] |
| 220 | |
| 221 | |
| 222 | @inside_glslc_testsuite('Unsupported') |
| 223 | class MultipleStdinUnsupported(expect.ErrorMessage): |
| 224 | """Tests the error message generated by having more than one - input.""" |
| 225 | |
| 226 | glslc_args = ['-c', '-fshader-stage=vertex', '-', '-'] |
| 227 | expected_error = [ |
| 228 | 'glslc: error: specifying standard input "-" as input more' |
| 229 | ' than once is not allowed.\n'] |
| 230 | |
| 231 | |
| 232 | @inside_glslc_testsuite('Parameters') |
| 233 | class StdinWithoutShaderStage(expect.StdoutMatch, expect.StderrMatch): |
| 234 | """Tests that you must use -fshader-stage when specifying - as input.""" |
| 235 | shader = StdinShader( |
David Neto | fab6411 | 2016-02-02 16:24:06 -0500 | [diff] [blame] | 236 | """#version 140 |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 237 | int a() { |
| 238 | } |
| 239 | void main() { |
| 240 | int x = a(); |
| 241 | } |
| 242 | """) |
| 243 | glslc_args = [shader] |
| 244 | |
| 245 | expected_stdout = '' |
| 246 | expected_stderr = [ |
| 247 | "glslc: error: '-': -fshader-stage required when input is from " |
| 248 | 'standard input "-"\n'] |
David Neto | 2df47b5 | 2016-11-12 13:55:21 -0800 | [diff] [blame] | 249 | |
| 250 | |
| 251 | @inside_glslc_testsuite('Parameters') |
| 252 | class LimitsHelp(expect.StdoutMatch, expect.StderrMatch): |
| 253 | """Tests --show-limits shows correct output.""" |
| 254 | |
| 255 | glslc_args = ['--show-limits'] |
| 256 | |
| 257 | expected_stderr = '' |
| 258 | expected_stdout = """MaxLights 8 |
| 259 | MaxClipPlanes 6 |
| 260 | MaxTextureUnits 2 |
| 261 | MaxTextureCoords 8 |
| 262 | MaxVertexAttribs 16 |
| 263 | MaxVertexUniformComponents 4096 |
| 264 | MaxVaryingFloats 60 |
| 265 | MaxVertexTextureImageUnits 16 |
| 266 | MaxCombinedTextureImageUnits 80 |
| 267 | MaxTextureImageUnits 16 |
| 268 | MaxFragmentUniformComponents 1024 |
David Neto | ef03acd | 2017-06-30 10:30:17 -0400 | [diff] [blame] | 269 | MaxDrawBuffers 8 |
David Neto | 2df47b5 | 2016-11-12 13:55:21 -0800 | [diff] [blame] | 270 | MaxVertexUniformVectors 256 |
| 271 | MaxVaryingVectors 15 |
| 272 | MaxFragmentUniformVectors 256 |
| 273 | MaxVertexOutputVectors 16 |
| 274 | MaxFragmentInputVectors 15 |
| 275 | MinProgramTexelOffset -8 |
| 276 | MaxProgramTexelOffset 7 |
| 277 | MaxClipDistances 8 |
| 278 | MaxComputeWorkGroupCountX 65535 |
| 279 | MaxComputeWorkGroupCountY 65535 |
| 280 | MaxComputeWorkGroupCountZ 65535 |
| 281 | MaxComputeWorkGroupSizeX 1024 |
| 282 | MaxComputeWorkGroupSizeY 1024 |
| 283 | MaxComputeWorkGroupSizeZ 64 |
| 284 | MaxComputeUniformComponents 512 |
| 285 | MaxComputeTextureImageUnits 16 |
| 286 | MaxComputeImageUniforms 8 |
| 287 | MaxComputeAtomicCounters 8 |
| 288 | MaxComputeAtomicCounterBuffers 1 |
| 289 | MaxVaryingComponents 60 |
| 290 | MaxVertexOutputComponents 64 |
| 291 | MaxGeometryInputComponents 64 |
| 292 | MaxGeometryOutputComponents 128 |
| 293 | MaxFragmentInputComponents 128 |
| 294 | MaxImageUnits 8 |
| 295 | MaxCombinedImageUnitsAndFragmentOutputs 8 |
| 296 | MaxCombinedShaderOutputResources 8 |
| 297 | MaxImageSamples 0 |
| 298 | MaxVertexImageUniforms 0 |
| 299 | MaxTessControlImageUniforms 0 |
| 300 | MaxTessEvaluationImageUniforms 0 |
| 301 | MaxGeometryImageUniforms 0 |
| 302 | MaxFragmentImageUniforms 8 |
| 303 | MaxCombinedImageUniforms 8 |
| 304 | MaxGeometryTextureImageUnits 16 |
| 305 | MaxGeometryOutputVertices 256 |
| 306 | MaxGeometryTotalOutputComponents 1024 |
| 307 | MaxGeometryUniformComponents 512 |
| 308 | MaxGeometryVaryingComponents 60 |
| 309 | MaxTessControlInputComponents 128 |
| 310 | MaxTessControlOutputComponents 128 |
| 311 | MaxTessControlTextureImageUnits 16 |
| 312 | MaxTessControlUniformComponents 1024 |
| 313 | MaxTessControlTotalOutputComponents 4096 |
| 314 | MaxTessEvaluationInputComponents 128 |
| 315 | MaxTessEvaluationOutputComponents 128 |
| 316 | MaxTessEvaluationTextureImageUnits 16 |
| 317 | MaxTessEvaluationUniformComponents 1024 |
| 318 | MaxTessPatchComponents 120 |
| 319 | MaxPatchVertices 32 |
| 320 | MaxTessGenLevel 64 |
| 321 | MaxViewports 16 |
| 322 | MaxVertexAtomicCounters 0 |
| 323 | MaxTessControlAtomicCounters 0 |
| 324 | MaxTessEvaluationAtomicCounters 0 |
| 325 | MaxGeometryAtomicCounters 0 |
| 326 | MaxFragmentAtomicCounters 8 |
| 327 | MaxCombinedAtomicCounters 8 |
| 328 | MaxAtomicCounterBindings 1 |
| 329 | MaxVertexAtomicCounterBuffers 0 |
| 330 | MaxTessControlAtomicCounterBuffers 0 |
| 331 | MaxTessEvaluationAtomicCounterBuffers 0 |
| 332 | MaxGeometryAtomicCounterBuffers 0 |
| 333 | MaxFragmentAtomicCounterBuffers 0 |
| 334 | MaxCombinedAtomicCounterBuffers 1 |
| 335 | MaxAtomicCounterBufferSize 32 |
| 336 | MaxTransformFeedbackBuffers 4 |
| 337 | MaxTransformFeedbackInterleavedComponents 64 |
| 338 | MaxCullDistances 8 |
| 339 | MaxCombinedClipAndCullDistances 8 |
| 340 | MaxSamples 4 |
| 341 | """ |