xgl: Fix pMemBarriers references
authorMark Lobodzinski <mark@lunarg.com>
Thu, 29 Jan 2015 20:24:14 +0000 (14:24 -0600)
committerCourtney Goeltzenleuchter <courtney@LunarG.com>
Thu, 5 Feb 2015 00:58:10 +0000 (17:58 -0700)
Arrays of MemBarrier pointers were incorrectly declared.  Reference
bug #13273, for xgl header rev #42.

icd/intel/cmd_prepare.c
include/xgl.h
tests/blit_tests.cpp
tests/xglrenderframework.cpp

index 983e8bf..3dd79f4 100644 (file)
@@ -123,39 +123,42 @@ static uint32_t cmd_get_flush_flags(const struct intel_cmd *cmd,
 }
 
 static void cmd_memory_barriers(struct intel_cmd *cmd,
-                               uint32_t flush_flags,
+                                               uint32_t flush_flags,
                                 uint32_t memory_barrier_count,
-                                const void* memory_barriers)
+                                const void** memory_barriers)
 {
     uint32_t i;
-    XGL_MEMORY_BARRIER *memory_barrier;
-    XGL_BUFFER_MEMORY_BARRIER *buffer_memory_barrier;
-    XGL_IMAGE_MEMORY_BARRIER *image_memory_barrier;
     XGL_FLAGS input_mask = 0;
     XGL_FLAGS output_mask = 0;
 
     for (i = 0; i < memory_barrier_count; i++) {
-        memory_barrier = &((XGL_MEMORY_BARRIER *) memory_barriers)[i];
-        switch(memory_barrier->sType)
+
+        const union {
+            XGL_STRUCTURE_TYPE type;
+
+            XGL_MEMORY_BARRIER mem;
+            XGL_BUFFER_MEMORY_BARRIER buf;
+            XGL_IMAGE_MEMORY_BARRIER img;
+        } *u = memory_barriers[i];
+
+        switch(u->type)
         {
         case XGL_STRUCTURE_TYPE_MEMORY_BARRIER:
-            output_mask |= memory_barrier->outputMask;
-            input_mask |= memory_barrier->inputMask;
+            output_mask |= u->mem.outputMask;
+            input_mask  |= u->mem.inputMask;
             break;
         case XGL_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER:
-            buffer_memory_barrier = (XGL_BUFFER_MEMORY_BARRIER *) memory_barrier;
-            output_mask |= buffer_memory_barrier->outputMask;
-            input_mask |= buffer_memory_barrier->inputMask;
+            output_mask |= u->buf.outputMask;
+            input_mask  |= u->buf.inputMask;
             break;
         case XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER:
-            image_memory_barrier = (XGL_IMAGE_MEMORY_BARRIER *) memory_barrier;
-            output_mask |= image_memory_barrier->outputMask;
-            input_mask |= image_memory_barrier->inputMask;
+            output_mask |= u->img.outputMask;
+            input_mask  |= u->img.inputMask;
             {
-                struct intel_img *img = intel_img(image_memory_barrier->image);
+                struct intel_img *img = intel_img(u->img.image);
                 flush_flags |= cmd_get_flush_flags(cmd,
-                        img_get_layout_caches(img, image_memory_barrier->oldLayout),
-                        img_get_layout_caches(img, image_memory_barrier->newLayout),
+                        img_get_layout_caches(img, u->img.oldLayout),
+                        img_get_layout_caches(img, u->img.newLayout),
                         icd_format_is_ds(img->layout.format));
             }
             break;
index a7b2c6c..1c1bf31 100644 (file)
@@ -1642,7 +1642,7 @@ typedef struct _XGL_EVENT_WAIT_INFO
     XGL_WAIT_EVENT                          waitEvent;                  // Pipeline event where the wait should happen
 
     uint32_t                                memBarrierCount;            // Number of memory barriers
-    const void*                             pMemBarriers;               // Array of pointers to memory barriers (any of them can be either XGL_MEMORY_BARRIER, XGL_BUFFER_MEMORY_BARRIER, or XGL_IMAGE_MEMORY_BARRIER)
+    const void**                            pMemBarriers;               // Array of pointers to memory barriers (any of them can be either XGL_MEMORY_BARRIER, XGL_BUFFER_MEMORY_BARRIER, or XGL_IMAGE_MEMORY_BARRIER)
 } XGL_EVENT_WAIT_INFO;
 
 typedef struct _XGL_PIPELINE_BARRIER
@@ -1656,7 +1656,7 @@ typedef struct _XGL_PIPELINE_BARRIER
     XGL_WAIT_EVENT                          waitEvent;                  // Pipeline event where the wait should happen
 
     uint32_t                                memBarrierCount;            // Number of memory barriers
-    const void*                             pMemBarriers;               // Array of pointers to memory barriers (any of them can be either XGL_MEMORY_BARRIER, XGL_BUFFER_MEMORY_BARRIER, or XGL_IMAGE_MEMORY_BARRIER)
+    const void**                            pMemBarriers;               // Array of pointers to memory barriers (any of them can be either XGL_MEMORY_BARRIER, XGL_BUFFER_MEMORY_BARRIER, or XGL_IMAGE_MEMORY_BARRIER)
 } XGL_PIPELINE_BARRIER;
 
 typedef struct _XGL_MEMORY_BARRIER
index ce615cd..ebda886 100644 (file)
@@ -901,6 +901,7 @@ TEST_F(XglCmdCopyBufferTest, RAWHazard)
     // is this necessary?
     XGL_BUFFER_MEMORY_BARRIER memory_barrier = bufs[0].buffer_memory_barrier(
             XGL_MEMORY_OUTPUT_COPY_BIT, XGL_MEMORY_INPUT_COPY_BIT, 0, 4);
+    XGL_BUFFER_MEMORY_BARRIER *pmemory_barrier = &memory_barrier;
 
     XGL_SET_EVENT set_events[] = { XGL_SET_EVENT_TRANSFER_COMPLETE };
     XGL_PIPELINE_BARRIER pipeline_barrier = {};
@@ -909,7 +910,7 @@ TEST_F(XglCmdCopyBufferTest, RAWHazard)
     pipeline_barrier.pEvents = set_events;
     pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE;
     pipeline_barrier.memBarrierCount = 1;
-    pipeline_barrier.pMemBarriers = &memory_barrier;
+    pipeline_barrier.pMemBarriers = (const void **)&pmemory_barrier;
     xglCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier);
 
     XGL_BUFFER_COPY region = {};
