vkd3d: Rewrite binary occlusion query resolve shader.

Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
This commit is contained in:
Philip Rebohle 2021-01-15 15:00:19 +01:00 committed by Philip Rebohle
parent 32f7ba6630
commit 5c550b5cda
3 changed files with 38 additions and 24 deletions

View File

@ -1078,17 +1078,24 @@ HRESULT vkd3d_query_ops_init(struct vkd3d_query_ops *meta_query_ops,
uint32_t field_count;
VkResult vr;
static const VkDescriptorSetLayoutBinding bindings[] =
static const VkDescriptorSetLayoutBinding gather_bindings[] =
{
{ 0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT },
{ 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT },
{ 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT },
};
static const VkDescriptorSetLayoutBinding resolve_bindings[] =
{
{ 0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT },
{ 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT },
};
static const VkSpecializationMapEntry spec_map = { 0, 0, sizeof(uint32_t) };
if ((vr = vkd3d_meta_create_descriptor_set_layout(device,
ARRAY_SIZE(bindings), bindings, &meta_query_ops->vk_gather_set_layout)) < 0)
ARRAY_SIZE(gather_bindings), gather_bindings,
&meta_query_ops->vk_gather_set_layout)) < 0)
goto fail;
push_constant_range.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT;
@ -1114,13 +1121,19 @@ HRESULT vkd3d_query_ops_init(struct vkd3d_query_ops *meta_query_ops,
meta_query_ops->vk_gather_pipeline_layout, &spec_info, &meta_query_ops->vk_gather_so_statistics_pipeline)) < 0)
goto fail;
push_constant_range.size = sizeof(struct vkd3d_query_op_args);
push_constant_range.size = sizeof(struct vkd3d_query_resolve_args);
if ((vr = vkd3d_meta_create_pipeline_layout(device, 0, NULL, 1, &push_constant_range, &meta_query_ops->vk_pipeline_layout)) < 0)
if ((vr = vkd3d_meta_create_descriptor_set_layout(device,
ARRAY_SIZE(resolve_bindings), resolve_bindings,
&meta_query_ops->vk_resolve_set_layout)) < 0)
goto fail;
if ((vr = vkd3d_meta_create_pipeline_layout(device, 1, &meta_query_ops->vk_resolve_set_layout,
1, &push_constant_range, &meta_query_ops->vk_resolve_pipeline_layout)) < 0)
goto fail;
if ((vr = vkd3d_meta_create_compute_pipeline(device, sizeof(cs_resolve_binary_queries), cs_resolve_binary_queries,
meta_query_ops->vk_pipeline_layout, NULL, &meta_query_ops->vk_resolve_binary_pipeline)) < 0)
meta_query_ops->vk_resolve_pipeline_layout, NULL, &meta_query_ops->vk_resolve_binary_pipeline)) < 0)
goto fail;
return S_OK;
@ -1141,7 +1154,8 @@ void vkd3d_query_ops_cleanup(struct vkd3d_query_ops *meta_query_ops,
VK_CALL(vkDestroyPipelineLayout(device->vk_device, meta_query_ops->vk_gather_pipeline_layout, NULL));
VK_CALL(vkDestroyDescriptorSetLayout(device->vk_device, meta_query_ops->vk_gather_set_layout, NULL));
VK_CALL(vkDestroyPipelineLayout(device->vk_device, meta_query_ops->vk_pipeline_layout, NULL));
VK_CALL(vkDestroyDescriptorSetLayout(device->vk_device, meta_query_ops->vk_resolve_set_layout, NULL));
VK_CALL(vkDestroyPipelineLayout(device->vk_device, meta_query_ops->vk_resolve_pipeline_layout, NULL));
VK_CALL(vkDestroyPipeline(device->vk_device, meta_query_ops->vk_resolve_binary_pipeline, NULL));
}

View File

@ -1,30 +1,29 @@
#version 450
#extension GL_EXT_buffer_reference : require
#extension GL_ARB_gpu_shader_int64 : require
layout(local_size_x = 64) in;
layout(buffer_reference, std430, buffer_reference_align = 8)
buffer query_buffer_t {
uvec2 data[];
layout(std430, binding = 0)
writeonly buffer dst_buffer_t {
uint64_t dst_queries[];
};
layout(std430, binding = 1)
readonly buffer src_buffer_t {
uint64_t src_queries[];
};
layout(push_constant)
uniform u_info_t {
query_buffer_t src_queries;
query_buffer_t dst_queries;
uint dst_index;
uint src_index;
uint query_count;
};
void main() {
uint thread_id = gl_GlobalInvocationID.x;
if (thread_id < query_count) {
uvec2 query_data = src_queries.data[thread_id];
if (any(greaterThan(query_data, uvec2(1, 0))))
query_data = uvec2(1, 0);
dst_queries.data[thread_id] = query_data;
}
if (thread_id < query_count)
dst_queries[dst_index + thread_id] = min(src_queries[src_index + thread_id], uint64_t(1u));
}

View File

@ -1883,10 +1883,10 @@ void vkd3d_swapchain_ops_cleanup(struct vkd3d_swapchain_ops *meta_swapchain_ops,
#define VKD3D_QUERY_OP_WORKGROUP_SIZE (64)
struct vkd3d_query_op_args
struct vkd3d_query_resolve_args
{
VkDeviceAddress src_queries;
VkDeviceAddress dst_queries;
uint32_t dst_index;
uint32_t src_index;
uint32_t query_count;
};
@ -1909,7 +1909,8 @@ struct vkd3d_query_ops
VkPipelineLayout vk_gather_pipeline_layout;
VkPipeline vk_gather_occlusion_pipeline;
VkPipeline vk_gather_so_statistics_pipeline;
VkPipelineLayout vk_pipeline_layout;
VkDescriptorSetLayout vk_resolve_set_layout;
VkPipelineLayout vk_resolve_pipeline_layout;
VkPipeline vk_resolve_binary_pipeline;
};