Skip to content

Commit

Permalink
fix(gl): handle compute shader version headers
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Nov 23, 2024
1 parent 059cdc2 commit daef590
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 0 additions & 2 deletions core/samples/gl/compute/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ int main()

// FIXME: createShaderStage will inject #version 330 core, so this will fail.
auto cs = renderDevice.createShaderStage(gl::Stage::Compute, R"glsl(
#version 430 core
layout(local_size_x = 16, local_size_y = 16) in;
layout(binding = 0, rgba32f) uniform image2D tex;
Expand Down
15 changes: 7 additions & 8 deletions core/src/gl/ogl_render_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2353,20 +2353,19 @@ ShaderStage OGLRenderDevice::createShaderStage(Stage stage, const char* src)
}

#ifdef __EMSCRIPTEN__
#define GLSL_HEADER \
"#version 300 es\n" \
"#define ES\n" \
"precision highp float;\n" \
"precision highp int;\n" \
"precision highp sampler2DArray;\n"
const char* header = "#version 300 es\n"
"#define ES\n"
"precision highp float;\n"
"precision highp int;\n"
"precision highp sampler2DArray;\n";
#else
#define GLSL_HEADER "#version 330 core\n"
const char* header = stage == Stage::Compute ? "#version 430 core" : "#version 330 core\n";

Check warning on line 2362 in core/src/gl/ogl_render_device.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/gl/ogl_render_device.cpp#L2362

Added line #L2362 was not covered by tests
#endif

// Initialize shader
GLuint id;
CHECK_VAL(id, glCreateShader(shaderType));
const char* srcs[] = {GLSL_HEADER, src};
const char* srcs[] = {header, src};
CHECK(glShaderSource(id, 2, (const GLchar* const*)srcs, nullptr));
CHECK(glCompileShader(id));

Check warning on line 2370 in core/src/gl/ogl_render_device.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/gl/ogl_render_device.cpp#L2367-L2370

Added lines #L2367 - L2370 were not covered by tests

Expand Down

0 comments on commit daef590

Please sign in to comment.