Support samplerBuffer as function parameters in HLSL.

This commit is contained in:
Hans-Kristian Arntzen 2017-08-21 10:26:44 +02:00
Родитель e8d5d71cad
Коммит e8d2c8e710
3 изменённых файлов: 18 добавлений и 10 удалений

Просмотреть файл

@ -8,9 +8,14 @@ struct SPIRV_Cross_Output
float4 gl_Position : SV_Position;
};
float4 sample_from_function(Buffer<float4> s0, Buffer<int4> s1, Buffer<uint4> s2)
{
return (s0.Load(20) + asfloat(s1.Load(40))) + asfloat(s2.Load(60));
}
void vert_main()
{
gl_Position = (uFloatSampler.Load(20) + asfloat(uIntSampler.Load(40))) + asfloat(uUintSampler.Load(60));
gl_Position = sample_from_function(uFloatSampler, uIntSampler, uUintSampler);
}
SPIRV_Cross_Output main()

Просмотреть файл

@ -4,10 +4,14 @@ layout(binding = 1) uniform samplerBuffer uFloatSampler;
layout(binding = 2) uniform isamplerBuffer uIntSampler;
layout(binding = 3) uniform usamplerBuffer uUintSampler;
vec4 sample_from_function(samplerBuffer s0, isamplerBuffer s1, usamplerBuffer s2)
{
return texelFetch(s0, 20) +
intBitsToFloat(texelFetch(s1, 40)) +
uintBitsToFloat(texelFetch(s2, 60));
}
void main()
{
gl_Position =
texelFetch(uFloatSampler, 20) +
intBitsToFloat(texelFetch(uIntSampler, 40)) +
uintBitsToFloat(texelFetch(uUintSampler, 60));
gl_Position = sample_from_function(uFloatSampler, uIntSampler, uUintSampler);
}

Просмотреть файл

@ -1032,7 +1032,7 @@ string CompilerHLSL::to_func_call_arg(uint32_t id)
// We don't have to consider combined image samplers here via OpSampledImage because
// those variables cannot be passed as arguments to functions.
// Only global SampledImage variables may be used as arguments.
if (type.basetype == SPIRType::SampledImage)
if (type.basetype == SPIRType::SampledImage && type.image.dim != DimBuffer)
arg_str += ", " + to_sampler_expression(id);
}
@ -1080,11 +1080,10 @@ void CompilerHLSL::emit_function_prototype(SPIRFunction &func, uint64_t return_f
// Flatten a combined sampler to two separate arguments in modern HLSL.
auto &arg_type = get<SPIRType>(arg.type);
if (options.shader_model > 30 && arg_type.basetype == SPIRType::SampledImage)
if (options.shader_model > 30 && arg_type.basetype == SPIRType::SampledImage && arg_type.image.dim != DimBuffer)
{
// Manufacture automatic sampler arg for SampledImage texture
decl += ", ";
if (arg_type.basetype == SPIRType::SampledImage)
decl += join(arg_type.image.depth ? "SamplerComparisonState " : "SamplerState ",
to_sampler_expression(arg.id));
}