Skip to content

Commit 2c985ce

Browse files
committed
Test GL_EXT_descriptor_heap
Extend the expect.ValidaAssemblyFileWithSubstr so it can use a list of expected strings.
1 parent 722b6db commit 2c985ce

File tree

2 files changed

+66
-9
lines changed

2 files changed

+66
-9
lines changed

glslc/test/expect.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def verify_assembly_file_preamble(self, filename):
242242
line3 = assembly_file.readline()
243243

244244
if (line1 != '; SPIR-V\n' or
245-
line2 != '; Version: 1.0\n' or
245+
(not line2.startswith('; Version: 1.')) or
246246
(not line3.startswith('; Generator: Google Shaderc over Glslang;'))):
247247
return False, 'Incorrect SPV assembly'
248248

@@ -427,10 +427,13 @@ class ValidAssemblyFileWithSubstr(ValidAssemblyFile):
427427
"""Mixin class for checking that every input file generates a valid assembly
428428
file following the assembly file naming rule, there is no output on
429429
stdout/stderr, and all assembly files have the given substring specified
430-
by expected_assembly_substr.
430+
as self.expected_assembly_substr (if present) and substrings specified
431+
by the list strings in self.expected_assembly_substrings (if present).
432+
At least one string must be specified.
431433
432-
To mix in this class, subclasses need to provde expected_assembly_substr
433-
as the expected substring.
434+
To mix in this class, subclasses need to provide
435+
self.expected_assembly_substr as the expected substring, or a list of
436+
strings in self.expected_assembly_substrings.
434437
"""
435438

436439
def check_assembly_with_substr(self, status):
@@ -441,11 +444,24 @@ def check_assembly_with_substr(self, status):
441444
if not success:
442445
return False, message
443446
with open(assembly_filename, 'r') as f:
444-
content = f.read()
445-
if self.expected_assembly_substr not in convert_to_unix_line_endings(content):
446-
return False, ('Incorrect assembly output:\n{asm}\n'
447-
'Expected substring not found:\n{exp}'.format(
448-
asm=content, exp=self.expected_assembly_substr))
447+
content = convert_to_unix_line_endings(f.read())
448+
expected_strs = []
449+
if 'expected_assembly_substrings' in dir(self):
450+
expected_strs.extend(self.expected_assembly_substrings)
451+
if 'expected_assembly_substr' in dir(self):
452+
expected_strs.append(self.expected_assembly_substr)
453+
assert(type(expected_strs) is list)
454+
assert(len(expected_strs) > 0)
455+
for es in expected_strs:
456+
assert(type(es) is str)
457+
print(f"=: es {es}")
458+
459+
for es in expected_strs:
460+
print(f"= es {es}")
461+
if es not in content:
462+
return False, ('Incorrect assembly output:\n{asm}\n'
463+
'Expected substring not found:\n{exp}'.format(
464+
asm=content, exp=es))
449465
return True, ''
450466

451467

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 2026 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+
from glslc_test_framework import inside_glslc_testsuite
17+
from placeholder import FileShader
18+
19+
# See GL_EXT_descriptor_heap
20+
# https://github.com/KhronosGroup/GLSL/blob/main/extensions/ext/GLSL_EXT_descriptor_heap.txt
21+
GLSL_COMPUTE_SHADER_DESCRIPTOR_HEAP_BUFFER = """#version 450
22+
#extension GL_EXT_descriptor_heap : require
23+
24+
layout(descriptor_heap) uniform U { uint source; } ubo[];
25+
layout(descriptor_heap) buffer B { uint dest; } ssbo[];
26+
27+
void main()
28+
{
29+
ssbo[42].dest = ubo[2026].source;
30+
}"""
31+
32+
@inside_glslc_testsuite('GL_EXT_descriptor_heap')
33+
class BufferSampleCompiles(expect.ValidAssemblyFileWithSubstr):
34+
shader = FileShader(GLSL_COMPUTE_SHADER_DESCRIPTOR_HEAP_BUFFER, '.comp')
35+
glslc_args = ['-S', shader, '--target-env=vulkan1.2']
36+
expected_assembly_substrings = [
37+
"OpCapability UntypedPointersKHR",
38+
"OpCapability DescriptorHeapEXT",
39+
"= OpUntypedAccessChainKHR",
40+
"= OpBufferPointerEXT",
41+
]

0 commit comments

Comments
 (0)