diff options
| author | Courtney Goeltzenleuchter <courtney@LunarG.com> | 2015-04-21 09:31:23 -0600 |
|---|---|---|
| committer | Courtney Goeltzenleuchter <courtney@LunarG.com> | 2015-04-22 10:48:24 -0600 |
| commit | c56c36a8fef8868c742c2d41cbbafdc6181c9a61 (patch) | |
| tree | 446d03c72eb58aee798bbafd45a7a60853ead56c | |
| parent | f3aeb2bdd72a84d0893a49cfb0798d1d0080a1a4 (diff) | |
| download | usermoji-c56c36a8fef8868c742c2d41cbbafdc6181c9a61.tar.xz | |
demos: update memory usage flags
Add memory usage flag parameter to prepare_texture
function so that images are allocated with proper usage
flags set.
| -rw-r--r-- | demos/cube.c | 30 | ||||
| -rw-r--r-- | demos/tri.c | 12 |
2 files changed, 23 insertions, 19 deletions
diff --git a/demos/cube.c b/demos/cube.c index 79aefccd..49c848ee 100644 --- a/demos/cube.c +++ b/demos/cube.c @@ -670,15 +670,15 @@ static void demo_prepare_depth(struct demo *demo) } /** loadTexture - * loads a png file into an memory object, using cstdio , libpng. + * loads a png file into an memory object, using cstdio , libpng. * - * \param demo : Needed to access VK calls - * \param filename : the png file to be loaded - * \param width : width of png, to be updated as a side effect of this function - * \param height : height of png, to be updated as a side effect of this function + * \param demo : Needed to access VK calls + * \param filename : the png file to be loaded + * \param width : width of png, to be updated as a side effect of this function + * \param height : height of png, to be updated as a side effect of this function * - * \return bool : an opengl texture id. true if successful?, - * should be validated by the client of this function. + * \return bool : an opengl texture id. true if successful?, + * should be validated by the client of this function. * * Source: http://en.wikibooks.org/wiki/OpenGL_Programming/Intermediate/Textures * Modified to copy image to memory @@ -821,6 +821,7 @@ static void demo_prepare_texture_image(struct demo *demo, const char *filename, struct texture_object *tex_obj, VkImageTiling tiling, + VkImageUsageFlags usage, VkFlags mem_props) { const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; @@ -844,7 +845,7 @@ static void demo_prepare_texture_image(struct demo *demo, .arraySize = 1, .samples = 1, .tiling = tiling, - .usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT, + .usage = usage, .flags = 0, }; VkMemoryAllocInfo mem_alloc = { @@ -876,7 +877,6 @@ static void demo_prepare_texture_image(struct demo *demo, VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS, &mem_reqs_size, mem_reqs); assert(!err && mem_reqs_size == num_allocations * sizeof(VkMemoryRequirements)); - mem_alloc.memProps = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; for (uint32_t j = 0; j < num_allocations; j ++) { mem_alloc.allocationSize = mem_reqs[j].size; @@ -962,17 +962,19 @@ static void demo_prepare_textures(struct demo *demo) if (props.linearTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT && !demo->use_staging_buffer) { /* Device can texture using linear textures */ demo_prepare_texture_image(demo, tex_files[i], &demo->textures[i], - VK_IMAGE_TILING_LINEAR, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); + VK_IMAGE_TILING_LINEAR, VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); } else if (props.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) { /* Must use staging buffer to copy linear texture to optimized */ struct texture_object staging_texture; memset(&staging_texture, 0, sizeof(staging_texture)); demo_prepare_texture_image(demo, tex_files[i], &staging_texture, - VK_IMAGE_TILING_LINEAR, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); + VK_IMAGE_TILING_LINEAR, VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); demo_prepare_texture_image(demo, tex_files[i], &demo->textures[i], - VK_IMAGE_TILING_OPTIMAL, VK_MEMORY_PROPERTY_DEVICE_ONLY); + VK_IMAGE_TILING_OPTIMAL, + (VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT | VK_IMAGE_USAGE_SAMPLED_BIT), + VK_MEMORY_PROPERTY_DEVICE_ONLY); demo_set_image_layout(demo, staging_texture.image, staging_texture.imageLayout, @@ -1120,7 +1122,7 @@ void demo_prepare_cube_data_buffer(struct demo *demo) err = vkMapMemory(demo->device, demo->uniform_data.mem[i], 0, 0, 0, (void **) &pData); assert(!err); - memcpy(pData, &data, (size_t)alloc_info.allocationSize); + memcpy(pData, &data, sizeof data); err = vkUnmapMemory(demo->device, demo->uniform_data.mem[i]); assert(!err); @@ -1871,7 +1873,7 @@ static void demo_init_vk(struct demo *demo) err = vkGetPhysicalDeviceInfo(demo->gpu, VK_PHYSICAL_DEVICE_INFO_TYPE_QUEUE_PROPERTIES, &data_size, demo->queue_props); assert(!err); - queue_count = (uint32_t)(data_size / sizeof(VkPhysicalDeviceQueueProperties)); + queue_count = (uint32_t)(data_size / sizeof(VkPhysicalDeviceQueueProperties)); assert(queue_count >= 1); // Graphics queue and MemMgr queue can be separate. diff --git a/demos/tri.c b/demos/tri.c index 2bcf6e0e..32a9ab69 100644 --- a/demos/tri.c +++ b/demos/tri.c @@ -481,6 +481,7 @@ static void demo_prepare_texture_image(struct demo *demo, const uint32_t *tex_colors, struct texture_object *tex_obj, VkImageTiling tiling, + VkImageUsageFlags usage, VkFlags mem_props) { const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; @@ -501,7 +502,7 @@ static void demo_prepare_texture_image(struct demo *demo, .arraySize = 1, .samples = 1, .tiling = tiling, - .usage = VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT, + .usage = usage, .flags = 0, }; VkMemoryAllocInfo mem_alloc = { @@ -533,7 +534,6 @@ static void demo_prepare_texture_image(struct demo *demo, VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS, &mem_reqs_size, mem_reqs); assert(!err && mem_reqs_size == num_allocations * sizeof(VkMemoryRequirements)); - mem_alloc.memProps = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; for (uint32_t j = 0; j < num_allocations; j ++) { mem_alloc.allocationSize = mem_reqs[j].size; @@ -624,17 +624,19 @@ static void demo_prepare_textures(struct demo *demo) if ((props.linearTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) && !demo->use_staging_buffer) { /* Device can texture using linear textures */ demo_prepare_texture_image(demo, tex_colors[i], &demo->textures[i], - VK_IMAGE_TILING_LINEAR, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); + VK_IMAGE_TILING_LINEAR, VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); } else if (props.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT){ /* Must use staging buffer to copy linear texture to optimized */ struct texture_object staging_texture; memset(&staging_texture, 0, sizeof(staging_texture)); demo_prepare_texture_image(demo, tex_colors[i], &staging_texture, - VK_IMAGE_TILING_LINEAR, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); + VK_IMAGE_TILING_LINEAR, VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); demo_prepare_texture_image(demo, tex_colors[i], &demo->textures[i], - VK_IMAGE_TILING_OPTIMAL, VK_MEMORY_PROPERTY_DEVICE_ONLY); + VK_IMAGE_TILING_OPTIMAL, + (VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT | VK_IMAGE_USAGE_SAMPLED_BIT), + VK_MEMORY_PROPERTY_DEVICE_ONLY); demo_set_image_layout(demo, staging_texture.image, staging_texture.imageLayout, |
