Skip to content

Commit

Permalink
merian-shaders: Sanitize gbuffer macros
Browse files Browse the repository at this point in the history
  • Loading branch information
LDAP committed Aug 5, 2024
1 parent 5e93432 commit 5d727f2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions include/merian-shaders/gbuffer.glsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace merian_nodes {
#else
#extension GL_EXT_shader_explicit_arithmetic_types : enable
#extension GL_EXT_scalar_block_layout : enable
#endif

struct GBuffer {
Expand All @@ -25,15 +26,15 @@ struct GBuffer {
#define gbuffer_block_size (1 << gbuffer_block_size_power)
#define gbuffer_block_size_minus_one (gbuffer_block_size - 1)
// increases the number such that it is divisible by the block size
#define gbuffer_dimension_for_block_size(number) ((number + gbuffer_block_size_minus_one) & ~gbuffer_block_size_minus_one)
#define gbuffer_dimension_for_block_size(number) (((number) + gbuffer_block_size_minus_one) & ~gbuffer_block_size_minus_one)
// computes the buffer size for the GBuffer
#define gbuffer_size(width, height) (gbuffer_dimension_for_block_size(width) * gbuffer_dimension_for_block_size(height))
// only valid in C
#define gbuffer_size_bytes(width, height) (gbuffer_size(width, height) * sizeof(merian_nodes::GBuffer))

// z-Curve for better memory locality
#define gbuffer_block(ipos, resolution) ((ipos.x >> gbuffer_block_size_power) + ((resolution.x + gbuffer_block_size_minus_one) >> gbuffer_block_size_power) * (ipos.y >> gbuffer_block_size_power))
#define gbuffer_inner(ipos) ((ipos.x & gbuffer_block_size_minus_one) + gbuffer_block_size * (ipos.y & gbuffer_block_size_minus_one))
#define gbuffer_block(ipos, resolution) (((ipos).x >> gbuffer_block_size_power) + (((resolution).x + gbuffer_block_size_minus_one) >> gbuffer_block_size_power) * ((ipos).y >> gbuffer_block_size_power))
#define gbuffer_inner(ipos) (((ipos).x & gbuffer_block_size_minus_one) + gbuffer_block_size * ((ipos).y & gbuffer_block_size_minus_one))
#define gbuffer_index(ipos, resolution) (gbuffer_inner(ipos) + gbuffer_block(ipos, resolution) * gbuffer_block_size * gbuffer_block_size)

#ifdef __cplusplus
Expand Down

0 comments on commit 5d727f2

Please sign in to comment.