@@ -918,12 +919,13 @@ TEST_F(XglCmdCopyBufferTest, RAWHazard)
 
     memory_barrier = bufs[1].buffer_memory_barrier(
             XGL_MEMORY_OUTPUT_COPY_BIT, XGL_MEMORY_INPUT_COPY_BIT, 0, 4);
+    pmemory_barrier = &memory_barrier;
     pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER;
     pipeline_barrier.eventCount = 1;
     pipeline_barrier.pEvents = set_events;
     pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE;
     pipeline_barrier.memBarrierCount = 1;
-    pipeline_barrier.pMemBarriers = &memory_barrier;
+    pipeline_barrier.pMemBarriers = (const void **)&pmemory_barrier;
     xglCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier);
 
     xglCmdCopyBuffer(cmd_.obj(), bufs[1].obj(), bufs[2].obj(), 1, &region);
@@ -937,13 +939,14 @@ TEST_F(XglCmdCopyBufferTest, RAWHazard)
 
     memory_barrier = bufs[1].buffer_memory_barrier(
             XGL_MEMORY_OUTPUT_COPY_BIT, XGL_MEMORY_INPUT_CPU_READ_BIT, 0, 4);
+    pmemory_barrier = &memory_barrier;
     XGL_EVENT_WAIT_INFO wait_info = {};
     wait_info.sType = XGL_STRUCTURE_TYPE_EVENT_WAIT_INFO;
     wait_info.eventCount = 1;
     wait_info.pEvents = &event;
     wait_info.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE;
     wait_info.memBarrierCount = 1;
