Emit readonly, writeonly for SSBOs.

This commit is contained in:
Hans-Kristian Arntzen 2017-01-21 10:07:38 +01:00
parent 2c7359d1d3
commit 016b1d86e9
19 changed files with 106 additions and 30 deletions

View File

@ -1,12 +1,12 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, std430) buffer SSBO
layout(binding = 0, std430) readonly buffer SSBO
{
vec4 in_data[];
} _23;
layout(binding = 1, std430) buffer SSBO2
layout(binding = 1, std430) writeonly buffer SSBO2
{
vec4 out_data[];
} _45;

View File

@ -1,12 +1,12 @@
#version 310 es
layout(local_size_x = 4, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, std430) buffer SSBO
layout(binding = 0, std430) readonly buffer SSBO
{
float in_data[];
} _22;
layout(binding = 1, std430) buffer SSBO2
layout(binding = 1, std430) writeonly buffer SSBO2
{
float out_data[];
} _38;

View File

@ -1,13 +1,13 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, std430) buffer SSBO
layout(binding = 0, std430) readonly buffer SSBO
{
mat4 mvp;
vec4 in_data[];
} _28;
layout(binding = 1, std430) buffer SSBO2
layout(binding = 1, std430) writeonly buffer SSBO2
{
vec4 out_data[];
} _52;

View File

@ -1,7 +1,7 @@
#version 310 es
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, std430) buffer Distribution
layout(binding = 0, std430) readonly buffer Distribution
{
vec2 distribution[];
} _190;
@ -11,7 +11,7 @@ layout(binding = 2, std140) uniform UBO
vec4 uModTime;
} _218;
layout(binding = 1, std430) buffer HeightmapFFT
layout(binding = 1, std430) writeonly buffer HeightmapFFT
{
uint heights[];
} _276;

View File

@ -9,17 +9,17 @@ struct Foo
vec4 d;
};
layout(binding = 1, std430) buffer SSBO2
layout(binding = 1, std430) readonly buffer SSBO2
{
vec4 data[];
} indata;
layout(binding = 0, std430) buffer SSBO
layout(binding = 0, std430) writeonly buffer SSBO
{
vec4 data[];
} outdata;
layout(binding = 2, std430) buffer SSBO3
layout(binding = 2, std430) readonly buffer SSBO3
{
Foo foos[];
} foobar;

View File

@ -1,7 +1,7 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, std430) buffer SSBO
layout(binding = 0, std430) writeonly buffer SSBO
{
vec4 out_data[];
} _27;

View File

@ -1,13 +1,13 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, std430) buffer SSBO
layout(binding = 0, std430) readonly buffer SSBO
{
mat4 mvp;
vec4 in_data[];
} _24;
layout(binding = 1, std430) buffer SSBO2
layout(binding = 1, std430) writeonly buffer SSBO2
{
vec4 out_data[];
} _177;

View File

@ -1,7 +1,7 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 1, std430) buffer SSBO2
layout(binding = 1, std430) writeonly buffer SSBO2
{
mat3 out_data[];
} _22;

View File

@ -1,12 +1,12 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, std430) buffer SSBO
layout(binding = 0, std430) readonly buffer SSBO
{
vec4 in_data[];
} _23;
layout(binding = 1, std430) buffer SSBO2
layout(binding = 1, std430) writeonly buffer SSBO2
{
vec4 out_data[];
} _33;

View File

@ -1,12 +1,12 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, std430) buffer SSBO
layout(binding = 0, std430) readonly buffer SSBO
{
vec4 in_data[];
} _23;
layout(binding = 1, std430) buffer SSBO2
layout(binding = 1, std430) writeonly buffer SSBO2
{
vec4 out_data[];
} _35;

View File

@ -0,0 +1,27 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 2, std430) restrict writeonly buffer SSBO2
{
vec4 data4;
vec4 data5;
} _10;
layout(binding = 0, std430) readonly buffer SSBO0
{
vec4 data0;
vec4 data1;
} _15;
layout(binding = 1, std430) restrict buffer SSBO1
{
vec4 data2;
vec4 data3;
} _21;
void main()
{
_10.data4 = _15.data0 + _21.data2;
_10.data5 = _15.data1 + _21.data3;
}

View File

@ -1,7 +1,7 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 1, std430) buffer SSBO2
layout(binding = 1, std430) writeonly buffer SSBO2
{
vec4 out_data[];
} _27;

View File

