This commit is contained in:
Bill Hollings 2016-04-19 10:14:01 -04:00
commit 2570121582
5 changed files with 108 additions and 16 deletions

View File

@ -0,0 +1,38 @@
#version 310 es
precision mediump float;
precision highp int;
layout(binding = 1) uniform mediump texture2D uTexture;
layout(binding = 0) uniform mediump sampler uSampler;
layout(binding = 4) uniform mediump texture2DArray uTextureArray;
layout(binding = 3) uniform mediump textureCube uTextureCube;
layout(binding = 2) uniform mediump texture3D uTexture3D;
layout(location = 0) in vec2 vTex;
layout(location = 1) in vec3 vTex3;
layout(location = 0) out vec4 FragColor;
vec4 sample_func(mediump sampler samp, vec2 uv)
{
return texture(sampler2D(uTexture, samp), uv);
}
vec4 sample_func_dual(mediump sampler samp, mediump texture2D tex, vec2 uv)
{
return texture(sampler2D(tex, samp), uv);
}
void main()
{
vec2 off = (vec2(1.0) / vec2(textureSize(uTexture, 0)));
vec2 off2 = (vec2(1.0) / vec2(textureSize(sampler2D(uTexture, uSampler), 1)));
highp vec2 param = ((vTex + off) + off2);
vec4 c0 = sample_func(uSampler, param);
highp vec2 param_1 = ((vTex + off) + off2);
vec4 c1 = sample_func_dual(uSampler, uTexture, param_1);
vec4 c2 = texture(sampler2DArray(uTextureArray, uSampler), vTex3);
vec4 c3 = texture(samplerCube(uTextureCube, uSampler), vTex3);
vec4 c4 = texture(sampler3D(uTexture3D, uSampler), vTex3);
FragColor = ((((c0 + c1) + c2) + c3) + c4);
}

View File

@ -0,0 +1,36 @@
#version 310 es
precision mediump float;
layout(set = 0, binding = 0) uniform mediump sampler uSampler;
layout(set = 0, binding = 1) uniform mediump texture2D uTexture;
layout(set = 0, binding = 2) uniform mediump texture3D uTexture3D;
layout(set = 0, binding = 3) uniform mediump textureCube uTextureCube;
layout(set = 0, binding = 4) uniform mediump texture2DArray uTextureArray;
layout(location = 0) out vec4 FragColor;
layout(location = 0) in vec2 vTex;
layout(location = 1) in vec3 vTex3;
vec4 sample_func(mediump sampler samp, vec2 uv)
{
return texture(sampler2D(uTexture, samp), uv);
}
vec4 sample_func_dual(mediump sampler samp, mediump texture2D tex, vec2 uv)
{
return texture(sampler2D(tex, samp), uv);
}
void main()
{
vec2 off = 1.0 / vec2(textureSize(uTexture, 0));
vec2 off2 = 1.0 / vec2(textureSize(sampler2D(uTexture, uSampler), 1));
vec4 c0 = sample_func(uSampler, vTex + off + off2);
vec4 c1 = sample_func_dual(uSampler, uTexture, vTex + off + off2);
vec4 c2 = texture(sampler2DArray(uTextureArray, uSampler), vTex3);
vec4 c3 = texture(samplerCube(uTextureCube, uSampler), vTex3);
vec4 c4 = texture(sampler3D(uTexture3D, uSampler), vTex3);
FragColor = c0 + c1 + c2 + c3 + c4;
}

View File

