Updated python and cpp with working gslslangvalidator

This commit is contained in:
Alejandro Saucedo 2021-07-21 18:16:29 +01:00
parent 71b08d9f58
commit b7fd1b4d79
10 changed files with 32 additions and 20 deletions

0
python/test/__init__.py Normal file
View file

View file

@ -1,4 +1,3 @@
pyshader==0.7.0
numpy==1.19.5
pytest==6.2.1
pyshaderc==1.1.2

View file

@ -5,7 +5,7 @@ import numpy as np
import logging
import pyshader as ps
import pyshaderc
from .utils import compile_source
DIRNAME = os.path.dirname(os.path.abspath(__file__))
@ -55,7 +55,7 @@ def test_end_to_end():
push_consts_a = [2]
push_consts_b = [3]
algo = mgr.algorithm(params, pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp"), workgroup, spec_consts, push_consts_a)
algo = mgr.algorithm(params, compile_source(shader), workgroup, spec_consts, push_consts_a)
(mgr.sequence()
.record(kp.OpTensorSyncDevice(params))
@ -91,7 +91,7 @@ void main()
}
"""
spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp")
spirv = compile_source(shader)
mgr = kp.Manager()
@ -131,7 +131,7 @@ def test_sequence():
}
"""
spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp")
spirv = compile_source(shader)
mgr = kp.Manager(0)
@ -171,7 +171,7 @@ def test_sequence():
def test_pushconsts():
spirv = pyshaderc.compile_into_spirv("""
spirv = compile_source("""
#version 450
layout(push_constant) uniform PushConstants {
float x;
@ -185,7 +185,7 @@ def test_pushconsts():
pa[1] += pcs.y;
pa[2] += pcs.z;
}
""".encode("utf-8"), "comp", "shader.comp")
""")
mgr = kp.Manager()

View file

@ -1,10 +1,10 @@
import pyshader as ps
import pyshaderc
import os
import pytest
import kp
import numpy as np
from .utils import compile_source
VK_ICD_FILENAMES = os.environ.get("VK_ICD_FILENAMES", "")
def test_type_float():
@ -23,7 +23,7 @@ def test_type_float():
}
"""
spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp")
spirv = compile_source(shader)
arr_in_a = np.array([123., 153., 231.], dtype=np.float32)
arr_in_b = np.array([9482, 1208, 1238], dtype=np.float32)
@ -62,7 +62,7 @@ def test_type_float_double_incorrect():
}
"""
spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp")
spirv = compile_source(shader)
arr_in_a = np.array([123., 153., 231.], dtype=np.float32)
arr_in_b = np.array([9482, 1208, 1238], dtype=np.uint32)
@ -104,7 +104,7 @@ def test_type_double():
}
"""
spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp")
spirv = compile_source(shader)
arr_in_a = np.array([123., 153., 231.], dtype=np.float64)
arr_in_b = np.array([9482, 1208, 1238], dtype=np.float64)
@ -144,7 +144,7 @@ def test_type_int():
}
"""
spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp")
spirv = compile_source(shader)
arr_in_a = np.array([123, 153, 231], dtype=np.int32)
arr_in_b = np.array([9482, 1208, 1238], dtype=np.int32)
@ -184,7 +184,7 @@ def test_type_unsigned_int():
}
"""
spirv = pyshaderc.compile_into_spirv(shader.encode("utf-8"), "comp", "shader.comp")
spirv = compile_source(shader)
arr_in_a = np.array([123, 153, 231], dtype=np.uint32)
arr_in_b = np.array([9482, 1208, 1238], dtype=np.uint32)

7
python/test/utils.py Normal file
View file

@ -0,0 +1,7 @@
import os
def compile_source(source):
os.system("glslangValidator --stdin -S comp -V -o tmp_kp_shader.comp.spv << END\n" + source + "\nEND")
return open("tmp_kp_shader.comp.spv", "rb").read()