Fix compatibility with FXC.

This commit is contained in:
Hans-Kristian Arntzen 2017-12-12 11:03:46 +01:00
parent f7b1ac2e6a
commit 950732512e
7 changed files with 47 additions and 23 deletions

View File

@ -10,27 +10,27 @@ layout(r32ui, binding = 5) uniform writeonly uimage2D uImageOutU;
layout(r32f, binding = 6) uniform readonly imageBuffer uImageInBuffer;
layout(r32f, binding = 7) uniform writeonly imageBuffer uImageOutBuffer;
layout(rg32f, binding = 0) uniform readonly image2D uImageInF2;
layout(rg32f, binding = 1) uniform writeonly image2D uImageOutF2;
layout(rg32i, binding = 2) uniform readonly iimage2D uImageInI2;
layout(rg32i, binding = 3) uniform writeonly iimage2D uImageOutI2;
layout(rg32ui, binding = 4) uniform readonly uimage2D uImageInU2;
layout(rg32ui, binding = 5) uniform writeonly uimage2D uImageOutU2;
layout(rg32f, binding = 6) uniform readonly imageBuffer uImageInBuffer2;
layout(rg32f, binding = 7) uniform writeonly imageBuffer uImageOutBuffer2;
layout(rg32f, binding = 8) uniform readonly image2D uImageInF2;
layout(rg32f, binding = 9) uniform writeonly image2D uImageOutF2;
layout(rg32i, binding = 10) uniform readonly iimage2D uImageInI2;
layout(rg32i, binding = 11) uniform writeonly iimage2D uImageOutI2;
layout(rg32ui, binding = 12) uniform readonly uimage2D uImageInU2;
layout(rg32ui, binding = 13) uniform writeonly uimage2D uImageOutU2;
layout(rg32f, binding = 14) uniform readonly imageBuffer uImageInBuffer2;
layout(rg32f, binding = 15) uniform writeonly imageBuffer uImageOutBuffer2;
layout(rgba32f, binding = 0) uniform readonly image2D uImageInF4;
layout(rgba32f, binding = 1) uniform writeonly image2D uImageOutF4;
layout(rgba32i, binding = 2) uniform readonly iimage2D uImageInI4;
layout(rgba32i, binding = 3) uniform writeonly iimage2D uImageOutI4;
layout(rgba32ui, binding = 4) uniform readonly uimage2D uImageInU4;
layout(rgba32ui, binding = 5) uniform writeonly uimage2D uImageOutU4;
layout(rgba32f, binding = 6) uniform readonly imageBuffer uImageInBuffer4;
layout(rgba32f, binding = 7) uniform writeonly imageBuffer uImageOutBuffer4;
layout(rgba32f, binding = 16) uniform readonly image2D uImageInF4;
layout(rgba32f, binding = 17) uniform writeonly image2D uImageOutF4;
layout(rgba32i, binding = 18) uniform readonly iimage2D uImageInI4;
layout(rgba32i, binding = 19) uniform writeonly iimage2D uImageOutI4;
layout(rgba32ui, binding = 20) uniform readonly uimage2D uImageInU4;
layout(rgba32ui, binding = 21) uniform writeonly uimage2D uImageOutU4;
layout(rgba32f, binding = 22) uniform readonly imageBuffer uImageInBuffer4;
layout(rgba32f, binding = 23) uniform writeonly imageBuffer uImageOutBuffer4;
layout(binding = 8) uniform writeonly image2D uImageNoFmtF;
layout(binding = 9) uniform writeonly uimage2D uImageNoFmtU;
layout(binding = 10) uniform writeonly iimage2D uImageNoFmtI;
layout(binding = 24) uniform writeonly image2D uImageNoFmtF;
layout(binding = 25) uniform writeonly uimage2D uImageNoFmtU;
layout(binding = 26) uniform writeonly iimage2D uImageNoFmtI;
void main()
{

View File

@ -1,7 +1,7 @@
#version 310 es
precision mediump float;
layout(set = 0, binding = 1) uniform mediump sampler2D uSampler;
layout(set = 0, binding = 0) uniform mediump sampler2D uSampler;
layout(set = 0, binding = 1) uniform mediump sampler2DShadow uSamplerShadow;
layout(location = 0) out float FragColor;

View File

@ -71,7 +71,10 @@ void main()
// Flexible sized arrays with spec constants and spec constant ops.
float vec0[c + 3][8];
float vec1[c + 2];
vec0[0][0] = 10.0;
vec1[0] = 20.0;
Foo foo;
foo.elems[c] = 10.0;
FragColor = vec4(t0 + t1) + vec0[0][0] + vec1[0] + foo.elems[c];
}

View File

@ -1722,7 +1722,7 @@ string CompilerGLSL::remap_swizzle(const SPIRType &out_type, uint32_t input_comp
{
if (out_type.vecsize == input_components)
return expr;
else if (input_components == 1)
else if (input_components == 1 && !backend.can_swizzle_scalar)
return join(type_to_glsl(out_type), "(", expr, ")");
else
{
@ -5369,6 +5369,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
// Arrays and structs must be initialized properly in full.
bool composite = !out_type.array.empty() || out_type.basetype == SPIRType::Struct;
bool splat = in_type.vecsize == 1 && in_type.columns == 1 && !composite && backend.use_constructor_splatting;
bool swizzle_splat = in_type.vecsize == 1 && in_type.columns == 1 && backend.can_swizzle_scalar;
if (splat)
{
@ -5390,6 +5391,10 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
constructor_op += build_composite_combiner(elems, length);
constructor_op += " }";
}
else if (splat && swizzle_splat && !composite)
{
constructor_op = remap_swizzle(get<SPIRType>(result_type), 1, to_expression(elems[0]));
}
else
{
constructor_op = type_to_glsl_constructor(get<SPIRType>(result_type)) + "(";

View File

@ -320,6 +320,7 @@ protected:
bool use_constructor_splatting = true;
bool boolean_mix_support = true;
bool allow_precision_qualifiers = false;
bool can_swizzle_scalar = false;
} backend;
void emit_struct(SPIRType &type);

View File

@ -1232,7 +1232,10 @@ void CompilerHLSL::emit_resources()
if (has_lod[index])
statement("Tex.GetDimensions(Level, ret.x, Param);");
else
{
statement("Tex.GetDimensions(ret.x);");
statement("Param = 0u;");
}
break;
case 2:
if (has_lod[index])
@ -3596,6 +3599,7 @@ string CompilerHLSL::compile()
backend.use_initializer_list = true;
backend.use_constructor_splatting = false;
backend.boolean_mix_support = false;
backend.can_swizzle_scalar = true;
update_active_builtins();
analyze_sampler_comparison_states();

View File

@ -105,10 +105,21 @@ def cross_compile_msl(shader, spirv, opt):
subprocess.check_call(['spirv-val', spirv_path])
return (spirv_path, msl_path)
def shader_model_hlsl(shader):
if '.vert' in shader:
return '-Tvs_5_1'
elif '.frag' in shader:
return '-Tps_5_1'
elif '.comp' in shader:
return '-Tcs_5_1'
else:
return None
def validate_shader_hlsl(shader):
subprocess.check_call(['glslangValidator', '-e', 'main', '-D', '-V', shader])
if (not force_no_external_validation) and os.path.exists('fxc'):
subprocess.check_call(['fxc', shader])
is_asm = '.asm' in shader
if (not force_no_external_validation) and (not is_asm) and os.path.exists('fxc'):
subprocess.check_call(['fxc', '-nologo', shader_model_hlsl(shader), shader])
def shader_to_sm(shader):
if '.sm51.' in shader: