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