vulkan: Move sampler object outside of texture.

This commit is contained in:
Vincent Lejeune 2016-03-21 01:00:48 +01:00
parent 6f9f5f7918
commit a14dd8ea51
3 changed files with 49 additions and 69 deletions

View file

@ -562,7 +562,13 @@ void VKGSRender::end()
}
vk::texture &tex = (texture0)? (*texture0): m_texture_cache.upload_texture(m_command_buffer, textures[i], m_rtts);
m_program->bind_uniform({ tex, tex, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL }, "tex" + std::to_string(i), descriptor_sets);
vk::sampler sampler(*m_device,
vk::vk_wrap_mode(textures[i].wrap_s()), vk::vk_wrap_mode(textures[i].wrap_t()), vk::vk_wrap_mode(textures[i].wrap_r()),
!!(textures[i].format() & CELL_GCM_TEXTURE_UN),
textures[i].bias(), vk::max_aniso(textures[i].max_aniso()), textures[i].min_lod(), textures[i].max_lod(),
VK_FILTER_LINEAR, VK_FILTER_LINEAR, VK_SAMPLER_MIPMAP_MODE_NEAREST
);
m_program->bind_uniform({ sampler.value, tex, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL }, "tex" + std::to_string(i), descriptor_sets);
texture0 = &tex;
}
}

View file