-    wait_info.pMemBarriers = &memory_barrier;
+    wait_info.pMemBarriers = (const void **)&pmemory_barrier;
     xglCmdWaitEvents(cmd_.obj(), &wait_info);
 
     cmd_.end();
@@ -1440,7 +1443,9 @@ protected:
                 XGL_MEMORY_INPUT_COPY_BIT;
 
         std::vector<XGL_IMAGE_MEMORY_BARRIER> to_clear;
+        std::vector<XGL_IMAGE_MEMORY_BARRIER *> p_to_clear;
         std::vector<XGL_IMAGE_MEMORY_BARRIER> to_xfer;
+        std::vector<XGL_IMAGE_MEMORY_BARRIER *> p_to_xfer;
 
         for (std::vector<XGL_IMAGE_SUBRESOURCE_RANGE>::const_iterator it = ranges.begin();
              it != ranges.end(); it++) {
@@ -1448,9 +1453,11 @@ protected:
                     XGL_IMAGE_LAYOUT_GENERAL,
                     XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL,
                     *it));
+            p_to_clear.push_back(&to_clear.back());
             to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
                     XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL,
                     XGL_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it));
+            p_to_xfer.push_back(&to_xfer.back());
         }
 
         cmd_.begin();
@@ -1462,7 +1469,7 @@ protected:
         pipeline_barrier.pEvents = set_events;
         pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE;
         pipeline_barrier.memBarrierCount = to_clear.size();
-        pipeline_barrier.pMemBarriers = &to_clear[0];
+        pipeline_barrier.pMemBarriers = (const void **)&p_to_clear[0];
         xglCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier);
 
         if (test_raw_) {
@@ -1476,7 +1483,7 @@ protected:
         pipeline_barrier.pEvents = set_events;
         pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE;
         pipeline_barrier.memBarrierCount = to_xfer.size();
-        pipeline_barrier.pMemBarriers = &to_xfer[0];
+        pipeline_barrier.pMemBarriers = (const void **)&p_to_xfer[0];
         xglCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier);
 
         cmd_.end();
@@ -1668,7 +1675,9 @@ protected:
                 XGL_MEMORY_INPUT_COPY_BIT;
 
         std::vector<XGL_IMAGE_MEMORY_BARRIER> to_clear;
+        std::vector<XGL_IMAGE_MEMORY_BARRIER *> p_to_clear;
         std::vector<XGL_IMAGE_MEMORY_BARRIER> to_xfer;
+        std::vector<XGL_IMAGE_MEMORY_BARRIER *> p_to_xfer;
 
         for (std::vector<XGL_IMAGE_SUBRESOURCE_RANGE>::const_iterator it = ranges.begin();
              it != ranges.end(); it++) {
@@ -1676,9 +1685,11 @@ protected:
                     XGL_IMAGE_LAYOUT_GENERAL,
                     XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL,
                     *it));
+            p_to_clear.push_back(&to_clear.back());
             to_xfer.push_back(img.image_memory_barrier(all_cache_outputs, all_cache_inputs,
                     XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL,
                     XGL_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, *it));
+            p_to_xfer.push_back(&to_xfer.back());
         }
 
         cmd_.begin();
@@ -1690,7 +1701,7 @@ protected:
         pipeline_barrier.pEvents = set_events;
         pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE;
         pipeline_barrier.memBarrierCount = to_clear.size();
-        pipeline_barrier.pMemBarriers = &to_clear[0];
+        pipeline_barrier.pMemBarriers = (const void **)&p_to_clear[0];
         xglCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier);
 
         xglCmdClearDepthStencil(cmd_.obj(), img.obj(), depth, stencil, ranges.size(), &ranges[0]);
