Compare commits

...
4 changed files with 91 additions and 7 deletions

No files matched your search

+77 -5
View File
@@ -456,8 +456,22 @@ VKAPI_ATTR void VKAPI_CALL CmdBindVertexBuffers2(VkCommandBuffer cmd, uint32_t f
/* --- depthCompareOp while the depth test is off --- */
/* Per command buffer, packed into the map's value pointer so it is never NULL: bit 0 always set,
* bit 1 the test enable is known, bit 2 the test is on, bit 3 an op was set, bits 4 and up that op. */
enum { DEPTH_VALID = 1, DEPTH_KNOWN = 2, DEPTH_ON = 4, DEPTH_OP = 8 };
* bit 1 the test enable is known, bit 2 the test is on, bit 3 an op was set, bit 4 the bound
* pipeline has the compare op dynamic, bit 5 the known enable came from a pipeline's static state,
* bits 8 and up the op. The layer only issues compare-op commands while the bound pipeline has it
* dynamic: on a static one they would be invalid. */
enum {
DEPTH_VALID = 1,
DEPTH_KNOWN = 2,
DEPTH_ON = 4,
DEPTH_OP = 8,
DEPTH_OP_DYNAMIC = 16,
DEPTH_FROM_PIPELINE = 32,
DEPTH_OP_SHIFT = 8,
};
/* Per pipeline, same packing: bit 0 always set. */
enum { PIPE_VALID = 1, PIPE_TEST_DYNAMIC = 2, PIPE_OP_DYNAMIC = 4, PIPE_TEST_ON = 8 };
static uintptr_t depth_state(struct device *dev, VkCommandBuffer cmd)
{
@@ -472,19 +486,77 @@ void depth_state_forget(struct device *dev, VkCommandBuffer cmd)
pthread_mutex_unlock(&dev->lock);
}
void depth_pipeline_record(struct device *dev, VkPipeline pipeline, const VkGraphicsPipelineCreateInfo *info)
{
uintptr_t flags = PIPE_VALID;
for (uint32_t i = 0; info->pDynamicState && i < info->pDynamicState->dynamicStateCount; i++) {
VkDynamicState state = info->pDynamicState->pDynamicStates[i];
if (state == VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE)
flags |= PIPE_TEST_DYNAMIC;
else if (state == VK_DYNAMIC_STATE_DEPTH_COMPARE_OP)
flags |= PIPE_OP_DYNAMIC;
}
if (info->pDepthStencilState && info->pDepthStencilState->depthTestEnable)
flags |= PIPE_TEST_ON;
pthread_mutex_lock(&dev->lock);
map_put(&dev->depth_pipelines, (uint64_t)(uintptr_t)pipeline, (void *)flags);
pthread_mutex_unlock(&dev->lock);
}
VKAPI_ATTR void VKAPI_CALL DestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks *allocator)
{
struct device *dev = device_from_handle(device);
pthread_mutex_lock(&dev->lock);
map_remove(&dev->depth_pipelines, (uint64_t)(uintptr_t)pipeline);
pthread_mutex_unlock(&dev->lock);
dev->DestroyPipeline(device, pipeline, allocator);
}
VKAPI_ATTR void VKAPI_CALL CmdBindPipeline(VkCommandBuffer cmd, VkPipelineBindPoint point, VkPipeline pipeline)
{
struct device *dev = device_from_handle(cmd);
dev->CmdBindPipeline(cmd, point, pipeline);
if (point != VK_PIPELINE_BIND_POINT_GRAPHICS)
return;
pthread_mutex_lock(&dev->lock);
uintptr_t flags = (uintptr_t)map_get(&dev->depth_pipelines, (uint64_t)(uintptr_t)pipeline);
uintptr_t state = depth_state(dev, cmd);
uintptr_t next = state & ~(uintptr_t)DEPTH_OP_DYNAMIC;
if (flags & PIPE_OP_DYNAMIC)
next |= DEPTH_OP_DYNAMIC;
if (flags && !(flags & PIPE_TEST_DYNAMIC)) {
next = (next & ~(uintptr_t)DEPTH_ON) | DEPTH_KNOWN | DEPTH_FROM_PIPELINE | ((flags & PIPE_TEST_ON) ? DEPTH_ON : 0);
} else if (flags && (next & DEPTH_FROM_PIPELINE)) {
/* A static enable made the dynamic value undefined until the application sets it again. */
next &= ~(uintptr_t)(DEPTH_KNOWN | DEPTH_ON | DEPTH_FROM_PIPELINE);
}
map_put(&dev->depth_states, (uint64_t)(uintptr_t)cmd, (void *)next);
pthread_mutex_unlock(&dev->lock);
if (!(flags & PIPE_OP_DYNAMIC) || !(next & DEPTH_KNOWN))
return;
if (!(next & DEPTH_ON))
dev->CmdSetDepthCompareOp(cmd, VK_COMPARE_OP_ALWAYS);
else if (next & DEPTH_OP)
dev->CmdSetDepthCompareOp(cmd, (VkCompareOp)(next >> DEPTH_OP_SHIFT));
}
VKAPI_ATTR void VKAPI_CALL CmdSetDepthTestEnable(VkCommandBuffer cmd, VkBool32 enable)
{
struct device *dev = device_from_handle(cmd);
dev->CmdSetDepthTestEnable(cmd, enable);
pthread_mutex_lock(&dev->lock);
uintptr_t state = depth_state(dev, cmd);
uintptr_t next = (state & ~(uintptr_t)DEPTH_ON) | DEPTH_KNOWN | (enable ? DEPTH_ON : 0);
uintptr_t next = (state & ~(uintptr_t)(DEPTH_ON | DEPTH_FROM_PIPELINE)) | DEPTH_KNOWN | (enable ? DEPTH_ON : 0);
map_put(&dev->depth_states, (uint64_t)(uintptr_t)cmd, (void *)next);
pthread_mutex_unlock(&dev->lock);
if (!(state & DEPTH_OP_DYNAMIC))
return;
if (!enable)
dev->CmdSetDepthCompareOp(cmd, VK_COMPARE_OP_ALWAYS);
else if (state & DEPTH_OP)
dev->CmdSetDepthCompareOp(cmd, (VkCompareOp)(state >> 4));
dev->CmdSetDepthCompareOp(cmd, (VkCompareOp)(state >> DEPTH_OP_SHIFT));
}
VKAPI_ATTR void VKAPI_CALL CmdSetDepthCompareOp(VkCommandBuffer cmd, VkCompareOp op)
@@ -492,7 +564,7 @@ VKAPI_ATTR void VKAPI_CALL CmdSetDepthCompareOp(VkCommandBuffer cmd, VkCompareOp
struct device *dev = device_from_handle(cmd);
pthread_mutex_lock(&dev->lock);
uintptr_t state = depth_state(dev, cmd);
uintptr_t next = (state & (uintptr_t)(DEPTH_VALID | DEPTH_KNOWN | DEPTH_ON)) | DEPTH_OP | ((uintptr_t)op << 4);
uintptr_t next = (state & ~((uintptr_t)-1 << DEPTH_OP_SHIFT)) | DEPTH_OP | ((uintptr_t)op << DEPTH_OP_SHIFT);
map_put(&dev->depth_states, (uint64_t)(uintptr_t)cmd, (void *)next);
pthread_mutex_unlock(&dev->lock);
bool off = (state & DEPTH_KNOWN) && !(state & DEPTH_ON);
+3
View File
@@ -672,6 +672,7 @@ static VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocat
}
map_free(&dev->shader_modules);
map_free(&dev->depth_states);
map_free(&dev->depth_pipelines);
pthread_mutex_destroy(&dev->lock);
free(dev);
}
@@ -703,6 +704,8 @@ static const struct hook device_hooks[] = {
HOOK_ALIAS(CmdSetDepthTestEnable, CmdSetDepthTestEnableEXT, GAP_DEPTH_OP),
HOOK(CmdSetDepthCompareOp, GAP_DEPTH_OP),
HOOK_ALIAS(CmdSetDepthCompareOp, CmdSetDepthCompareOpEXT, GAP_DEPTH_OP),
HOOK(CmdBindPipeline, GAP_DEPTH_OP),
HOOK(DestroyPipeline, GAP_DEPTH_OP),
HOOK(CreateImage, GAP_BC),
HOOK(DestroyImage, GAP_BC),
HOOK(CreateImageView, GAP_BC),
+7 -1
View File
@@ -144,7 +144,9 @@ struct instance {
X(CmdBindVertexBuffers2) \
X(CmdSetColorBlendEquationEXT) \
X(CmdSetDepthTestEnable) \
X(CmdSetDepthCompareOp)
X(CmdSetDepthCompareOp) \
X(CmdBindPipeline) \
X(DestroyPipeline)
struct staging_block;
@@ -170,6 +172,7 @@ struct device {
struct staging_block *free_staging;
struct handle_map templates; /* VkDescriptorUpdateTemplate -> struct template_info (draw.c) */
struct handle_map depth_states; /* VkCommandBuffer -> packed depth test state (draw.c) */
struct handle_map depth_pipelines; /* VkPipeline -> packed depth dynamic-state flags (draw.c) */
/* nullDescriptor stand-ins (draw.c): 0 not made yet, 1 ready, -1 failed. */
int null_ready;
VkBuffer null_buffer;
@@ -320,5 +323,8 @@ VKAPI_ATTR void VKAPI_CALL CmdBindVertexBuffers2(VkCommandBuffer cmd, uint32_t f
void null_resources_destroy(struct device *dev);
VKAPI_ATTR void VKAPI_CALL CmdSetDepthTestEnable(VkCommandBuffer cmd, VkBool32 enable);
VKAPI_ATTR void VKAPI_CALL CmdSetDepthCompareOp(VkCommandBuffer cmd, VkCompareOp op);
VKAPI_ATTR void VKAPI_CALL CmdBindPipeline(VkCommandBuffer cmd, VkPipelineBindPoint point, VkPipeline pipeline);
VKAPI_ATTR void VKAPI_CALL DestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks *allocator);
void depth_state_forget(struct device *dev, VkCommandBuffer cmd);
void depth_pipeline_record(struct device *dev, VkPipeline pipeline, const VkGraphicsPipelineCreateInfo *info);
#endif
+4 -1
View File
@@ -455,8 +455,11 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateGraphicsPipelines(VkDevice device, VkPipeli
rewrite_pipeline(dev, &copies[i], &rewrites[i]);
}
VkResult result = dev->CreateGraphicsPipelines(device, cache, count, copies, allocator, pipelines);
for (uint32_t i = 0; i < count; i++)
for (uint32_t i = 0; i < count; i++) {
undo_rewrite(dev, &rewrites[i]);
if ((dev->emulated & GAP_DEPTH_OP) && pipelines[i] != VK_NULL_HANDLE)
depth_pipeline_record(dev, pipelines[i], &infos[i]);
}
free(rewrites);
free(copies);
return result;