From a9ae38392fd4359242fda1d2961f8347dbe970f7 Mon Sep 17 00:00:00 2001 From: Jon Ashburn Date: Fri, 16 Jan 2015 09:37:43 -0700 Subject: [PATCH] memory alloc: Add MEMORY_ALLOCATION_COUNT support and usage in tests. Driver always does one allocation but tests support drivers with N allocations. Conflicts: demos/cube.c demos/tri.c tests/image_tests.cpp tests/render_tests.cpp --- demos/cube.c | 131 ++++++++++++++++++++++++++++------------------- demos/tri.c | 130 ++++++++++++++++++++++++++++------------------ icd/intel/obj.c | 8 +++ include/xgl.h | 6 ++- tests/image_tests.cpp | 74 ++++++++++++++++---------- tests/render_tests.cpp | 54 +++++++++++-------- tests/xgltestbinding.cpp | 13 +++-- 7 files changed, 260 insertions(+), 156 deletions(-) diff --git a/demos/cube.c b/demos/cube.c index d6dec16..c0ce5fe 100644 --- a/demos/cube.c +++ b/demos/cube.c @@ -212,7 +212,8 @@ struct demo { XGL_FORMAT format; XGL_IMAGE image; - XGL_GPU_MEMORY mem; + XGL_UINT num_mem; + XGL_GPU_MEMORY *mem; XGL_DEPTH_STENCIL_VIEW view; } depth; @@ -221,7 +222,8 @@ struct demo { char *filename; XGL_IMAGE image; - XGL_GPU_MEMORY mem; + XGL_UINT num_mem; + XGL_GPU_MEMORY *mem; XGL_IMAGE_VIEW view; } textures[DEMO_TEXTURE_COUNT]; @@ -477,9 +479,11 @@ static void demo_prepare_depth(struct demo *demo) .arraySize = 1, .flags = 0, }; - XGL_MEMORY_REQUIREMENTS mem_reqs; + XGL_MEMORY_REQUIREMENTS *mem_reqs; XGL_SIZE mem_reqs_size = sizeof(XGL_MEMORY_REQUIREMENTS); XGL_RESULT err; + XGL_UINT num_allocations = 0; + XGL_SIZE num_alloc_size = sizeof(num_allocations); demo->depth.format = depth_format; @@ -488,28 +492,36 @@ static void demo_prepare_depth(struct demo *demo) &demo->depth.image); assert(!err); - err = xglGetObjectInfo(demo->depth.image, - XGL_INFO_TYPE_MEMORY_REQUIREMENTS, - &mem_reqs_size, &mem_reqs); - assert(!err && mem_reqs_size == sizeof(mem_reqs)); - mem_alloc.allocationSize = mem_reqs.size; - mem_alloc.alignment = mem_reqs.alignment; - mem_alloc.heapCount = mem_reqs.heapCount; - XGL_UINT heapInfo[1]; - mem_alloc.pHeaps = (const XGL_UINT *)&heapInfo; - memcpy(&heapInfo, mem_reqs.pHeaps, - sizeof(mem_reqs.pHeaps[0]) * mem_reqs.heapCount); + err = xglGetObjectInfo(demo->depth.image, XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT, &num_alloc_size, &num_allocations); + assert(!err && num_alloc_size == sizeof(num_allocations)); + mem_reqs = malloc(num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS)); + demo->depth.mem = malloc(num_allocations * sizeof(XGL_GPU_MEMORY)); + demo->depth.num_mem = num_allocations; + err = xglGetObjectInfo(demo->depth.image, + XGL_INFO_TYPE_MEMORY_REQUIREMENTS, + &mem_reqs_size, mem_reqs); + assert(!err && mem_reqs_size == num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS)); + + for (XGL_UINT i = 0; i < num_allocations; i ++) { + mem_alloc.allocationSize = mem_reqs[i].size; + mem_alloc.alignment = mem_reqs[i].alignment; + mem_alloc.heapCount = mem_reqs[i].heapCount; + XGL_UINT heapInfo[mem_reqs[i].heapCount]; + mem_alloc.pHeaps = (const XGL_UINT *) heapInfo; + memcpy(heapInfo, mem_reqs[i].pHeaps, + sizeof(mem_reqs[i].pHeaps[0]) * mem_reqs[i].heapCount); - /* allocate memory */ - err = xglAllocMemory(demo->device, &mem_alloc, - &demo->depth.mem); - assert(!err); + /* allocate memory */ + err = xglAllocMemory(demo->device, &mem_alloc, + &(demo->depth.mem[i])); + assert(!err); - /* bind memory */ - err = xglBindObjectMemory(demo->depth.image, 0, - demo->depth.mem, 0); - assert(!err); + /* bind memory */ + err = xglBindObjectMemory(demo->depth.image, i, + demo->depth.mem[i], 0); + assert(!err); + } /* create image view */ view.image = demo->depth.image; @@ -730,8 +742,11 @@ static void demo_prepare_textures(struct demo *demo) .subresourceRange = { XGL_IMAGE_ASPECT_COLOR, 0, 1, 0, 1 }, .minLod = 0.0f, }; - XGL_MEMORY_REQUIREMENTS mem_reqs; + + XGL_MEMORY_REQUIREMENTS *mem_reqs; XGL_SIZE mem_reqs_size = sizeof(XGL_MEMORY_REQUIREMENTS); + XGL_UINT num_allocations = 0; + XGL_SIZE num_alloc_size = sizeof(num_allocations); /* create sampler */ err = xglCreateSampler(demo->device, &sampler, @@ -744,27 +759,36 @@ static void demo_prepare_textures(struct demo *demo) assert(!err); err = xglGetObjectInfo(demo->textures[i].image, - XGL_INFO_TYPE_MEMORY_REQUIREMENTS, - &mem_reqs_size, &mem_reqs); - assert(!err && mem_reqs_size == sizeof(mem_reqs)); - - mem_alloc.allocationSize = mem_reqs.size; - mem_alloc.alignment = mem_reqs.alignment; - mem_alloc.heapCount = mem_reqs.heapCount; - XGL_UINT heapInfo[1]; - mem_alloc.pHeaps = (const XGL_UINT *)&heapInfo; - memcpy(&heapInfo, mem_reqs.pHeaps, - sizeof(mem_reqs.pHeaps[0]) * mem_reqs.heapCount); - - /* allocate memory */ - err = xglAllocMemory(demo->device, &mem_alloc, - &demo->textures[i].mem); - assert(!err); - - /* bind memory */ - err = xglBindObjectMemory(demo->textures[i].image, 0, - demo->textures[i].mem, 0); - assert(!err); + XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT, + &num_alloc_size, &num_allocations); + assert(!err && num_alloc_size == sizeof(num_allocations)); + mem_reqs = malloc(num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS)); + demo->textures[i].mem = malloc(num_allocations * sizeof(XGL_GPU_MEMORY)); + demo->textures[i].num_mem = num_allocations; + err = xglGetObjectInfo(demo->textures[i].image, + XGL_INFO_TYPE_MEMORY_REQUIREMENTS, + &mem_reqs_size, mem_reqs); + assert(!err && mem_reqs_size == num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS)); + + for (XGL_UINT j = 0; j < num_allocations; j ++) { + mem_alloc.allocationSize = mem_reqs[j].size; + mem_alloc.alignment = mem_reqs[j].alignment; + mem_alloc.heapCount = mem_reqs[j].heapCount; + XGL_UINT heapInfo[mem_reqs[j].heapCount]; + mem_alloc.pHeaps = (const XGL_UINT *)heapInfo; + memcpy(heapInfo, mem_reqs[j].pHeaps, + sizeof(mem_reqs[j].pHeaps[0]) * mem_reqs[j].heapCount); + + /* allocate memory */ + err = xglAllocMemory(demo->device, &mem_alloc, + &(demo->textures[i].mem[j])); + assert(!err); + + /* bind memory */ + err = xglBindObjectMemory(demo->textures[i].image, j, + demo->textures[i].mem[j], 0); + assert(!err); + } /* create image view */ view.image = demo->textures[i].image; @@ -786,13 +810,14 @@ static void demo_prepare_textures(struct demo *demo) err = xglGetImageSubresourceInfo(demo->textures[i].image, &subres, XGL_INFO_TYPE_SUBRESOURCE_LAYOUT, &layout_size, &layout); assert(!err && layout_size == sizeof(layout)); + assert(demo->textures[i].num_mem == 1); - err = xglMapMemory(demo->textures[i].mem, 0, &data); + err = xglMapMemory(demo->textures[i].mem[0], 0, &data); assert(!err); loadTexture(tex_files[i], data, &layout, &tex_width, &tex_height); - err = xglUnmapMemory(demo->textures[i].mem); + err = xglUnmapMemory(demo->textures[i].mem[0]); assert(!err); } } @@ -843,9 +868,9 @@ void demo_prepare_cube_data_buffer(struct demo *demo) alloc_info.allocationSize = mem_reqs.size; alloc_info.alignment = mem_reqs.alignment; alloc_info.heapCount = mem_reqs.heapCount; - XGL_UINT heapInfo[1]; - alloc_info.pHeaps = (const XGL_UINT *)&heapInfo; - memcpy(&heapInfo, mem_reqs.pHeaps, + XGL_UINT heapInfo[mem_reqs.heapCount]; + alloc_info.pHeaps = (const XGL_UINT *)heapInfo; + memcpy(heapInfo, mem_reqs.pHeaps, sizeof(mem_reqs.pHeaps[0]) * mem_reqs.heapCount); alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; @@ -1482,7 +1507,7 @@ static void demo_init(struct demo *demo) static void demo_cleanup(struct demo *demo) { - XGL_UINT i; + XGL_UINT i, j; xglDestroyObject(demo->desc_set); xglDestroyObject(demo->desc_region); @@ -1503,13 +1528,15 @@ static void demo_cleanup(struct demo *demo) for (i = 0; i < DEMO_TEXTURE_COUNT; i++) { xglDestroyObject(demo->textures[i].view); xglDestroyObject(demo->textures[i].image); - xglFreeMemory(demo->textures[i].mem); + for (j = 0; j < demo->textures[i].num_mem; j++) + xglFreeMemory(demo->textures[i].mem[j]); xglDestroyObject(demo->textures[i].sampler); } xglDestroyObject(demo->depth.view); xglDestroyObject(demo->depth.image); - xglFreeMemory(demo->depth.mem); + for (j = 0; j < demo->depth.num_mem; j++) + xglFreeMemory(demo->depth.mem[j]); for (i = 0; i < DEMO_BUFFER_COUNT; i++) { xglDestroyObject(demo->buffers[i].fence); diff --git a/demos/tri.c b/demos/tri.c index 5c16e53..d2a780b 100644 --- a/demos/tri.c +++ b/demos/tri.c @@ -43,7 +43,8 @@ struct demo { XGL_FORMAT format; XGL_IMAGE image; - XGL_GPU_MEMORY mem; + XGL_UINT num_mem; + XGL_GPU_MEMORY *mem; XGL_DEPTH_STENCIL_VIEW view; } depth; @@ -51,7 +52,8 @@ struct demo { XGL_SAMPLER sampler; XGL_IMAGE image; - XGL_GPU_MEMORY mem; + XGL_UINT num_mem; + XGL_GPU_MEMORY *mem; XGL_IMAGE_VIEW view; } textures[DEMO_TEXTURE_COUNT]; @@ -288,9 +290,12 @@ static void demo_prepare_depth(struct demo *demo) .arraySize = 1, .flags = 0, }; - XGL_MEMORY_REQUIREMENTS mem_reqs; - XGL_SIZE mem_reqs_size= sizeof(XGL_MEMORY_REQUIREMENTS); + + XGL_MEMORY_REQUIREMENTS *mem_reqs; + XGL_SIZE mem_reqs_size = sizeof(XGL_MEMORY_REQUIREMENTS); XGL_RESULT err; + XGL_UINT num_allocations = 0; + XGL_SIZE num_alloc_size = sizeof(num_allocations); demo->depth.format = depth_format; @@ -299,28 +304,36 @@ static void demo_prepare_depth(struct demo *demo) &demo->depth.image); assert(!err); - err = xglGetObjectInfo(demo->depth.image, - XGL_INFO_TYPE_MEMORY_REQUIREMENTS, - &mem_reqs_size, &mem_reqs); - assert(!err && mem_reqs_size == sizeof(mem_reqs)); - mem_alloc.allocationSize = mem_reqs.size; - mem_alloc.alignment = mem_reqs.alignment; - mem_alloc.heapCount = mem_reqs.heapCount; - XGL_UINT heapInfo[1]; - mem_alloc.pHeaps = (const XGL_UINT *)&heapInfo; - memcpy(&heapInfo, mem_reqs.pHeaps, - sizeof(mem_reqs.pHeaps[0]) * mem_reqs.heapCount); + err = xglGetObjectInfo(demo->depth.image, XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT, &num_alloc_size, &num_allocations); + assert(!err && num_alloc_size == sizeof(num_allocations)); + mem_reqs = malloc(num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS)); + demo->depth.mem = malloc(num_allocations * sizeof(XGL_GPU_MEMORY)); + demo->depth.num_mem = num_allocations; + err = xglGetObjectInfo(demo->depth.image, + XGL_INFO_TYPE_MEMORY_REQUIREMENTS, + &mem_reqs_size, mem_reqs); + assert(!err && mem_reqs_size == num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS)); + + for (XGL_UINT i = 0; i < num_allocations; i ++) { + mem_alloc.allocationSize = mem_reqs[i].size; + mem_alloc.alignment = mem_reqs[i].alignment; + mem_alloc.heapCount = mem_reqs[i].heapCount; + XGL_UINT heapInfo[mem_reqs[i].heapCount]; + mem_alloc.pHeaps = (const XGL_UINT *)heapInfo; + memcpy(heapInfo, mem_reqs[i].pHeaps, + sizeof(mem_reqs[i].pHeaps[0]) * mem_reqs[i].heapCount); - /* allocate memory */ - err = xglAllocMemory(demo->device, &mem_alloc, - &demo->depth.mem); - assert(!err); + /* allocate memory */ + err = xglAllocMemory(demo->device, &mem_alloc, + &(demo->depth.mem[i])); + assert(!err); - /* bind memory */ - err = xglBindObjectMemory(demo->depth.image, 0, - demo->depth.mem, 0); - assert(!err); + /* bind memory */ + err = xglBindObjectMemory(demo->depth.image, i, + demo->depth.mem[i], 0); + assert(!err); + } /* create image view */ view.image = demo->depth.image; @@ -392,8 +405,11 @@ static void demo_prepare_textures(struct demo *demo) .subresourceRange = { XGL_IMAGE_ASPECT_COLOR, 0, 1, 0, 1 }, .minLod = 0.0f, }; - XGL_MEMORY_REQUIREMENTS mem_reqs; - XGL_SIZE mem_reqs_size= sizeof(XGL_MEMORY_REQUIREMENTS); + + XGL_MEMORY_REQUIREMENTS *mem_reqs; + XGL_SIZE mem_reqs_size = sizeof(XGL_MEMORY_REQUIREMENTS); + XGL_UINT num_allocations = 0; + XGL_SIZE num_alloc_size = sizeof(num_allocations); /* create sampler */ err = xglCreateSampler(demo->device, &sampler, @@ -406,27 +422,36 @@ static void demo_prepare_textures(struct demo *demo) assert(!err); err = xglGetObjectInfo(demo->textures[i].image, - XGL_INFO_TYPE_MEMORY_REQUIREMENTS, - &mem_reqs_size, &mem_reqs); - assert(!err && mem_reqs_size == sizeof(mem_reqs)); - - mem_alloc.allocationSize = mem_reqs.size; - mem_alloc.alignment = mem_reqs.alignment; - mem_alloc.heapCount = mem_reqs.heapCount; - XGL_UINT heapInfo[0]; - mem_alloc.pHeaps = (const XGL_UINT *)&heapInfo; - memcpy(&heapInfo, mem_reqs.pHeaps, - sizeof(mem_reqs.pHeaps[0]) * mem_reqs.heapCount); - - /* allocate memory */ - err = xglAllocMemory(demo->device, &mem_alloc, - &demo->textures[i].mem); - assert(!err); - - /* bind memory */ - err = xglBindObjectMemory(demo->textures[i].image, 0, - demo->textures[i].mem, 0); - assert(!err); + XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT, + &num_alloc_size, &num_allocations); + assert(!err && num_alloc_size == sizeof(num_allocations)); + mem_reqs = malloc(num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS)); + demo->textures[i].mem = malloc(num_allocations * sizeof(XGL_GPU_MEMORY)); + demo->textures[i].num_mem = num_allocations; + err = xglGetObjectInfo(demo->textures[i].image, + XGL_INFO_TYPE_MEMORY_REQUIREMENTS, + &mem_reqs_size, mem_reqs); + assert(!err && mem_reqs_size == num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS)); + + for (XGL_UINT j = 0; j < num_allocations; j ++) { + mem_alloc.allocationSize = mem_reqs[j].size; + mem_alloc.alignment = mem_reqs[j].alignment; + mem_alloc.heapCount = mem_reqs[j].heapCount; + XGL_UINT heapInfo[mem_reqs[j].heapCount]; + mem_alloc.pHeaps = (const XGL_UINT *)heapInfo; + memcpy(heapInfo, mem_reqs[j].pHeaps, + sizeof(mem_reqs[j].pHeaps[0]) * mem_reqs[j].heapCount); + + /* allocate memory */ + err = xglAllocMemory(demo->device, &mem_alloc, + &(demo->textures[i].mem[j])); + assert(!err); + + /* bind memory */ + err = xglBindObjectMemory(demo->textures[i].image, j, + demo->textures[i].mem[j], 0); + assert(!err); + } /* create image view */ view.image = demo->textures[i].image; @@ -449,8 +474,9 @@ static void demo_prepare_textures(struct demo *demo) err = xglGetImageSubresourceInfo(demo->textures[i].image, &subres, XGL_INFO_TYPE_SUBRESOURCE_LAYOUT, &layout_size, &layout); assert(!err && layout_size == sizeof(layout)); + assert(demo->textures[i].num_mem == 1); - err = xglMapMemory(demo->textures[i].mem, 0, &data); + err = xglMapMemory(demo->textures[i].mem[0], 0, &data); assert(!err); for (y = 0; y < tex_height; y++) { @@ -459,7 +485,7 @@ static void demo_prepare_textures(struct demo *demo) row[x] = tex_colors[i][(x & 1) ^ (y & 1)]; } - err = xglUnmapMemory(demo->textures[i].mem); + err = xglUnmapMemory(demo->textures[i].mem[0]); assert(!err); } } @@ -1022,7 +1048,7 @@ static void demo_init(struct demo *demo) static void demo_cleanup(struct demo *demo) { - XGL_UINT i; + XGL_UINT i, j; xglDestroyObject(demo->desc_set); xglDestroyObject(demo->desc_region); @@ -1045,14 +1071,16 @@ static void demo_cleanup(struct demo *demo) xglDestroyObject(demo->textures[i].view); xglBindObjectMemory(demo->textures[i].image, 0, XGL_NULL_HANDLE, 0); xglDestroyObject(demo->textures[i].image); - xglFreeMemory(demo->textures[i].mem); + for (j = 0; j < demo->textures[i].num_mem; j++) + xglFreeMemory(demo->textures[i].mem[j]); xglDestroyObject(demo->textures[i].sampler); } xglDestroyObject(demo->depth.view); xglBindObjectMemory(demo->depth.image, 0, XGL_NULL_HANDLE, 0); xglDestroyObject(demo->depth.image); - xglFreeMemory(demo->depth.mem); + for (j = 0; j < demo->depth.num_mem; j++) + xglFreeMemory(demo->depth.mem[j]); for (i = 0; i < DEMO_BUFFER_COUNT; i++) { xglDestroyObject(demo->buffers[i].fence); diff --git a/icd/intel/obj.c b/icd/intel/obj.c index 817affa..eb502e7 100644 --- a/icd/intel/obj.c +++ b/icd/intel/obj.c @@ -49,6 +49,7 @@ XGL_RESULT intel_base_get_info(struct intel_base *base, int type, { XGL_RESULT ret = XGL_SUCCESS; XGL_SIZE s; + XGL_UINT *count; switch (type) { case XGL_INFO_TYPE_MEMORY_REQUIREMENTS: @@ -59,6 +60,13 @@ XGL_RESULT intel_base_get_info(struct intel_base *base, int type, memset(data, 0, s); break; + case XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT: + *size = sizeof(XGL_UINT); + if (data == NULL) + return ret; + count = (XGL_UINT *) data; + *count = 1; + break; default: ret = XGL_ERROR_INVALID_VALUE; break; diff --git a/include/xgl.h b/include/xgl.h index f9e794b..80f0a64 100644 --- a/include/xgl.h +++ b/include/xgl.h @@ -711,8 +711,10 @@ typedef enum _XGL_SUBRESOURCE_INFO_TYPE typedef enum _XGL_OBJECT_INFO_TYPE { // Info type for xglGetObjectInfo() - XGL_INFO_TYPE_MEMORY_REQUIREMENTS = 0x00000000, - + XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT = 0x00000000, + XGL_INFO_TYPE_MEMORY_REQUIREMENTS = 0x00000001, + XGL_INFO_TYPE_BUFFER_MEMORY_REQUIREMENTS = 0x00000002, + XGL_INFO_TYPE_IMAGE_MEMORY_REQUIREMENTS = 0x00000003, XGL_MAX_ENUM(_XGL_OBJECT_INFO_TYPE) } XGL_OBJECT_INFO_TYPE; diff --git a/tests/image_tests.cpp b/tests/image_tests.cpp index 2694e92..57213c1 100644 --- a/tests/image_tests.cpp +++ b/tests/image_tests.cpp @@ -79,7 +79,8 @@ protected: XGL_PHYSICAL_GPU objs[XGL_MAX_PHYSICAL_GPUS]; XGL_UINT gpu_count; XGL_IMAGE m_image; - XGL_GPU_MEMORY m_image_mem; + XGL_GPU_MEMORY *m_image_mem; + XGL_UINT m_num_mem; virtual void SetUp() { XGL_RESULT err; @@ -188,43 +189,60 @@ void XglImageTest::CreateImage(XGL_UINT w, XGL_UINT h) err = xglCreateImage(device(), &imageCreateInfo, &m_image); ASSERT_XGL_SUCCESS(err); - XGL_MEMORY_REQUIREMENTS mem_req; - size_t data_size = sizeof(mem_req); - err = xglGetObjectInfo(m_image, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, - &data_size, &mem_req); - ASSERT_XGL_SUCCESS(err); - ASSERT_EQ(data_size, sizeof(mem_req)); - ASSERT_NE(0, mem_req.size) << "xglGetObjectInfo (Event): Failed - expect images to require memory"; - - // XGL_RESULT XGLAPI xglAllocMemory( - // XGL_DEVICE device, - // const XGL_MEMORY_ALLOC_INFO* pAllocInfo, - // XGL_GPU_MEMORY* pMem); + XGL_MEMORY_REQUIREMENTS *mem_req; + XGL_SIZE mem_reqs_size = sizeof(XGL_MEMORY_REQUIREMENTS); + XGL_UINT num_allocations = 0; + XGL_SIZE num_alloc_size = sizeof(num_allocations); XGL_MEMORY_ALLOC_INFO mem_info; - XGL_UINT heapInfo[mem_req.heapCount]; - - memset(&mem_info, 0, sizeof(mem_info)); - mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; - mem_info.allocationSize = mem_req.size; - mem_info.alignment = mem_req.alignment; - mem_info.heapCount = mem_req.heapCount; - mem_info.pHeaps = heapInfo; - memcpy(heapInfo, mem_req.pHeaps, sizeof(XGL_UINT)*mem_info.heapCount); - mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; - mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT; - err = xglAllocMemory(device(), &mem_info, &m_image_mem); - ASSERT_XGL_SUCCESS(err); - err = xglBindObjectMemory(m_image, 0, m_image_mem, 0); + err = xglGetObjectInfo(m_image, XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT, + &num_alloc_size, &num_allocations); ASSERT_XGL_SUCCESS(err); + ASSERT_EQ(num_alloc_size,sizeof(num_allocations)); + mem_req = (XGL_MEMORY_REQUIREMENTS *) malloc(num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS)); + m_image_mem = (XGL_GPU_MEMORY *) malloc(num_allocations * sizeof(XGL_GPU_MEMORY)); + m_num_mem = num_allocations; + err = xglGetObjectInfo(m_image, + XGL_INFO_TYPE_MEMORY_REQUIREMENTS, + &mem_reqs_size, mem_req); + ASSERT_XGL_SUCCESS(err); + ASSERT_EQ(mem_reqs_size, num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS)); + + + for (XGL_UINT i = 0; i < num_allocations; i ++) { + ASSERT_NE(0, mem_req[i].size) << "xglGetObjectInfo (Image): Failed - expect images to require memory"; + memset(&mem_info, 0, sizeof(mem_info)); + mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; + mem_info.allocationSize = mem_req[i].size; + mem_info.alignment = mem_req[i].alignment; + mem_info.heapCount = mem_req[i].heapCount; + XGL_UINT heapInfo[mem_req[i].heapCount]; + mem_info.pHeaps = heapInfo; + memcpy(heapInfo, mem_req[i].pHeaps, sizeof(XGL_UINT)*mem_info.heapCount); + mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; + mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT; + + /* allocate memory */ + err = xglAllocMemory(device(), &mem_info, &m_image_mem[i]); + ASSERT_XGL_SUCCESS(err); + + /* bind memory */ + err = xglBindObjectMemory(m_image, i, m_image_mem[i], 0); + ASSERT_XGL_SUCCESS(err); + } } void XglImageTest::DestroyImage() { + XGL_RESULT err; // All done with image memory, clean up ASSERT_XGL_SUCCESS(xglBindObjectMemory(m_image, 0, XGL_NULL_HANDLE, 0)); - ASSERT_XGL_SUCCESS(xglFreeMemory(m_image_mem)); + for (XGL_UINT i = 0 ; i < m_num_mem; i++) { + err = xglFreeMemory(m_image_mem[i]); + ASSERT_XGL_SUCCESS(err); + } + ASSERT_XGL_SUCCESS(xglDestroyObject(m_image)); } diff --git a/tests/render_tests.cpp b/tests/render_tests.cpp index 226472f..92603b7 100644 --- a/tests/render_tests.cpp +++ b/tests/render_tests.cpp @@ -230,7 +230,8 @@ protected: XGL_FORMAT m_depth_stencil_fmt; XGL_IMAGE m_depthStencilImage; - XGL_GPU_MEMORY m_depthStencilMem; + XGL_UINT m_num_mem; + XGL_GPU_MEMORY *m_depthStencilMem; XGL_DEPTH_STENCIL_VIEW m_depthStencilView; XglMemoryRefManager m_memoryRefManager; @@ -329,8 +330,10 @@ void XglRenderTest::InitDepthStencil() XGL_IMAGE_CREATE_INFO image; XGL_MEMORY_ALLOC_INFO mem_alloc; XGL_DEPTH_STENCIL_VIEW_CREATE_INFO view; - XGL_MEMORY_REQUIREMENTS mem_reqs; + XGL_MEMORY_REQUIREMENTS *mem_reqs; XGL_SIZE mem_reqs_size=sizeof(XGL_MEMORY_REQUIREMENTS); + XGL_UINT num_allocations = 0; + XGL_SIZE num_alloc_size = sizeof(num_allocations); // Clean up default state created by framework if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil); @@ -366,26 +369,37 @@ void XglRenderTest::InitDepthStencil() ASSERT_XGL_SUCCESS(err); err = xglGetObjectInfo(m_depthStencilImage, - XGL_INFO_TYPE_MEMORY_REQUIREMENTS, - &mem_reqs_size, &mem_reqs); + XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT, + &num_alloc_size, &num_allocations); ASSERT_XGL_SUCCESS(err); - ASSERT_EQ(mem_reqs_size, sizeof(mem_reqs)); - - XGL_UINT heapInfo[mem_reqs.heapCount]; - mem_alloc.allocationSize = mem_reqs.size; - mem_alloc.alignment = mem_reqs.alignment; - mem_alloc.heapCount = mem_reqs.heapCount; - mem_alloc.pHeaps = heapInfo; - memcpy(heapInfo, mem_reqs.pHeaps, - sizeof(mem_reqs.pHeaps) * mem_reqs.heapCount); - - /* allocate memory */ - err = xglAllocMemory(device(), &mem_alloc, &m_depthStencilMem); - ASSERT_XGL_SUCCESS(err); - - /* bind memory */ - err = xglBindObjectMemory(m_depthStencilImage, 0, m_depthStencilMem, 0); + ASSERT_EQ(num_alloc_size, sizeof(num_allocations)); + mem_reqs = (XGL_MEMORY_REQUIREMENTS *) malloc(num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS)); + m_depthStencilMem = (XGL_GPU_MEMORY *) malloc(num_allocations * sizeof(XGL_GPU_MEMORY)); + m_num_mem = num_allocations; + err = xglGetObjectInfo(m_depthStencilImage, + XGL_INFO_TYPE_MEMORY_REQUIREMENTS, + &mem_reqs_size, mem_reqs); ASSERT_XGL_SUCCESS(err); + ASSERT_EQ(mem_reqs_size, sizeof(*mem_reqs)); + + for (XGL_UINT i = 0; i < num_allocations; i ++) { + mem_alloc.allocationSize = mem_reqs[i].size; + mem_alloc.alignment = mem_reqs[i].alignment; + mem_alloc.heapCount = mem_reqs[i].heapCount; + XGL_UINT heapInfo[mem_reqs[i].heapCount]; + mem_alloc.pHeaps = heapInfo; + memcpy(heapInfo, mem_reqs[i].pHeaps, + sizeof(mem_reqs[i].pHeaps[0]) * mem_reqs[i].heapCount); + + /* allocate memory */ + err = xglAllocMemory(device(), &mem_alloc, &m_depthStencilMem[i]); + ASSERT_XGL_SUCCESS(err); + + /* bind memory */ + err = xglBindObjectMemory(m_depthStencilImage, i, + m_depthStencilMem[i], 0); + ASSERT_XGL_SUCCESS(err); + } XGL_DYNAMIC_DS_STATE_CREATE_INFO depthStencil = {}; depthStencil.sType = XGL_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO; diff --git a/tests/xgltestbinding.cpp b/tests/xgltestbinding.cpp index 1f388a4..226442d 100644 --- a/tests/xgltestbinding.cpp +++ b/tests/xgltestbinding.cpp @@ -183,13 +183,20 @@ void BaseObject::reinit(XGL_BASE_OBJECT obj, bool own) uint32_t BaseObject::memory_allocation_count() const { - return memory_requirements().size(); + return get_info(obj_, XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT, 1)[0]; } std::vector BaseObject::memory_requirements() const { + XGL_RESULT err; + XGL_UINT num_allocations = 0; + XGL_SIZE num_alloc_size = sizeof(num_allocations); + err = xglGetObjectInfo(obj_, XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT, + &num_alloc_size, &num_allocations); + EXPECT(err == XGL_SUCCESS && num_alloc_size == sizeof(num_allocations)); std::vector info = get_info(obj_, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, 0); + EXPECT(info.size() == num_allocations); if (info.size() == 1 && !info[0].size) info.clear(); @@ -230,7 +237,7 @@ void Object::cleanup() void Object::bind_memory(uint32_t alloc_idx, const GpuMemory &mem, XGL_GPU_SIZE mem_offset) { - EXPECT(!alloc_idx && xglBindObjectMemory(obj(), 0, mem.obj(), mem_offset) == XGL_SUCCESS); + EXPECT(xglBindObjectMemory(obj(), alloc_idx, mem.obj(), mem_offset) == XGL_SUCCESS); } void Object::bind_memory(uint32_t alloc_idx, XGL_GPU_SIZE offset, XGL_GPU_SIZE size, @@ -241,7 +248,7 @@ void Object::bind_memory(uint32_t alloc_idx, XGL_GPU_SIZE offset, XGL_GPU_SIZE s void Object::unbind_memory(uint32_t alloc_idx) { - EXPECT(!alloc_idx && xglBindObjectMemory(obj(), 0, XGL_NULL_HANDLE, 0) == XGL_SUCCESS); + EXPECT(xglBindObjectMemory(obj(), alloc_idx, XGL_NULL_HANDLE, 0) == XGL_SUCCESS); } void Object::unbind_memory() -- 2.7.4