Skip to content

Commit fa9749f

Browse files
committed
Add initial support for compute shaders.
1 parent bc4f75e commit fa9749f

File tree

12 files changed

+722
-389
lines changed

12 files changed

+722
-389
lines changed

opengl/src/generated/gl-api.ads

Lines changed: 262 additions & 253 deletions
Large diffs are not rendered by default.

opengl/src/generated/gl-load_function_pointers.adb

Lines changed: 139 additions & 133 deletions
Large diffs are not rendered by default.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
-- part of OpenGLAda, (c) 2022 Felix Krause
2+
-- released under the terms of the MIT license, see the file "COPYING"
3+
4+
with GL.Enums.Getter;
5+
with GL.API;
6+
7+
package body GL.Compute is
8+
function Max_Compute_Work_Group_Count (Index : Index_Type) return Int is
9+
Value : aliased Int;
10+
begin
11+
API.Get_Integer_Indexed
12+
(GL.Enums.Getter.Max_Compute_Work_Group_Count,
13+
Index_Type'Pos (Index),
14+
Value'Access);
15+
Raise_Exception_On_OpenGL_Error;
16+
return Value;
17+
end Max_Compute_Work_Group_Count;
18+
19+
function Max_Compute_Work_Group_Size (Index : Index_Type) return Int is
20+
Value : aliased Int;
21+
begin
22+
API.Get_Integer_Indexed
23+
(GL.Enums.Getter.Max_Compute_Work_Group_Size,
24+
Index_Type'Pos (Index),
25+
Value'Access);
26+
Raise_Exception_On_OpenGL_Error;
27+
return Value;
28+
end Max_Compute_Work_Group_Size;
29+
30+
function Max_Compute_Work_Group_Invocations return Int is
31+
Value : aliased Int;
32+
begin
33+
API.Get_Integer
34+
(GL.Enums.Getter.Max_Compute_Work_Group_Invocations,
35+
Value'Access);
36+
Raise_Exception_On_OpenGL_Error;
37+
return Value;
38+
end Max_Compute_Work_Group_Invocations;
39+
40+
procedure Dispatch_Compute
41+
(Num_Groups_X, Num_Groups_Y, Num_Groups_Z : UInt) is
42+
begin
43+
API.Dispatch_Compute (Num_Groups_X, Num_Groups_Y, Num_Groups_Z);
44+
Raise_Exception_On_OpenGL_Error;
45+
end Dispatch_Compute;
46+
end GL.Compute;
47+
48+

opengl/src/implementation/gl-enums-getter.ads

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,12 @@ package GL.Enums.Getter is
248248
Stencil_Back_Ref,
249249
Stencil_Back_Value_Mask,
250250
Stencil_Back_Writemask,
251+
Max_Compute_Work_Group_Invocations,
251252
Max_Debug_Message_Length,
252253
Max_Debug_Logged_Messages,
253254
Debug_Logged_Messages,
255+
Max_Compute_Work_Group_Count,
256+
Max_Compute_Work_Group_Size,
254257
Max_Framebuffer_Width,
255258
Max_Framebuffer_Height,
256259
Max_Framebuffer_Layers,
@@ -497,9 +500,12 @@ package GL.Enums.Getter is
497500
Stencil_Back_Ref => 16#8CA3#,
498501
Stencil_Back_Value_Mask => 16#8CA4#,
499502
Stencil_Back_Writemask => 16#8CA5#,
503+
Max_Compute_Work_Group_Invocations => 16#90EB#,
500504
Max_Debug_Message_Length => 16#9143#,
501505
Max_Debug_Logged_Messages => 16#9144#,
502506
Debug_Logged_Messages => 16#9145#,
507+
Max_Compute_Work_Group_Count => 16#91BE#,
508+
Max_Compute_Work_Group_Size => 16#91BF#,
503509
Max_Framebuffer_Width => 16#9315#,
504510
Max_Framebuffer_Height => 16#9316#,
505511
Max_Framebuffer_Layers => 16#9317#,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- part of OpenGLAda, (c) 2022 Felix Krause
2+
-- released under the terms of the MIT license, see the file "COPYING"
3+
4+
with Ada.Unchecked_Conversion;
5+
6+
with GL.API;
7+
8+
package body GL.Memory_Barriers is
9+
procedure Memory_Barrier (Bits : Barrier_Bits) is
10+
function To_BitField is new Ada.Unchecked_Conversion
11+
(Barrier_Bits, GL.Low_Level.Bitfield);
12+
begin
13+
API.Memory_Barrier (To_BitField (Bits));
14+
Raise_Exception_On_OpenGL_Error;
15+
end Memory_Barrier;
16+
end GL.Memory_Barriers;
17+

opengl/src/interface/gl-compute.ads

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- part of OpenGLAda, (c) 2022 Felix Krause
2+
-- released under the terms of the MIT license, see the file "COPYING"
3+
4+
with GL.Types;
5+
6+
package GL.Compute is
7+
pragma Preelaborate;
8+
9+
use GL.Types;
10+
11+
type Index_Type is (X, Y, Z);
12+
13+
function Max_Compute_Work_Group_Count (Index : Index_Type) return Int;
14+
function Max_Compute_Work_Group_Size (Index : Index_Type) return Int;
15+
function Max_Compute_Work_Group_Invocations return Int;
16+
17+
procedure Dispatch_Compute
18+
(Num_Groups_X, Num_Groups_Y, Num_Groups_Z : UInt);
19+
20+
private
21+
for Index_Type use (X => 0, Y => 1, Z => 2);
22+
end GL.Compute;
23+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
-- part of OpenGLAda, (c) 2022 Felix Krause
2+
-- released under the terms of the MIT license, see the file "COPYING"
3+
4+
private with GL.Low_Level;
5+
6+
package GL.Memory_Barriers is
7+
pragma Preelaborate;
8+
9+
type Barrier_Bits is record
10+
Vertex_Attrib_Array : Boolean := False;
11+
Element_Array : Boolean := False;
12+
Uniform : Boolean := False;
13+
Texture_Fetch : Boolean := False;
14+
15+
Shader_Image_Access : Boolean := False;
16+
Command : Boolean := False;
17+
Pixel_Buffer : Boolean := False;
18+
Texture_Update : Boolean := False;
19+
Buffer_Update : Boolean := False;
20+
Framebuffer : Boolean := False;
21+
Transform_Feedback : Boolean := False;
22+
Atomic_Counter : Boolean := False;
23+
Shader_Storage : Boolean := False;
24+
Client_Mapped_Buffer : Boolean := False;
25+
Query_Buffer : Boolean := False;
26+
27+
Unused : Boolean := False;
28+
end record;
29+
pragma Convention (C, Barrier_Bits);
30+
31+
procedure Memory_Barrier (Bits : Barrier_Bits);
32+
33+
private
34+
for Barrier_Bits use record
35+
Vertex_Attrib_Array at 0 range 0 .. 0;
36+
Element_Array at 0 range 1 .. 1;
37+
Uniform at 0 range 2 .. 2;
38+
Texture_Fetch at 0 range 3 .. 3;
39+
40+
Shader_Image_Access at 0 range 5 .. 5;
41+
Command at 0 range 6 .. 6;
42+
Pixel_Buffer at 0 range 7 .. 7;
43+
Texture_Update at 0 range 8 .. 8;
44+
Buffer_Update at 0 range 9 .. 9;
45+
Framebuffer at 0 range 10 .. 10;
46+
Transform_Feedback at 0 range 11 .. 11;
47+
Atomic_Counter at 0 range 12 .. 12;
48+
Shader_Storage at 0 range 13 .. 13;
49+
Client_Mapped_Buffer at 0 range 14 .. 14;
50+
Query_Buffer at 0 range 15 .. 15;
51+
52+
Unused at 0 range 16 .. 31;
53+
end record;
54+
for Barrier_Bits'Size use Low_Level.Bitfield'Size;
55+
end GL.Memory_Barriers;
56+

opengl/src/interface/gl-objects-shaders.ads

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ package GL.Objects.Shaders is
77
pragma Preelaborate;
88

99
type Shader_Type is (Fragment_Shader, Vertex_Shader, Geometry_Shader,
10-
Tess_Evaluation_Shader, Tess_Control_Shader);
10+
Tess_Evaluation_Shader, Tess_Control_Shader,
11+
Compute_Shader);
1112

1213
type Shader (Kind : Shader_Type) is new GL_Object with private;
1314

@@ -39,7 +40,8 @@ private
3940
Vertex_Shader => 16#8B31#,
4041
Geometry_Shader => 16#8DD9#,
4142
Tess_Evaluation_Shader => 16#8E87#,
42-
Tess_Control_Shader => 16#8E88#);
43+
Tess_Control_Shader => 16#8E88#,
44+
Compute_Shader => 16#91B9#);
4345
for Shader_Type'Size use Low_Level.Enum'Size;
4446

4547
end GL.Objects.Shaders;

opengl/src/specs/gl-api.spec

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ spec GL.API is
103103
Static => "glGetFloatv";
104104
procedure Get_Integer (Name : Enums.Getter.Parameter;
105105
Target : access Int) with Static => "glGetIntegerv";
106+
procedure Get_Integer_Indexed (Name : Enums.Getter.Parameter;
107+
Index : UInt;
108+
Target : access Int) with
109+
Dynamic => "glGetIntegeri_v";
106110
procedure Get_Int_Vec4 (Name : Enums.Getter.Parameter;
107111
Target : in out Ints.Vector4) with
108112
Static => "glGetIntegerv";
@@ -1300,4 +1304,16 @@ spec GL.API is
13001304
Static => "glDepthRange", Wrapper => "GL.Window.Set_Depth_Range";
13011305
procedure Viewport (X, Y : Int; Width, Height : Size) with
13021306
Static => "glViewport", Wrapper => "GL.Window.Set_Viewport";
1307+
1308+
-----------------------------------------------------------------------------
1309+
-- Compute Shaders --
1310+
-----------------------------------------------------------------------------
1311+
1312+
procedure Dispatch_Compute
1313+
(Num_Groups_X, Num_Groups_Y, Num_Groups_Z : UInt) with
1314+
Dynamic => "glDispatchCompute",
1315+
Wrapper => "GL.Compute.Dispatch_Compute";
1316+
procedure Memory_Barrier (Bits : Low_Level.Bitfield) with
1317+
Dynamic => "glMemoryBarrier",
1318+
Wrapper => "GL.Memory_Barriers.Memory_Barrier";
13031319
end GL.API;

tests/opengl-test.gpr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ project OpenGL.Test is
1111

1212
for Main use ("gl_test-vbos", "gl_test-immediate", "gl_test-shaders",
1313
"gl_test-opengl3", "gl_test-context", "gl_test-framebuffers",
14-
"gl_test-debugging");
14+
"gl_test-debugging", "gl_test-compute");
1515

1616
package Ide renames OpenGL.Ide;
1717
package Builder renames OpenGL.Builder;

0 commit comments

Comments
 (0)