@@ -1700,7 +1711,7 @@ protected:
         pipeline_barrier.pEvents = set_events;
         pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE;
         pipeline_barrier.memBarrierCount = to_xfer.size();
-        pipeline_barrier.pMemBarriers = &to_xfer[0];
+        pipeline_barrier.pMemBarriers = (const void **)&p_to_xfer[0];
         xglCmdPipelineBarrier(cmd_.obj(), &pipeline_barrier);
 
         cmd_.end();
index aaff412..87a5bdc 100644 (file)
@@ -591,6 +591,7 @@ void XglConstantBufferObj::BufferMemoryBarrier(
 
     XGL_BUFFER_MEMORY_BARRIER memory_barrier =
         buffer_memory_barrier(outputMask, inputMask, 0, m_numVertices * m_stride);
+    XGL_BUFFER_MEMORY_BARRIER *pmemory_barrier = &memory_barrier;
 
     XGL_SET_EVENT set_events[] = { XGL_SET_EVENT_GPU_COMMANDS_COMPLETE };
     XGL_PIPELINE_BARRIER pipeline_barrier = {};
@@ -599,7 +600,7 @@ void XglConstantBufferObj::BufferMemoryBarrier(
     pipeline_barrier.pEvents = set_events;
     pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE;
     pipeline_barrier.memBarrierCount = 1;
-    pipeline_barrier.pMemBarriers = &memory_barrier;
+    pipeline_barrier.pMemBarriers = (const void **)&pmemory_barrier;
 
     // write barrier to the command buffer
     m_commandBuffer->PipelineBarrier(&pipeline_barrier);
@@ -1022,6 +1023,7 @@ void XglCommandBufferObj::ClearAllBuffers(XGL_DEPTH_STENCIL_BIND_INFO *depthSten
     memory_barrier.inputMask = input_mask;
     memory_barrier.newLayout = XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL;
     memory_barrier.subresourceRange = srRange;
+    XGL_IMAGE_MEMORY_BARRIER *pmemory_barrier = &memory_barrier;
 
     XGL_SET_EVENT set_events[] = { XGL_SET_EVENT_GPU_COMMANDS_COMPLETE };
     XGL_PIPELINE_BARRIER pipeline_barrier = {};
@@ -1030,7 +1032,7 @@ void XglCommandBufferObj::ClearAllBuffers(XGL_DEPTH_STENCIL_BIND_INFO *depthSten
     pipeline_barrier.pEvents = set_events;
     pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE;
     pipeline_barrier.memBarrierCount = 1;
-    pipeline_barrier.pMemBarriers = &memory_barrier;
+    pipeline_barrier.pMemBarriers = (const void **)&pmemory_barrier;
 
     // clear the back buffer to dark grey
     uint32_t clearColor[4] = {64, 64, 64, 0};
@@ -1108,6 +1110,7 @@ void XglCommandBufferObj::PrepareAttachments()
     memory_barrier.inputMask = input_mask;
     memory_barrier.newLayout = XGL_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
     memory_barrier.subresourceRange = srRange;
+    XGL_IMAGE_MEMORY_BARRIER *pmemory_barrier = &memory_barrier;
 
     XGL_SET_EVENT set_events[] = { XGL_SET_EVENT_GPU_COMMANDS_COMPLETE };
     XGL_PIPELINE_BARRIER pipeline_barrier = {};
@@ -1116,7 +1119,7 @@ void XglCommandBufferObj::PrepareAttachments()
     pipeline_barrier.pEvents = set_events;
     pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE;
     pipeline_barrier.memBarrierCount = 1;
-    pipeline_barrier.pMemBarriers = &memory_barrier;
+    pipeline_barrier.pMemBarriers = (const void **)&pmemory_barrier;
 
     for(i=0; i<m_renderTargetCount; i++)
     {