HLSL: Support OpArrayLength.
This commit is contained in:
parent
ab1fa9011f
commit
e9da5ed631
15
reference/opt/shaders-hlsl/comp/ssbo-array-length.comp
Normal file
15
reference/opt/shaders-hlsl/comp/ssbo-array-length.comp
Normal 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();
|
||||
}
|
14
reference/opt/shaders/comp/ssbo-array-length.comp
Normal file
14
reference/opt/shaders/comp/ssbo-array-length.comp
Normal 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()));
|
||||
}
|
||||
|
15
reference/shaders-hlsl/comp/ssbo-array-length.comp
Normal file
15
reference/shaders-hlsl/comp/ssbo-array-length.comp
Normal 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();
|
||||
}
|
14
reference/shaders/comp/ssbo-array-length.comp
Normal file
14
reference/shaders/comp/ssbo-array-length.comp
Normal 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()));
|
||||
}
|
||||
|
12
shaders-hlsl/comp/ssbo-array-length.comp
Normal file
12
shaders-hlsl/comp/ssbo-array-length.comp
Normal 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();
|
||||
}
|
12
shaders/comp/ssbo-array-length.comp
Normal file
12
shaders/comp/ssbo-array-length.comp
Normal 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();
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user