Ejemplo n.º 1
0
class TestDashCapMSingleInputAbsolutePathNoInclude(DependencyInfoStdoutMatch):
    """Tests -M with single input file which doesn't contain #include and is
    represented in absolute path.
    e.g. glslc -M /usr/local/shader.vert
      => shader.vert.spv: /usr/local/shader.vert
    """
    shader = FileShader(MINIMAL_SHADER, '.vert')
    glslc_args = ['-M', shader]
    dependency_rules_expected = [{'target': shader,
                                  'target_extension': '.spv',
                                  'dependency': {shader}}]
Ejemplo n.º 2
0
class TestSpaceAroundVersion(expect.ValidObjectFileWithWarning):
    """Tests that space around #version is correctly handled."""

    shader = FileShader(
        '\t   \t  # \t \f\f version  \v \t\t  310 \v\v \t  es \n' +
        core_vert_shader_without_version(), '.vert')
    glslc_args = ['-c', '-std=450core', shader]

    expected_warning = [
        shader, ': warning: (version, profile) forced to be (450, core), while '
                'in source code it is (310, es)\n1 warning generated.\n']
class HlslFTextureBindingBaseOptionRespected(expect.ValidAssemblyFileWithSubstr
                                             ):
    """Tests that -ftexture-binding-base sets binding base for textures in HLSL
    compilation."""

    shader = FileShader(HLSL_SHADER_WITHOUT_BINDINGS, '.frag')
    glslc_args = [
        '-S', '-x', 'hlsl', '-fhlsl-iomap', shader, '-ftexture-binding-base',
        '100'
    ]
    expected_assembly_substr = "OpDecorate %t6 Binding 116"
Ejemplo n.º 4
0
class TestSpacesAroundPSS(expect.ValidObjectFile):
    """Tests that spaces around #pragma shader_stage() works."""

    shader = FileShader(
        """#version 310 es
               #     pragma      shader_stage     (    vertex     )
        void main() {
            gl_Position = vec4(1.);
        }
        """, '.glsl')
    glslc_args = ['-c', shader]
Ejemplo n.º 5
0
class FImageBindingBaseForVertOptionIgnoredOnImageCompileAsFrag(
        expect.ValidAssemblyFileWithSubstr):
    """Tests that -fimage-binding-base with vert stage value is ignored when cmopiled as
    fragment."""

    shader = FileShader(GLSL_SHADER_WITH_UNIFORMS_WITHOUT_BINDINGS, '.frag')
    glslc_args = [
        '-S', shader, '-fauto-bind-uniforms', '-fimage-binding-base', 'vert',
        '44'
    ]
    expected_assembly_substr = "OpDecorate %my_img Binding 2"
Ejemplo n.º 6
0
class FSsboBindingBaseForFragOptionIgnoredOnSsboCompileAsVert(
        expect.ValidAssemblyFileWithSubstr):
    """Tests that -fssbo-binding-base with frag stage value is ignored on SSBOs
    when compiling as a vertex shader."""

    shader = FileShader(GLSL_SHADER_WITH_UNIFORMS_WITHOUT_BINDINGS, '.vert')
    glslc_args = [
        '-S', shader, '-fauto-bind-uniforms', '-fssbo-binding-base', 'frag',
        '100'
    ]
    expected_assembly_substr = "OpDecorate %my_ssbo Binding 5"
Ejemplo n.º 7
0
class TestShaderStageWithAssemblyFile(expect.ErrorMessage):
    """Tests that assembly files don't work with -fshader-stage"""

    shader = FileShader(empty_main_assembly(), '.spvasm')
    glslc_args = ['-c', '-fshader-stage=vertex', shader]

    expected_error = [
        shader, ": error: #version: Desktop shaders for Vulkan SPIR-V require "
        "version 140 or higher\n", shader, ":2: error: '' :  syntax error\n",
        '2 errors generated.\n'
    ]
