meta: Add fs_copy_uint path.

For stencil -> color copies.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
This commit is contained in:
Hans-Kristian Arntzen 2021-05-04 14:40:14 +02:00
parent ef5ad082a0
commit 4f0872152a
5 changed files with 52 additions and 4 deletions

View File

@ -18,6 +18,7 @@ vkd3d_shaders =[
'shaders/cs_resolve_query.comp',
'shaders/fs_copy_image_float.frag',
'shaders/fs_copy_image_uint.frag',
'shaders/gs_fullscreen.geom',
'shaders/vs_fullscreen.vert',

View File

@ -597,7 +597,15 @@ HRESULT vkd3d_copy_image_ops_init(struct vkd3d_copy_image_ops *meta_copy_image_o
goto fail;
}
if ((vr = vkd3d_meta_create_shader_module(device, SPIRV_CODE(fs_copy_image_float), &meta_copy_image_ops->vk_fs_module)) < 0)
if ((vr = vkd3d_meta_create_shader_module(device, SPIRV_CODE(fs_copy_image_float),
&meta_copy_image_ops->vk_fs_float_module)) < 0)
{
ERR("Failed to create shader modules, vr %d.\n", vr);
goto fail;
}
if ((vr = vkd3d_meta_create_shader_module(device, SPIRV_CODE(fs_copy_image_uint),
&meta_copy_image_ops->vk_fs_uint_module)) < 0)
{
ERR("Failed to create shader modules, vr %d.\n", vr);
goto fail;
@ -626,7 +634,8 @@ void vkd3d_copy_image_ops_cleanup(struct vkd3d_copy_image_ops *meta_copy_image_o
VK_CALL(vkDestroyDescriptorSetLayout(device->vk_device, meta_copy_image_ops->vk_set_layout, NULL));
VK_CALL(vkDestroyPipelineLayout(device->vk_device, meta_copy_image_ops->vk_pipeline_layout, NULL));
VK_CALL(vkDestroyShaderModule(device->vk_device, meta_copy_image_ops->vk_fs_module, NULL));
VK_CALL(vkDestroyShaderModule(device->vk_device, meta_copy_image_ops->vk_fs_float_module, NULL));
VK_CALL(vkDestroyShaderModule(device->vk_device, meta_copy_image_ops->vk_fs_uint_module, NULL));
pthread_mutex_destroy(&meta_copy_image_ops->mutex);
@ -750,6 +759,7 @@ static HRESULT vkd3d_meta_create_copy_image_pipeline(struct vkd3d_meta_ops *meta
VkPipelineDepthStencilStateCreateInfo ds_state;
VkPipelineColorBlendStateCreateInfo cb_state;
VkSpecializationInfo spec_info;
VkShaderModule vk_module;
bool has_depth_target;
VkResult vr;
@ -817,9 +827,15 @@ static HRESULT vkd3d_meta_create_copy_image_pipeline(struct vkd3d_meta_ops *meta
key->sample_count, key->format, &pipeline->vk_render_pass)) < 0)
return hresult_from_vk_result(vr);
/* Special path when copying stencil -> color. */
if (key->format->vk_format == VK_FORMAT_R8_UINT)
vk_module = meta_copy_image_ops->vk_fs_uint_module;
else
vk_module = meta_copy_image_ops->vk_fs_float_module;
if ((vr = vkd3d_meta_create_graphics_pipeline(meta_ops,
meta_copy_image_ops->vk_pipeline_layout, pipeline->vk_render_pass,
VK_NULL_HANDLE, meta_copy_image_ops->vk_fs_module, key->sample_count,
VK_NULL_HANDLE, vk_module, key->sample_count,
has_depth_target ? &ds_state : NULL, has_depth_target ? NULL : &cb_state,
&spec_info, &pipeline->vk_pipeline)) < 0)
{

View File

@ -0,0 +1,29 @@
#version 450
#extension GL_EXT_samplerless_texture_functions : enable
#define MODE_1D 0
#define MODE_2D 1
#define MODE_MS 2
layout(constant_id = 0) const uint c_mode = MODE_2D;
layout(binding = 0) uniform utexture1DArray tex_1d;
layout(binding = 0) uniform utexture2DArray tex_2d;
layout(binding = 0) uniform utexture2DMSArray tex_ms;
layout(location = 0) out uint o_color;
layout(push_constant)
uniform u_info_t {
ivec2 offset;
} u_info;
void main() {
ivec3 coord = ivec3(u_info.offset + ivec2(gl_FragCoord.xy), gl_Layer);
uint value;
if (c_mode == MODE_1D) value = texelFetch(tex_1d, coord.xz, 0).r;
if (c_mode == MODE_2D) value = texelFetch(tex_2d, coord, 0).r;
if (c_mode == MODE_MS) value = texelFetch(tex_ms, coord, gl_SampleID).r;
o_color = value;
}

View File

@ -2253,7 +2253,8 @@ struct vkd3d_copy_image_ops
{
VkDescriptorSetLayout vk_set_layout;
VkPipelineLayout vk_pipeline_layout;
VkShaderModule vk_fs_module;
VkShaderModule vk_fs_float_module;
VkShaderModule vk_fs_uint_module;
pthread_mutex_t mutex;

View File

@ -49,6 +49,7 @@ enum vkd3d_meta_copy_mode
#include <vs_fullscreen.h>
#include <gs_fullscreen.h>
#include <fs_copy_image_float.h>
#include <fs_copy_image_uint.h>
#include <vs_swapchain_fullscreen.h>
#include <fs_swapchain_fullscreen.h>