Skip to content

Commit

Permalink
[Shaders] Added the 'restrict' keyword to all images in compute shaders
Browse files Browse the repository at this point in the history
- As per https://www.khronos.org/opengl/wiki/Image_Load_Store#Memory_qualifiers, this is something that should be done wherever possible

- Fixed the Z local size layout declaration in most compute shaders, which was incorrectly set for X
  - This was not an issue, as 1 is the default for all three components anyway
  • Loading branch information
Razakhel committed Sep 2, 2023
1 parent c8b365f commit 1476dbe
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions shaders/perlin_noise_1d.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
layout(local_size_x = 1, local_size_y = 1, local_size_x = 1) in;
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

layout(r16f, binding = 0) uniform writeonly image1D uniNoiseMap;
layout(r16f, binding = 0) uniform writeonly restrict image1D uniNoiseMap;
uniform float uniNoiseFactor = 0.01;
uniform int uniOctaveCount = 1;

Expand Down
4 changes: 2 additions & 2 deletions shaders/perlin_noise_2d.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
layout(local_size_x = 1, local_size_y = 1, local_size_x = 1) in;
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

layout(r16f, binding = 0) uniform writeonly image2D uniNoiseMap;
layout(r16f, binding = 0) uniform writeonly restrict image2D uniNoiseMap;
uniform float uniNoiseFactor = 0.01;
uniform int uniOctaveCount = 1;

Expand Down
4 changes: 2 additions & 2 deletions shaders/perlin_noise_3d.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
layout(local_size_x = 1, local_size_y = 1, local_size_x = 1) in;
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

layout(r16f, binding = 0) uniform writeonly image3D uniNoiseMap;
layout(r16f, binding = 0) uniform writeonly restrict image3D uniNoiseMap;
uniform float uniNoiseFactor = 0.01;
uniform int uniOctaveCount = 1;

Expand Down
4 changes: 2 additions & 2 deletions shaders/worley_noise_2d.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
layout(local_size_x = 1, local_size_y = 1, local_size_x = 1) in;
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

layout(r16f, binding = 0) uniform writeonly image2D uniNoiseMap;
layout(r16f, binding = 0) uniform writeonly restrict image2D uniNoiseMap;
uniform float uniNoiseFactor = 0.01;

const vec2 offsets[9] = vec2[](
Expand Down
4 changes: 2 additions & 2 deletions shaders/worley_noise_3d.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
layout(local_size_x = 1, local_size_y = 1, local_size_x = 1) in;
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

layout(r16f, binding = 0) uniform writeonly image3D uniNoiseMap;
layout(r16f, binding = 0) uniform writeonly restrict image3D uniNoiseMap;
uniform float uniNoiseFactor = 0.01;

const vec3 offsets[27] = vec3[](
Expand Down
4 changes: 2 additions & 2 deletions tests/assets/shaders/basic.comp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Enabling the extension (if supported) on the shader's side is required if GL <4.3
// Enabling the extension (if supported) on the shader's side is required for GL <4.3
#extension GL_ARB_compute_shader : enable

layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

layout(rgba32f, binding = 0) uniform writeonly image2D uniOutput;
layout(rgba32f, binding = 0) uniform writeonly restrict image2D uniOutput;

void main() {
imageStore(uniOutput, ivec2(0), vec4(0.0));
Expand Down
2 changes: 1 addition & 1 deletion tests/src/RaZ/Render/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ TEST_CASE("Compute shader from source") {
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(rgba32f, binding = 0) uniform writeonly image2D uniOutput;
layout(rgba32f, binding = 0) uniform writeonly restrict image2D uniOutput;
void main() {
imageStore(uniOutput, ivec2(0), vec4(0.0));
Expand Down
2 changes: 1 addition & 1 deletion tests/src/RaZ/Render/ShaderProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ constexpr std::string_view compSource = R"(
uniform int uniInt[2];
uniform uint uniUint;
layout(rgba32f, binding = 0) uniform writeonly image2D uniImage2D;
layout(rgba32f, binding = 0) uniform writeonly restrict image2D uniImage2D;
void main() {
imageStore(uniImage2D, ivec2(uniInt[0] + uniInt[1], int(uniUint)), vec4(uniVec3, uniFloat[0] + uniFloat[1] + uniFloat[2]));
Expand Down

0 comments on commit 1476dbe

Please sign in to comment.