Add sampler buffer support to HLSL.
This commit is contained in:
Родитель
6b7b76a63f
Коммит
e8d5d71cad
|
@ -0,0 +1,22 @@
|
||||||
|
Buffer<float4> uFloatSampler : register(t1);
|
||||||
|
Buffer<int4> uIntSampler : register(t2);
|
||||||
|
Buffer<uint4> uUintSampler : register(t3);
|
||||||
|
|
||||||
|
static float4 gl_Position;
|
||||||
|
struct SPIRV_Cross_Output
|
||||||
|
{
|
||||||
|
float4 gl_Position : SV_Position;
|
||||||
|
};
|
||||||
|
|
||||||
|
void vert_main()
|
||||||
|
{
|
||||||
|
gl_Position = (uFloatSampler.Load(20) + asfloat(uIntSampler.Load(40))) + asfloat(uUintSampler.Load(60));
|
||||||
|
}
|
||||||
|
|
||||||
|
SPIRV_Cross_Output main()
|
||||||
|
{
|
||||||
|
vert_main();
|
||||||
|
SPIRV_Cross_Output stage_output;
|
||||||
|
stage_output.gl_Position = gl_Position;
|
||||||
|
return stage_output;
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
layout(binding = 1) uniform samplerBuffer uFloatSampler;
|
||||||
|
layout(binding = 2) uniform isamplerBuffer uIntSampler;
|
||||||
|
layout(binding = 3) uniform usamplerBuffer uUintSampler;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position =
|
||||||
|
texelFetch(uFloatSampler, 20) +
|
||||||
|
intBitsToFloat(texelFetch(uIntSampler, 40)) +
|
||||||
|
uintBitsToFloat(texelFetch(uUintSampler, 60));
|
||||||
|
}
|
|
@ -48,6 +48,8 @@ string CompilerHLSL::image_type_hlsl_modern(const SPIRType &type)
|
||||||
{
|
{
|
||||||
auto &imagetype = get<SPIRType>(type.image.type);
|
auto &imagetype = get<SPIRType>(type.image.type);
|
||||||
const char *dim = nullptr;
|
const char *dim = nullptr;
|
||||||
|
uint32_t components = 4;
|
||||||
|
|
||||||
switch (type.image.dim)
|
switch (type.image.dim)
|
||||||
{
|
{
|
||||||
case Dim1D:
|
case Dim1D:
|
||||||
|
@ -63,17 +65,23 @@ string CompilerHLSL::image_type_hlsl_modern(const SPIRType &type)
|
||||||
dim = "Cube";
|
dim = "Cube";
|
||||||
break;
|
break;
|
||||||
case DimRect:
|
case DimRect:
|
||||||
SPIRV_CROSS_THROW("Rectangle texture support is not yet implemented for HLSL"); // TODO
|
SPIRV_CROSS_THROW("Rectangle texture support is not yet implemented for HLSL."); // TODO
|
||||||
case DimBuffer:
|
case DimBuffer:
|
||||||
// Buffer/RWBuffer.
|
if (type.image.sampled == 1)
|
||||||
SPIRV_CROSS_THROW("Buffer/RWBuffer support is not yet implemented for HLSL"); // TODO
|
return join("Buffer<", type_to_glsl(imagetype), components, ">");
|
||||||
|
else if (type.image.sampled == 2)
|
||||||
|
{
|
||||||
|
SPIRV_CROSS_THROW("RWBuffer is not implemented yet for HLSL.");
|
||||||
|
//return join("RWBuffer<", type_to_glsl(imagetype), components, ">");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
SPIRV_CROSS_THROW("Sampler buffers must be either sampled or unsampled. Cannot deduce in runtime.");
|
||||||
case DimSubpassData:
|
case DimSubpassData:
|
||||||
// This should be implemented same way as desktop GL. Fetch on a 2D texture based on int2(SV_Position).
|
// This should be implemented same way as desktop GL. Fetch on a 2D texture based on int2(SV_Position).
|
||||||
SPIRV_CROSS_THROW("Subpass data support is not yet implemented for HLSL"); // TODO
|
SPIRV_CROSS_THROW("Subpass data support is not yet implemented for HLSL"); // TODO
|
||||||
default:
|
default:
|
||||||
SPIRV_CROSS_THROW("Invalid dimension.");
|
SPIRV_CROSS_THROW("Invalid dimension.");
|
||||||
}
|
}
|
||||||
uint32_t components = 4;
|
|
||||||
const char *arrayed = type.image.arrayed ? "Array" : "";
|
const char *arrayed = type.image.arrayed ? "Array" : "";
|
||||||
return join("Texture", dim, arrayed, "<", type_to_glsl(imagetype), components, ">");
|
return join("Texture", dim, arrayed, "<", type_to_glsl(imagetype), components, ">");
|
||||||
}
|
}
|
||||||
|
@ -1582,7 +1590,8 @@ void CompilerHLSL::emit_texture_op(const Instruction &i)
|
||||||
if (op == OpImageFetch)
|
if (op == OpImageFetch)
|
||||||
{
|
{
|
||||||
auto &coordtype = expression_type(coord);
|
auto &coordtype = expression_type(coord);
|
||||||
coord_expr = join("int", coordtype.vecsize + 1, "(", coord_expr, ", ", to_expression(lod), ")");
|
if (imgtype.image.dim != DimBuffer)
|
||||||
|
coord_expr = join("int", coordtype.vecsize + 1, "(", coord_expr, ", ", to_expression(lod), ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (op != OpImageFetch)
|
if (op != OpImageFetch)
|
||||||
|
@ -1728,7 +1737,7 @@ void CompilerHLSL::emit_modern_uniform(const SPIRVariable &var)
|
||||||
{
|
{
|
||||||
statement(image_type_hlsl_modern(type), " ", to_name(var.self), to_resource_binding(var), ";");
|
statement(image_type_hlsl_modern(type), " ", to_name(var.self), to_resource_binding(var), ";");
|
||||||
|
|
||||||
if (type.basetype == SPIRType::SampledImage)
|
if (type.basetype == SPIRType::SampledImage && type.image.dim != DimBuffer)
|
||||||
{
|
{
|
||||||
// For combined image samplers, also emit a combined image sampler.
|
// For combined image samplers, also emit a combined image sampler.
|
||||||
if (type.image.depth)
|
if (type.image.depth)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче