HLSL: Support OpArrayLength.

This commit is contained in:
Hans-Kristian Arntzen 2019-05-07 15:49:38 +02:00
parent ab1fa9011f
commit e9da5ed631
7 changed files with 101 additions and 0 deletions

View File

@ -0,0 +1,15 @@
RWByteAddressBuffer _11 : register(u1);
void comp_main()
{
uint _14;
_11.GetDimensions(_14);
_14 = (_14 - 16) / 16;
_11.Store(0, uint(int(_14)));
}
[numthreads(1, 1, 1)]
void main()
{
comp_main();
}

View File

@ -0,0 +1,14 @@
#version 450
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 1, std140) buffer SSBO
{
uint size;
float v[];
} _11;
void main()
{
_11.size = uint(int(_11.v.length()));
}

View File

@ -0,0 +1,15 @@
RWByteAddressBuffer _11 : register(u1);
void comp_main()
{
uint _14;
_11.GetDimensions(_14);
_14 = (_14 - 16) / 16;
_11.Store(0, uint(int(_14)));
}
[numthreads(1, 1, 1)]
void main()
{
comp_main();
}

View File

@ -0,0 +1,14 @@
#version 450
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 1, std140) buffer SSBO
{
uint size;
float v[];
} _11;
void main()
{
_11.size = uint(int(_11.v.length()));
}

View File

@ -0,0 +1,12 @@
#version 450
layout(local_size_x = 1) in;
layout(set = 0, binding = 1, std140) buffer SSBO
{
uint size;
float v[];
};
void main()
{
size = v.length();
}

View File

@ -0,0 +1,12 @@
#version 450
layout(local_size_x = 1) in;
layout(set = 0, binding = 1, std140) buffer SSBO
{
uint size;
float v[];
};
void main()
{
size = v.length();
}

View File

@ -4508,6 +4508,25 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
HLSL_UFOP(reversebits);
break;
case OpArrayLength:
{
auto *var = maybe_get<SPIRVariable>(ops[2]);
if (!var)
SPIRV_CROSS_THROW("Array length must point directly to an SSBO block.");
auto &type = get<SPIRType>(var->basetype);
if (!has_decoration(type.self, DecorationBlock) && !has_decoration(type.self, DecorationBufferBlock))
SPIRV_CROSS_THROW("Array length expression must point to a block type.");
// This must be 32-bit uint, so we're good to go.
emit_uninitialized_temporary_expression(ops[0], ops[1]);
statement(to_expression(ops[2]), ".GetDimensions(", to_expression(ops[1]), ");");
uint32_t offset = type_struct_member_offset(type, ops[3]);
uint32_t stride = type_struct_member_array_stride(type, ops[3]);
statement(to_expression(ops[1]), " = (", to_expression(ops[1]), " - ", offset, ") / ", stride, ";");
break;
}
default:
CompilerGLSL::emit_instruction(instruction);
break;