Ejemplo n.º 8
0
class TestCommentBeforeVersion(expect.ValidObjectFileWithWarning):
    """Tests that comments before #version (same line) is correctly handled."""

    shader = FileShader(
        '/* some comment */ #version 150\n' +
        core_vert_shader_without_version(), '.vert')
    glslc_args = ['-c', '-std=450', shader]

    expected_warning = [
        shader, ': warning: (version, profile) forced to be (450, none), while '
                'in source code it is (150, none)\n1 warning generated.\n']
Ejemplo n.º 9
0
class HlslFSamplerBindingBaseForFragOptionRespected(
        expect.ValidAssemblyFileWithSubstr):
    """Tests that -fsampler-binding-base for frag sets binding base for samplers
    in HLSL compilation."""

    shader = FileShader(HLSL_SHADER_WITHOUT_BINDINGS, '.frag')
    glslc_args = [
        '-S', '-x', 'hlsl', '-fhlsl-iomap', shader, '-fsampler-binding-base',
        'frag', '100'
    ]
    expected_assembly_substr = "OpDecorate %s2 Binding 102"
Ejemplo n.º 10
0
class HlslFSamplerBindingBaseForComputeOptionIgnoredWhenCompilingAsFrag(
        expect.ValidAssemblyFileWithSubstr):
    """Tests that -fsampler-binding-base for compute is ignored when compiling
    as a fragment shader."""

    shader = FileShader(HLSL_SHADER_WITHOUT_BINDINGS, '.frag')
    glslc_args = [
        '-S', '-x', 'hlsl', '-fhlsl-iomap', shader, '-fsampler-binding-base',
        'compute', '100'
    ]
    expected_assembly_substr = "OpDecorate %s2 Binding 2"
Ejemplo n.º 11
0
class SuppressedWarningOnLine(expect.SuccessfulReturn):
    """Tests that a warning message with a file/line number is suppressed in the
    presence of -w."""

    shader = FileShader(
        """#version 400
    layout(location = 0) attribute float x;
    void main() {
    }
    """, '.vert')
    glslc_args = ['-c', shader, '-w']
Ejemplo n.º 12
0
class FailureToMakeOutputFileAsCurrentDirIsErrorWithNoOutputFile(
        expect.NoNamedOutputFiles, expect.NoOutputOnStdout,
        expect.ErrorMessageSubstr):
    """Tests that if we fail to make an output file because it is the current
    directory, then no file is generated, and we have certain error messages."""

    shader = FileShader('#version 150\nvoid main() {}', '.frag')
    bad_file = '.'  # Current directory
    glslc_args = ['-c', shader, '-o', bad_file]
    expected_output_filenames = [bad_file]
    expected_error_substr = ['cannot open output file']
Ejemplo n.º 13
0
class TestTabsAroundPSS(expect.ValidObjectFile):
    """Tests that tabs around #pragma shader_stage() works."""

    shader = FileShader(
        """#version 310 es
        \t\t#\tpragma\t\t\tshader_stage\t\t(\t\t\t\tvertex\t\t)\t\t\t\t
        void main() {
            gl_Position = vec4(1.);
        }
        """, '.glsl')
    glslc_args = ['-c', shader]
Ejemplo n.º 14
0
class TestDashCapDWithDashE(expect.ReturnCodeIsZero, expect.StdoutMatch):
    """Tests -E outputs expanded -D macros."""

    shader = FileShader("""
        void main(){Y}
""", '.vert')
    glslc_args = ['-DY=return 3;', '-E', '-std=450core', shader]

    expected_stdout = ["""
        void main(){ return 3;}
"""]
Ejemplo n.º 15
0
class TestDashCapDReservedMacro(expect.WarningMessage):
    """Tests that we cannot -D GLSL's predefined macros."""

    shader = FileShader('void main(){}', '.vert')
    # Consecutive underscores are banned anywhere in the name.
    glslc_args = [
        '-D__LINE__=1', '-Dmid__dle', '-Dend__', '-D_single_is_valid_', shader
    ]

    w = 'glslc: warning: names containing consecutive underscores are reserved: '
    expected_warning = [w, '-D__LINE__=1\n', w, '-Dmid__dle\n', w, '-Dend__\n']
