mojoshader_vulkan.c
changeset 1275 7fc13cff18ff
parent 1272 cddbd25553fe
child 1276 89c389e4112f
--- a/mojoshader_vulkan.c	Fri Jul 03 10:43:01 2020 -0400
+++ b/mojoshader_vulkan.c	Mon Jul 06 12:51:28 2020 -0400
@@ -181,14 +181,11 @@
 static uint32_t uniform_data_size(MOJOSHADER_vkShader *shader)
 {
     int32_t i;
-    int32_t uniformSize;
     int32_t buflen = 0;
+    const int32_t uniformSize = 16; // Yes, even the bool registers
     for (i = 0; i < shader->parseData->uniform_count; i++)
     {
         const int32_t arrayCount = shader->parseData->uniforms[i].array_count;
-        uniformSize = 16;
-        if (shader->parseData->uniforms[i].type == MOJOSHADER_UNIFORM_BOOL)
-            uniformSize = 1;
         buflen += (arrayCount ? arrayCount : 1) * uniformSize;
     } // for
 
@@ -230,10 +227,11 @@
 
 static void update_uniform_buffer(MOJOSHADER_vkShader *shader)
 {
-    int32_t i;
+    int32_t i, j;
     void *map;
     int32_t offset;
     uint8_t *contents;
+    uint32_t *contentsI;
     float *regF; int *regI; uint8_t *regB;
     MOJOSHADER_vkUniformBuffer *ubo;
     VkDeviceMemory uboMemory;
@@ -321,7 +319,7 @@
         {
             case MOJOSHADER_UNIFORM_FLOAT:
                 memcpy(
-                    contents + (offset * 16),
+                    contents + offset,
                     &regF[4 * index],
                     size * 16
                 );
@@ -329,18 +327,16 @@
 
             case MOJOSHADER_UNIFORM_INT:
                 memcpy(
-                    contents + (offset * 16),
+                    contents + offset,
                     &regI[4 * index],
                     size * 16
                 );
                 break;
 
             case MOJOSHADER_UNIFORM_BOOL:
-                memcpy(
-                    contents + offset,
-                    &regB[index],
-                    size
-                );
+                contentsI = (uint32_t *) (contents + offset);
+                for (j = 0; j < size; j++)
+                    contentsI[j * 4] = regB[index + j];
                 break;
 
             default:
@@ -351,7 +347,7 @@
                 break;
         } // switch
 
-        offset += size;
+        offset += size * 16;
     } // for
 
     ctx->vkUnmapMemory(