Path: blob/main/glslc/test/parameter_tests.py
1560 views
# Copyright 2015 The Shaderc Authors. All rights reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License");3# you may not use this file except in compliance with the License.4# You may obtain a copy of the License at5#6# http://www.apache.org/licenses/LICENSE-2.07#8# Unless required by applicable law or agreed to in writing, software9# distributed under the License is distributed on an "AS IS" BASIS,10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11# See the License for the specific language governing permissions and12# limitations under the License.1314import expect15import os.path16from glslc_test_framework import inside_glslc_testsuite17from placeholder import FileShader, StdinShader, TempFileName181920@inside_glslc_testsuite('File')21class SimpleFileCompiled(expect.ValidObjectFile):22"""Tests whether or not a simple glsl file compiles."""2324shader = FileShader('#version 310 es\nvoid main() {}', '.frag')25glslc_args = ['-c', shader]262728@inside_glslc_testsuite('File')29class NotSpecifyingOutputName(expect.SuccessfulReturn,30expect.CorrectObjectFilePreamble):31"""Tests that when there is no -o and -E/-S/-c specified, output as a.spv."""3233shader = FileShader('#version 140\nvoid main() {}', '.frag')34glslc_args = [shader]3536def check_output_a_spv(self, status):37output_name = os.path.join(status.directory, 'a.spv')38return self.verify_object_file_preamble(output_name)394041@inside_glslc_testsuite('Parameters')42class HelpParameters(43expect.ReturnCodeIsZero, expect.StdoutMatch, expect.StderrMatch):44"""Tests the --help flag outputs correctly and does not produce and error."""4546glslc_args = ['--help']4748expected_stdout = '''glslc - Compile shaders into SPIR-V4950Usage: glslc [options] file...5152An input file of - represents standard input.5354Options:55-c Only run preprocess, compile, and assemble steps.56-Dmacro[=defn] Add an implicit macro definition.57-E Outputs only the results of the preprocessing step.58Output defaults to standard output.59-fauto-bind-uniforms60Automatically assign bindings to uniform variables that61don't have an explicit 'binding' layout in the shader62source.63-fauto-map-locations64Automatically assign locations to uniform variables that65don't have an explicit 'location' layout in the shader66source.67-fauto-combined-image-sampler68Removes sampler variables and converts existing textures69to combined image-samplers.70-fentry-point=<name>71Specify the entry point name for HLSL compilation, for72all subsequent source files. Default is "main".73-fhlsl-16bit-types74Enable 16-bit type support for HLSL.75-fhlsl_functionality1, -fhlsl-functionality176Enable extension SPV_GOOGLE_hlsl_functionality1 for HLSL77compilation.78-fhlsl-iomap Use HLSL IO mappings for bindings.79-fhlsl-offsets Use HLSL offset rules for packing members of blocks.80Affects only GLSL. HLSL rules are always used for HLSL.81-finvert-y Invert position.Y output in vertex shader.82-flimit=<settings>83Specify resource limits. Each limit is specified by a limit84name followed by an integer value. Tokens should be85separated by whitespace. If the same limit is specified86several times, only the last setting takes effect.87-flimit-file <file>88Set limits as specified in the given file.89-fnan-clamp Generate code for max and min builtins so that, when given90a NaN operand, the other operand is returned. Similarly,91the clamp builtin will favour the non-NaN operands, as if92clamp were implemented as a composition of max and min.93-fpreserve-bindings94Preserve all binding declarations, even if those bindings95are not used.96-fresource-set-binding [stage] <reg0> <set0> <binding0>97[<reg1> <set1> <binding1>...]98Explicitly sets the descriptor set and binding for99HLSL resources, by register name. Optionally restrict100it to a single stage.101-fcbuffer-binding-base [stage] <value>102Same as -fubo-binding-base.103-fimage-binding-base [stage] <value>104Sets the lowest automatically assigned binding number for105images. Optionally only set it for a single shader stage.106For HLSL, the resource register number is added to this107base.108-fsampler-binding-base [stage] <value>109Sets the lowest automatically assigned binding number for110samplers Optionally only set it for a single shader stage.111For HLSL, the resource register number is added to this112base.113-fssbo-binding-base [stage] <value>114Sets the lowest automatically assigned binding number for115shader storage buffer objects (SSBO). Optionally only set116it for a single shader stage. Only affects GLSL.117-ftexture-binding-base [stage] <value>118Sets the lowest automatically assigned binding number for119textures. Optionally only set it for a single shader stage.120For HLSL, the resource register number is added to this121base.122-fuav-binding-base [stage] <value>123For automatically assigned bindings for unordered access124views (UAV), the register number is added to this base to125determine the binding number. Optionally only set it for126a single shader stage. Only affects HLSL.127-fubo-binding-base [stage] <value>128Sets the lowest automatically assigned binding number for129uniform buffer objects (UBO). Optionally only set it for130a single shader stage.131For HLSL, the resource register number is added to this132base.133-fshader-stage=<stage>134Treat subsequent input files as having stage <stage>.135Valid stages are vertex, vert, fragment, frag, tesscontrol,136tesc, tesseval, tese, geometry, geom, compute, and comp.137-g Generate source-level debug information.138-h Display available options.139--help Display available options.140-I <value> Add directory to include search path.141-mfmt=<format> Output SPIR-V binary code using the selected format. This142option may be specified only when the compilation output is143in SPIR-V binary code form. Available options are:144bin - SPIR-V binary words. This is the default.145c - Binary words as C initializer list of 32-bit ints146num - List of comma-separated 32-bit hex integers147-M Generate make dependencies. Implies -E and -w.148-MM An alias for -M.149-MD Generate make dependencies and compile.150-MF <file> Write dependency output to the given file.151-MT <target> Specify the target of the rule emitted by dependency152generation.153-O Optimize the generated SPIR-V code for better performance.154-Os Optimize the generated SPIR-V code for smaller size.155-O0 Disable optimization.156-o <file> Write output to <file>.157A file name of '-' represents standard output.158-std=<value> Version and profile for GLSL input files. Possible values159are concatenations of version and profile, e.g. 310es,160450core, etc. Ignored for HLSL files.161-S Emit SPIR-V assembly instead of binary.162--show-limits Display available limit names and their default values.163--target-env=<environment>164Set the target client environment, and the semantics165of warnings and errors. An optional suffix can specify166the client version. Values are:167vulkan1.0 # The default168vulkan1.1169vulkan1.2170vulkan1.3171vulkan # Same as vulkan1.0172opengl4.5173opengl # Same as opengl4.5174--target-spv=<spirv-version>175Set the SPIR-V version to be used for the generated SPIR-V176module. The default is the highest version of SPIR-V177required to be supported for the target environment.178For example, default for vulkan1.0 is spv1.0, and179the default for vulkan1.1 is spv1.3,180the default for vulkan1.2 is spv1.5.181the default for vulkan1.3 is spv1.6.182Values are:183spv1.0, spv1.1, spv1.2, spv1.3, spv1.4, spv1.5, spv1.6184--version Display compiler version information.185-w Suppresses all warning messages.186-Werror Treat all warnings as errors.187-x <language> Treat subsequent input files as having type <language>.188Valid languages are: glsl, hlsl.189For files ending in .hlsl the default is hlsl.190Otherwise the default is glsl.191'''192193expected_stderr = ''194195196@inside_glslc_testsuite('Parameters')197class HelpIsNotTooWide(expect.StdoutNoWiderThan80Columns):198"""Tests that --help output is not too wide."""199200glslc_args = ['--help']201202203@inside_glslc_testsuite('Parameters')204class UnknownSingleLetterArgument(expect.ErrorMessage):205"""Tests that an unknown argument triggers an error message."""206207glslc_args = ['-a']208expected_error = ["glslc: error: unknown argument: '-a'\n"]209210211@inside_glslc_testsuite('Parameters')212class UnknownMultiLetterArgument(expect.ErrorMessage):213"""Tests that an unknown argument triggers an error message."""214215glslc_args = ['-zzz']216expected_error = ["glslc: error: unknown argument: '-zzz'\n"]217218219@inside_glslc_testsuite('Parameters')220class UnsupportedOption(expect.ErrorMessage):221"""Tests that an unsupported option triggers an error message."""222223glslc_args = ['--unsupported-option']224expected_error = [225"glslc: error: unsupported option: '--unsupported-option'\n"]226227228@inside_glslc_testsuite('File')229class FileNotFound(expect.ErrorMessage):230"""Tests the error message if a file cannot be found."""231232blabla_file = TempFileName('blabla.frag')233glslc_args = [blabla_file]234expected_error = [235"glslc: error: cannot open input file: '", blabla_file,236"': No such file or directory\n"]237238239@inside_glslc_testsuite('Unsupported')240class LinkingNotSupported(expect.ErrorMessage):241"""Tests the error message generated by linking not supported yet."""242243shader1 = FileShader('#version 140\nvoid main() {}', '.vert')244shader2 = FileShader('#version 140\nvoid main() {}', '.frag')245glslc_args = [shader1, shader2]246expected_error = [247'glslc: error: linking multiple files is not supported yet. ',248'Use -c to compile files individually.\n']249250251@inside_glslc_testsuite('Unsupported')252class MultipleStdinUnsupported(expect.ErrorMessage):253"""Tests the error message generated by having more than one - input."""254255glslc_args = ['-c', '-fshader-stage=vertex', '-', '-']256expected_error = [257'glslc: error: specifying standard input "-" as input more'258' than once is not allowed.\n']259260261@inside_glslc_testsuite('Parameters')262class StdinWithoutShaderStage(expect.StdoutMatch, expect.StderrMatch):263"""Tests that you must use -fshader-stage when specifying - as input."""264shader = StdinShader(265"""#version 140266int a() {267}268void main() {269int x = a();270}271""")272glslc_args = [shader]273274expected_stdout = ''275expected_stderr = [276"glslc: error: '-': -fshader-stage required when input is from "277'standard input "-"\n']278279280@inside_glslc_testsuite('Parameters')281class LimitsHelp(expect.StdoutMatch, expect.StderrMatch):282"""Tests --show-limits shows correct output."""283284glslc_args = ['--show-limits']285286expected_stderr = ''287expected_stdout = """MaxLights 8288MaxClipPlanes 6289MaxTextureUnits 2290MaxTextureCoords 8291MaxVertexAttribs 16292MaxVertexUniformComponents 4096293MaxVaryingFloats 60294MaxVertexTextureImageUnits 16295MaxCombinedTextureImageUnits 80296MaxTextureImageUnits 16297MaxFragmentUniformComponents 1024298MaxDrawBuffers 8299MaxVertexUniformVectors 256300MaxVaryingVectors 15301MaxFragmentUniformVectors 256302MaxVertexOutputVectors 16303MaxFragmentInputVectors 15304MinProgramTexelOffset -8305MaxProgramTexelOffset 7306MaxClipDistances 8307MaxComputeWorkGroupCountX 65535308MaxComputeWorkGroupCountY 65535309MaxComputeWorkGroupCountZ 65535310MaxComputeWorkGroupSizeX 1024311MaxComputeWorkGroupSizeY 1024312MaxComputeWorkGroupSizeZ 64313MaxComputeUniformComponents 512314MaxComputeTextureImageUnits 16315MaxComputeImageUniforms 8316MaxComputeAtomicCounters 8317MaxComputeAtomicCounterBuffers 1318MaxVaryingComponents 60319MaxVertexOutputComponents 64320MaxGeometryInputComponents 64321MaxGeometryOutputComponents 128322MaxFragmentInputComponents 128323MaxImageUnits 8324MaxCombinedImageUnitsAndFragmentOutputs 8325MaxCombinedShaderOutputResources 8326MaxImageSamples 0327MaxVertexImageUniforms 0328MaxTessControlImageUniforms 0329MaxTessEvaluationImageUniforms 0330MaxGeometryImageUniforms 0331MaxFragmentImageUniforms 8332MaxCombinedImageUniforms 8333MaxGeometryTextureImageUnits 16334MaxGeometryOutputVertices 256335MaxGeometryTotalOutputComponents 1024336MaxGeometryUniformComponents 512337MaxGeometryVaryingComponents 60338MaxTessControlInputComponents 128339MaxTessControlOutputComponents 128340MaxTessControlTextureImageUnits 16341MaxTessControlUniformComponents 1024342MaxTessControlTotalOutputComponents 4096343MaxTessEvaluationInputComponents 128344MaxTessEvaluationOutputComponents 128345MaxTessEvaluationTextureImageUnits 16346MaxTessEvaluationUniformComponents 1024347MaxTessPatchComponents 120348MaxPatchVertices 32349MaxTessGenLevel 64350MaxViewports 16351MaxVertexAtomicCounters 0352MaxTessControlAtomicCounters 0353MaxTessEvaluationAtomicCounters 0354MaxGeometryAtomicCounters 0355MaxFragmentAtomicCounters 8356MaxCombinedAtomicCounters 8357MaxAtomicCounterBindings 1358MaxVertexAtomicCounterBuffers 0359MaxTessControlAtomicCounterBuffers 0360MaxTessEvaluationAtomicCounterBuffers 0361MaxGeometryAtomicCounterBuffers 0362MaxFragmentAtomicCounterBuffers 0363MaxCombinedAtomicCounterBuffers 1364MaxAtomicCounterBufferSize 32365MaxTransformFeedbackBuffers 4366MaxTransformFeedbackInterleavedComponents 64367MaxCullDistances 8368MaxCombinedClipAndCullDistances 8369MaxSamples 4370MaxMeshOutputVerticesNV 256371MaxMeshOutputPrimitivesNV 512372MaxMeshWorkGroupSizeX_NV 32373MaxMeshWorkGroupSizeY_NV 1374MaxMeshWorkGroupSizeZ_NV 1375MaxTaskWorkGroupSizeX_NV 32376MaxTaskWorkGroupSizeY_NV 1377MaxTaskWorkGroupSizeZ_NV 1378MaxMeshViewCountNV 4379MaxMeshOutputVerticesEXT 256380MaxMeshOutputPrimitivesEXT 256381MaxMeshWorkGroupSizeX_EXT 128382MaxMeshWorkGroupSizeY_EXT 128383MaxMeshWorkGroupSizeZ_EXT 128384MaxTaskWorkGroupSizeX_EXT 128385MaxTaskWorkGroupSizeY_EXT 128386MaxTaskWorkGroupSizeZ_EXT 128387MaxMeshViewCountEXT 4388MaxDualSourceDrawBuffersEXT 1389"""390391392