Ejemplo n.º 16
0
class TestCommentAfterVersion(expect.ValidObjectFileWithWarning):
    """Tests that multiple-line comments after #version is correctly handled."""

    shader = FileShader(
        '#version 150 compatibility ' +
        '/* start \n second line \n end */\n' +
        core_vert_shader_without_version(), '.vert')
    glslc_args = ['-c', '-std=450core', shader]

    expected_warning = [
        shader, ': warning: (version, profile) forced to be (450, core), while '
                'in source code it is (150, compatibility)\n1 warning generated.\n']
Ejemplo n.º 17
0
class TestDashCapDWithDashENestedMacro(expect.ReturnCodeIsZero,
                                       expect.StdoutMatch):
    """Tests -E processes referencing -D options correctly."""

    shader = FileShader("""
        void main(){ return X;}
""", '.vert')
    glslc_args = ['-DY=4', '-DX=Y', '-E', '-std=450core', shader]

    expected_stdout = ["""
        void main(){ return 4;}
"""]
Ejemplo n.º 18
0
class FailureToMakeOutputFileIsErrorWithNoOutputFile(expect.NoNamedOutputFiles,
                                                     expect.NoOutputOnStdout,
                                                     expect.ErrorMessageSubstr
                                                     ):
    """Tests that if we fail to make an output file, no file is generated,
    and we have certain error messages."""

    shader = FileShader('#version 150\nvoid main() {}', '.frag')
    bad_file = '/file/should/not/exist/today'
    glslc_args = ['-c', shader, '-o', bad_file]
    expected_output_filenames = [bad_file]
    expected_error_substr = ['cannot open output file']
Ejemplo n.º 19
0
class TestDashCapDWithDashEFunctionMacro(expect.ReturnCodeIsZero,
                                         expect.StdoutMatch):
    """Tests -E processes -D function macros correctly."""

    shader = FileShader("""
        void main(){ return FOO(3);}
""", '.vert')
    glslc_args = ['-DFOO(x)=(2*x+1)*x*x', '-E', '-std=450core', shader]

    expected_stdout = ["""
        void main(){ return(2 * 3 + 1)* 3 * 3;}
"""]
Ejemplo n.º 20
0
class TestConflictingVersionAndStd(expect.ValidObjectFileWithWarning):
    """Tests that with both #version and -std, -std takes precedence."""

    # Wrong #version here on purpose.
    shader = FileShader(
        '#version 310 es\n' + core_frag_shader_without_version(), '.frag')
    # -std overwrites the wrong #version.
    glslc_args = ['-c', '-std=450core', shader]

    expected_warning = [
        shader, ': warning: (version, profile) forced to be (450, core), while '
                'in source code it is (310, es)\n1 warning generated.\n']
Ejemplo n.º 21
0
class TestOSSOverridePSS(expect.ValidObjectFile):
    """Tests that -fshader-stage overrides #pragma shader_stage()."""

    # wrong pragma and wrong file extension
    shader = FileShader(
        """#version 310 es
        #pragma shader_stage(fragment)
        void main() {
            gl_Position = vec4(1.);
        }""", '.frag')
    # -fshader-stage to the rescue! ^.^
    glslc_args = ['-c', '-fshader-stage=vertex', shader]
Ejemplo n.º 22
0
class GlobalWarning(expect.WarningMessage):
    """Tests that a warning message without file/line number is emitted."""

    shader = FileShader(
        """#version 550
    void main() {
    }
    """, '.vert')
    glslc_args = ['-c', shader]

    expected_warning = [
        shader, ': warning: version 550 is unknown.\n1 warning generated.\n']
