Add drawing code for devices without descriptor indexing

This commit is contained in:
Benau 2022-03-19 16:09:32 +08:00
parent 1cf2c0c5bf
commit bb6551fdf6
4 changed files with 38 additions and 3 deletions

View File

@ -3,6 +3,7 @@
#include "ge_main.hpp"
#include "ge_vulkan_driver.hpp"
#include "ge_vulkan_dynamic_buffer.hpp"
#include "ge_vulkan_features.hpp"
#include "ge_vulkan_shader_manager.hpp"
#include <algorithm>
@ -421,8 +422,34 @@ void GEVulkan2dRenderer::render()
VK_PIPELINE_BIND_POINT_GRAPHICS, g_pipeline_layout, 0, 1,
&g_descriptor_sets[g_vk->getCurrentFrame()], 0, NULL);
vkCmdDrawIndexed(g_vk->getCurrentCommandBuffer(),
(uint32_t)(g_tris_index_queue.size()), 1, 0, 0, 0);
if (GEVulkanFeatures::supportsDifferentTexturePerDraw())
{
vkCmdDrawIndexed(g_vk->getCurrentCommandBuffer(),
(uint32_t)(g_tris_index_queue.size()), 1, 0, 0, 0);
}
else
{
unsigned idx = 0;
unsigned idx_count = 0;
int sampler_idx = g_tris_queue[0].sampler_idx;
for (; idx < g_tris_index_queue.size(); idx += 3)
{
Tri& cur_tri = g_tris_queue[g_tris_index_queue[idx]];
if (cur_tri.sampler_idx != sampler_idx)
{
vkCmdDrawIndexed(g_vk->getCurrentCommandBuffer(), idx_count, 1,
idx - idx_count, 0, 0);
sampler_idx = cur_tri.sampler_idx;
idx_count = 3;
}
else
{
idx_count += 3;
}
}
vkCmdDrawIndexed(g_vk->getCurrentCommandBuffer(), idx_count, 1,
idx - idx_count, 0, 0);
}
end_cmd:
vkCmdEndRenderPass(g_vk->getCurrentCommandBuffer());

View File

@ -81,6 +81,12 @@ bool GEVulkanFeatures::supportsNonUniformIndexing()
return g_supports_non_uniform_indexing;
} // supportsNonUniformIndexing
// ----------------------------------------------------------------------------
bool GEVulkanFeatures::supportsDifferentTexturePerDraw()
{
return g_supports_descriptor_indexing && g_supports_non_uniform_indexing;
} // supportsDifferentTexturePerDraw
// ----------------------------------------------------------------------------
bool GEVulkanFeatures::supportsPartiallyBound()
{

View File

@ -17,6 +17,8 @@ bool supportsDescriptorIndexing();
// ----------------------------------------------------------------------------
bool supportsNonUniformIndexing();
// ----------------------------------------------------------------------------
bool supportsDifferentTexturePerDraw();
// ----------------------------------------------------------------------------
bool supportsPartiallyBound();
}; // GEVulkanFeatures

View File

@ -42,7 +42,7 @@ void GEVulkanShaderManager::init(GEVulkanDriver* vk)
std::ostringstream oss;
oss << "#version 450\n";
oss << "#define SAMPLER_SIZE " << g_sampler_size << "\n";
if (GEVulkanFeatures::supportsDescriptorIndexing())
if (GEVulkanFeatures::supportsDifferentTexturePerDraw())
{
oss << "#extension GL_EXT_nonuniform_qualifier : enable\n";
oss << "#define GE_SAMPLE_TEX_INDEX nonuniformEXT\n";