Merge pull request #966 from KhronosGroup/array-length-hlsl

HLSL: Support OpArrayLength.
This commit is contained in:
Hans-Kristian Arntzen 2019-05-07 19:03:58 +02:00 committed by GitHub
commit c125bbd248
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 103 additions and 1 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(uint(_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(uint(_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

@ -7566,7 +7566,8 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
uint32_t result_type = ops[0];
uint32_t id = ops[1];
auto e = access_chain_internal(ops[2], &ops[3], length - 3, ACCESS_CHAIN_INDEX_IS_LITERAL_BIT, nullptr);
set<SPIRExpression>(id, e + ".length()", result_type, true);
set<SPIRExpression>(id, join(type_to_glsl(get<SPIRType>(result_type)), "(", e, ".length())"), result_type,
true);
break;
}

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;