@ -335,7 +335,6 @@ namespace vk
class texture
{
VkImageView m_view = nullptr;
VkSampler m_sampler = nullptr;
VkImage m_image_contents = nullptr;
VkMemoryRequirements m_memory_layout;
VkFormat m_internal_format;
@ -355,7 +354,6 @@ namespace vk
vk::texture *staging_texture = nullptr;
bool ready = false;
void sampler_setup(rsx::texture& tex, VkImageViewType type, VkComponentMapping swizzle);
public:
texture(vk::swap_chain_image &img);
@ -381,7 +379,6 @@ namespace vk
const u16 mipmaps();
const VkFormat get_format();
operator VkSampler();
operator VkImageView();
operator VkImage();
};
@ -462,6 +459,48 @@ namespace vk
VkDevice m_device;
};
struct sampler
{
VkSampler value;
VkSamplerCreateInfo info = {};
sampler(VkDevice dev, VkSamplerAddressMode clamp_u, VkSamplerAddressMode clamp_v, VkSamplerAddressMode clamp_w,
bool unnormalized_coordinates, float mipLodBias, float max_anisotropy, float min_lod, float max_lod,
VkFilter min_filter, VkFilter mag_filter, VkSamplerMipmapMode mipmap_mode)
: m_device(dev)
{
VkSamplerCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
info.addressModeU = clamp_u;
info.addressModeV = clamp_v;
info.addressModeW = clamp_w;
info.anisotropyEnable = VK_TRUE;
info.compareEnable = VK_FALSE;
info.unnormalizedCoordinates = unnormalized_coordinates;
info.mipLodBias = mipLodBias;
info.maxAnisotropy = max_anisotropy;
info.maxLod = max_lod;
info.minLod = min_lod;
info.magFilter = mag_filter;
info.minFilter = min_filter;
info.mipmapMode = mipmap_mode;
info.compareOp = VK_COMPARE_OP_NEVER;
info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
CHECK_RESULT(vkCreateSampler(m_device, &info, nullptr, &value));
}
~sampler()
{
vkDestroySampler(m_device, value, nullptr);
}
sampler(const sampler&) = delete;
sampler(sampler&&) = delete;
private:
VkDevice m_device;
};
class framebuffer
{
VkFramebuffer m_vk_framebuffer = nullptr;

View file

@ -133,7 +133,6 @@ namespace vk
{
m_image_contents = img;
m_view = img;
m_sampler = nullptr;
//We did not create this object, do not allow internal modification!
owner = nullptr;
@ -190,32 +189,6 @@ namespace vk
m_usage = usage;
m_tiling = tiling;
if (usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT ||
usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
{
VkSamplerAddressMode clamp_s = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
VkSamplerAddressMode clamp_t = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
VkSamplerAddressMode clamp_r = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
VkSamplerCreateInfo sampler_info = {};
sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
sampler_info.addressModeU = clamp_s;
sampler_info.addressModeV = clamp_t;
sampler_info.addressModeW = clamp_r;
sampler_info.anisotropyEnable = VK_FALSE;
sampler_info.compareEnable = VK_FALSE;
sampler_info.unnormalizedCoordinates = VK_FALSE;
sampler_info.mipLodBias = 0;
sampler_info.maxAnisotropy = 0;
sampler_info.magFilter = VK_FILTER_LINEAR;
sampler_info.minFilter = VK_FILTER_LINEAR;
sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
sampler_info.compareOp = VK_COMPARE_OP_NEVER;
sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
CHECK_RESULT(vkCreateSampler((*owner), &sampler_info, nullptr, &m_sampler));
}
ready = true;
}
@ -269,33 +242,6 @@ namespace vk
create(device, format, usage, tiling, width, height, mipmaps, gpu_only, swizzle);
}
void texture::sampler_setup(rsx::texture &tex, VkImageViewType type, VkComponentMapping swizzle)
{
VkSamplerAddressMode clamp_s = vk::vk_wrap_mode(tex.wrap_s());
VkSamplerAddressMode clamp_t = vk::vk_wrap_mode(tex.wrap_t());
VkSamplerAddressMode clamp_r = vk::vk_wrap_mode(tex.wrap_r());
VkSamplerCreateInfo sampler_info = {};
sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
sampler_info.addressModeU = clamp_s;
sampler_info.addressModeV = clamp_t;
sampler_info.addressModeW = clamp_r;
sampler_info.anisotropyEnable = VK_TRUE;
sampler_info.compareEnable = VK_FALSE;
sampler_info.unnormalizedCoordinates = !!(tex.format() & CELL_GCM_TEXTURE_UN);
sampler_info.mipLodBias = tex.bias();
sampler_info.maxAnisotropy = vk::max_aniso(tex.max_aniso());
sampler_info.maxLod = tex.max_lod();
sampler_info.minLod = tex.min_lod();
sampler_info.magFilter = VK_FILTER_LINEAR;
sampler_info.minFilter = VK_FILTER_LINEAR;
sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
sampler_info.compareOp = VK_COMPARE_OP_NEVER;
sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
CHECK_RESULT(vkCreateSampler((*owner), &sampler_info, nullptr, &m_sampler));
}
void texture::init(rsx::texture& tex, vk::command_buffer &cmd, bool ignore_checks)
{
VkImageViewType best_type = VK_IMAGE_VIEW_TYPE_2D;
@ -324,9 +270,6 @@ namespace vk
create(dev, format, VK_IMAGE_TYPE_3D, VK_IMAGE_VIEW_TYPE_3D, 0, usage, tiling, tex.width(), tex.height(), tex.mipmap(), false, default_component_map());
}
if (!m_sampler)
sampler_setup(tex, best_type, default_component_map());
VkImageSubresource subres = {};
subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
subres.mipLevel = 0;
@ -495,9 +438,6 @@ namespace vk
{
if (!owner) return;
if (m_sampler)
vkDestroySampler((*owner), m_sampler, nullptr);
//Destroy all objects managed by this object
vkDestroyImageView((*owner), m_view, nullptr);
vkDestroyImage((*owner), m_image_contents, nullptr);
@ -505,7 +445,6 @@ namespace vk
vram_allocation.destroy();
owner = nullptr;
m_sampler = nullptr;
m_view = nullptr;
m_image_contents = nullptr;
@ -532,8 +471,4 @@ namespace vk
return m_view;
}
texture::operator VkSampler()
{
return m_sampler;
}
}