Skip to content

Commit

Permalink
[text_renderer] fixed a few bugs which triggered when we ran out of s…
Browse files Browse the repository at this point in the history
…trings and attempted to resize. there are still more bugs - namely device is lost at some point when string churn is very high - its almost certainly dodgy logic not resizing something properly by the time the compute shader is sended
  • Loading branch information
harrand committed Feb 27, 2024
1 parent c4bee5a commit 3dba699
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/tz/gl/impl/vulkan/detail/fence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ namespace tz::gl::vk2

void Fence::wait_until_signalled() const
{
vkWaitForFences(this->get_device().native(), 1, &this->fence, VK_FALSE, std::numeric_limits<std::uint64_t>::max());
VkResult res = vkWaitForFences(this->get_device().native(), 1, &this->fence, VK_FALSE, std::numeric_limits<std::uint64_t>::max());
tz::assert(res == VK_SUCCESS);
}

void Fence::unsignal()
Expand Down
31 changes: 25 additions & 6 deletions src/tz/ren/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace tz::ren
const std::size_t old_capacity = this->get_char_capacity(rh);
// double or add by string size, whichever is larger.
const std::size_t new_capacity = std::max(old_capacity + str.size(), old_capacity * 2);
this->set_char_capacity(rh, new_capacity);
this->set_char_capacity(rh, ch, new_capacity);
maybe_region = this->try_find_char_region(str.size(), rh);
tz::assert(maybe_region.has_value());
}
Expand Down Expand Up @@ -93,7 +93,7 @@ namespace tz::ren
if(string_id >= this->get_string_capacity(rh))
{
// expand. double capacity.
this->set_string_capacity(rh, capacity * 2);
this->set_string_capacity(rh, ch, capacity * 2);
}
this->write_string_locator(rh, ch, string_id, loc);
this->string_cursor++;
Expand Down Expand Up @@ -253,9 +253,9 @@ namespace tz::ren
std::size_t char_storage::get_char_occupancy(tz::gl::renderer_handle rh) const
{
std::size_t total_char_count = 0;
std::vector<string_locator> locators(this->get_string_capacity(rh));
std::vector<string_locator> locators(this->string_cursor);
auto resource_data = tz::gl::get_device().get_renderer(rh).get_resource(this->string_buffer)->data_as<const string_locator>();
std::copy(resource_data.begin(), resource_data.end(), locators.begin());
std::copy(resource_data.begin(), resource_data.begin() + this->string_cursor, locators.begin());
for(const auto& loc : locators)
{
total_char_count += loc.count;
Expand All @@ -272,7 +272,7 @@ namespace tz::ren

//--------------------------------------------------------------------------------------------------

void char_storage::set_char_capacity(tz::gl::renderer_handle rh, std::size_t char_count)
void char_storage::set_char_capacity(tz::gl::renderer_handle rh, tz::gl::renderer_handle ch, std::size_t char_count)
{
std::size_t old_cap = this->get_char_capacity(rh);
if(old_cap <= char_count)
Expand All @@ -288,6 +288,16 @@ namespace tz::ren
})
.build()
);
tz::gl::get_device().get_renderer(ch).edit(
tz::gl::RendererEditBuilder{}
.mark_dirty
({
.work_commands = true,
.buffers = true,
})
.build()
);

tz::assert(this->get_char_capacity(rh) == char_count);
}

Expand All @@ -300,7 +310,7 @@ namespace tz::ren

//--------------------------------------------------------------------------------------------------

void char_storage::set_string_capacity(tz::gl::renderer_handle rh, std::size_t string_count)
void char_storage::set_string_capacity(tz::gl::renderer_handle rh, tz::gl::renderer_handle ch, std::size_t string_count)
{
std::size_t old_cap = this->get_string_capacity(rh);
if(old_cap >= string_count)
Expand All @@ -316,6 +326,15 @@ namespace tz::ren
})
.build()
);
tz::gl::get_device().get_renderer(ch).edit(
tz::gl::RendererEditBuilder{}
.mark_dirty
({
.work_commands = true,
.buffers = true,
})
.build()
);
tz::assert(this->get_string_capacity(rh) == string_count);
}

Expand Down
4 changes: 2 additions & 2 deletions src/tz/ren/text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ namespace tz::ren
void write_string_locator(tz::gl::renderer_handle rh, tz::gl::renderer_handle ch, std::size_t string_id, const string_locator& loc);
std::size_t get_char_occupancy(tz::gl::renderer_handle rh) const;
std::size_t get_char_capacity(tz::gl::renderer_handle rh) const;
void set_char_capacity(tz::gl::renderer_handle rh, std::size_t char_count);
void set_char_capacity(tz::gl::renderer_handle rh, tz::gl::renderer_handle ch, std::size_t char_count);
std::size_t get_string_capacity(tz::gl::renderer_handle rh) const;
void set_string_capacity(tz::gl::renderer_handle rh, std::size_t string_count);
void set_string_capacity(tz::gl::renderer_handle rh, tz::gl::renderer_handle ch, std::size_t string_count);
// convert ascii chars into alphabet indices (in-place)
static constexpr void format(std::span<char> ascii_str)
{
Expand Down

0 comments on commit 3dba699

Please sign in to comment.