Skip to content

Commit bdfb3e7

Browse files
committed
Fix support for 64-bit attributes and uniforms
1 parent 4cb2654 commit bdfb3e7

10 files changed

Lines changed: 286 additions & 104 deletions

File tree

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
- Fixed support for 64-bit attributes and uniforms
2+
13
### 5.6.4
24
- [GL] Dispose MultimediaTimer in LodRenderer to avoid resource exhaustion
35
- [GL] Fixed M22f, M23f, M33f geometry attributes in LodRenderer

paket.dependencies

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ nuget Aardvark.Base.Fonts ~> 5.3.20
2222

2323
nuget Aardvark.Assembler ~> 0.1.0
2424

25-
nuget FShade.Core ~> 5.7.0
26-
nuget FShade ~> 5.7.0
27-
nuget FShade.Debug ~> 5.7.0
25+
nuget FShade.Core ~> 5.7.3
26+
nuget FShade ~> 5.7.3
27+
nuget FShade.Debug ~> 5.7.3
2828

2929
nuget Unofficial.OpenVR ~> 1.1.0
3030
nuget CommonMark.NET ~> 0.15.1

paket.lock

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -123,39 +123,39 @@ NUGET
123123
Hopac (>= 0.4.1)
124124
FsCheck (2.16.6)
125125
FSharp.Core (>= 4.2.3)
126-
FShade (5.7)
127-
FShade.Core (5.7)
128-
FShade.GLSL (5.7)
129-
FShade.Imperative (5.7)
130-
FShade.SpirV (5.7)
131-
FShade.Core (5.7)
126+
FShade (5.7.3)
127+
FShade.Core (5.7.3)
128+
FShade.GLSL (5.7.3)
129+
FShade.Imperative (5.7.3)
130+
FShade.SpirV (5.7.3)
131+
FShade.Core (5.7.3)
132132
Aardvark.Base (>= 5.3.18 < 5.4)
133133
Aardvark.Base.FSharp (>= 5.3.18 < 5.4)
134-
FShade.Imperative (5.7)
135-
FSharp.Core (>= 8.0)
136-
FShade.Debug (5.7)
134+
FShade.Imperative (5.7.3)
135+
FSharp.Core (>= 8.0.100)
136+
FShade.Debug (5.7.3)
137137
Aardvark.Base (>= 5.3.18 < 5.4)
138138
Aardvark.Base.FSharp (>= 5.3.18 < 5.4)
139-
FShade.Core (5.7)
140-
FShade.Imperative (5.7)
141-
FSharp.Core (>= 8.0)
142-
FShade.GLSL (5.7)
139+
FShade.Core (5.7.3)
140+
FShade.Imperative (5.7.3)
141+
FSharp.Core (>= 8.0.100)
142+
FShade.GLSL (5.7.3)
143143
Aardvark.Base (>= 5.3.18 < 5.4)
144144
Aardvark.Base.FSharp (>= 5.3.18 < 5.4)
145-
FShade.Core (5.7)
146-
FShade.Imperative (5.7)
147-
FSharp.Core (>= 8.0)
148-
FShade.Imperative (5.7)
145+
FShade.Core (5.7.3)
146+
FShade.Imperative (5.7.3)
147+
FSharp.Core (>= 8.0.100)
148+
FShade.Imperative (5.7.3)
149149
Aardvark.Base (>= 5.3.18 < 5.4)
150150
Aardvark.Base.FSharp (>= 5.3.18 < 5.4)
151-
FSharp.Core (>= 8.0)
151+
FSharp.Core (>= 8.0.100)
152152
FsPickler (>= 5.3.2 < 5.4)
153-
FShade.SpirV (5.7)
153+
FShade.SpirV (5.7.3)
154154
Aardvark.Base (>= 5.3.18 < 5.4)
155155
Aardvark.Base.FSharp (>= 5.3.18 < 5.4)
156-
FShade.Core (5.7)
157-
FShade.Imperative (5.7)
158-
FSharp.Core (>= 8.0)
156+
FShade.Core (5.7.3)
157+
FShade.Imperative (5.7.3)
158+
FSharp.Core (>= 8.0.100)
159159
FSharp.Core (8.0.100)
160160
FSharp.Data (6.4)
161161
FSharp.Core (>= 6.0.1)

src/Aardvark.Rendering.GL/Resources/Pointers.fs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ module PointerContextExtensions =
116116
let mt = typeof<GLSLType.Interop.M24f>
117117
struct (mt, struct (V2i(4, 2), VertexAttribPointerType.Float, sizeof<float32>))
118118

119-
m24f :: builtin
119+
let m24d =
120+
let mt = typeof<GLSLType.Interop.M24d>
121+
struct (mt, struct (V2i(4, 2), VertexAttribPointerType.Double, sizeof<float>))
122+
123+
m24f :: m24d :: builtin
120124

121125
Dictionary.ofListV (primitives @ vectors @ colors @ matrices)
122126

src/Aardvark.Rendering.Vulkan/Management/ResourceManager.fs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,9 +904,13 @@ module Resources =
904904

