1# Copyright 2018 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
15import expect
16from glslc_test_framework import inside_glslc_testsuite
17from placeholder import FileShader
18
19# An HLSL shader with a counter buffer with a counter increment.
20# Glslang doesn't automatically assign a binding to the counter, and
21# it doesn't understand [[vk::counter_binding(n)]], so compile this
22# with --auto-bind-uniforms.
23# See https://github.com/KhronosGroup/glslang/issues/1616
24HLSL_VERTEX_SHADER_WITH_COUNTER_BUFFER = """
25RWStructuredBuffer<int> Ainc;
26float4 main() : SV_Target0 {
27  return float4(Ainc.IncrementCounter(), 0, 1, 2);
28}
29"""
30
31
32@inside_glslc_testsuite('OptionFHlslFunctionality1')
33class TestHlslFunctionality1MentionsExtension(expect.ValidAssemblyFileWithSubstr):
34    """Tests that -fhlsl_functionality1 enabled SPV_GOOGLE_hlsl_functionality1."""
35
36    shader = FileShader(HLSL_VERTEX_SHADER_WITH_COUNTER_BUFFER, '.frag')
37    glslc_args = ['-S', '-x', 'hlsl', '-fhlsl_functionality1',
38                  '-fauto-bind-uniforms', shader]
39    expected_assembly_substr = 'OpExtension "SPV_GOOGLE_hlsl_functionality1"'
40
41
42@inside_glslc_testsuite('OptionFHlslFunctionality1')
43class TestHlslFunctionality1DecoratesCounter(expect.ValidAssemblyFileWithSubstr):
44    """Tests that -fhlsl_functionality1 decorates the output target"""
45
46    shader = FileShader(HLSL_VERTEX_SHADER_WITH_COUNTER_BUFFER, '.frag')
47    glslc_args = ['-S', '-x', 'hlsl', '-fhlsl_functionality1',
48                  '-fauto-bind-uniforms', shader]
49    expected_assembly_substr = 'OpDecorateString'
50
51
52## Next tests use the option with the hypen instead of underscore.
53
54@inside_glslc_testsuite('OptionFHlslFunctionality1')
55class TestHlslHyphenFunctionality1MentionsExtension(expect.ValidAssemblyFileWithSubstr):
56    """Tests that -fhlsl-functionality1 enabled SPV_GOOGLE_hlsl_functionality1."""
57
58    shader = FileShader(HLSL_VERTEX_SHADER_WITH_COUNTER_BUFFER, '.frag')
59    glslc_args = ['-S', '-x', 'hlsl', '-fhlsl_functionality1',
60                  '-fauto-bind-uniforms', shader]
61    expected_assembly_substr = 'OpExtension "SPV_GOOGLE_hlsl_functionality1"'
62
63
64@inside_glslc_testsuite('OptionFHlslFunctionality1')
65class TestHlslHyphenFunctionality1DecoratesCounter(expect.ValidAssemblyFileWithSubstr):
66    """Tests that -fhlsl-functionality1 decorates the output target"""
67
68    shader = FileShader(HLSL_VERTEX_SHADER_WITH_COUNTER_BUFFER, '.frag')
69    glslc_args = ['-S', '-x', 'hlsl', '-fhlsl_functionality1',
70                  '-fauto-bind-uniforms', shader]
71    expected_assembly_substr = 'OpDecorateString'
72