From: Vivek Pandya Date: Sun, 21 Feb 2021 08:40:50 +0000 (+0530) Subject: Add pointer in libresoc_device_memory to hold bytes for images. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=df494d9287f13d4cd7802909bf385b48b619421b;p=mesa.git Add pointer in libresoc_device_memory to hold bytes for images. After this commit , driver is able to show white/black (shaded) box on windows through WSI. --- diff --git a/src/libre-soc/vulkan/libresoc_device.c b/src/libre-soc/vulkan/libresoc_device.c index 898b3712654..fe63fe4f6ca 100644 --- a/src/libre-soc/vulkan/libresoc_device.c +++ b/src/libre-soc/vulkan/libresoc_device.c @@ -135,13 +135,13 @@ static VkResult libresoc_alloc_memory(struct libresoc_device *device, vk_object_base_init(&device->vk, &mem->base, VK_OBJECT_TYPE_DEVICE_MEMORY); - if (dedicate_info) { - mem->image = libresoc_image_from_handle(dedicate_info->image); - //mem->buffer = libresoc_buffer_from_handle(dedicate_info->buffer); - } else { - mem->image = NULL; - //mem->buffer = NULL; - } + // if (dedicate_info) { + // mem->image = libresoc_image_from_handle(dedicate_info->image); + // mem->buffer = libresoc_buffer_from_handle(dedicate_info->buffer); + // } else { + // mem->image = NULL; + // mem->buffer = NULL; + // } // float priority_float = 0.5; // const struct VkMemoryPriorityAllocateInfoEXT *priority_ext = @@ -230,6 +230,8 @@ static VkResult libresoc_alloc_memory(struct libresoc_device *device, mtx_unlock(&device->overallocation_mutex); } + mem->bytes = vk_zalloc2(&device->vk.alloc, pAllocator, alloc_size, 8, + VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); // mem->bo = device->ws->buffer_create(device->ws, alloc_size, device->physical_device->rad_info.max_alignment, // domain, flags, priority); @@ -1493,7 +1495,7 @@ VkResult libresoc_BindImageMemory2(VkDevice device, LIBRESOC_FROM_HANDLE(libresoc_image, image, pBindInfos[i].image); if (mem) { - // image->bo = mem->bo; + image->bytes = mem->bytes; // image->offset = pBindInfos[i].memoryOffset; } else { // image->bo = NULL; @@ -1687,8 +1689,9 @@ VkResult libresoc_MapMemory( if (mem->user_ptr) *ppData = mem->user_ptr; - // else - // *ppData = device->ws->buffer_map(mem->bo); + else + *ppData = mem->bytes; + //*ppData = device->ws->buffer_map(mem->bo); if (*ppData) { *ppData += offset; diff --git a/src/libre-soc/vulkan/libresoc_image.c b/src/libre-soc/vulkan/libresoc_image.c index 4778d4cd471..cd8fe7cd023 100644 --- a/src/libre-soc/vulkan/libresoc_image.c +++ b/src/libre-soc/vulkan/libresoc_image.c @@ -60,8 +60,9 @@ libresoc_image_create(VkDevice _device, vk_object_base_init(&device->vk, &image->base, VK_OBJECT_TYPE_IMAGE); image->type = pCreateInfo->imageType; - // image->info.width = pCreateInfo->extent.width; - // image->info.height = pCreateInfo->extent.height; + image->size = pCreateInfo->extent.width * pCreateInfo->extent.height * 4; + image->width = pCreateInfo->extent.width; + image->height = pCreateInfo->extent.height; // image->info.depth = pCreateInfo->extent.depth; // image->info.samples = pCreateInfo->samples; // image->info.storage_samples = pCreateInfo->samples; @@ -155,7 +156,10 @@ void libresoc_GetImageSubresourceLayout( const VkImageSubresource* pSubresource, VkSubresourceLayout* pLayout) { -//TODO: stub + LIBRESOC_FROM_HANDLE(libresoc_image, image, _image); + + pLayout->size = image->size; + pLayout->rowPitch = image->width; } VkResult diff --git a/src/libre-soc/vulkan/libresoc_meta_clear.c b/src/libre-soc/vulkan/libresoc_meta_clear.c index a0a0f41cbf4..5650d3e94a9 100644 --- a/src/libre-soc/vulkan/libresoc_meta_clear.c +++ b/src/libre-soc/vulkan/libresoc_meta_clear.c @@ -32,5 +32,13 @@ void libresoc_CmdClearColorImage( uint32_t rangeCount, const VkImageSubresourceRange* pRanges) { -//TODO: stub + + LIBRESOC_FROM_HANDLE(libresoc_image, image, image_h); + float r = pColor->float32[0]; + float g = pColor->float32[1]; + float b = pColor->float32[2]; + float temp = 100.00 * ((r * 0.3 ) + (g * 0.3) + (b * 0.3)); + for (int i=0; i < image->size; ++i) { + image->bytes[i] = temp; + } } diff --git a/src/libre-soc/vulkan/libresoc_private.h b/src/libre-soc/vulkan/libresoc_private.h index a997dd70a35..84eb55c70d4 100644 --- a/src/libre-soc/vulkan/libresoc_private.h +++ b/src/libre-soc/vulkan/libresoc_private.h @@ -50,6 +50,8 @@ #include "wsi_common.h" #define LIBRESOC_MAX_QUEUE_FAMILIES 1 +typedef unsigned char byte; + static inline gl_shader_stage vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage) { @@ -166,11 +168,13 @@ struct libresoc_image { VkDeviceSize size; uint32_t alignment; + uint32_t height; + uint32_t width; unsigned queue_family_mask; bool exclusive; bool shareable; - + byte *bytes; }; VkResult libresoc_image_create(VkDevice _device, @@ -405,12 +409,14 @@ struct libresoc_cmd_buffer { struct libresoc_device_memory { struct vk_object_base base; /* for dedicated allocations */ - struct libresoc_image *image; + //struct libresoc_image *image; //struct libresoc_buffer *buffer; uint32_t heap_index; uint64_t alloc_size; void * map; void * user_ptr; + VkDeviceSize size; + byte *bytes; }; void libresoc_free_memory(struct libresoc_device *device,