[07/16] radv: Implement VK_KHR_maintenance3.

Submitted by Bas Nieuwenhuizen on March 7, 2018, 2:47 p.m.

Details

Message ID 20180307144744.4816-7-bas@basnieuwenhuizen.nl
State New
Series "Series without cover letter"
Headers show

Commit Message

Bas Nieuwenhuizen March 7, 2018, 2:47 p.m.
Reviewed-by: Dave Airlie <airlied@redhat.com>
---
 src/amd/vulkan/radv_descriptor_set.c | 82 ++++++++++++++++++++++++++++++++++--
 src/amd/vulkan/radv_device.c         | 10 +++++
 src/amd/vulkan/radv_extensions.py    |  1 +
 3 files changed, 89 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/amd/vulkan/radv_descriptor_set.c b/src/amd/vulkan/radv_descriptor_set.c
index 38b8dc78e1..265028df2b 100644
--- a/src/amd/vulkan/radv_descriptor_set.c
+++ b/src/amd/vulkan/radv_descriptor_set.c
@@ -31,6 +31,20 @@ 
 #include "radv_private.h"
 #include "sid.h"
 
+
+static bool has_equal_immutable_samplers(const VkSampler *samplers, uint32_t count)
+{
+	if (!samplers)
+		return false;
+	for(uint32_t i = 1; i < count; ++i) {
+		if (memcmp(radv_sampler_from_handle(samplers[0])->state,
+		           radv_sampler_from_handle(samplers[i])->state, 16)) {
+			return false;
+		}
+	}
+	return true;
+}
+
 VkResult radv_CreateDescriptorSetLayout(
 	VkDevice                                    _device,
 	const VkDescriptorSetLayoutCreateInfo*      pCreateInfo,
@@ -132,15 +146,13 @@  VkResult radv_CreateDescriptorSetLayout(
 
 		if (binding->pImmutableSamplers) {
 			set_layout->binding[b].immutable_samplers_offset = samplers_offset;
-			set_layout->binding[b].immutable_samplers_equal = true;
+			set_layout->binding[b].immutable_samplers_equal =
+				has_equal_immutable_samplers(binding->pImmutableSamplers, binding->descriptorCount);
 			set_layout->has_immutable_samplers = true;
 
 
 			for (uint32_t i = 0; i < binding->descriptorCount; i++)
 				memcpy(samplers + 4 * i, &radv_sampler_from_handle(binding->pImmutableSamplers[i])->state, 16);
-			for (uint32_t i = 1; i < binding->descriptorCount; i++)
-				if (memcmp(samplers + 4 * i, samplers, 16) != 0)
-					set_layout->binding[b].immutable_samplers_equal = false;
 
 			/* Don't reserve space for the samplers if they're not accessed. */
 			if (set_layout->binding[b].immutable_samplers_equal) {
@@ -182,6 +194,68 @@  void radv_DestroyDescriptorSetLayout(
 	vk_free2(&device->alloc, pAllocator, set_layout);
 }
 
+void radv_GetDescriptorSetLayoutSupport(VkDevice device,
+                                        const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
+                                        VkDescriptorSetLayoutSupport* pSupport)
+{
+	bool supported = true;
+	uint64_t size = 0;
+	for (uint32_t i = 0; i < pCreateInfo->bindingCount; i++) {
+		const VkDescriptorSetLayoutBinding *binding = &pCreateInfo->pBindings[i];
+
+		if (binding->descriptorCount == 0)
+			continue;
+
+		uint64_t descriptor_size = 0;
+		uint64_t descriptor_alignment = 1;
+		switch (binding->descriptorType) {
+		case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
+		case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
+			break;
+		case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
+		case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
+		case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
+		case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
+			descriptor_size = 16;
+			descriptor_alignment = 16;
+			break;
+		case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
+		case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
+		case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
+			descriptor_size = 64;
+			descriptor_alignment = 32;
+			break;
+		case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
+			if (!has_equal_immutable_samplers(binding->pImmutableSamplers, binding->descriptorCount)) {
+				descriptor_size = 64;
+			} else {
+				descriptor_size = 96;
+			}
+			descriptor_alignment = 32;
+		case VK_DESCRIPTOR_TYPE_SAMPLER:
+			if (!has_equal_immutable_samplers(binding->pImmutableSamplers, binding->descriptorCount)) {
+				descriptor_size = 16;
+				descriptor_alignment = 16;
+			}
+			break;
+		default:
+			unreachable("unknown descriptor type\n");
+			break;
+		}
+
+		if (size && !align_u64(size, descriptor_alignment)) {
+			supported = false;
+		}
+		size = align_u64(size, descriptor_alignment);
+		if (descriptor_size && (UINT64_MAX - size) / descriptor_size < binding->descriptorCount) {
+			supported = false;
+		}
+		size += binding->descriptorCount * descriptor_size;
+	}
+
+	pSupport->supported = supported;
+}
+
 /*
  * Pipeline layouts.  These have nothing to do with the pipeline.  They are
  * just muttiple descriptor set layouts pasted together
diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index 00bb70612e..593cfc9a36 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -875,6 +875,16 @@  void radv_GetPhysicalDeviceProperties2(
 			properties->quadOperationsInAllStages = false;
 			break;
 		}
+		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES: {
+			VkPhysicalDeviceMaintenance3Properties *properties =
+			    (VkPhysicalDeviceMaintenance3Properties*)ext;
+			/* Make sure evrything is addressable by a signed 32-bit int, and our
+			 * largest descriptors are 96 bytes. */
+			properties->maxPerSetDescriptors = (1ull << 31) / 96;
+			/* Our buffer size fields allow only this much */
+			properties->maxMemoryAllocationSize = 0xFFFFFFFFull;
+			break;
+		}
 		default:
 			break;
 		}
diff --git a/src/amd/vulkan/radv_extensions.py b/src/amd/vulkan/radv_extensions.py
index 6fa553e589..3b4f75bff6 100644
--- a/src/amd/vulkan/radv_extensions.py
+++ b/src/amd/vulkan/radv_extensions.py
@@ -70,6 +70,7 @@  EXTENSIONS = [
     Extension('VK_KHR_incremental_present',               1, True),
     Extension('VK_KHR_maintenance1',                      1, True),
     Extension('VK_KHR_maintenance2',                      1, True),
+    Extension('VK_KHR_maintenance3',                      1, True),
     Extension('VK_KHR_push_descriptor',                   1, True),
     Extension('VK_KHR_relaxed_block_layout',              1, True),
     Extension('VK_KHR_sampler_mirror_clamp_to_edge',      1, True),

Comments

Gustaw Smolarczyk March 7, 2018, 5:54 p.m.
2018-03-07 15:47 GMT+01:00 Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>:

> Reviewed-by: Dave Airlie <airlied@redhat.com>
> ---
>  src/amd/vulkan/radv_descriptor_set.c | 82 ++++++++++++++++++++++++++++++
> ++++--
>  src/amd/vulkan/radv_device.c         | 10 +++++
>  src/amd/vulkan/radv_extensions.py    |  1 +
>  3 files changed, 89 insertions(+), 4 deletions(-)
>
> diff --git a/src/amd/vulkan/radv_descriptor_set.c b/src/amd/vulkan/radv_
> descriptor_set.c
> index 38b8dc78e1..265028df2b 100644
> --- a/src/amd/vulkan/radv_descriptor_set.c
> +++ b/src/amd/vulkan/radv_descriptor_set.c
> @@ -31,6 +31,20 @@
>  #include "radv_private.h"
>  #include "sid.h"
>
> +
> +static bool has_equal_immutable_samplers(const VkSampler *samplers,
> uint32_t count)
> +{
> +       if (!samplers)
> +               return false;
> +       for(uint32_t i = 1; i < count; ++i) {
> +               if (memcmp(radv_sampler_from_handle(samplers[0])->state,
> +                          radv_sampler_from_handle(samplers[i])->state,
> 16)) {
> +                       return false;
> +               }
> +       }
> +       return true;
> +}
> +
>  VkResult radv_CreateDescriptorSetLayout(
>         VkDevice                                    _device,
>         const VkDescriptorSetLayoutCreateInfo*      pCreateInfo,
> @@ -132,15 +146,13 @@ VkResult radv_CreateDescriptorSetLayout(
>
>                 if (binding->pImmutableSamplers) {
>                         set_layout->binding[b].immutable_samplers_offset
> = samplers_offset;
> -                       set_layout->binding[b].immutable_samplers_equal =
> true;
> +                       set_layout->binding[b].immutable_samplers_equal =
> +                               has_equal_immutable_samplers(binding->pImmutableSamplers,
> binding->descriptorCount);
>                         set_layout->has_immutable_samplers = true;
>
>
>                         for (uint32_t i = 0; i < binding->descriptorCount;
> i++)
>                                 memcpy(samplers + 4 * i,
> &radv_sampler_from_handle(binding->pImmutableSamplers[i])->state, 16);
> -                       for (uint32_t i = 1; i < binding->descriptorCount;
> i++)
> -                               if (memcmp(samplers + 4 * i, samplers, 16)
> != 0)
> -                                       set_layout->binding[b].immutable_samplers_equal
> = false;
>
>                         /* Don't reserve space for the samplers if they're
> not accessed. */
>                         if (set_layout->binding[b].immutable_samplers_equal)
> {
> @@ -182,6 +194,68 @@ void radv_DestroyDescriptorSetLayout(
>         vk_free2(&device->alloc, pAllocator, set_layout);
>  }
>
> +void radv_GetDescriptorSetLayoutSupport(VkDevice device,
> +                                        const
> VkDescriptorSetLayoutCreateInfo* pCreateInfo,
> +                                        VkDescriptorSetLayoutSupport*
> pSupport)
> +{
> +       bool supported = true;
> +       uint64_t size = 0;
> +       for (uint32_t i = 0; i < pCreateInfo->bindingCount; i++) {
> +               const VkDescriptorSetLayoutBinding *binding =
> &pCreateInfo->pBindings[i];
> +
> +               if (binding->descriptorCount == 0)
> +                       continue;
> +
> +               uint64_t descriptor_size = 0;
> +               uint64_t descriptor_alignment = 1;
> +               switch (binding->descriptorType) {
> +               case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
> +               case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
> +                       break;
> +               case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
> +               case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
> +               case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
> +               case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
> +                       descriptor_size = 16;
> +                       descriptor_alignment = 16;
> +                       break;
> +               case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
> +               case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
> +               case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
> +                       descriptor_size = 64;
> +                       descriptor_alignment = 32;
> +                       break;
> +               case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
> +                       if (!has_equal_immutable_samplers(binding->pImmutableSamplers,
> binding->descriptorCount)) {
> +                               descriptor_size = 64;
> +                       } else {
> +                               descriptor_size = 96;
> +                       }
> +                       descriptor_alignment = 32;
> +               case VK_DESCRIPTOR_TYPE_SAMPLER:
> +                       if (!has_equal_immutable_samplers(binding->pImmutableSamplers,
> binding->descriptorCount)) {
> +                               descriptor_size = 16;
> +                               descriptor_alignment = 16;
> +                       }
> +                       break;
> +               default:
> +                       unreachable("unknown descriptor type\n");
> +                       break;
> +               }
> +
> +               if (size && !align_u64(size, descriptor_alignment)) {
> +                       supported = false;
> +               }
> +               size = align_u64(size, descriptor_alignment);
> +               if (descriptor_size && (UINT64_MAX - size) /
> descriptor_size < binding->descriptorCount) {
> +                       supported = false;
> +               }
> +               size += binding->descriptorCount * descriptor_size;
> +       }
> +
> +       pSupport->supported = supported;
> +}
> +
>  /*
>   * Pipeline layouts.  These have nothing to do with the pipeline.  They
> are
>   * just muttiple descriptor set layouts pasted together
> diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
> index 00bb70612e..593cfc9a36 100644
> --- a/src/amd/vulkan/radv_device.c
> +++ b/src/amd/vulkan/radv_device.c
> @@ -875,6 +875,16 @@ void radv_GetPhysicalDeviceProperties2(
>                         properties->quadOperationsInAllStages = false;
>                         break;
>                 }
> +               case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES:
> {
> +                       VkPhysicalDeviceMaintenance3Properties
> *properties =
> +                           (VkPhysicalDeviceMaintenance3Properties*)ext;
> +                       /* Make sure evrything is addressable by a signed
> 32-bit int, and our
>
> Typo: everything
>
> Regards,
> Gustaw Smolarczyk
>
> +                        * largest descriptors are 96 bytes. */
> +                       properties->maxPerSetDescriptors = (1ull << 31) /
> 96;
> +                       /* Our buffer size fields allow only this much */
> +                       properties->maxMemoryAllocationSize =
> 0xFFFFFFFFull;
> +                       break;
> +               }
>                 default:
>                         break;
>                 }
> diff --git a/src/amd/vulkan/radv_extensions.py b/src/amd/vulkan/radv_
> extensions.py
> index 6fa553e589..3b4f75bff6 100644
> --- a/src/amd/vulkan/radv_extensions.py
> +++ b/src/amd/vulkan/radv_extensions.py
> @@ -70,6 +70,7 @@ EXTENSIONS = [
>      Extension('VK_KHR_incremental_present',               1, True),
>      Extension('VK_KHR_maintenance1',                      1, True),
>      Extension('VK_KHR_maintenance2',                      1, True),
> +    Extension('VK_KHR_maintenance3',                      1, True),
>      Extension('VK_KHR_push_descriptor',                   1, True),
>      Extension('VK_KHR_relaxed_block_layout',              1, True),
>      Extension('VK_KHR_sampler_mirror_clamp_to_edge',      1, True),
> --
> 2.16.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
Samuel Pitoiset March 7, 2018, 6:19 p.m.
On 03/07/2018 03:47 PM, Bas Nieuwenhuizen wrote:
> Reviewed-by: Dave Airlie <airlied@redhat.com>
> ---
>   src/amd/vulkan/radv_descriptor_set.c | 82 ++++++++++++++++++++++++++++++++++--
>   src/amd/vulkan/radv_device.c         | 10 +++++
>   src/amd/vulkan/radv_extensions.py    |  1 +
>   3 files changed, 89 insertions(+), 4 deletions(-)
> 
> diff --git a/src/amd/vulkan/radv_descriptor_set.c b/src/amd/vulkan/radv_descriptor_set.c
> index 38b8dc78e1..265028df2b 100644
> --- a/src/amd/vulkan/radv_descriptor_set.c
> +++ b/src/amd/vulkan/radv_descriptor_set.c
> @@ -31,6 +31,20 @@
>   #include "radv_private.h"
>   #include "sid.h"
>   
> +
> +static bool has_equal_immutable_samplers(const VkSampler *samplers, uint32_t count)
> +{
> +	if (!samplers)
> +		return false;
> +	for(uint32_t i = 1; i < count; ++i) {
> +		if (memcmp(radv_sampler_from_handle(samplers[0])->state,
> +		           radv_sampler_from_handle(samplers[i])->state, 16)) {
> +			return false;
> +		}
> +	}
> +	return true;
> +}
> +
>   VkResult radv_CreateDescriptorSetLayout(
>   	VkDevice                                    _device,
>   	const VkDescriptorSetLayoutCreateInfo*      pCreateInfo,
> @@ -132,15 +146,13 @@ VkResult radv_CreateDescriptorSetLayout(
>   
>   		if (binding->pImmutableSamplers) {
>   			set_layout->binding[b].immutable_samplers_offset = samplers_offset;
> -			set_layout->binding[b].immutable_samplers_equal = true;
> +			set_layout->binding[b].immutable_samplers_equal =
> +				has_equal_immutable_samplers(binding->pImmutableSamplers, binding->descriptorCount);
>   			set_layout->has_immutable_samplers = true;
>   
>   
>   			for (uint32_t i = 0; i < binding->descriptorCount; i++)
>   				memcpy(samplers + 4 * i, &radv_sampler_from_handle(binding->pImmutableSamplers[i])->state, 16);
> -			for (uint32_t i = 1; i < binding->descriptorCount; i++)
> -				if (memcmp(samplers + 4 * i, samplers, 16) != 0)
> -					set_layout->binding[b].immutable_samplers_equal = false;
>   
>   			/* Don't reserve space for the samplers if they're not accessed. */
>   			if (set_layout->binding[b].immutable_samplers_equal) {
> @@ -182,6 +194,68 @@ void radv_DestroyDescriptorSetLayout(
>   	vk_free2(&device->alloc, pAllocator, set_layout);
>   }
>   
> +void radv_GetDescriptorSetLayoutSupport(VkDevice device,
> +                                        const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
> +                                        VkDescriptorSetLayoutSupport* pSupport)
> +{
> +	bool supported = true;
> +	uint64_t size = 0;
> +	for (uint32_t i = 0; i < pCreateInfo->bindingCount; i++) {
> +		const VkDescriptorSetLayoutBinding *binding = &pCreateInfo->pBindings[i];
> +
> +		if (binding->descriptorCount == 0)
> +			continue;
> +
> +		uint64_t descriptor_size = 0;
> +		uint64_t descriptor_alignment = 1;
> +		switch (binding->descriptorType) {
> +		case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
> +		case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
> +			break;
> +		case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
> +		case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
> +		case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
> +		case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
> +			descriptor_size = 16;
> +			descriptor_alignment = 16;
> +			break;
> +		case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
> +		case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
> +		case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
> +			descriptor_size = 64;
> +			descriptor_alignment = 32;
> +			break;
> +		case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
> +			if (!has_equal_immutable_samplers(binding->pImmutableSamplers, binding->descriptorCount)) {
> +				descriptor_size = 64;
> +			} else {
> +				descriptor_size = 96;
> +			}
> +			descriptor_alignment = 32;

Missing break?

> +		case VK_DESCRIPTOR_TYPE_SAMPLER:
> +			if (!has_equal_immutable_samplers(binding->pImmutableSamplers, binding->descriptorCount)) {
> +				descriptor_size = 16;
> +				descriptor_alignment = 16;
> +			}
> +			break;
> +		default:
> +			unreachable("unknown descriptor type\n");
> +			break;
> +		}
> +
> +		if (size && !align_u64(size, descriptor_alignment)) {
> +			supported = false;
> +		}
> +		size = align_u64(size, descriptor_alignment);
> +		if (descriptor_size && (UINT64_MAX - size) / descriptor_size < binding->descriptorCount) {
> +			supported = false;
> +		}
> +		size += binding->descriptorCount * descriptor_size;
> +	}
> +
> +	pSupport->supported = supported;
> +}
> +
>   /*
>    * Pipeline layouts.  These have nothing to do with the pipeline.  They are
>    * just muttiple descriptor set layouts pasted together
> diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
> index 00bb70612e..593cfc9a36 100644
> --- a/src/amd/vulkan/radv_device.c
> +++ b/src/amd/vulkan/radv_device.c
> @@ -875,6 +875,16 @@ void radv_GetPhysicalDeviceProperties2(
>   			properties->quadOperationsInAllStages = false;
>   			break;
>   		}
> +		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES: {
> +			VkPhysicalDeviceMaintenance3Properties *properties =
> +			    (VkPhysicalDeviceMaintenance3Properties*)ext;
> +			/* Make sure evrything is addressable by a signed 32-bit int, and our
> +			 * largest descriptors are 96 bytes. */
> +			properties->maxPerSetDescriptors = (1ull << 31) / 96;
> +			/* Our buffer size fields allow only this much */
> +			properties->maxMemoryAllocationSize = 0xFFFFFFFFull;
> +			break;
> +		}
>   		default:
>   			break;
>   		}
> diff --git a/src/amd/vulkan/radv_extensions.py b/src/amd/vulkan/radv_extensions.py
> index 6fa553e589..3b4f75bff6 100644
> --- a/src/amd/vulkan/radv_extensions.py
> +++ b/src/amd/vulkan/radv_extensions.py
> @@ -70,6 +70,7 @@ EXTENSIONS = [
>       Extension('VK_KHR_incremental_present',               1, True),
>       Extension('VK_KHR_maintenance1',                      1, True),
>       Extension('VK_KHR_maintenance2',                      1, True),
> +    Extension('VK_KHR_maintenance3',                      1, True),
>       Extension('VK_KHR_push_descriptor',                   1, True),
>       Extension('VK_KHR_relaxed_block_layout',              1, True),
>       Extension('VK_KHR_sampler_mirror_clamp_to_edge',      1, True),
>
Bas Nieuwenhuizen March 7, 2018, 6:32 p.m.
On Wed, Mar 7, 2018 at 7:19 PM, Samuel Pitoiset
<samuel.pitoiset@gmail.com> wrote:
>
>
> On 03/07/2018 03:47 PM, Bas Nieuwenhuizen wrote:
>>
>> Reviewed-by: Dave Airlie <airlied@redhat.com>
>> ---
>>   src/amd/vulkan/radv_descriptor_set.c | 82
>> ++++++++++++++++++++++++++++++++++--
>>   src/amd/vulkan/radv_device.c         | 10 +++++
>>   src/amd/vulkan/radv_extensions.py    |  1 +
>>   3 files changed, 89 insertions(+), 4 deletions(-)
>>
>> diff --git a/src/amd/vulkan/radv_descriptor_set.c
>> b/src/amd/vulkan/radv_descriptor_set.c
>> index 38b8dc78e1..265028df2b 100644
>> --- a/src/amd/vulkan/radv_descriptor_set.c
>> +++ b/src/amd/vulkan/radv_descriptor_set.c
>> @@ -31,6 +31,20 @@
>>   #include "radv_private.h"
>>   #include "sid.h"
>>   +
>> +static bool has_equal_immutable_samplers(const VkSampler *samplers,
>> uint32_t count)
>> +{
>> +       if (!samplers)
>> +               return false;
>> +       for(uint32_t i = 1; i < count; ++i) {
>> +               if (memcmp(radv_sampler_from_handle(samplers[0])->state,
>> +                          radv_sampler_from_handle(samplers[i])->state,
>> 16)) {
>> +                       return false;
>> +               }
>> +       }
>> +       return true;
>> +}
>> +
>>   VkResult radv_CreateDescriptorSetLayout(
>>         VkDevice                                    _device,
>>         const VkDescriptorSetLayoutCreateInfo*      pCreateInfo,
>> @@ -132,15 +146,13 @@ VkResult radv_CreateDescriptorSetLayout(
>>                 if (binding->pImmutableSamplers) {
>>                         set_layout->binding[b].immutable_samplers_offset =
>> samplers_offset;
>> -                       set_layout->binding[b].immutable_samplers_equal =
>> true;
>> +                       set_layout->binding[b].immutable_samplers_equal =
>> +
>> has_equal_immutable_samplers(binding->pImmutableSamplers,
>> binding->descriptorCount);
>>                         set_layout->has_immutable_samplers = true;
>>                         for (uint32_t i = 0; i < binding->descriptorCount;
>> i++)
>>                                 memcpy(samplers + 4 * i,
>> &radv_sampler_from_handle(binding->pImmutableSamplers[i])->state, 16);
>> -                       for (uint32_t i = 1; i < binding->descriptorCount;
>> i++)
>> -                               if (memcmp(samplers + 4 * i, samplers, 16)
>> != 0)
>> -
>> set_layout->binding[b].immutable_samplers_equal = false;
>>                         /* Don't reserve space for the samplers if they're
>> not accessed. */
>>                         if
>> (set_layout->binding[b].immutable_samplers_equal) {
>> @@ -182,6 +194,68 @@ void radv_DestroyDescriptorSetLayout(
>>         vk_free2(&device->alloc, pAllocator, set_layout);
>>   }
>>   +void radv_GetDescriptorSetLayoutSupport(VkDevice device,
>> +                                        const
>> VkDescriptorSetLayoutCreateInfo* pCreateInfo,
>> +                                        VkDescriptorSetLayoutSupport*
>> pSupport)
>> +{
>> +       bool supported = true;
>> +       uint64_t size = 0;
>> +       for (uint32_t i = 0; i < pCreateInfo->bindingCount; i++) {
>> +               const VkDescriptorSetLayoutBinding *binding =
>> &pCreateInfo->pBindings[i];
>> +
>> +               if (binding->descriptorCount == 0)
>> +                       continue;
>> +
>> +               uint64_t descriptor_size = 0;
>> +               uint64_t descriptor_alignment = 1;
>> +               switch (binding->descriptorType) {
>> +               case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
>> +               case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
>> +                       break;
>> +               case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
>> +               case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
>> +               case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
>> +               case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
>> +                       descriptor_size = 16;
>> +                       descriptor_alignment = 16;
>> +                       break;
>> +               case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
>> +               case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
>> +               case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
>> +                       descriptor_size = 64;
>> +                       descriptor_alignment = 32;
>> +                       break;
>> +               case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
>> +                       if
>> (!has_equal_immutable_samplers(binding->pImmutableSamplers,
>> binding->descriptorCount)) {
>> +                               descriptor_size = 64;
>> +                       } else {
>> +                               descriptor_size = 96;
>> +                       }
>> +                       descriptor_alignment = 32;
>
>
> Missing break?

So much for the tests ...

Fixed locally.

>
>
>> +               case VK_DESCRIPTOR_TYPE_SAMPLER:
>> +                       if
>> (!has_equal_immutable_samplers(binding->pImmutableSamplers,
>> binding->descriptorCount)) {
>> +                               descriptor_size = 16;
>> +                               descriptor_alignment = 16;
>> +                       }
>> +                       break;
>> +               default:
>> +                       unreachable("unknown descriptor type\n");
>> +                       break;
>> +               }
>> +
>> +               if (size && !align_u64(size, descriptor_alignment)) {
>> +                       supported = false;
>> +               }
>> +               size = align_u64(size, descriptor_alignment);
>> +               if (descriptor_size && (UINT64_MAX - size) /
>> descriptor_size < binding->descriptorCount) {
>> +                       supported = false;
>> +               }
>> +               size += binding->descriptorCount * descriptor_size;
>> +       }
>> +
>> +       pSupport->supported = supported;
>> +}
>> +
>>   /*
>>    * Pipeline layouts.  These have nothing to do with the pipeline.  They
>> are
>>    * just muttiple descriptor set layouts pasted together
>> diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
>> index 00bb70612e..593cfc9a36 100644
>> --- a/src/amd/vulkan/radv_device.c
>> +++ b/src/amd/vulkan/radv_device.c
>> @@ -875,6 +875,16 @@ void radv_GetPhysicalDeviceProperties2(
>>                         properties->quadOperationsInAllStages = false;
>>                         break;
>>                 }
>> +               case
>> VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES: {
>> +                       VkPhysicalDeviceMaintenance3Properties *properties
>> =
>> +                           (VkPhysicalDeviceMaintenance3Properties*)ext;
>> +                       /* Make sure evrything is addressable by a signed
>> 32-bit int, and our
>> +                        * largest descriptors are 96 bytes. */
>> +                       properties->maxPerSetDescriptors = (1ull << 31) /
>> 96;
>> +                       /* Our buffer size fields allow only this much */
>> +                       properties->maxMemoryAllocationSize =
>> 0xFFFFFFFFull;
>> +                       break;
>> +               }
>>                 default:
>>                         break;
>>                 }
>> diff --git a/src/amd/vulkan/radv_extensions.py
>> b/src/amd/vulkan/radv_extensions.py
>> index 6fa553e589..3b4f75bff6 100644
>> --- a/src/amd/vulkan/radv_extensions.py
>> +++ b/src/amd/vulkan/radv_extensions.py
>> @@ -70,6 +70,7 @@ EXTENSIONS = [
>>       Extension('VK_KHR_incremental_present',               1, True),
>>       Extension('VK_KHR_maintenance1',                      1, True),
>>       Extension('VK_KHR_maintenance2',                      1, True),
>> +    Extension('VK_KHR_maintenance3',                      1, True),
>>       Extension('VK_KHR_push_descriptor',                   1, True),
>>       Extension('VK_KHR_relaxed_block_layout',              1, True),
>>       Extension('VK_KHR_sampler_mirror_clamp_to_edge',      1, True),
>>
>
Samuel Pitoiset March 7, 2018, 6:35 p.m.
On 03/07/2018 07:32 PM, Bas Nieuwenhuizen wrote:
> On Wed, Mar 7, 2018 at 7:19 PM, Samuel Pitoiset
> <samuel.pitoiset@gmail.com> wrote:
>>
>>
>> On 03/07/2018 03:47 PM, Bas Nieuwenhuizen wrote:
>>>
>>> Reviewed-by: Dave Airlie <airlied@redhat.com>
>>> ---
>>>    src/amd/vulkan/radv_descriptor_set.c | 82
>>> ++++++++++++++++++++++++++++++++++--
>>>    src/amd/vulkan/radv_device.c         | 10 +++++
>>>    src/amd/vulkan/radv_extensions.py    |  1 +
>>>    3 files changed, 89 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/src/amd/vulkan/radv_descriptor_set.c
>>> b/src/amd/vulkan/radv_descriptor_set.c
>>> index 38b8dc78e1..265028df2b 100644
>>> --- a/src/amd/vulkan/radv_descriptor_set.c
>>> +++ b/src/amd/vulkan/radv_descriptor_set.c
>>> @@ -31,6 +31,20 @@
>>>    #include "radv_private.h"
>>>    #include "sid.h"
>>>    +
>>> +static bool has_equal_immutable_samplers(const VkSampler *samplers,
>>> uint32_t count)
>>> +{
>>> +       if (!samplers)
>>> +               return false;
>>> +       for(uint32_t i = 1; i < count; ++i) {
>>> +               if (memcmp(radv_sampler_from_handle(samplers[0])->state,
>>> +                          radv_sampler_from_handle(samplers[i])->state,
>>> 16)) {
>>> +                       return false;
>>> +               }
>>> +       }
>>> +       return true;
>>> +}
>>> +
>>>    VkResult radv_CreateDescriptorSetLayout(
>>>          VkDevice                                    _device,
>>>          const VkDescriptorSetLayoutCreateInfo*      pCreateInfo,
>>> @@ -132,15 +146,13 @@ VkResult radv_CreateDescriptorSetLayout(
>>>                  if (binding->pImmutableSamplers) {
>>>                          set_layout->binding[b].immutable_samplers_offset =
>>> samplers_offset;
>>> -                       set_layout->binding[b].immutable_samplers_equal =
>>> true;
>>> +                       set_layout->binding[b].immutable_samplers_equal =
>>> +
>>> has_equal_immutable_samplers(binding->pImmutableSamplers,
>>> binding->descriptorCount);
>>>                          set_layout->has_immutable_samplers = true;
>>>                          for (uint32_t i = 0; i < binding->descriptorCount;
>>> i++)
>>>                                  memcpy(samplers + 4 * i,
>>> &radv_sampler_from_handle(binding->pImmutableSamplers[i])->state, 16);
>>> -                       for (uint32_t i = 1; i < binding->descriptorCount;
>>> i++)
>>> -                               if (memcmp(samplers + 4 * i, samplers, 16)
>>> != 0)
>>> -
>>> set_layout->binding[b].immutable_samplers_equal = false;
>>>                          /* Don't reserve space for the samplers if they're
>>> not accessed. */
>>>                          if
>>> (set_layout->binding[b].immutable_samplers_equal) {
>>> @@ -182,6 +194,68 @@ void radv_DestroyDescriptorSetLayout(
>>>          vk_free2(&device->alloc, pAllocator, set_layout);
>>>    }
>>>    +void radv_GetDescriptorSetLayoutSupport(VkDevice device,
>>> +                                        const
>>> VkDescriptorSetLayoutCreateInfo* pCreateInfo,
>>> +                                        VkDescriptorSetLayoutSupport*
>>> pSupport)
>>> +{
>>> +       bool supported = true;
>>> +       uint64_t size = 0;
>>> +       for (uint32_t i = 0; i < pCreateInfo->bindingCount; i++) {
>>> +               const VkDescriptorSetLayoutBinding *binding =
>>> &pCreateInfo->pBindings[i];
>>> +
>>> +               if (binding->descriptorCount == 0)
>>> +                       continue;
>>> +
>>> +               uint64_t descriptor_size = 0;
>>> +               uint64_t descriptor_alignment = 1;
>>> +               switch (binding->descriptorType) {
>>> +               case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
>>> +               case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
>>> +                       break;
>>> +               case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
>>> +               case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
>>> +               case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
>>> +               case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
>>> +                       descriptor_size = 16;
>>> +                       descriptor_alignment = 16;
>>> +                       break;
>>> +               case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
>>> +               case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
>>> +               case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
>>> +                       descriptor_size = 64;
>>> +                       descriptor_alignment = 32;
>>> +                       break;
>>> +               case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
>>> +                       if
>>> (!has_equal_immutable_samplers(binding->pImmutableSamplers,
>>> binding->descriptorCount)) {
>>> +                               descriptor_size = 64;
>>> +                       } else {
>>> +                               descriptor_size = 96;
>>> +                       }
>>> +                       descriptor_alignment = 32;
>>
>>
>> Missing break?
> 
> So much for the tests ...

Yes...

The rest looks good to me, nice work!

> 
> Fixed locally.
> 
>>
>>
>>> +               case VK_DESCRIPTOR_TYPE_SAMPLER:
>>> +                       if
>>> (!has_equal_immutable_samplers(binding->pImmutableSamplers,
>>> binding->descriptorCount)) {
>>> +                               descriptor_size = 16;
>>> +                               descriptor_alignment = 16;
>>> +                       }
>>> +                       break;
>>> +               default:
>>> +                       unreachable("unknown descriptor type\n");
>>> +                       break;
>>> +               }
>>> +
>>> +               if (size && !align_u64(size, descriptor_alignment)) {
>>> +                       supported = false;
>>> +               }
>>> +               size = align_u64(size, descriptor_alignment);
>>> +               if (descriptor_size && (UINT64_MAX - size) /
>>> descriptor_size < binding->descriptorCount) {
>>> +                       supported = false;
>>> +               }
>>> +               size += binding->descriptorCount * descriptor_size;
>>> +       }
>>> +
>>> +       pSupport->supported = supported;
>>> +}
>>> +
>>>    /*
>>>     * Pipeline layouts.  These have nothing to do with the pipeline.  They
>>> are
>>>     * just muttiple descriptor set layouts pasted together
>>> diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
>>> index 00bb70612e..593cfc9a36 100644
>>> --- a/src/amd/vulkan/radv_device.c
>>> +++ b/src/amd/vulkan/radv_device.c
>>> @@ -875,6 +875,16 @@ void radv_GetPhysicalDeviceProperties2(
>>>                          properties->quadOperationsInAllStages = false;
>>>                          break;
>>>                  }
>>> +               case
>>> VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES: {
>>> +                       VkPhysicalDeviceMaintenance3Properties *properties
>>> =
>>> +                           (VkPhysicalDeviceMaintenance3Properties*)ext;
>>> +                       /* Make sure evrything is addressable by a signed
>>> 32-bit int, and our
>>> +                        * largest descriptors are 96 bytes. */
>>> +                       properties->maxPerSetDescriptors = (1ull << 31) /
>>> 96;
>>> +                       /* Our buffer size fields allow only this much */
>>> +                       properties->maxMemoryAllocationSize =
>>> 0xFFFFFFFFull;
>>> +                       break;
>>> +               }
>>>                  default:
>>>                          break;
>>>                  }
>>> diff --git a/src/amd/vulkan/radv_extensions.py
>>> b/src/amd/vulkan/radv_extensions.py
>>> index 6fa553e589..3b4f75bff6 100644
>>> --- a/src/amd/vulkan/radv_extensions.py
>>> +++ b/src/amd/vulkan/radv_extensions.py
>>> @@ -70,6 +70,7 @@ EXTENSIONS = [
>>>        Extension('VK_KHR_incremental_present',               1, True),
>>>        Extension('VK_KHR_maintenance1',                      1, True),
>>>        Extension('VK_KHR_maintenance2',                      1, True),
>>> +    Extension('VK_KHR_maintenance3',                      1, True),
>>>        Extension('VK_KHR_push_descriptor',                   1, True),
>>>        Extension('VK_KHR_relaxed_block_layout',              1, True),
>>>        Extension('VK_KHR_sampler_mirror_clamp_to_edge',      1, True),
>>>
>>
Emil Velikov March 7, 2018, 7:56 p.m.
On 7 March 2018 at 18:32, Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl> wrote:

>>
>> Missing break?
>
> So much for the tests ...
>
Speaking of tests, I hope they check that both KHR and non KHR
annotated functions (the ones changed in 04/16) are tested.
We don't want them to disappear for setups using a pre 1.1 loader.

Just a fly-by comment ;-)

-Emil
Emil Velikov March 8, 2018, 12:09 p.m.
On 7 March 2018 at 19:56, Emil Velikov <emil.l.velikov@gmail.com> wrote:
> On 7 March 2018 at 18:32, Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl> wrote:
>
>>>
>>> Missing break?
>>
>> So much for the tests ...
>>
> Speaking of tests, I hope they check that both KHR and non KHR
> annotated functions (the ones changed in 04/16) are tested.
> We don't want them to disappear for setups using a pre 1.1 loader.
>
To answer my own nit:
The python scripts produce both entrypoints, hence using an old loader
should be fine ;-)

-Emil