905905
let inputAttributes =
906906
paramsWithInputs |> List.collecti (fun binding struct (location, desc) ->
907-
desc.offsets |> List.mapi (fun i offset ->
907+
let slotsPerRow =
908+
let rowSize = VkFormat.pixelSizeInBytes desc.inputFormat
909+
(rowSize + 15) / 16
910+
911+
desc.offsets |> List.mapi (fun row offset ->
908912
VkVertexInputAttributeDescription(
909-
uint32 (location + i),
913+
uint32 (location + row * slotsPerRow),
910914
uint32 binding,
911915
desc.inputFormat,
912916
uint32 offset

src/Aardvark.Rendering/Uniforms/UniformWriters.fs

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,43 @@ module GLSLType =
5454
{ M00 = float32 m.M00; M01 = float32 m.M01; M02 = float32 m.M02; M03 = 0.0f
5555
M10 = float32 m.M10; M11 = float32 m.M11; M12 = float32 m.M12; M13 = 0.0f }
5656

57+
/// Type representing 2x4 matrices
58+
/// Only used for padding rows of 2x3 matrices
59+
[<Struct; StructLayout(LayoutKind.Sequential)>]
60+
type M24d =
61+
val M00 : float
62+
val M01 : float
63+
val M02 : float
64+
val M03 : float
65+
val M10 : float
66+
val M11 : float
67+
val M12 : float
68+
val M13 : float
69+
70+
static do PrimitiveValueConverter.addConverters [
71+
// padding for 2 row matrices
72+
( fun (i : M22f) -> M24d &i ) :> obj
73+
( fun (i : M22d) -> M24d &i ) :> obj
74+
( fun (i : M23f) -> M24d &i ) :> obj
75+
( fun (i : M23d) -> M24d &i ) :> obj
76+
]
77+
78+
new (m : inref<M22f>) =
79+
{ M00 = float m.M00; M01 = float m.M01; M02 = 0.0; M03 = 0.0
80+
M10 = float m.M10; M11 = float m.M11; M12 = 0.0; M13 = 0.0 }
81+
82+
new (m : inref<M22d>) =
83+
{ M00 = m.M00; M01 = m.M01; M02 = 0.0; M03 = 0.0
84+
M10 = m.M10; M11 = m.M11; M12 = 0.0; M13 = 0.0 }
85+
86+
new (m : inref<M23f>) =
87+
{ M00 = float m.M00; M01 = float m.M01; M02 = float m.M02; M03 = 0.0
88+
M10 = float m.M10; M11 = float m.M11; M12 = float m.M12; M13 = 0.0 }
89+
90+
new (m : inref<M23d>) =
91+
{ M00 = m.M00; M01 = m.M01; M02 = m.M02; M03 = 0.0
92+
M10 = m.M10; M11 = m.M11; M12 = m.M12; M13 = 0.0 }
93+
5794
module Patterns =
5895
open TypeMeta
5996

@@ -64,6 +101,7 @@ module GLSLType =
64101
| MatrixOf r -> ValueSome r
65102
| _ ->
66103
if t = typeof<M24f> then ValueSome (V2i(4, 2), typeof<float32>)
104+
elif t = typeof<M24d> then ValueSome (V2i(4, 2), typeof<float>)
67105
else ValueNone
68106

69107
let toType =
@@ -83,7 +121,7 @@ module GLSLType =
83121

84122
Float(16), typeof<float16>
85123
Float(32), typeof<float32>
86-
Float(64), typeof<float32>
124+
Float(64), typeof<float>
87125

88126
Vec(3, Int(false, 8)), typeof<C3b>
89127
Vec(4, Int(false, 8)), typeof<C4b>
@@ -103,21 +141,21 @@ module GLSLType =
103141
Vec(3, Float(32)), typeof<V3f>
104142
Vec(4, Float(32)), typeof<V4f>
105143

106-
Vec(2, Float(64)), typeof<V2f>
107-
Vec(3, Float(64)), typeof<V3f>
108-
Vec(4, Float(64)), typeof<V4f>
109-
110-
Mat(2,2,Float(32)), typeof<Interop.M24f> // Matrix rows need to be padded to 4 elements according to std140
111-
Mat(2,3,Float(32)), typeof<Interop.M24f>
112-
Mat(3,3,Float(32)), typeof<M34f>
113-
Mat(3,4,Float(32)), typeof<M34f>
114-
Mat(4,4,Float(32)), typeof<M44f>
115-
116-
Mat(2,2,Float(64)), typeof<Interop.M24f>
117-
Mat(2,3,Float(64)), typeof<Interop.M24f>
118-
Mat(3,3,Float(64)), typeof<M34f>
119-
Mat(3,4,Float(64)), typeof<M34f>
120-
Mat(4,4,Float(64)), typeof<M44f>
144+
Vec(2, Float(64)), typeof<V2d>
145+
Vec(3, Float(64)), typeof<V3d>
146+
Vec(4, Float(64)), typeof<V4d>
147+
148+
Mat(2, 2, Float(32)), typeof<Interop.M24f> // Matrix rows need to be padded to 4 elements according to std140
149+
Mat(2, 3, Float(32)), typeof<Interop.M24f>
150+
Mat(3, 3, Float(32)), typeof<M34f>
151+
Mat(3, 4, Float(32)), typeof<M34f>
152+
Mat(4, 4, Float(32)), typeof<M44f>
153+
154+
Mat(2, 2, Float(64)), typeof<M22d>
155+
Mat(2, 3, Float(64)), typeof<Interop.M24d>
156+
Mat(3, 3, Float(64)), typeof<M34d>
157+
Mat(3, 4, Float(64)), typeof<M34d>
158+
Mat(4, 4, Float(64)), typeof<M44d>
121159
]
122160

123161
let rec sizeof (t : GLSLType) =

src/GLVM/glvm.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ DllExport(void) vmInit()
102102
glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDPROC)getProc("glDrawArraysInstanced");
103103
glDrawElementsBaseVertex = (PFNGLDRAWELEMENTSBASEVERTEXPROC)getProc("glDrawElementsBaseVertex");
104104
glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)getProc("glVertexAttribPointer");
105+
glVertexAttribLPointer = (PFNGLVERTEXATTRIBLPOINTERPROC)getProc("glVertexAttribLPointer");
105106
glVertexAttribIPointer = (PFNGLVERTEXATTRIBIPOINTERPROC)getProc("glVertexAttribIPointer");
106107
glUniform1fv = (PFNGLUNIFORM1FVPROC)getProc("glUniform1fv");
107108
glUniform1iv = (PFNGLUNIFORM1IVPROC)getProc("glUniform1iv");
@@ -120,7 +121,7 @@ DllExport(void) vmInit()
120121
glVertexAttrib4f = (PFNGLVERTEXATTRIB4FPROC)getProc("glVertexAttrib4f");
121122

122123
glVertexAttrib4fv = (PFNGLVERTEXATTRIB4FVPROC)getProc("glVertexAttrib4fv");
123-
glVertexAttrib4dv = (PFNGLVERTEXATTRIB4DVPROC)getProc("glVertexAttrib4dv");
124+
glVertexAttribL4dv = (PFNGLVERTEXATTRIB4DVPROC)getProc("glVertexAttribL4dv");
124125

125126
glVertexAttrib4sv = (PFNGLVERTEXATTRIB4SVPROC)getProc("glVertexAttrib4sv");
126127
glVertexAttrib4iv = (PFNGLVERTEXATTRIB4IVPROC)getProc("glVertexAttrib4iv");
@@ -1273,10 +1274,13 @@ DllExport(void) hglBindVertexAttributes(void** contextHandle, VertexInputBinding
12731274
switch (b.Type)
12741275
{
12751276
case GL_FLOAT:
1276-
case GL_DOUBLE:
12771277
glVertexAttribPointer(b.Index, b.Size, b.Type, 0, b.Stride, (void*)(size_t)b.Offset);
12781278
break;
12791279

1280+
case GL_DOUBLE:
1281+
glVertexAttribLPointer(b.Index, b.Size, b.Type, b.Stride, (void*)(size_t)b.Offset);
1282+
break;
1283+
12801284
case GL_BYTE:
12811285
case GL_UNSIGNED_BYTE:
12821286
case GL_SHORT:
@@ -1323,8 +1327,7 @@ DllExport(void) hglBindVertexAttributes(void** contextHandle, VertexInputBinding
13231327
break;
13241328

13251329
case GL_DOUBLE:
1326-
// Note: Even if input is double, we assume that shader wants float (hence no L)
1327-
glVertexAttrib4dv(b.Index, (GLdouble*)&b.Value);
1330+
glVertexAttribL4dv(b.Index, (GLdouble*)&b.Value);
13281331
break;
13291332

13301333
case GL_BYTE:

src/GLVM/glvm.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static PFNGLSTENCILOPSEPARATEPROC glStencilOpSeparate;
5151
static PFNGLPATCHPARAMETERIPROC glPatchParameteri;
5252
static PFNGLDRAWARRAYSINSTANCEDPROC glDrawArraysInstanced;
5353
static PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;
54+
static PFNGLVERTEXATTRIBLPOINTERPROC glVertexAttribLPointer;
5455
static PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer;
5556
static PFNGLUNIFORM1FVPROC glUniform1fv;
5657
static PFNGLUNIFORM1IVPROC glUniform1iv;
@@ -68,7 +69,7 @@ static PFNGLVERTEXATTRIB2FPROC glVertexAttrib2f;
6869
static PFNGLVERTEXATTRIB3FPROC glVertexAttrib3f;
6970
static PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f;
7071
static PFNGLVERTEXATTRIB4FVPROC glVertexAttrib4fv;
71-
static PFNGLVERTEXATTRIB4DVPROC glVertexAttrib4dv;
72+
static PFNGLVERTEXATTRIBL4DVPROC glVertexAttribL4dv;
7273
static PFNGLVERTEXATTRIB4SVPROC glVertexAttrib4sv;
7374
static PFNGLVERTEXATTRIB4IVPROC glVertexAttrib4iv;
7475
static PFNGLVERTEXATTRIB4BVPROC glVertexAttrib4bv;

0 commit comments

Comments
 (0)