[Mesa-dev] [PATCH] radv: Return correct result in EnumeratePhysicalDevices

2016-10-12 Thread Nicolas Koch
If pPhysicalDevices is too small for all physical devices,
the driver must return VK_INCOMPLETE. Since only a single
physical device is supported, this is only the case when
pPhysicalDeviceCount == 0 && pPhysicalDevices != NULL.
---
 src/amd/vulkan/radv_device.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index 6e06863..71b1481 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -295,6 +295,8 @@ VkResult radv_EnumeratePhysicalDevices(
} else if (*pPhysicalDeviceCount >= 1) {
pPhysicalDevices[0] = 
radv_physical_device_to_handle(>physicalDevice);
*pPhysicalDeviceCount = 1;
+   } else if (*pPhysicalDeviceCount < instance->physicalDeviceCount) {
+   return VK_INCOMPLETE;
} else {
*pPhysicalDeviceCount = 0;
}
-- 
2.10.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] anv: Return correct result in EnumeratePhysicalDevices

2016-10-12 Thread Nicolas Koch
On Wed, Oct 12, 2016 at 10:32 AM, Emil Velikov <emil.l.veli...@gmail.com> wrote:
> Hi Nicolas,
>
> On 6 October 2016 at 20:21, Nicolas Koch <nioko1...@gmail.com> wrote:
>> If pPhysicalDevices is too small for all physical devices,
>> the driver must return VK_INCOMPLETE.
>> Since only a single physical device is supported, this is only the case
>> when pPhysicalDeviceCount == 0 && pPhysicalDevices != NULL.
>> ---
>>  src/intel/vulkan/anv_device.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
>> index c7b9979..76cbb69 100644
>> --- a/src/intel/vulkan/anv_device.c
>> +++ b/src/intel/vulkan/anv_device.c
>> @@ -385,6 +385,8 @@ VkResult anv_EnumeratePhysicalDevices(
>> } else if (*pPhysicalDeviceCount >= 1) {
>>pPhysicalDevices[0] = 
>> anv_physical_device_to_handle(>physicalDevice);
>>*pPhysicalDeviceCount = 1;
>> +   } else if (*pPhysicalDeviceCount < instance->physicalDeviceCount) {
>> +  return VK_INCOMPLETE;
> Looks like RADV could use the exact same fix
> (s/intel/amd/;s/anv/radv/). Can you spin a patch for it ?
>
> -Emil

Sure, will do!
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] anv: Return correct result in EnumeratePhysicalDevices

2016-10-11 Thread Nicolas Koch
It's been a few days. Is anybody willing to push this?

On Thu, Oct 6, 2016 at 11:25 PM, Anuj Phogat <anuj.pho...@gmail.com> wrote:
> On Thu, Oct 6, 2016 at 12:21 PM, Nicolas Koch <nioko1...@gmail.com> wrote:
>> If pPhysicalDevices is too small for all physical devices,
>> the driver must return VK_INCOMPLETE.
>> Since only a single physical device is supported, this is only the case
>> when pPhysicalDeviceCount == 0 && pPhysicalDevices != NULL.
>> ---
>>  src/intel/vulkan/anv_device.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
>> index c7b9979..76cbb69 100644
>> --- a/src/intel/vulkan/anv_device.c
>> +++ b/src/intel/vulkan/anv_device.c
>> @@ -385,6 +385,8 @@ VkResult anv_EnumeratePhysicalDevices(
>> } else if (*pPhysicalDeviceCount >= 1) {
>>pPhysicalDevices[0] = 
>> anv_physical_device_to_handle(>physicalDevice);
>>*pPhysicalDeviceCount = 1;
>> +   } else if (*pPhysicalDeviceCount < instance->physicalDeviceCount) {
>> +  return VK_INCOMPLETE;
>> } else {
>>*pPhysicalDeviceCount = 0;
>> }
>> --
>> 2.10.0
>>
>> ___
>> mesa-dev mailing list
>> mesa-dev@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
> Reviewed-by: Anuj Phogat <anuj.pho...@gmail.com>
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] anv: Return correct result in EnumeratePhysicalDevices

2016-10-06 Thread Nicolas Koch
If pPhysicalDevices is too small for all physical devices,
the driver must return VK_INCOMPLETE.
Since only a single physical device is supported, this is only the case
when pPhysicalDeviceCount == 0 && pPhysicalDevices != NULL.
---
 src/intel/vulkan/anv_device.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index c7b9979..76cbb69 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -385,6 +385,8 @@ VkResult anv_EnumeratePhysicalDevices(
} else if (*pPhysicalDeviceCount >= 1) {
   pPhysicalDevices[0] = 
anv_physical_device_to_handle(>physicalDevice);
   *pPhysicalDeviceCount = 1;
+   } else if (*pPhysicalDeviceCount < instance->physicalDeviceCount) {
+  return VK_INCOMPLETE;
} else {
   *pPhysicalDeviceCount = 0;
}
-- 
2.10.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] anv: device: never allocate more memory than heap_size

