Add pointer in libresoc_device_memory to hold bytes for images.
authorVivek Pandya <vivekvpandya@gmail.com>
Sun, 21 Feb 2021 08:40:50 +0000 (14:10 +0530)
committerVivek Pandya <vivekvpandya@gmail.com>
Sun, 21 Feb 2021 08:40:50 +0000 (14:10 +0530)
After this commit , driver is able to show white/black (shaded) box
on windows through WSI.

src/libre-soc/vulkan/libresoc_device.c
src/libre-soc/vulkan/libresoc_image.c
src/libre-soc/vulkan/libresoc_meta_clear.c
src/libre-soc/vulkan/libresoc_private.h

index 898b3712654dc17896621e8dcb6eeff543bf1a74..fe63fe4f6ca6a3705bebe8f0fe554f587f6a97b8 100644 (file)
@@ -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;
index 4778d4cd47185918cbd415b1d637a50afe47bbbd..cd8fe7cd02337534d263778d20592cfd4c4b1178 100644 (file)
@@ -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
index a0a0f41cbf4dae3ae9acd185c2a3c17d13913c12..5650d3e94a96f201551fea7a0be72c909f37ea7f 100644 (file)
@@ -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;
+    }
 }
index a997dd70a3596c43811b52b6ff473d84c5709bfd..84eb55c70d4d44f10836f1ad977a09c36c3cebda 100644 (file)
@@ -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,