This finally permits using fully compiled shaders across multiple execution contexts.
Unified · Split
| @@ -262,6 +262,28 @@ void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool) · 261 unmodified lines | |||
| 262 | av_free(e->sem_wait); | 262 | av_free(e->sem_wait); |
| 263 | } | 263 | } |
| 264 | 264 | ||
| 265 | /* Free shader-specific data */ | ||
| 266 | for (int i = 0; i < pool->nb_reg_shd; i++) { | ||
| 267 | FFVulkanShaderData *sd = &pool->reg_shd[i]; | ||
| 268 | |||
| 269 | if (s->extensions & FF_VK_EXT_DESCRIPTOR_BUFFER) { | ||
| 270 | for (int j = 0; j < sd->nb_descriptor_sets; j++) { | ||
| 271 | FFVulkanDescriptorSetData *set_data = &sd->desc_set_buf[j]; | ||
| 272 | if (set_data->buf.mem) | ||
| 273 | ff_vk_unmap_buffer(s, &set_data->buf, 0); | ||
| 274 | ff_vk_free_buf(s, &set_data->buf); | ||
| 275 | } | ||
| 276 | } | ||
| 277 | |||
| 278 | if (sd->desc_pool) | ||
| 279 | vk->DestroyDescriptorPool(s->hwctx->act_dev, sd->desc_pool, | ||
| 280 | s->hwctx->alloc); | ||
| 281 | |||
| 282 | av_freep(&sd->desc_set_buf); | ||
| 283 | av_freep(&sd->desc_bind); | ||
| 284 | av_freep(&sd->desc_sets); | ||
| 285 | } | ||
| 286 | |||
| 265 | if (pool->cmd_bufs) | 287 | if (pool->cmd_bufs) |
| 266 | vk->FreeCommandBuffers(s->hwctx->act_dev, pool->cmd_buf_pool, | 288 | vk->FreeCommandBuffers(s->hwctx->act_dev, pool->cmd_buf_pool, |
| 267 | pool->pool_size, pool->cmd_bufs); | 289 | pool->pool_size, pool->cmd_bufs); |
| @@ -1655,6 +1677,16 @@ int ff_vk_shader_link(FFVulkanContext *s, FFVulkanShader *shd, · 1387 unmodified lines | |||
| 1655 | if (err < 0) | 1677 | if (err < 0) |
| 1656 | return err; | 1678 | return err; |
| 1657 | 1679 | ||
| 1680 | if (s->extensions & FF_VK_EXT_DESCRIPTOR_BUFFER) { | ||
| 1681 | shd->bound_buffer_indices = av_calloc(shd->nb_descriptor_sets, | ||
| 1682 | sizeof(*shd->bound_buffer_indices)); | ||
| 1683 | if (!shd->bound_buffer_indices) | ||
| 1684 | return AVERROR(ENOMEM); | ||
| 1685 | |||
| 1686 | for (int i = 0; i < shd->nb_descriptor_sets; i++) | ||
| 1687 | shd->bound_buffer_indices[i] = i; | ||
| 1688 | } | ||
| 1689 | |||
| 1658 | { | 1690 | { |
| 1659 | VkShaderModule mod; | 1691 | VkShaderModule mod; |
| 1660 | err = create_shader_module(s, shd, &mod, spirv, spirv_len); | 1692 | err = create_shader_module(s, shd, &mod, spirv, spirv_len); |
| @@ -1817,25 +1849,40 @@ int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, · 156 unmodified lines | |||
| 1817 | FFVulkanShader *shd) | 1849 | FFVulkanShader *shd) |
| 1818 | { | 1850 | { |
| 1819 | int err; | 1851 | int err; |
| 1852 | FFVulkanShaderData *sd; | ||
| 1820 | 1853 | ||
| 1821 | if (!shd->nb_descriptor_sets) | 1854 | if (!shd->nb_descriptor_sets) |
| 1822 | return 0; | 1855 | return 0; |
| 1823 | 1856 | ||
| 1857 | sd = av_realloc_array(pool->reg_shd, | ||
| 1858 | sizeof(*pool->reg_shd), | ||
| 1859 | pool->nb_reg_shd + 1); | ||
| 1860 | if (!sd) | ||
| 1861 | return AVERROR(ENOMEM); | ||
| 1862 | |||
| 1863 | pool->reg_shd = sd; | ||
| 1864 | sd = &sd[pool->nb_reg_shd++]; | ||
| 1865 | memset(sd, 0, sizeof(*sd)); | ||
| 1866 | |||
| 1867 | sd->shd = shd; | ||
| 1868 | sd->nb_descriptor_sets = shd->nb_descriptor_sets; | ||
| 1869 | |||
| 1824 | if (s->extensions & FF_VK_EXT_DESCRIPTOR_BUFFER) { | 1870 | if (s->extensions & FF_VK_EXT_DESCRIPTOR_BUFFER) { |
| 1825 | shd->desc_bind = av_calloc(shd->nb_descriptor_sets, sizeof(*shd->desc_bind)); | 1871 | sd->desc_bind = av_malloc_array(sd->nb_descriptor_sets, sizeof(*sd->desc_bind)); |
| 1826 | if (!shd->desc_bind) | 1872 | if (!sd->desc_bind) |
| 1827 | return AVERROR(ENOMEM); | 1873 | return AVERROR(ENOMEM); |
| 1828 | 1874 | ||
| 1829 | shd->bound_buffer_indices = av_calloc(shd->nb_descriptor_sets, | 1875 | sd->desc_set_buf = av_calloc(sd->nb_descriptor_sets, sizeof(*sd->desc_set_buf)); |
| 1830 | sizeof(*shd->bound_buffer_indices)); | 1876 | if (!sd->desc_set_buf) |
| 1831 | if (!shd->bound_buffer_indices) | ||
| 1832 | return AVERROR(ENOMEM); | 1877 | return AVERROR(ENOMEM); |
| 1833 | 1878 | ||
| 1834 | for (int i = 0; i < shd->nb_descriptor_sets; i++) { | 1879 | for (int i = 0; i < sd->nb_descriptor_sets; i++) { |
| 1835 | FFVulkanDescriptorSet *set = &shd->desc_set[i]; | 1880 | FFVulkanDescriptorSet *set = &shd->desc_set[i]; |
| 1881 | FFVulkanDescriptorSetData *sdb = &sd->desc_set_buf[i]; | ||
| 1836 | int nb = set->singular ? 1 : pool->pool_size; | 1882 | int nb = set->singular ? 1 : pool->pool_size; |
| 1837 | 1883 | ||
| 1838 | err = ff_vk_create_buf(s, &set->buf, set->aligned_size*nb, | 1884 | err = ff_vk_create_buf(s, &sdb->buf, |
| 1885 | set->aligned_size*nb, | ||
| 1839 | NULL, NULL, set->usage, | 1886 | NULL, NULL, set->usage, |
| 1840 | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | | 1887 | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | |
| 1841 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | | 1888 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | |
| @@ -1843,17 +1890,15 @@ int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, · 1 unmodified line | |||
| 1843 | if (err < 0) | 1890 | if (err < 0) |
| 1844 | return err; | 1891 | return err; |
| 1845 | 1892 | ||
| 1846 | err = ff_vk_map_buffer(s, &set->buf, &set->desc_mem, 0); | 1893 | err = ff_vk_map_buffer(s, &sdb->buf, &sdb->desc_mem, 0); |
| 1847 | if (err < 0) | 1894 | if (err < 0) |
| 1848 | return err; | 1895 | return err; |
| 1849 | 1896 | ||
| 1850 | shd->desc_bind[i] = (VkDescriptorBufferBindingInfoEXT) { | 1897 | sd->desc_bind[i] = (VkDescriptorBufferBindingInfoEXT) { |
| 1851 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_BUFFER_BINDING_INFO_EXT, | 1898 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_BUFFER_BINDING_INFO_EXT, |
| 1852 | .usage = set->usage, | 1899 | .usage = set->usage, |
| 1853 | .address = set->buf.address, | 1900 | .address = sdb->buf.address, |
| 1854 | }; | 1901 | }; |
| 1855 | |||
| 1856 | shd->bound_buffer_indices[i] = i; | ||
| 1857 | } | 1902 | } |
| 1858 | } else if (!shd->use_push) { | 1903 | } else if (!shd->use_push) { |
| 1859 | VkResult ret; | 1904 | VkResult ret; |
| @@ -1870,11 +1915,11 @@ int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, · 10 unmodified lines | |||
| 1870 | .flags = 0, | 1915 | .flags = 0, |
| 1871 | .pPoolSizes = shd->desc_pool_size, | 1916 | .pPoolSizes = shd->desc_pool_size, |
| 1872 | .poolSizeCount = shd->nb_desc_pool_size, | 1917 | .poolSizeCount = shd->nb_desc_pool_size, |
| 1873 | .maxSets = shd->nb_descriptor_sets*pool->pool_size, | 1918 | .maxSets = sd->nb_descriptor_sets*pool->pool_size, |
| 1874 | }; | 1919 | }; |
| 1875 | 1920 | ||
| 1876 | ret = vk->CreateDescriptorPool(s->hwctx->act_dev, &pool_create_info, | 1921 | ret = vk->CreateDescriptorPool(s->hwctx->act_dev, &pool_create_info, |
| 1877 | s->hwctx->alloc, &shd->desc_pool); | 1922 | s->hwctx->alloc, &sd->desc_pool); |
| 1878 | if (ret != VK_SUCCESS) { | 1923 | if (ret != VK_SUCCESS) { |
| 1879 | av_log(s, AV_LOG_ERROR, "Unable to create descriptor pool: %s\n", | 1924 | av_log(s, AV_LOG_ERROR, "Unable to create descriptor pool: %s\n", |
| 1880 | ff_vk_ret2str(ret)); | 1925 | ff_vk_ret2str(ret)); |
| @@ -1887,63 +1932,75 @@ int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, · 6 unmodified lines | |||
| 1887 | 1932 | ||
| 1888 | /* Colate each execution context's descriptor set layouts */ | 1933 | /* Colate each execution context's descriptor set layouts */ |
| 1889 | for (int i = 0; i < pool->pool_size; i++) | 1934 | for (int i = 0; i < pool->pool_size; i++) |
| 1890 | for (int j = 0; j < shd->nb_descriptor_sets; j++) | 1935 | for (int j = 0; j < sd->nb_descriptor_sets; j++) |
| 1891 | tmp_layouts[i*shd->nb_descriptor_sets + j] = shd->desc_layout[j]; | 1936 | tmp_layouts[i*sd->nb_descriptor_sets + j] = shd->desc_layout[j]; |
| 1892 | 1937 | ||
| 1893 | set_alloc_info = (VkDescriptorSetAllocateInfo) { | 1938 | set_alloc_info = (VkDescriptorSetAllocateInfo) { |
| 1894 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, | 1939 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, |
| 1895 | .descriptorPool = shd->desc_pool, | 1940 | .descriptorPool = sd->desc_pool, |
| 1896 | .pSetLayouts = tmp_layouts, | 1941 | .pSetLayouts = tmp_layouts, |
| 1897 | .descriptorSetCount = pool_create_info.maxSets, | 1942 | .descriptorSetCount = pool_create_info.maxSets, |
| 1898 | }; | 1943 | }; |
| 1899 | 1944 | ||
| 1900 | shd->desc_sets = av_malloc_array(pool_create_info.maxSets, | 1945 | sd->desc_sets = av_malloc_array(pool_create_info.maxSets, |
| 1901 | sizeof(*tmp_layouts)); | 1946 | sizeof(*tmp_layouts)); |
| 1902 | if (!shd->desc_sets) { | 1947 | if (!sd->desc_sets) { |
| 1903 | av_free(tmp_layouts); | 1948 | av_free(tmp_layouts); |
| 1904 | return AVERROR(ENOMEM); | 1949 | return AVERROR(ENOMEM); |
| 1905 | } | 1950 | } |
| 1906 | ret = vk->AllocateDescriptorSets(s->hwctx->act_dev, &set_alloc_info, | 1951 | ret = vk->AllocateDescriptorSets(s->hwctx->act_dev, &set_alloc_info, |
| 1907 | shd->desc_sets); | 1952 | sd->desc_sets); |
| 1908 | av_free(tmp_layouts); | 1953 | av_free(tmp_layouts); |
| 1909 | if (ret != VK_SUCCESS) { | 1954 | if (ret != VK_SUCCESS) { |
| 1910 | av_log(s, AV_LOG_ERROR, "Unable to allocate descriptor set: %s\n", | 1955 | av_log(s, AV_LOG_ERROR, "Unable to allocate descriptor set: %s\n", |
| 1911 | ff_vk_ret2str(ret)); | 1956 | ff_vk_ret2str(ret)); |
| 1912 | av_freep(&shd->desc_sets); | 1957 | av_freep(&sd->desc_sets); |
| 1913 | return AVERROR_EXTERNAL; | 1958 | return AVERROR_EXTERNAL; |
| 1914 | } | 1959 | } |
| 1915 | |||
| 1916 | shd->assoc_pool = pool; | ||
| 1917 | } | 1960 | } |
| 1918 | 1961 | ||
| 1919 | return 0; | 1962 | return 0; |
| 1920 | } | 1963 | } |
| 1921 | 1964 | ||
| 1965 | static inline FFVulkanShaderData *get_shd_data(FFVkExecContext *e, | ||
| 1966 | FFVulkanShader *shd) | ||
| 1967 | { | ||
| 1968 | for (int i = 0; i < e->parent->nb_reg_shd; i++) | ||
| 1969 | if (e->parent->reg_shd[i].shd == shd) | ||
| 1970 | return &e->parent->reg_shd[i]; | ||
| 1971 | av_assert0(0); | ||
| 1972 | } | ||
| 1973 | |||
| 1922 | static inline void update_set_descriptor(FFVulkanContext *s, FFVkExecContext *e, | 1974 | static inline void update_set_descriptor(FFVulkanContext *s, FFVkExecContext *e, |
| 1923 | FFVulkanDescriptorSet *set, | 1975 | FFVulkanShader *shd, int set, |
| 1924 | int bind_idx, int array_idx, | 1976 | int bind_idx, int array_idx, |
| 1925 | VkDescriptorGetInfoEXT *desc_get_info, | 1977 | VkDescriptorGetInfoEXT *desc_get_info, |
| 1926 | size_t desc_size) | 1978 | size_t desc_size) |
| 1927 | { | 1979 | { |
| 1928 | FFVulkanFunctions *vk = &s->vkfn; | 1980 | FFVulkanFunctions *vk = &s->vkfn; |
| 1929 | const size_t exec_offset = set->singular ? 0 : set->aligned_size*e->idx; | 1981 | FFVulkanDescriptorSet *desc_set = &shd->desc_set[set]; |
| 1930 | void *desc = set->desc_mem + /* Base */ | 1982 | FFVulkanShaderData *sd = get_shd_data(e, shd); |
| 1931 | exec_offset + /* Execution context */ | 1983 | const size_t exec_offset = desc_set->singular ? 0 : desc_set->aligned_size*e->idx; |
| 1932 | set->binding_offset[bind_idx] + /* Descriptor binding */ | 1984 | |
| 1933 | array_idx*desc_size; /* Array position */ | 1985 | void *desc = sd->desc_set_buf[set].desc_mem + /* Base */ |
| 1986 | exec_offset + /* Execution context */ | ||
| 1987 | desc_set->binding_offset[bind_idx] + /* Descriptor binding */ | ||
| 1988 | array_idx*desc_size; /* Array position */ | ||
| 1934 | 1989 | ||
| 1935 | vk->GetDescriptorEXT(s->hwctx->act_dev, desc_get_info, desc_size, desc); | 1990 | vk->GetDescriptorEXT(s->hwctx->act_dev, desc_get_info, desc_size, desc); |
| 1936 | } | 1991 | } |
| 1937 | 1992 | ||
| 1938 | static inline void update_set_pool_write(FFVulkanContext *s, FFVulkanShader *shd, | 1993 | static inline void update_set_pool_write(FFVulkanContext *s, FFVkExecContext *e, |
| 1939 | FFVkExecContext *e, | 1994 | FFVulkanShader *shd, int set, |
| 1940 | FFVulkanDescriptorSet *desc_set, int set, | ||
| 1941 | VkWriteDescriptorSet *write_info) | 1995 | VkWriteDescriptorSet *write_info) |
| 1942 | { | 1996 | { |
| 1943 | FFVulkanFunctions *vk = &s->vkfn; | 1997 | FFVulkanFunctions *vk = &s->vkfn; |
| 1998 | FFVulkanDescriptorSet *desc_set = &shd->desc_set[set]; | ||
| 1999 | FFVulkanShaderData *sd = get_shd_data(e, shd); | ||
| 2000 | |||
| 1944 | if (desc_set->singular) { | 2001 | if (desc_set->singular) { |
| 1945 | for (int i = 0; i < shd->assoc_pool->pool_size; i++) { | 2002 | for (int i = 0; i < e->parent->pool_size; i++) { |
| 1946 | write_info->dstSet = shd->desc_sets[i*shd->nb_descriptor_sets + set]; | 2003 | write_info->dstSet = sd->desc_sets[i*sd->nb_descriptor_sets + set]; |
| 1947 | vk->UpdateDescriptorSets(s->hwctx->act_dev, 1, write_info, 0, NULL); | 2004 | vk->UpdateDescriptorSets(s->hwctx->act_dev, 1, write_info, 0, NULL); |
| 1948 | } | 2005 | } |
| 1949 | } else { | 2006 | } else { |
| @@ -1954,7 +2011,7 @@ static inline void update_set_pool_write(FFVulkanContext *s, FFVulkanShader *shd · 4 unmodified lines | |||
| 1954 | set, 1, | 2011 | set, 1, |
| 1955 | write_info); | 2012 | write_info); |
| 1956 | } else { | 2013 | } else { |
| 1957 | write_info->dstSet = shd->desc_sets[e->idx*shd->nb_descriptor_sets + set]; | 2014 | write_info->dstSet = sd->desc_sets[e->idx*sd->nb_descriptor_sets + set]; |
| 1958 | vk->UpdateDescriptorSets(s->hwctx->act_dev, 1, write_info, 0, NULL); | 2015 | vk->UpdateDescriptorSets(s->hwctx->act_dev, 1, write_info, 0, NULL); |
| 1959 | } | 2016 | } |
| 1960 | } | 2017 | } |
| @@ -2003,7 +2060,7 @@ static int vk_set_descriptor_image(FFVulkanContext *s, FFVulkanShader *shd, · 42 unmodified lines | |||
| 2003 | break; | 2060 | break; |
| 2004 | }; | 2061 | }; |
| 2005 | 2062 | ||
| 2006 | update_set_descriptor(s, e, desc_set, bind, offs, | 2063 | update_set_descriptor(s, e, shd, set, bind, offs, |
| 2007 | &desc_get_info, desc_size); | 2064 | &desc_get_info, desc_size); |
| 2008 | } else { | 2065 | } else { |
| 2009 | VkDescriptorImageInfo desc_pool_write_info_img = { | 2066 | VkDescriptorImageInfo desc_pool_write_info_img = { |
| @@ -2019,7 +2076,7 @@ static int vk_set_descriptor_image(FFVulkanContext *s, FFVulkanShader *shd, · 9 unmodified lines | |||
| 2019 | .descriptorType = desc_set->binding[bind].descriptorType, | 2076 | .descriptorType = desc_set->binding[bind].descriptorType, |
| 2020 | .pImageInfo = &desc_pool_write_info_img, | 2077 | .pImageInfo = &desc_pool_write_info_img, |
| 2021 | }; | 2078 | }; |
| 2022 | update_set_pool_write(s, shd, e, desc_set, set, &desc_pool_write_info); | 2079 | update_set_pool_write(s, e, shd, set, &desc_pool_write_info); |
| 2023 | } | 2080 | } |
| 2024 | 2081 | ||
| 2025 | return 0; | 2082 | return 0; |
| @@ -2070,7 +2127,7 @@ int ff_vk_shader_update_desc_buffer(FFVulkanContext *s, FFVkExecContext *e, · 44 unmodified lines | |||
| 2070 | break; | 2127 | break; |
| 2071 | }; | 2128 | }; |
| 2072 | 2129 | ||
| 2073 | update_set_descriptor(s, e, desc_set, bind, elem, &desc_get_info, desc_size); | 2130 | update_set_descriptor(s, e, shd, set, bind, elem, &desc_get_info, desc_size); |
| 2074 | } else { | 2131 | } else { |
| 2075 | VkDescriptorBufferInfo desc_pool_write_info_buf = { | 2132 | VkDescriptorBufferInfo desc_pool_write_info_buf = { |
| 2076 | .buffer = buf->buf, | 2133 | .buffer = buf->buf, |
| @@ -2085,7 +2142,7 @@ int ff_vk_shader_update_desc_buffer(FFVulkanContext *s, FFVkExecContext *e, · 8 unmodified lines | |||
| 2085 | .descriptorType = desc_set->binding[bind].descriptorType, | 2142 | .descriptorType = desc_set->binding[bind].descriptorType, |
| 2086 | .pBufferInfo = &desc_pool_write_info_buf, | 2143 | .pBufferInfo = &desc_pool_write_info_buf, |
| 2087 | }; | 2144 | }; |
| 2088 | update_set_pool_write(s, shd, e, desc_set, set, &desc_pool_write_info); | 2145 | update_set_pool_write(s, e, shd, set, &desc_pool_write_info); |
| 2089 | } | 2146 | } |
| 2090 | 2147 | ||
| 2091 | return 0; | 2148 | return 0; |
| @@ -2119,25 +2176,26 @@ void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, · 27 unmodified lines | |||
| 2119 | { | 2176 | { |
| 2120 | FFVulkanFunctions *vk = &s->vkfn; | 2177 | FFVulkanFunctions *vk = &s->vkfn; |
| 2121 | VkDeviceSize offsets[1024]; | 2178 | VkDeviceSize offsets[1024]; |
| 2179 | FFVulkanShaderData *sd = get_shd_data(e, shd); | ||
| 2122 | 2180 | ||
| 2123 | /* Bind pipeline */ | 2181 | /* Bind pipeline */ |
| 2124 | vk->CmdBindPipeline(e->buf, shd->bind_point, shd->pipeline); | 2182 | vk->CmdBindPipeline(e->buf, shd->bind_point, shd->pipeline); |
| 2125 | 2183 | ||
| 2126 | if (shd->nb_descriptor_sets) { | 2184 | if (sd->nb_descriptor_sets) { |
| 2127 | if (s->extensions & FF_VK_EXT_DESCRIPTOR_BUFFER) { | 2185 | if (s->extensions & FF_VK_EXT_DESCRIPTOR_BUFFER) { |
| 2128 | for (int i = 0; i < shd->nb_descriptor_sets; i++) | 2186 | for (int i = 0; i < sd->nb_descriptor_sets; i++) |
| 2129 | offsets[i] = shd->desc_set[i].singular ? 0 : shd->desc_set[i].aligned_size*e->idx; | 2187 | offsets[i] = shd->desc_set[i].singular ? 0 : shd->desc_set[i].aligned_size*e->idx; |
| 2130 | 2188 | ||
| 2131 | /* Bind descriptor buffers */ | 2189 | /* Bind descriptor buffers */ |
| 2132 | vk->CmdBindDescriptorBuffersEXT(e->buf, shd->nb_descriptor_sets, shd->desc_bind); | 2190 | vk->CmdBindDescriptorBuffersEXT(e->buf, sd->nb_descriptor_sets, sd->desc_bind); |
| 2133 | /* Binding offsets */ | 2191 | /* Binding offsets */ |
| 2134 | vk->CmdSetDescriptorBufferOffsetsEXT(e->buf, shd->bind_point, shd->pipeline_layout, | 2192 | vk->CmdSetDescriptorBufferOffsetsEXT(e->buf, shd->bind_point, shd->pipeline_layout, |
| 2135 | 0, shd->nb_descriptor_sets, | 2193 | 0, sd->nb_descriptor_sets, |
| 2136 | shd->bound_buffer_indices, offsets); | 2194 | shd->bound_buffer_indices, offsets); |
| 2137 | } else if (!shd->use_push) { | 2195 | } else if (!shd->use_push) { |
| 2138 | vk->CmdBindDescriptorSets(e->buf, shd->bind_point, shd->pipeline_layout, | 2196 | vk->CmdBindDescriptorSets(e->buf, shd->bind_point, shd->pipeline_layout, |
| 2139 | 0, shd->nb_descriptor_sets, | 2197 | 0, sd->nb_descriptor_sets, |
| 2140 | &shd->desc_sets[e->idx*shd->nb_descriptor_sets], | 2198 | &sd->desc_sets[e->idx*sd->nb_descriptor_sets], |
| 2141 | 0, NULL); | 2199 | 0, NULL); |
| 2142 | } | 2200 | } |
| 2143 | } | 2201 | } |
| @@ -2163,9 +2221,6 @@ void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd) · 19 unmodified lines | |||
| 2163 | 2221 | ||
| 2164 | for (int i = 0; i < shd->nb_descriptor_sets; i++) { | 2222 | for (int i = 0; i < shd->nb_descriptor_sets; i++) { |
| 2165 | FFVulkanDescriptorSet *set = &shd->desc_set[i]; | 2223 | FFVulkanDescriptorSet *set = &shd->desc_set[i]; |
| 2166 | if (set->buf.mem) | ||
| 2167 | ff_vk_unmap_buffer(s, &set->buf, 0); | ||
| 2168 | ff_vk_free_buf(s, &set->buf); | ||
| 2169 | av_free(set->binding); | 2224 | av_free(set->binding); |
| 2170 | av_free(set->binding_offset); | 2225 | av_free(set->binding_offset); |
| 2171 | } | 2226 | } |
| @@ -2175,15 +2230,9 @@ void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd) · 3 unmodified lines | |||
| 2175 | vk->DestroyDescriptorSetLayout(s->hwctx->act_dev, shd->desc_layout[i], | 2230 | vk->DestroyDescriptorSetLayout(s->hwctx->act_dev, shd->desc_layout[i], |
| 2176 | s->hwctx->alloc); | 2231 | s->hwctx->alloc); |
| 2177 | 2232 | ||
| 2178 | if (shd->desc_pool) | ||
| 2179 | vk->DestroyDescriptorPool(s->hwctx->act_dev, shd->desc_pool, | ||
| 2180 | s->hwctx->alloc); | ||
| 2181 | |||
| 2182 | av_freep(&shd->desc_pool_size); | 2233 | av_freep(&shd->desc_pool_size); |
| 2183 | av_freep(&shd->desc_layout); | 2234 | av_freep(&shd->desc_layout); |
| 2184 | av_freep(&shd->desc_sets); | ||
| 2185 | av_freep(&shd->desc_set); | 2235 | av_freep(&shd->desc_set); |
| 2186 | av_freep(&shd->desc_bind); | ||
| 2187 | av_freep(&shd->bound_buffer_indices); | 2236 | av_freep(&shd->bound_buffer_indices); |
| 2188 | av_freep(&shd->push_consts); | 2237 | av_freep(&shd->push_consts); |
| 2189 | shd->push_consts_num = 0; | 2238 | shd->push_consts_num = 0; |
| @@ -162,31 +162,11 @@ typedef struct FFVkExecContext { · 161 unmodified lines | |||
| 162 | unsigned int frame_update_alloc_size; | 162 | unsigned int frame_update_alloc_size; |
| 163 | } FFVkExecContext; | 163 | } FFVkExecContext; |
| 164 | 164 | ||
| 165 | typedef struct FFVkExecPool { | ||
| 166 | FFVkExecContext *contexts; | ||
| 167 | atomic_int_least64_t idx; | ||
| 168 | |||
| 169 | VkCommandPool cmd_buf_pool; | ||
| 170 | VkCommandBuffer *cmd_bufs; | ||
| 171 | int pool_size; | ||
| 172 | |||
| 173 | VkQueryPool query_pool; | ||
| 174 | void *query_data; | ||
| 175 | int query_results; | ||
| 176 | int query_statuses; | ||
| 177 | int query_64bit; | ||
| 178 | int query_status_stride; | ||
| 179 | int nb_queries; | ||
| 180 | size_t qd_size; | ||
| 181 | } FFVkExecPool; | ||
| 182 | |||
| 183 | typedef struct FFVulkanDescriptorSet { | 165 | typedef struct FFVulkanDescriptorSet { |
| 184 | FFVkBuffer buf; | 166 | /* Descriptor buffer */ |
| 185 | uint8_t *desc_mem; | 167 | VkDeviceSize layout_size; |
| 186 | VkDeviceSize layout_size; | 168 | VkDeviceSize aligned_size; /* descriptorBufferOffsetAlignment */ |
| 187 | VkDeviceSize aligned_size; /* descriptorBufferOffsetAlignment */ | 169 | VkBufferUsageFlags usage; |
| 188 | VkDeviceSize total_size; /* Once registered to an exec context */ | ||
| 189 | VkBufferUsageFlags usage; | ||
| 190 | 170 | ||
| 191 | VkDescriptorSetLayoutBinding *binding; | 171 | VkDescriptorSetLayoutBinding *binding; |
| 192 | VkDeviceSize *binding_offset; | 172 | VkDeviceSize *binding_offset; |
| @@ -225,23 +205,62 @@ typedef struct FFVulkanShader { · 32 unmodified lines | |||
| 225 | VkPushConstantRange *push_consts; | 205 | VkPushConstantRange *push_consts; |
| 226 | int push_consts_num; | 206 | int push_consts_num; |
| 227 | 207 | ||
| 208 | /* Descriptor sets */ | ||
| 209 | FFVulkanDescriptorSet *desc_set; | ||
| 210 | int nb_descriptor_sets; | ||
| 211 | |||
| 228 | /* Descriptor buffer */ | 212 | /* Descriptor buffer */ |
| 229 | VkDescriptorSetLayout *desc_layout; | 213 | VkDescriptorSetLayout *desc_layout; |
| 230 | FFVulkanDescriptorSet *desc_set; | ||
| 231 | VkDescriptorBufferBindingInfoEXT *desc_bind; | ||
| 232 | uint32_t *bound_buffer_indices; | 214 | uint32_t *bound_buffer_indices; |
| 233 | int nb_descriptor_sets; | ||
| 234 | 215 | ||
| 235 | /* Descriptor pool */ | 216 | /* Descriptor pool */ |
| 236 | int use_push; | 217 | int use_push; |
| 237 | VkDescriptorSet *desc_sets; | ||
| 238 | VkDescriptorPool desc_pool; | ||
| 239 | VkDescriptorPoolSize *desc_pool_size; | 218 | VkDescriptorPoolSize *desc_pool_size; |
| 240 | int nb_desc_pool_size; | 219 | int nb_desc_pool_size; |
| 241 | int total_desc_sets; | ||
| 242 | FFVkExecPool *assoc_pool; | ||
| 243 | } FFVulkanShader; | 220 | } FFVulkanShader; |
| 244 | 221 | ||
| 222 | typedef struct FFVulkanDescriptorSetData { | ||
| 223 | /* Descriptor buffer */ | ||
| 224 | FFVkBuffer buf; | ||
| 225 | uint8_t *desc_mem; | ||
| 226 | } FFVulkanDescriptorSetData; | ||
| 227 | |||
| 228 | typedef struct FFVulkanShaderData { | ||
| 229 | /* Shader to which this data belongs to */ | ||
| 230 | FFVulkanShader *shd; | ||
| 231 | int nb_descriptor_sets; | ||
| 232 | |||
| 233 | /* Descriptor buffer */ | ||
| 234 | FFVulkanDescriptorSetData *desc_set_buf; | ||
| 235 | VkDescriptorBufferBindingInfoEXT *desc_bind; | ||
| 236 | |||
| 237 | /* Descriptor pools */ | ||
| 238 | VkDescriptorSet *desc_sets; | ||
| 239 | VkDescriptorPool desc_pool; | ||
| 240 | } FFVulkanShaderData; | ||
| 241 | |||
| 242 | typedef struct FFVkExecPool { | ||
| 243 | FFVkExecContext *contexts; | ||
| 244 | atomic_int_least64_t idx; | ||
| 245 | |||
| 246 | VkCommandPool cmd_buf_pool; | ||
| 247 | VkCommandBuffer *cmd_bufs; | ||
| 248 | int pool_size; | ||
| 249 | |||
| 250 | VkQueryPool query_pool; | ||
| 251 | void *query_data; | ||
| 252 | int query_results; | ||
| 253 | int query_statuses; | ||
| 254 | int query_64bit; | ||
| 255 | int query_status_stride; | ||
| 256 | int nb_queries; | ||
| 257 | size_t qd_size; | ||
| 258 | |||
| 259 | /* Registered shaders' data */ | ||
| 260 | FFVulkanShaderData *reg_shd; | ||
| 261 | int nb_reg_shd; | ||
| 262 | } FFVkExecPool; | ||
| 263 | |||
| 245 | typedef struct FFVulkanContext { | 264 | typedef struct FFVulkanContext { |
| 246 | const AVClass *class; | 265 | const AVClass *class; |
| 247 | void *log_parent; | 266 | void *log_parent; |