2016-09-22 Thread Nicolas Koch
Previously, the heap size of a physical device was kind of useless
because it was not enforced.
Now, we keep track of allocation sizes so that the sum of
all allocations can never exceed the heap size advertised by
anv_GetPhysicalDeviceMemoryProperties.
---
 src/intel/vulkan/anv_device.c  | 42 +-
 src/intel/vulkan/anv_private.h |  8 
 2 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index fecb850..162e372 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -190,6 +190,18 @@ anv_physical_device_init(struct anv_physical_device 
*device,
/* XXX: Actually detect bit6 swizzling */
isl_device_init(>isl_dev, device->info, swizzled);
 
+   /* Reserve some wiggle room for the driver by exposing only 75% of the
+* aperture to the heap.
+*/
+   device->heap_size = 3 * device->aperture_size / 4;
+   device->used_heap_space = 0;
+   int ret = pthread_mutex_init(>mutex, NULL);
+   if (ret != 0) {
+  result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+  ralloc_free(device->compiler);
+  goto fail;
+   }
+
return VK_SUCCESS;
 
 fail:
@@ -202,6 +214,7 @@ anv_physical_device_finish(struct anv_physical_device 
*device)
 {
anv_finish_wsi(device);
ralloc_free(device->compiler);
+   pthread_mutex_destroy(>mutex);
 }
 
 static const VkExtensionProperties global_extensions[] = {
@@ -638,12 +651,6 @@ void anv_GetPhysicalDeviceMemoryProperties(
 VkPhysicalDeviceMemoryProperties*   pMemoryProperties)
 {
ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);
-   VkDeviceSize heap_size;
-
-   /* Reserve some wiggle room for the driver by exposing only 75% of the
-* aperture to the heap.
-*/
-   heap_size = 3 * physical_device->aperture_size / 4;
 
if (physical_device->info->has_llc) {
   /* Big core GPUs share LLC with the CPU and thus one memory type can be
@@ -680,7 +687,7 @@ void anv_GetPhysicalDeviceMemoryProperties(
 
pMemoryProperties->memoryHeapCount = 1;
pMemoryProperties->memoryHeaps[0] = (VkMemoryHeap) {
-  .size = heap_size,
+  .size = physical_device->heap_size,
   .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
};
 }
@@ -1172,6 +1179,8 @@ VkResult anv_AllocateMemory(
 VkDeviceMemory* pMem)
 {
ANV_FROM_HANDLE(anv_device, device, _device);
+   struct anv_physical_device *physical_device =
+  >instance->physicalDevice;
struct anv_device_memory *mem;
VkResult result;
 
@@ -1187,20 +1196,28 @@ VkResult anv_AllocateMemory(
assert(pAllocateInfo->memoryTypeIndex == 0 ||
   (!device->info.has_llc && pAllocateInfo->memoryTypeIndex < 2));
 
-   /* FINISHME: Fail if allocation request exceeds heap size. */
-
mem = anv_alloc2(>alloc, pAllocator, sizeof(*mem), 8,
 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (mem == NULL)
   return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
+   pthread_mutex_lock(_device->mutex);
+
/* The kernel is going to give us whole pages anyway */
uint64_t alloc_size = align_u64(pAllocateInfo->allocationSize, 4096);
 
+   if (alloc_size + physical_device->used_heap_space > 
physical_device->heap_size) {
+result = vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY);
+goto fail;
+   }
+
result = anv_bo_init_new(>bo, device, alloc_size);
if (result != VK_SUCCESS)
   goto fail;
 
+   physical_device->used_heap_space += alloc_size;
+   pthread_mutex_unlock(_device->mutex);
+
mem->type_index = pAllocateInfo->memoryTypeIndex;
 
*pMem = anv_device_memory_to_handle(mem);
@@ -1208,6 +1225,7 @@ VkResult anv_AllocateMemory(
return VK_SUCCESS;
 
  fail:
+   pthread_mutex_unlock(_device->mutex);
anv_free2(>alloc, pAllocator, mem);
 
return result;
@@ -1220,6 +1238,8 @@ void anv_FreeMemory(
 {
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_device_memory, mem, _mem);
+   struct anv_physical_device *physical_device =
+  >instance->physicalDevice;
 
if (mem == NULL)
   return;
@@ -1230,6 +1250,10 @@ void anv_FreeMemory(
if (mem->bo.gem_handle != 0)
   anv_gem_close(device, mem->bo.gem_handle);
 
+   pthread_mutex_lock(_device->mutex);
+   physical_device->used_heap_space -= mem->bo.size;
+   pthread_mutex_unlock(_device->mutex);
+
anv_free2(>alloc, pAllocator, mem);
 }
 
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index f578a9d..ec888a6 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -574,6 +574,14 @@ struct anv_physical_device {
 uint32_tsubslice_total;
 
 /**
+ * Variables used to track the memory occupied by allocations from
+ * anv_AllocateMemory.
+ */
+uint64_theap_size;
+uint64_t

[Mesa-dev] [PATCH] anv: Check for VK_WHOLE_SIZE in anv_CmdFillBuffer

2016-09-20 Thread Nicolas Koch
Vulkan spec:
Size is the number of bytes to fill, and must be either a multiple of 4,
or VK_WHOLE_SIZE to fill the range from offset to the end of the buffer.
If VK_WHOLE_SIZE is used and the remaining size of the buffer is not a
multiple of 4, then the nearest smaller multiple is used.
---
 src/intel/vulkan/anv_meta_clear.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/src/intel/vulkan/anv_meta_clear.c 
b/src/intel/vulkan/anv_meta_clear.c
index ed4d1db..fd0797f 100644
--- a/src/intel/vulkan/anv_meta_clear.c
+++ b/src/intel/vulkan/anv_meta_clear.c
@@ -1012,6 +1012,12 @@ void anv_CmdFillBuffer(
 
meta_clear_begin(_state, cmd_buffer);
 
+   if (fillSize == VK_WHOLE_SIZE) {
+  fillSize = dst_buffer->size - dstOffset;
+  /* Make sure fillSize is a multiple of 4 */
+  fillSize -= fillSize & 3;
+   }
+
VkFormat format;
int bs;
if ((fillSize & 15) == 0 && (dstOffset & 15) == 0) {
-- 
2.10.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev