changeset 871:1f1e959a5fa3

fix: error on bad uniform-attribute ordering
author Sam <sam@basx.dev>
date Mon, 08 Jan 2024 19:18:01 +0700
parents b975eab2b694
children 1ee397815b0b
files semicongine/core/gpu_types.nim
diffstat 1 files changed, 3 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/semicongine/core/gpu_types.nim	Sun Jan 07 00:56:44 2024 +0700
+++ b/semicongine/core/gpu_types.nim	Mon Jan 08 19:18:01 2024 +0700
@@ -371,11 +371,14 @@
     return @[]
   # currently only a single uniform block supported, therefore binding = 0
   result.add(&"layout(std430, binding = {binding}) uniform T{blockName} {{")
+  var last_size = high(int)
   for attribute in group:
+    assert attribute.size <= last_size, &"The attribute '{attribute.name}' is bigger than the attribute before, which is not allowed" # using smaller uniform-types first will lead to problems (I think due to alignment, there is also some stuff on the internet about this ;)
     var arrayDecl = ""
     if attribute.arrayCount > 0:
       arrayDecl = &"[{attribute.arrayCount}]"
     result.add(&"    {attribute.theType.glslType} {attribute.name}{arrayDecl};")
+    last_size = attribute.size
   result.add(&"}} {blockName};")
 
 func glslSamplers*(group: openArray[ShaderAttribute], basebinding: int): seq[string] =