Skip to content

Commit

Permalink
Zephyr: Renderer: optimize geometry cache lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
fleroviux committed Jun 8, 2024
1 parent ec34612 commit 5a69498
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
15 changes: 11 additions & 4 deletions zephyr/renderer/include/zephyr/renderer/engine/geometry_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <zephyr/renderer/backend/render_backend.hpp>
#include <zephyr/renderer/resource/geometry.hpp>
#include <EASTL/hash_map.h>
#include <memory>
#include <unordered_map>
#include <vector>

namespace zephyr {
Expand All @@ -21,7 +21,14 @@ namespace zephyr {

// Render Thread API:
void ProcessPendingUpdates();
RenderGeometry* GetCachedRenderGeometry(const Geometry* geometry) const;

RenderGeometry* GetCachedRenderGeometry(const Geometry* geometry) const {
const auto match = m_render_geometry_table.find(geometry);
if(match == m_render_geometry_table.end()) {
ZEPHYR_PANIC("Bad attempt to retrieve cached render geometry of a geometry which isn't cached.")
}
return match->second;
}

private:
struct GeometryState {
Expand All @@ -48,8 +55,8 @@ namespace zephyr {
void ProcessPendingUploads();

std::shared_ptr<RenderBackend> m_render_backend;
std::unordered_map<const Geometry*, GeometryState> m_geometry_state_table{};
mutable std::unordered_map<const Geometry*, RenderGeometry*> m_render_geometry_table{};
eastl::hash_map<const Geometry*, GeometryState> m_geometry_state_table{};
mutable eastl::hash_map<const Geometry*, RenderGeometry*> m_render_geometry_table{};
std::vector<UploadTask> m_upload_tasks{};
std::vector<DeleteTask> m_delete_tasks[2]{};
};
Expand Down
7 changes: 0 additions & 7 deletions zephyr/renderer/src/engine/geometry_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,6 @@ namespace zephyr {
ProcessPendingUploads();
}

RenderGeometry* GeometryCache::GetCachedRenderGeometry(const Geometry* geometry) const {
if(!m_render_geometry_table.contains(geometry)) {
ZEPHYR_PANIC("Bad attempt to retrieve cached render geometry of a geometry which isn't cached.")
}
return m_render_geometry_table[geometry];
}

void GeometryCache::ProcessPendingDeletes() {
for(const auto& delete_task : m_delete_tasks[0]) {
RenderGeometry* render_geometry = m_render_geometry_table[delete_task.geometry];
Expand Down

0 comments on commit 5a69498

Please sign in to comment.