@ -286,6 +286,7 @@ bool Compiler::expression_is_lvalue(uint32_t id) const
{
case SPIRType::SampledImage:
case SPIRType::Image:
case SPIRType::Sampler:
return false;
default:

View File

@ -3045,6 +3045,14 @@ void CompilerGLSL::emit_instruction(const Instruction &i)
break;
}
case OpSampledImage:
{
uint32_t result_type = ops[0];
uint32_t id = ops[1];
emit_binary_func_op(result_type, id, ops[2], ops[3], type_to_glsl(get<SPIRType>(result_type)).c_str());
break;
}
case OpImageQuerySizeLod:
BFOP(textureSize);
break;
@ -3247,12 +3255,13 @@ const char* CompilerGLSL::flags_to_precision_qualifiers_glsl(const SPIRType &typ
{
if (options.es)
{
// Structs to not have precision qualifiers.
// Structs do not have precision qualifiers.
if (type.basetype != SPIRType::Float &&
type.basetype != SPIRType::Int &&
type.basetype != SPIRType::UInt &&
type.basetype != SPIRType::Image &&
type.basetype != SPIRType::SampledImage)
type.basetype != SPIRType::SampledImage &&
type.basetype != SPIRType::Sampler)
return "";
if (flags & (1ull << DecorationRelaxedPrecision))
@ -3315,7 +3324,7 @@ string CompilerGLSL::to_qualifiers_glsl(uint32_t id)
res += "invariant ";
auto &type = expression_type(id);
if (type.image.dim != DimSubpassData)
if (type.image.dim != DimSubpassData && type.image.sampled == 2)
{
if (flags & (1ull << DecorationNonWritable))
res += "readonly ";
@ -3402,8 +3411,10 @@ string CompilerGLSL::image_type_glsl(const SPIRType &type)
// If we're emulating subpassInput with samplers, force sampler2D
// so we don't have to specify format.
res += type.basetype == SPIRType::Image && type.image.dim != DimSubpassData ?
"image" : "sampler";
if (type.basetype == SPIRType::Image && type.image.dim != DimSubpassData)
res += type.image.sampled == 2 ? "image" : "texture";
else
res += "sampler";
switch (type.image.dim)
{

View File

@ -60,18 +60,21 @@ def get_shader_stats(shader):
returned = stdout.decode('utf-8')
return parse_stats(returned)
def validate_shader(shader):
def validate_shader(shader, vulkan):
if vulkan:
subprocess.check_call(['glslangValidator', '-V', shader])
else:
subprocess.check_call(['glslangValidator', shader])
def cross_compile(shader):
def cross_compile(shader, vulkan):
spirv_f, spirv_path = tempfile.mkstemp()
glsl_f, glsl_path = tempfile.mkstemp(suffix = os.path.basename(shader))
os.close(spirv_f)
os.close(glsl_f)
subprocess.check_call(['glslangValidator', '-G', '-o', spirv_path, shader])
subprocess.check_call(['glslangValidator', '-V' if vulkan else '-G', '-o', spirv_path, shader])
subprocess.check_call(['./spirv-cross', '--output', glsl_path, spirv_path])
validate_shader(glsl_path)
validate_shader(glsl_path, vulkan)
return (spirv_path, glsl_path)
def md5_for_file(path):
@ -110,9 +113,9 @@ def regression_check(shader, glsl, update, keep):
make_reference_dir(reference)
shutil.move(glsl, reference)
def test_shader(stats, shader, update, keep):
def test_shader(stats, shader, update, keep, vulkan):
print('Testing shader:', shader)
spirv, glsl = cross_compile(shader)
spirv, glsl = cross_compile(shader, vulkan)
if stats:
cross_stats = get_shader_stats(glsl)
@ -131,19 +134,19 @@ def test_shader(stats, shader, update, keep):
a.append(str(i))
print(','.join(a), file = stats)
def test_shaders(shader_dir, update, malisc, keep):
def test_shaders(shader_dir, update, malisc, keep, vulkan):
if malisc:
with open('stats.csv', 'w') as stats:
print('Shader,OrigRegs,OrigUniRegs,OrigALUShort,OrigLSShort,OrigTEXShort,OrigALULong,OrigLSLong,OrigTEXLong,CrossRegs,CrossUniRegs,CrossALUShort,CrossLSShort,CrossTEXShort,CrossALULong,CrossLSLong,CrossTEXLong', file = stats)
for f in os.walk(os.path.join(shader_dir)):
for i in f[2]:
shader = os.path.join(f[0], i)
test_shader(stats, shader, update, keep)
test_shader(stats, shader, update, keep, vulkan)
else:
for f in os.walk(os.path.join(shader_dir)):
for i in f[2]:
shader = os.path.join(f[0], i)
test_shader(None, shader, update, keep)
test_shader(None, shader, update, keep, vulkan)
def main():
parser = argparse.ArgumentParser(description = 'Script for regression testing.')
@ -158,13 +161,16 @@ def main():
parser.add_argument('--malisc',
action = 'store_true',
help = 'Use malisc offline compiler to determine static cycle counts before and after spirv-cross.')
parser.add_argument('--vulkan',
action = 'store_true',
help = 'Test shaders using Vulkan semantics instead of OpenGL.')
args = parser.parse_args()
if not args.folder:
sys.stderr.write('Need shader folder.\n')
sys.exit(1)
test_shaders(args.folder, args.update, args.malisc, args.keep)
test_shaders(args.folder, args.update, args.malisc, args.keep, args.vulkan)
if args.malisc:
print('Stats in stats.csv!')
print('Tests completed!')