mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 06:15:58 +00:00
fix(vkbridge): BC emulation without VK_KHR_push_descriptor
Mali-G720 on driver 44.1 has no push descriptors, so the first device run had BC emulation switched off. The decoder now binds ordinary descriptor sets from per-command-buffer scratch pools (reset when the command buffer is begun again) when push descriptors are missing. The host Mali imitation now hides them too (VKBRIDGE_FAKE_MISSING=push, VKBRIDGE_HIDE_EXTS); bcn_check bit-exact and host suite 14/14. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S1U9H1evGNjHRQ3wRUdv5V
This commit is contained in:
1 parent
05c62481f8
commit
af5098e699
4 files changed
+83
-10
No files matched your search
@@ -44,6 +44,7 @@ void vkb_emu_cmdstate_install(vkb_srv_table *dev);
|
||||
void vkb_emu_cmdstate_uninstall(vkb_srv_table *dev);
|
||||
void vkb_emu_restore_compute(vkb_emu_device *e, VkCommandBuffer cb);
|
||||
void *vkb_emu_cb_gfx(vkb_emu_device *e, VkCommandBuffer cb, size_t size);
|
||||
VkDescriptorSet vkb_emu_cb_scratch_set(vkb_emu_device *e, VkCommandBuffer cb, VkDescriptorSetLayout dsl);
|
||||
/* vertex attribute divisor (server_emu_divisor.c) */
|
||||
typedef struct div_info div_info;
|
||||
size_t vkb_emu_divisor_info_size(void);
|
||||
|
||||
@@ -25,6 +25,7 @@ typedef struct bcn_state {
|
||||
VkPipelineLayout layout;
|
||||
VkPipeline pipes[FAM_COUNT];
|
||||
VkDeviceSize ssbo_align;
|
||||
int push; /* VK_KHR_push_descriptor; else per-command-buffer sets */
|
||||
pthread_mutex_t lock;
|
||||
} bcn_state;
|
||||
|
||||
@@ -84,11 +85,28 @@ int vkb_emu_bcn_supported(const vkb_dispatch *idt, VkPhysicalDevice pd)
|
||||
idt->vkEnumerateDeviceExtensionProperties(pd, NULL, &n, NULL);
|
||||
VkExtensionProperties *e = calloc(n ? n : 1, sizeof(*e));
|
||||
idt->vkEnumerateDeviceExtensionProperties(pd, NULL, &n, e);
|
||||
free(e);
|
||||
/* Without VK_KHR_push_descriptor (Mali-G720 on driver 44.1) the decoder binds ordinary sets. */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Push descriptors for the decoder; without them, sets from the command buffer's scratch pools.
|
||||
* VKBRIDGE_FAKE_MISSING=...,push takes the second way on a GPU that has them (host tests). */
|
||||
static int has_push(vkb_srv_table *dev)
|
||||
{
|
||||
const char *fake = getenv("VKBRIDGE_FAKE_MISSING");
|
||||
if (fake && strstr(fake, "push")) return 0;
|
||||
VkPhysicalDeviceProperties p;
|
||||
dev->real.vkGetPhysicalDeviceProperties(dev->physical, &p);
|
||||
if (p.apiVersion >= VK_API_VERSION_1_4 && dev->api_version >= VK_API_VERSION_1_4) return dev->real.vkCmdPushDescriptorSet != NULL;
|
||||
uint32_t n = 0;
|
||||
dev->real.vkEnumerateDeviceExtensionProperties(dev->physical, NULL, &n, NULL);
|
||||
VkExtensionProperties *e = calloc(n ? n : 1, sizeof(*e));
|
||||
dev->real.vkEnumerateDeviceExtensionProperties(dev->physical, NULL, &n, e);
|
||||
int ok = 0;
|
||||
for (uint32_t i = 0; i < n; i++) ok |= !strcmp(e[i].extensionName, "VK_KHR_push_descriptor");
|
||||
free(e);
|
||||
if (!ok) VKB_WARN("BC emulation: the GPU lacks VK_KHR_push_descriptor");
|
||||
return ok;
|
||||
return ok && dev->real.vkCmdPushDescriptorSet != NULL;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ images */
|
||||
@@ -245,7 +263,18 @@ static void decode(vkb_emu_device *e, VkCommandBuffer cb, VkBuffer src, vkb_emu_
|
||||
{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, NULL, VK_NULL_HANDLE, 0, 0, 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, NULL, &bi, NULL},
|
||||
{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, NULL, VK_NULL_HANDLE, 1, 0, 1, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &ii, NULL, NULL}};
|
||||
r->vkCmdBindPipeline(cb, VK_PIPELINE_BIND_POINT_COMPUTE, pipe);
|
||||
r->vkCmdPushDescriptorSet(cb, VK_PIPELINE_BIND_POINT_COMPUTE, s->layout, 0, 2, w);
|
||||
if (s->push) {
|
||||
r->vkCmdPushDescriptorSet(cb, VK_PIPELINE_BIND_POINT_COMPUTE, s->layout, 0, 2, w);
|
||||
} else {
|
||||
VkDescriptorSet set = vkb_emu_cb_scratch_set(e, cb, s->dsl);
|
||||
if (!set) {
|
||||
VKB_ONCE(VKB_LOG_ERROR, "BC emulation: no descriptor set for the decoder (logged once)");
|
||||
continue;
|
||||
}
|
||||
w[0].dstSet = w[1].dstSet = set;
|
||||
r->vkUpdateDescriptorSets(e->dev->device, 2, w, 0, NULL);
|
||||
r->vkCmdBindDescriptorSets(cb, VK_PIPELINE_BIND_POINT_COMPUTE, s->layout, 0, 1, &set, 0, NULL);
|
||||
}
|
||||
uint32_t w_tex = g->row_length ? g->row_length : g->iext.width;
|
||||
uint32_t h_tex = g->image_height ? g->image_height : g->iext.height;
|
||||
pc_t pc;
|
||||
@@ -372,8 +401,10 @@ void vkb_emu_bcn_install(vkb_srv_table *dev)
|
||||
s->ssbo_align = p.limits.minStorageBufferOffsetAlignment ? p.limits.minStorageBufferOffsetAlignment : 4;
|
||||
VkDescriptorSetLayoutBinding b[2] = {{0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, NULL},
|
||||
{1, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, NULL}};
|
||||
s->push = has_push(dev);
|
||||
VKB_INFO("BC emulation: decoder binds with %s", s->push ? "push descriptors" : "descriptor sets (no VK_KHR_push_descriptor)");
|
||||
VkDescriptorSetLayoutCreateInfo dci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, NULL,
|
||||
VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT, 2, b};
|
||||
s->push ? VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT : 0, 2, b};
|
||||
VkPushConstantRange pr = {VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(pc_t)};
|
||||
if (dev->real.vkCreateDescriptorSetLayout(dev->device, &dci, NULL, &s->dsl) != VK_SUCCESS) {
|
||||
VKB_ERR("BC emulation: cannot create the decoder's descriptor layout");
|
||||
|
||||
@@ -43,10 +43,14 @@ typedef struct cb_state {
|
||||
push_tmpl *pts;
|
||||
uint32_t npts, cappts;
|
||||
void *gfx; /* graphics-side state (divisor emulation) */
|
||||
/* Descriptor sets emulations record with (no push descriptors), alive until the next begin. */
|
||||
VkDescriptorPool *scratch;
|
||||
uint32_t nscratch, cur_scratch, used_scratch;
|
||||
struct cb_state *next;
|
||||
} cb_state;
|
||||
|
||||
#define CB_BUCKETS 512
|
||||
#define SCRATCH_SETS 64
|
||||
typedef struct cmdstate {
|
||||
pthread_mutex_t lock;
|
||||
cb_state *b[CB_BUCKETS];
|
||||
@@ -81,6 +85,37 @@ static cb_state *get(vkb_emu_device *e, VkCommandBuffer cb)
|
||||
return c;
|
||||
}
|
||||
|
||||
/* A descriptor set of layout `dsl` (storage buffers and images only) for a command the emulation
|
||||
* records into cb; it lives until cb is begun again, when the app has seen the work finish. */
|
||||
VkDescriptorSet vkb_emu_cb_scratch_set(vkb_emu_device *e, VkCommandBuffer cb, VkDescriptorSetLayout dsl)
|
||||
{
|
||||
cb_state *c = get(e, cb);
|
||||
const vkb_dispatch *r = &e->dev->real;
|
||||
for (;;) {
|
||||
if (c->cur_scratch >= c->nscratch) {
|
||||
VkDescriptorPoolSize sizes[2] = {{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, SCRATCH_SETS * 2},
|
||||
{VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, SCRATCH_SETS * 2}};
|
||||
VkDescriptorPoolCreateInfo pci = {VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, NULL, 0, SCRATCH_SETS, 2, sizes};
|
||||
VkDescriptorPool pool;
|
||||
VkDescriptorPool *np = realloc(c->scratch, (c->nscratch + 1) * sizeof(*np));
|
||||
if (!np) return VK_NULL_HANDLE;
|
||||
c->scratch = np;
|
||||
if (r->vkCreateDescriptorPool(e->dev->device, &pci, NULL, &pool) != VK_SUCCESS) return VK_NULL_HANDLE;
|
||||
c->scratch[c->nscratch++] = pool;
|
||||
}
|
||||
if (c->used_scratch < SCRATCH_SETS) {
|
||||
VkDescriptorSetAllocateInfo ai = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, NULL, c->scratch[c->cur_scratch], 1, &dsl};
|
||||
VkDescriptorSet set;
|
||||
if (r->vkAllocateDescriptorSets(e->dev->device, &ai, &set) == VK_SUCCESS) {
|
||||
c->used_scratch++;
|
||||
return set;
|
||||
}
|
||||
}
|
||||
c->cur_scratch++;
|
||||
c->used_scratch = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void *vkb_emu_cb_gfx(vkb_emu_device *e, VkCommandBuffer cb, size_t size)
|
||||
{
|
||||
cb_state *c = get(e, cb);
|
||||
@@ -88,8 +123,12 @@ void *vkb_emu_cb_gfx(vkb_emu_device *e, VkCommandBuffer cb, size_t size)
|
||||
return c->gfx;
|
||||
}
|
||||
|
||||
static void reset(cb_state *c)
|
||||
static void reset(vkb_emu_device *e, cb_state *c)
|
||||
{
|
||||
for (uint32_t i = 0; i < c->nscratch && i <= c->cur_scratch; i++)
|
||||
e->dev->real.vkResetDescriptorPool(e->dev->device, c->scratch[i], 0);
|
||||
c->cur_scratch = 0;
|
||||
c->used_scratch = 0;
|
||||
c->compute_pipeline = VK_NULL_HANDLE;
|
||||
c->nsets = 0;
|
||||
c->npcs = 0;
|
||||
@@ -102,7 +141,7 @@ static void reset(cb_state *c)
|
||||
|
||||
static VKAPI_ATTR VkResult VKAPI_CALL emu_BeginCommandBuffer(VkCommandBuffer cb, const VkCommandBufferBeginInfo *info)
|
||||
{
|
||||
reset(get(vkb_emu_cur(), cb));
|
||||
reset(vkb_emu_cur(), get(vkb_emu_cur(), cb));
|
||||
return vkb_emu_real()->vkBeginCommandBuffer(cb, info);
|
||||
}
|
||||
|
||||
@@ -235,7 +274,9 @@ void vkb_emu_cmdstate_uninstall(vkb_srv_table *dev)
|
||||
while (s->b[i]) {
|
||||
cb_state *c = s->b[i];
|
||||
s->b[i] = c->next;
|
||||
reset(c);
|
||||
reset(dev->emu, c);
|
||||
for (uint32_t j = 0; j < c->nscratch; j++) dev->real.vkDestroyDescriptorPool(dev->device, c->scratch[j], NULL);
|
||||
free(c->scratch);
|
||||
free(c->sets);
|
||||
free(c->pcs);
|
||||
free(c->pts);
|
||||
|
||||
Reference in new issue
Block a user