| @@ -1561,7 +1561,8 @@ int ff_vk_pipeline_descriptor_set_add(FFVulkanContext *s, FFVulkanPipeline *pl, · 1560 unmodified lines |
| 1561 | 1561 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, |
| 1562 | 1562 | .bindingCount = nb, |
| 1563 | 1563 | .pBindings = set->binding, |
| 1564 | | − .flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_DESCRIPTOR_BUFFER_BIT_EXT, |
| 1564 | + .flags = (s->extensions & FF_VK_EXT_DESCRIPTOR_BUFFER) ? |
| 1565 | + VK_DESCRIPTOR_SET_LAYOUT_CREATE_DESCRIPTOR_BUFFER_BIT_EXT : 0x0, |
| 1565 | 1566 | }; |
| 1566 | 1567 | |
| 1567 | 1568 | for (int i = 0; i < nb; i++) { |
| @@ -1589,13 +1590,35 @@ int ff_vk_pipeline_descriptor_set_add(FFVulkanContext *s, FFVulkanPipeline *pl, · 21 unmodified lines |
| 1589 | 1590 | return AVERROR_EXTERNAL; |
| 1590 | 1591 | } |
| 1591 | 1592 | |
| 1592 | | − vk->GetDescriptorSetLayoutSizeEXT(s->hwctx->act_dev, *layout, &set->layout_size); |
| 1593 | + if (s->extensions & FF_VK_EXT_DESCRIPTOR_BUFFER) { |
| 1594 | + vk->GetDescriptorSetLayoutSizeEXT(s->hwctx->act_dev, *layout, &set->layout_size); |
| 1595 | + set->aligned_size = FFALIGN(set->layout_size, s->desc_buf_props.descriptorBufferOffsetAlignment); |
| 1593 | 1596 | |
| 1594 | | − set->aligned_size = FFALIGN(set->layout_size, s->desc_buf_props.descriptorBufferOffsetAlignment); |
| 1595 | | − |
| 1596 | | − for (int i = 0; i < nb; i++) |
| 1597 | | − vk->GetDescriptorSetLayoutBindingOffsetEXT(s->hwctx->act_dev, *layout, |
| 1598 | | − i, &set->binding_offset[i]); |
| 1597 | + for (int i = 0; i < nb; i++) |
| 1598 | + vk->GetDescriptorSetLayoutBindingOffsetEXT(s->hwctx->act_dev, *layout, |
| 1599 | + i, &set->binding_offset[i]); |
| 1600 | + } else { |
| 1601 | + for (int i = 0; i < nb; i++) { |
| 1602 | + int j; |
| 1603 | + VkDescriptorPoolSize *desc_pool_size; |
| 1604 | + for (j = 0; j < pl->nb_desc_pool_size; j++) |
| 1605 | + if (pl->desc_pool_size[j].type == desc[i].type) |
| 1606 | + break; |
| 1607 | + if (j >= pl->nb_desc_pool_size) { |
| 1608 | + desc_pool_size = av_realloc_array(pl->desc_pool_size, |
| 1609 | + sizeof(*desc_pool_size), |
| 1610 | + pl->nb_desc_pool_size + 1); |
| 1611 | + if (!desc_pool_size) |
| 1612 | + return AVERROR(ENOMEM); |
| 1613 | + |
| 1614 | + pl->desc_pool_size = desc_pool_size; |
| 1615 | + pl->nb_desc_pool_size++; |
| 1616 | + memset(&desc_pool_size[j], 0, sizeof(VkDescriptorPoolSize)); |
| 1617 | + } |
| 1618 | + pl->desc_pool_size[j].type = desc[i].type; |
| 1619 | + pl->desc_pool_size[j].descriptorCount += FFMAX(desc[i].elems, 1); |
| 1620 | + } |
| 1621 | + } |
| 1599 | 1622 | |
| 1600 | 1623 | set->singular = singular; |
| 1601 | 1624 | set->nb_bindings = nb; |
| @@ -1643,38 +1666,102 @@ int ff_vk_exec_pipeline_register(FFVulkanContext *s, FFVkExecPool *pool, · 41 unmodified lines |
| 1643 | 1666 | { |
| 1644 | 1667 | int err; |
| 1645 | 1668 | |
| 1646 | | − pl->desc_bind = av_calloc(pl->nb_descriptor_sets, sizeof(*pl->desc_bind)); |
| 1647 | | − if (!pl->desc_bind) |
| 1648 | | − return AVERROR(ENOMEM); |
| 1669 | + if (!pl->nb_descriptor_sets) |
| 1670 | + return 0; |
| 1649 | 1671 | |
| 1650 | | − pl->bound_buffer_indices = av_calloc(pl->nb_descriptor_sets, |
| 1651 | | − sizeof(*pl->bound_buffer_indices)); |
| 1652 | | − if (!pl->bound_buffer_indices) |
| 1653 | | − return AVERROR(ENOMEM); |
| 1672 | + if (s->extensions & FF_VK_EXT_DESCRIPTOR_BUFFER) { |
| 1673 | + pl->desc_bind = av_calloc(pl->nb_descriptor_sets, sizeof(*pl->desc_bind)); |
| 1674 | + if (!pl->desc_bind) |
| 1675 | + return AVERROR(ENOMEM); |
| 1654 | 1676 | |
| 1655 | | − for (int i = 0; i < pl->nb_descriptor_sets; i++) { |
| 1656 | | − FFVulkanDescriptorSet *set = &pl->desc_set[i]; |
| 1657 | | − int nb = set->singular ? 1 : pool->pool_size; |
| 1658 | | − |
| 1659 | | − err = ff_vk_create_buf(s, &set->buf, set->aligned_size*nb, |
| 1660 | | − NULL, NULL, set->usage, |
| 1661 | | − VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | |
| 1662 | | − VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | |
| 1663 | | − VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); |
| 1664 | | − if (err < 0) |
| 1665 | | − return err; |
| 1677 | + pl->bound_buffer_indices = av_calloc(pl->nb_descriptor_sets, |
| 1678 | + sizeof(*pl->bound_buffer_indices)); |
| 1679 | + if (!pl->bound_buffer_indices) |
| 1680 | + return AVERROR(ENOMEM); |
| 1666 | 1681 | |
| 1667 | | − err = ff_vk_map_buffer(s, &set->buf, &set->desc_mem, 0); |
| 1668 | | − if (err < 0) |
| 1669 | | − return err; |
| 1682 | + for (int i = 0; i < pl->nb_descriptor_sets; i++) { |
| 1683 | + FFVulkanDescriptorSet *set = &pl->desc_set[i]; |
| 1684 | + int nb = set->singular ? 1 : pool->pool_size; |
| 1685 | + |
| 1686 | + err = ff_vk_create_buf(s, &set->buf, set->aligned_size*nb, |
| 1687 | + NULL, NULL, set->usage, |
| 1688 | + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | |
| 1689 | + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | |
| 1690 | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); |
| 1691 | + if (err < 0) |
| 1692 | + return err; |
| 1693 | + |
| 1694 | + err = ff_vk_map_buffer(s, &set->buf, &set->desc_mem, 0); |
| 1695 | + if (err < 0) |
| 1696 | + return err; |
| 1697 | + |
| 1698 | + pl->desc_bind[i] = (VkDescriptorBufferBindingInfoEXT) { |
| 1699 | + .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_BUFFER_BINDING_INFO_EXT, |
| 1700 | + .usage = set->usage, |
| 1701 | + .address = set->buf.address, |
| 1702 | + }; |
| 1670 | 1703 | |
| 1671 | | − pl->desc_bind[i] = (VkDescriptorBufferBindingInfoEXT) { |
| 1672 | | − .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_BUFFER_BINDING_INFO_EXT, |
| 1673 | | − .usage = set->usage, |
| 1674 | | − .address = set->buf.address, |
| 1704 | + pl->bound_buffer_indices[i] = i; |
| 1705 | + } |
| 1706 | + } else { |
| 1707 | + VkResult ret; |
| 1708 | + FFVulkanFunctions *vk = &s->vkfn; |
| 1709 | + VkDescriptorSetLayout *tmp_layouts; |
| 1710 | + VkDescriptorSetAllocateInfo set_alloc_info; |
| 1711 | + VkDescriptorPoolCreateInfo pool_create_info; |
| 1712 | + |
| 1713 | + for (int i = 0; i < pl->nb_desc_pool_size; i++) |
| 1714 | + pl->desc_pool_size[i].descriptorCount *= pool->pool_size; |
| 1715 | + |
| 1716 | + pool_create_info = (VkDescriptorPoolCreateInfo) { |
| 1717 | + .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, |
| 1718 | + .flags = 0, |
| 1719 | + .pPoolSizes = pl->desc_pool_size, |
| 1720 | + .poolSizeCount = pl->nb_desc_pool_size, |
| 1721 | + .maxSets = pl->nb_descriptor_sets*pool->pool_size, |
| 1675 | 1722 | }; |
| 1676 | 1723 | |
| 1677 | | − pl->bound_buffer_indices[i] = i; |
| 1724 | + ret = vk->CreateDescriptorPool(s->hwctx->act_dev, &pool_create_info, |
| 1725 | + s->hwctx->alloc, &pl->desc_pool); |
| 1726 | + if (ret != VK_SUCCESS) { |
| 1727 | + av_log(s, AV_LOG_ERROR, "Unable to create descriptor pool: %s\n", |
| 1728 | + ff_vk_ret2str(ret)); |
| 1729 | + return AVERROR_EXTERNAL; |
| 1730 | + } |
| 1731 | + |
| 1732 | + tmp_layouts = av_malloc_array(pool_create_info.maxSets, sizeof(*tmp_layouts)); |
| 1733 | + if (!tmp_layouts) |
| 1734 | + return AVERROR(ENOMEM); |
| 1735 | + |
| 1736 | + /* Colate each execution context's descriptor set layouts */ |
| 1737 | + for (int i = 0; i < pool->pool_size; i++) |
| 1738 | + for (int j = 0; j < pl->nb_descriptor_sets; j++) |
| 1739 | + tmp_layouts[i*pl->nb_descriptor_sets + j] = pl->desc_layout[j]; |
| 1740 | + |
| 1741 | + set_alloc_info = (VkDescriptorSetAllocateInfo) { |
| 1742 | + .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, |
| 1743 | + .descriptorPool = pl->desc_pool, |
| 1744 | + .pSetLayouts = tmp_layouts, |
| 1745 | + .descriptorSetCount = pool_create_info.maxSets, |
| 1746 | + }; |
| 1747 | + |
| 1748 | + pl->desc_sets = av_malloc_array(pool_create_info.maxSets, |
| 1749 | + sizeof(*tmp_layouts)); |
| 1750 | + if (!pl->desc_sets) { |
| 1751 | + av_free(tmp_layouts); |
| 1752 | + return AVERROR(ENOMEM); |
| 1753 | + } |
| 1754 | + ret = vk->AllocateDescriptorSets(s->hwctx->act_dev, &set_alloc_info, |
| 1755 | + pl->desc_sets); |
| 1756 | + av_free(tmp_layouts); |
| 1757 | + if (ret != VK_SUCCESS) { |
| 1758 | + av_log(s, AV_LOG_ERROR, "Unable to allocate descriptor set: %s\n", |
| 1759 | + ff_vk_ret2str(ret)); |
| 1760 | + av_freep(&pl->desc_sets); |
| 1761 | + return AVERROR_EXTERNAL; |
| 1762 | + } |
| 1763 | + |
| 1764 | + pl->assoc_pool = pool; |
| 1678 | 1765 | } |
| 1679 | 1766 | |
| 1680 | 1767 | return 0; |
| @@ -1696,94 +1783,150 @@ static inline void update_set_descriptor(FFVulkanContext *s, FFVkExecContext *e, · 15 unmodified lines |
| 1696 | 1783 | vk->GetDescriptorEXT(s->hwctx->act_dev, desc_get_info, desc_size, desc); |
| 1697 | 1784 | } |
| 1698 | 1785 | |
| 1786 | +static inline void update_set_pool_write(FFVulkanContext *s, |
| 1787 | + FFVulkanPipeline *pl, |
| 1788 | + FFVkExecContext *e, |
| 1789 | + FFVulkanDescriptorSet *desc_set, int set, |
| 1790 | + VkWriteDescriptorSet *write_info) |
| 1791 | +{ |
| 1792 | + FFVulkanFunctions *vk = &s->vkfn; |
| 1793 | + if (desc_set->singular) { |
| 1794 | + for (int i = 0; i < pl->assoc_pool->pool_size; i++) { |
| 1795 | + write_info->dstSet = pl->desc_sets[i*pl->nb_descriptor_sets + set]; |
| 1796 | + vk->UpdateDescriptorSets(s->hwctx->act_dev, 1, write_info, 0, NULL); |
| 1797 | + } |
| 1798 | + } else { |
| 1799 | + write_info->dstSet = pl->desc_sets[e->idx*pl->nb_descriptor_sets + set]; |
| 1800 | + vk->UpdateDescriptorSets(s->hwctx->act_dev, 1, write_info, 0, NULL); |
| 1801 | + } |
| 1802 | +} |
| 1803 | + |
| 1699 | 1804 | static int vk_set_descriptor_image(FFVulkanContext *s, FFVulkanPipeline *pl, |
| 1700 | 1805 | FFVkExecContext *e, int set, int bind, int offs, |
| 1701 | 1806 | VkImageView view, VkImageLayout layout, |
| 1702 | 1807 | VkSampler sampler) |
| 1703 | 1808 | { |
| 1704 | 1809 | FFVulkanDescriptorSet *desc_set = &pl->desc_set[set]; |
| 1705 | | − VkDescriptorGetInfoEXT desc_get_info = { |
| 1706 | | − .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_GET_INFO_EXT, |
| 1707 | | − .type = desc_set->binding[bind].descriptorType, |
| 1708 | | − }; |
| 1709 | | − VkDescriptorImageInfo desc_img_info = { |
| 1710 | | − .imageView = view, |
| 1711 | | − .sampler = sampler, |
| 1712 | | − .imageLayout = layout, |
| 1713 | | − }; |
| 1714 | | − size_t desc_size; |
| 1715 | 1810 | |
| 1716 | | − switch (desc_get_info.type) { |
| 1717 | | − case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 1718 | | − desc_get_info.data.pSampledImage = &desc_img_info; |
| 1719 | | − desc_size = s->desc_buf_props.sampledImageDescriptorSize; |
| 1720 | | − break; |
| 1721 | | − case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: |
| 1722 | | − desc_get_info.data.pStorageImage = &desc_img_info; |
| 1723 | | − desc_size = s->desc_buf_props.storageImageDescriptorSize; |
| 1724 | | − break; |
| 1725 | | − case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 1726 | | − desc_get_info.data.pInputAttachmentImage = &desc_img_info; |
| 1727 | | − desc_size = s->desc_buf_props.inputAttachmentDescriptorSize; |
| 1728 | | − break; |
| 1729 | | − case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: |
| 1730 | | − desc_get_info.data.pCombinedImageSampler = &desc_img_info; |
| 1731 | | − desc_size = s->desc_buf_props.combinedImageSamplerDescriptorSize; |
| 1732 | | − break; |
| 1733 | | − default: |
| 1734 | | − av_log(s, AV_LOG_ERROR, "Invalid descriptor type at set %i binding %i: %i!\n", |
| 1735 | | − set, bind, desc_get_info.type); |
| 1736 | | − return AVERROR(EINVAL); |
| 1737 | | − break; |
| 1738 | | − }; |
| 1811 | + if (s->extensions & FF_VK_EXT_DESCRIPTOR_BUFFER) { |
| 1812 | + VkDescriptorGetInfoEXT desc_get_info = { |
| 1813 | + .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_GET_INFO_EXT, |
| 1814 | + .type = desc_set->binding[bind].descriptorType, |
| 1815 | + }; |
| 1816 | + VkDescriptorImageInfo desc_img_info = { |
| 1817 | + .imageView = view, |
| 1818 | + .sampler = sampler, |
| 1819 | + .imageLayout = layout, |
| 1820 | + }; |
| 1821 | + size_t desc_size; |
| 1822 | + |
| 1823 | + switch (desc_get_info.type) { |
| 1824 | + case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 1825 | + desc_get_info.data.pSampledImage = &desc_img_info; |
| 1826 | + desc_size = s->desc_buf_props.sampledImageDescriptorSize; |
| 1827 | + break; |
| 1828 | + case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: |
| 1829 | + desc_get_info.data.pStorageImage = &desc_img_info; |
| 1830 | + desc_size = s->desc_buf_props.storageImageDescriptorSize; |
| 1831 | + break; |
| 1832 | + case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 1833 | + desc_get_info.data.pInputAttachmentImage = &desc_img_info; |
| 1834 | + desc_size = s->desc_buf_props.inputAttachmentDescriptorSize; |
| 1835 | + break; |
| 1836 | + case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: |
| 1837 | + desc_get_info.data.pCombinedImageSampler = &desc_img_info; |
| 1838 | + desc_size = s->desc_buf_props.combinedImageSamplerDescriptorSize; |
| 1839 | + break; |
| 1840 | + default: |
| 1841 | + av_log(s, AV_LOG_ERROR, "Invalid descriptor type at set %i binding %i: %i!\n", |
| 1842 | + set, bind, desc_get_info.type); |
| 1843 | + return AVERROR(EINVAL); |
| 1844 | + break; |
| 1845 | + }; |
| 1739 | 1846 | |
| 1740 | | − update_set_descriptor(s, e, desc_set, bind, offs, &desc_get_info, desc_size); |
| 1847 | + update_set_descriptor(s, e, desc_set, bind, offs, |
| 1848 | + &desc_get_info, desc_size); |
| 1849 | + } else { |
| 1850 | + VkDescriptorImageInfo desc_pool_write_info_img = { |
| 1851 | + .sampler = sampler, |
| 1852 | + .imageView = view, |
| 1853 | + .imageLayout = layout, |
| 1854 | + }; |
| 1855 | + VkWriteDescriptorSet desc_pool_write_info = { |
| 1856 | + .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, |
| 1857 | + .dstBinding = bind, |
| 1858 | + .descriptorCount = 1, |
| 1859 | + .dstArrayElement = offs, |
| 1860 | + .descriptorType = desc_set->binding[bind].descriptorType, |
| 1861 | + .pImageInfo = &desc_pool_write_info_img, |
| 1862 | + }; |
| 1863 | + update_set_pool_write(s, pl, e, desc_set, set, &desc_pool_write_info); |
| 1864 | + } |
| 1741 | 1865 | |
| 1742 | 1866 | return 0; |
| 1743 | 1867 | } |
| 1744 | 1868 | |
| 1745 | 1869 | int ff_vk_set_descriptor_buffer(FFVulkanContext *s, FFVulkanPipeline *pl, |
| 1746 | | − FFVkExecContext *e, int set, int bind, int offs, |
| 1747 | | − VkDeviceAddress addr, VkDeviceSize len, VkFormat fmt) |
| 1870 | + FFVkExecContext *e, int set, int bind, int elem, |
| 1871 | + FFVkBuffer *buf, VkDeviceSize offset, VkDeviceSize len, |
| 1872 | + VkFormat fmt) |
| 1748 | 1873 | { |
| 1749 | 1874 | FFVulkanDescriptorSet *desc_set = &pl->desc_set[set]; |
| 1750 | | − VkDescriptorGetInfoEXT desc_get_info = { |
| 1751 | | − .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_GET_INFO_EXT, |
| 1752 | | − .type = desc_set->binding[bind].descriptorType, |
| 1753 | | − }; |
| 1754 | | − VkDescriptorAddressInfoEXT desc_buf_info = { |
| 1755 | | − .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_ADDRESS_INFO_EXT, |
| 1756 | | − .address = addr, |
| 1757 | | − .range = len, |
| 1758 | | − .format = fmt, |
| 1759 | | − }; |
| 1760 | | − size_t desc_size; |
| 1761 | 1875 | |
| 1762 | | − switch (desc_get_info.type) { |
| 1763 | | − case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 1764 | | − desc_get_info.data.pUniformBuffer = &desc_buf_info; |
| 1765 | | − desc_size = s->desc_buf_props.uniformBufferDescriptorSize; |
| 1766 | | − break; |
| 1767 | | − case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 1768 | | − desc_get_info.data.pStorageBuffer = &desc_buf_info; |
| 1769 | | − desc_size = s->desc_buf_props.storageBufferDescriptorSize; |
| 1770 | | − break; |
| 1771 | | − case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 1772 | | − desc_get_info.data.pUniformTexelBuffer = &desc_buf_info; |
| 1773 | | − desc_size = s->desc_buf_props.uniformTexelBufferDescriptorSize; |
| 1774 | | − break; |
| 1775 | | − case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
| 1776 | | − desc_get_info.data.pStorageTexelBuffer = &desc_buf_info; |
| 1777 | | − desc_size = s->desc_buf_props.storageTexelBufferDescriptorSize; |
| 1778 | | − break; |
| 1779 | | − default: |
| 1780 | | − av_log(s, AV_LOG_ERROR, "Invalid descriptor type at set %i binding %i: %i!\n", |
| 1781 | | − set, bind, desc_get_info.type); |
| 1782 | | − return AVERROR(EINVAL); |
| 1783 | | − break; |
| 1784 | | − }; |
| 1876 | + if (s->extensions & FF_VK_EXT_DESCRIPTOR_BUFFER) { |
| 1877 | + VkDescriptorGetInfoEXT desc_get_info = { |
| 1878 | + .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_GET_INFO_EXT, |
| 1879 | + .type = desc_set->binding[bind].descriptorType, |
| 1880 | + }; |
| 1881 | + VkDescriptorAddressInfoEXT desc_buf_info = { |
| 1882 | + .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_ADDRESS_INFO_EXT, |
| 1883 | + .address = buf->address + offset, |
| 1884 | + .range = len, |
| 1885 | + .format = fmt, |
| 1886 | + }; |
| 1887 | + size_t desc_size; |
| 1888 | + |
| 1889 | + switch (desc_get_info.type) { |
| 1890 | + case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 1891 | + desc_get_info.data.pUniformBuffer = &desc_buf_info; |
| 1892 | + desc_size = s->desc_buf_props.uniformBufferDescriptorSize; |
| 1893 | + break; |
| 1894 | + case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 1895 | + desc_get_info.data.pStorageBuffer = &desc_buf_info; |
| 1896 | + desc_size = s->desc_buf_props.storageBufferDescriptorSize; |
| 1897 | + break; |
| 1898 | + case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 1899 | + desc_get_info.data.pUniformTexelBuffer = &desc_buf_info; |
| 1900 | + desc_size = s->desc_buf_props.uniformTexelBufferDescriptorSize; |
| 1901 | + break; |
| 1902 | + case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
| 1903 | + desc_get_info.data.pStorageTexelBuffer = &desc_buf_info; |
| 1904 | + desc_size = s->desc_buf_props.storageTexelBufferDescriptorSize; |
| 1905 | + break; |
| 1906 | + default: |
| 1907 | + av_log(s, AV_LOG_ERROR, "Invalid descriptor type at set %i binding %i: %i!\n", |
| 1908 | + set, bind, desc_get_info.type); |
| 1909 | + return AVERROR(EINVAL); |
| 1910 | + break; |
| 1911 | + }; |
| 1785 | 1912 | |
| 1786 | | − update_set_descriptor(s, e, desc_set, bind, offs, &desc_get_info, desc_size); |
| 1913 | + update_set_descriptor(s, e, desc_set, bind, elem, &desc_get_info, desc_size); |
| 1914 | + } else { |
| 1915 | + VkDescriptorBufferInfo desc_pool_write_info_buf = { |
| 1916 | + .buffer = buf->buf, |
| 1917 | + .offset = offset, |
| 1918 | + .range = len, |
| 1919 | + }; |
| 1920 | + VkWriteDescriptorSet desc_pool_write_info = { |
| 1921 | + .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, |
| 1922 | + .dstBinding = bind, |
| 1923 | + .descriptorCount = 1, |
| 1924 | + .dstArrayElement = elem, |
| 1925 | + .descriptorType = desc_set->binding[bind].descriptorType, |
| 1926 | + .pBufferInfo = &desc_pool_write_info_buf, |
| 1927 | + }; |
| 1928 | + update_set_pool_write(s, pl, e, desc_set, set, &desc_pool_write_info); |
| 1929 | + } |
| 1787 | 1930 | |
| 1788 | 1931 | return 0; |
| 1789 | 1932 | } |
| @@ -1852,7 +1995,8 @@ int ff_vk_init_compute_pipeline(FFVulkanContext *s, FFVulkanPipeline *pl, · 62 unmodified lines |
| 1852 | 1995 | |
| 1853 | 1996 | pipeline_create_info = (VkComputePipelineCreateInfo) { |
| 1854 | 1997 | .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 1855 | | − .flags = VK_PIPELINE_CREATE_DESCRIPTOR_BUFFER_BIT_EXT, |
| 1998 | + .flags = (s->extensions & FF_VK_EXT_DESCRIPTOR_BUFFER) ? |
| 1999 | + VK_PIPELINE_CREATE_DESCRIPTOR_BUFFER_BIT_EXT : 0x0, |
| 1856 | 2000 | .layout = pl->pipeline_layout, |
| 1857 | 2001 | .stage = shd->shader, |
| 1858 | 2002 | }; |
| @@ -1884,15 +2028,22 @@ void ff_vk_exec_bind_pipeline(FFVulkanContext *s, FFVkExecContext *e, · 25 unmodified lines |
| 1884 | 2028 | vk->CmdBindPipeline(e->buf, pl->bind_point, pl->pipeline); |
| 1885 | 2029 | |
| 1886 | 2030 | if (pl->nb_descriptor_sets) { |
| 1887 | | − for (int i = 0; i < pl->nb_descriptor_sets; i++) |
| 1888 | | − offsets[i] = pl->desc_set[i].singular ? 0 : pl->desc_set[i].aligned_size*e->idx; |
| 1889 | | − |
| 1890 | | − /* Bind descriptor buffers */ |
| 1891 | | − vk->CmdBindDescriptorBuffersEXT(e->buf, pl->nb_descriptor_sets, pl->desc_bind); |
| 1892 | | − /* Binding offsets */ |
| 1893 | | − vk->CmdSetDescriptorBufferOffsetsEXT(e->buf, pl->bind_point, pl->pipeline_layout, |
| 1894 | | − 0, pl->nb_descriptor_sets, |
| 1895 | | − pl->bound_buffer_indices, offsets); |
| 2031 | + if (s->extensions & FF_VK_EXT_DESCRIPTOR_BUFFER) { |
| 2032 | + for (int i = 0; i < pl->nb_descriptor_sets; i++) |
| 2033 | + offsets[i] = pl->desc_set[i].singular ? 0 : pl->desc_set[i].aligned_size*e->idx; |
| 2034 | + |
| 2035 | + /* Bind descriptor buffers */ |
| 2036 | + vk->CmdBindDescriptorBuffersEXT(e->buf, pl->nb_descriptor_sets, pl->desc_bind); |
| 2037 | + /* Binding offsets */ |
| 2038 | + vk->CmdSetDescriptorBufferOffsetsEXT(e->buf, pl->bind_point, pl->pipeline_layout, |
| 2039 | + 0, pl->nb_descriptor_sets, |
| 2040 | + pl->bound_buffer_indices, offsets); |
| 2041 | + } else { |
| 2042 | + vk->CmdBindDescriptorSets(e->buf, pl->bind_point, pl->pipeline_layout, |
| 2043 | + 0, pl->nb_descriptor_sets, |
| 2044 | + &pl->desc_sets[e->idx*pl->nb_descriptor_sets], |
| 2045 | + 0, NULL); |
| 2046 | + } |
| 1896 | 2047 | } |
| 1897 | 2048 | } |
| 1898 | 2049 | |
| @@ -1920,7 +2071,13 @@ void ff_vk_pipeline_free(FFVulkanContext *s, FFVulkanPipeline *pl) · 21 unmodified lines |
| 1920 | 2071 | vk->DestroyDescriptorSetLayout(s->hwctx->act_dev, pl->desc_layout[i], |
| 1921 | 2072 | s->hwctx->alloc); |
| 1922 | 2073 | |
| 2074 | + if (pl->desc_pool) |
| 2075 | + vk->DestroyDescriptorPool(s->hwctx->act_dev, pl->desc_pool, |
| 2076 | + s->hwctx->alloc); |
| 2077 | + |
| 2078 | + av_freep(&pl->desc_pool_size); |
| 1923 | 2079 | av_freep(&pl->desc_layout); |
| 2080 | + av_freep(&pl->desc_sets); |
| 1924 | 2081 | av_freep(&pl->desc_set); |
| 1925 | 2082 | av_freep(&pl->desc_bind); |
| 1926 | 2083 | av_freep(&pl->bound_buffer_indices); |