tests:Use command buffer object in SetMemoryState
diff --git a/tests/xglrenderframework.cpp b/tests/xglrenderframework.cpp
index 3acac40..12ad1cc 100644
--- a/tests/xglrenderframework.cpp
+++ b/tests/xglrenderframework.cpp
@@ -551,6 +551,8 @@
 XglConstantBufferObj::XglConstantBufferObj(XglDevice *device)
 {
     m_device = device;
+    m_commandBuffer = 0;
+    m_fence = 0;
 
     memset(&m_constantBufferView,0,sizeof(m_constantBufferView));
     memset(&m_constantBufferMem,0,sizeof(m_constantBufferMem));
@@ -567,6 +569,8 @@
 
     memset(&m_constantBufferView,0,sizeof(m_constantBufferView));
     memset(&m_constantBufferMem,0,sizeof(m_constantBufferMem));
+    m_commandBuffer = 0;
+    m_fence = 0;
 
     alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
     alloc_info.allocationSize = constantCount * constantSize;
@@ -601,6 +605,7 @@
 XglConstantBufferObj::~XglConstantBufferObj()
 {
     if (m_constantBufferMem != XGL_NULL_HANDLE) xglFreeMemory(m_constantBufferMem);
+    if (m_fence != XGL_NULL_HANDLE) xglDestroyObject(m_fence);
 }
 
 void XglConstantBufferObj::Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset, XGL_UINT binding)
@@ -611,11 +616,31 @@
 
 void XglConstantBufferObj::SetMemoryState(XGL_CMD_BUFFER cmdBuffer, XGL_MEMORY_STATE newState)
 {
+    XGL_RESULT err = XGL_SUCCESS;
+    XGL_CMD_BUFFER bufferArray[1];
+
     if (this->m_constantBufferView.state == newState)
         return;
 
+    if (!m_commandBuffer)
+    {
+        XGL_FENCE_CREATE_INFO fence_info;
+        memset(&fence_info, 0, sizeof(fence_info));
+        fence_info.sType = XGL_STRUCTURE_TYPE_FENCE_CREATE_INFO;
+        err = xglCreateFence(m_device->device(), &fence_info, &m_fence);
+
+        m_commandBuffer = new XglCommandBufferObj(m_device);
+
+    }
+    else
+    {
+        err = xglWaitForFences(m_device->device(), 1, &m_fence, XGL_TRUE, 0);
+    }
+
+    bufferArray[0] = m_commandBuffer->GetBufferHandle();
+
     // open the command buffer
-    XGL_RESULT err = xglBeginCommandBuffer( cmdBuffer, 0 );
+    err = xglBeginCommandBuffer( bufferArray[0], 0 );
     ASSERT_XGL_SUCCESS(err);
 
     XGL_MEMORY_STATE_TRANSITION transition = {};
@@ -626,11 +651,11 @@
     transition.regionSize = m_numVertices * m_stride;
 
     // write transition to the command buffer
-    xglCmdPrepareMemoryRegions( cmdBuffer, 1, &transition );
+    xglCmdPrepareMemoryRegions( bufferArray[0], 1, &transition );
     this->m_constantBufferView.state = newState;
 
     // finish recording the command buffer
-    err = xglEndCommandBuffer( cmdBuffer );
+    err = xglEndCommandBuffer( bufferArray[0] );
     ASSERT_XGL_SUCCESS(err);
 
     XGL_UINT32     numMemRefs=1;
@@ -640,7 +665,7 @@
     memRefs.mem = m_constantBufferMem;
 
     // submit the command buffer to the universal queue
-    err = xglQueueSubmit( m_device->m_queue, 1, &cmdBuffer, numMemRefs, &memRefs, NULL );
+    err = xglQueueSubmit( m_device->m_queue, 1, bufferArray, numMemRefs, &memRefs, m_fence );
     ASSERT_XGL_SUCCESS(err);
 }
 
@@ -1000,10 +1025,6 @@
 {
     return m_cmdBuffer;
 }
-XGL_CMD_BUFFER* XglCommandBufferObj::GetBufferPointer()
-{
-    return &m_cmdBuffer;
-}
 XglCommandBufferObj::~XglCommandBufferObj()
 {
     if (m_cmdBuffer != XGL_NULL_HANDLE) xglDestroyObject(m_cmdBuffer);
diff --git a/tests/xglrenderframework.h b/tests/xglrenderframework.h
index a1e2ea3..9c19eb3 100644
--- a/tests/xglrenderframework.h
+++ b/tests/xglrenderframework.h
@@ -103,7 +103,6 @@
     XglCommandBufferObj(XglDevice *device);
     ~XglCommandBufferObj();
     XGL_CMD_BUFFER  GetBufferHandle();
-    XGL_CMD_BUFFER* GetBufferPointer();
 
 protected:
     XglDevice                      *m_device;
@@ -127,6 +126,8 @@
     XglDevice                      *m_device;
     int                             m_numVertices;
     int                             m_stride;
+    XglCommandBufferObj             *m_commandBuffer;
+    XGL_FENCE                       m_fence;
 };
 
 class XglIndexBufferObj : public XglConstantBufferObj