@ -1,15 +1,15 @@
#version 310 es
layout(local_size_x = 4, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, std430) buffer SSBO
layout(binding = 0, std430) readonly buffer SSBO
{
float in_data[];
} _22;
layout(binding = 1, std430) buffer SSBO2
layout(binding = 1, std430) writeonly buffer SSBO2
{
float out_data[];
} _44;
} _43;
shared float sShared[4];
@ -20,6 +20,6 @@ void main()
sShared[gl_LocalInvocationIndex] = idata;
memoryBarrierShared();
barrier();
_44.out_data[ident] = sShared[(4u - gl_LocalInvocationIndex) - 1u];
_43.out_data[ident] = sShared[(4u - gl_LocalInvocationIndex) - 1u];
}

View File

@ -6,12 +6,12 @@ struct Foo
mat4 m;
};
layout(binding = 1, std430) buffer SSBO2
layout(binding = 1, std430) writeonly buffer SSBO2
{
Foo out_data[];
} _23;
layout(binding = 0, std430) buffer SSBO
layout(binding = 0, std430) readonly buffer SSBO
{
Foo in_data[];
} _30;

View File

@ -1,13 +1,13 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, std430) buffer SSBO
layout(binding = 0, std430) readonly buffer SSBO
{
mat4 mvp;
vec4 in_data[];
} _24;
layout(binding = 1, std430) buffer SSBO2
layout(binding = 1, std430) writeonly buffer SSBO2
{
vec4 out_data[];
} _89;

View File

@ -0,0 +1,26 @@
#version 310 es
layout(local_size_x = 1) in;
layout(binding = 0, std430) readonly buffer SSBO0
{
vec4 data0;
vec4 data1;
};
layout(binding = 1, std430) restrict buffer SSBO1
{
vec4 data2;
vec4 data3;
};
layout(binding = 2, std430) restrict writeonly buffer SSBO2
{
vec4 data4;
vec4 data5;
};
void main()
{
data4 = data0 + data2;
data5 = data1 + data3;
}

View File

@ -3008,3 +3008,18 @@ void Compiler::analyze_variable_scope(SPIRFunction &entry)
this->get<SPIRVariable>(loop_variable.first).loop_variable = true;
}
}
uint64_t Compiler::get_buffer_block_flags(const SPIRVariable &var)
{
auto &type = get<SPIRType>(var.basetype);
// Some flags like non-writable, non-readable are actually found
// as member decorations. If all members have a decoration set, propagate
// the decoration up as a regular variable decoration.
uint64_t base_flags = meta[var.self].decoration.decoration_flags;
uint64_t all_members_flag_mask = 0;
for (uint32_t i = 0; i < uint32_t(type.member_types.size()); i++)
all_members_flag_mask |= ~get_member_decoration_mask(type.self, i);
return base_flags | (~all_members_flag_mask);
}

View File

@ -576,6 +576,8 @@ protected:
ShaderResources get_shader_resources(const std::unordered_set<uint32_t> *active_variables) const;
VariableTypeRemapCallback variable_remap_callback;
uint64_t get_buffer_block_flags(const SPIRVariable &var);
};
}

View File

@ -1050,8 +1050,12 @@ void CompilerGLSL::emit_buffer_block_legacy(const SPIRVariable &var)
void CompilerGLSL::emit_buffer_block_native(const SPIRVariable &var)
{
auto &type = get<SPIRType>(var.basetype);
uint64_t flags = get_buffer_block_flags(var);
bool ssbo = (meta[type.self].decoration.decoration_flags & (1ull << DecorationBufferBlock)) != 0;
bool is_restrict = (meta[var.self].decoration.decoration_flags & (1ull << DecorationRestrict)) != 0;
bool is_restrict = ssbo && (flags & (1ull << DecorationRestrict)) != 0;
bool is_writeonly = ssbo && (flags & (1ull << DecorationNonReadable)) != 0;
bool is_readonly = ssbo && (flags & (1ull << DecorationNonWritable)) != 0;
add_resource_name(var.self);
@ -1065,7 +1069,9 @@ void CompilerGLSL::emit_buffer_block_native(const SPIRVariable &var)
else
resource_names.insert(buffer_name);
statement(layout_for_variable(var), is_restrict ? "restrict " : "", ssbo ? "buffer " : "uniform ", buffer_name);
statement(layout_for_variable(var), is_restrict ? "restrict " : "", is_writeonly ? "writeonly " : "",
is_readonly ? "readonly " : "", ssbo ? "buffer " : "uniform ", buffer_name);
begin_scope();
type.member_name_cache.clear();