Ejemplo n.º 23
0
class TestShaderStageWithAssemblyFile(expect.ErrorMessage):
    """Tests that assembly files don't work with -fshader-stage"""

    shader = FileShader(empty_main_assembly(), '.spvasm')
    glslc_args = ['-c', '-fshader-stage=vertex', shader]

    expected_error = [
        shader, ": error: #version: Desktop shaders for Vulkan SPIR-V require "
        "version 140 or higher\n",
        shader, ":2: error: 'extraneous semicolon' :",
        " not supported for this version or the enabled extensions\n",
        shader, ":2: error: '' :  syntax error, unexpected IDENTIFIER\n",
        '3 errors generated.\n']
Ejemplo n.º 24
0
class GlobalWarningAsError(expect.ErrorMessage):
    """Tests that with -Werror an error warning message without file/line
    number is emitted instead of a warning."""

    shader = FileShader(
        """#version 550
    void main() {
    }
    """, '.vert')
    glslc_args = ['-c', shader, '-Werror']

    expected_error= [
        shader, ': error: version 550 is unknown.\n1 error generated.\n']
Ejemplo n.º 25
0
class GlobalWarning(expect.WarningMessage):
    """Tests that a warning message without file/line number is emitted."""

    shader = FileShader(
        """#version 550
    void main() {
    }
    """, '.vert')
    glslc_args = ['-c', '-std=400', shader]

    expected_warning = [
        shader, ': warning: (version, profile) forced to be (400, none),'
                ' while in source code it is (550, none)\n1 warning generated.\n']
Ejemplo n.º 26
0
class TestVersionInsideSlashStarComment(expect.ValidObjectFileWithWarning):
    """Tests that -std substitutes the correct #version string."""

    # The second #version string should be substituted and this shader
    # should compile successfully with -std=450core.
    shader = FileShader(
        '/* #version 310 es */\n#version 310 es\n' +
        core_vert_shader_without_version(), '.vert')
    glslc_args = ['-c', '-std=450core', shader]

    expected_warning = [
        shader, ': warning: (version, profile) forced to be (450, core), while '
                'in source code it is (310, es)\n1 warning generated.\n']
Ejemplo n.º 27
0
class TestDashCapDWithVersion(expect.ErrorMessage):
    """Tests -D works well when #version is present."""

    shader = FileShader(
        """#version 310 es
        void main(){X}
        void foo(){Y}""", '.vert')
    glslc_args = ['-DX=', '-DY=return 3;', shader]

    expected_error = [
        shader, ":3: error: 'return' : void function cannot return a value\n",
        '1 error generated.\n'
    ]
Ejemplo n.º 28
0
class WarningOnLine(expect.WarningMessage):
    """Tests that a warning message with a file/line number is emitted."""

    shader = FileShader(
        """#version 140
    attribute float x;
    void main() {
    }
    """, '.vert')
    glslc_args = ['-c', shader]

    expected_warning = [
        shader, ':2: warning: attribute deprecated in version 130; ',
        'may be removed in future release\n1 warning generated.\n']
Ejemplo n.º 29
0
class TestDashCapEOutputFile(expect.SuccessfulReturn,
                             expect.ValidFileContents):
    """Tests to make sure -E works with output files."""

    shader = FileShader('''#version 140
void function() {
}
''', '.vert')
    expected_file_contents = '''#version 140
void function(){
}
'''
    target_filename = 'foo'
    glslc_args = ['-E', shader, '-ofoo']
Ejemplo n.º 30
0
class GlobalWarningAsError(expect.ErrorMessage):
    """Tests that with -Werror an error warning message without file/line
    number is emitted instead of a warning."""

    shader = FileShader(
        """#version 550
    void main() {
    }
    """, '.vert')
    glslc_args = ['-c', '-std=400', shader, '-Werror']

    expected_error = [
        shader, ': error: (version, profile) forced to be (400, none),'
                ' while in source code it is (550, none)\n1 error generated.\n']