Permalink
Browse files

... And also for the vertex decoder (DenseHashMap)

  • Loading branch information...
hrydgard committed Aug 20, 2017
1 parent 2f85e65 commit 9c3549f0be6db03ff5c39c86396f2d915a43c3ef
Showing with 21 additions and 25 deletions.
  1. +0 −2 Common/Hashmaps.h
  2. +19 −22 GPU/Common/DrawEngineCommon.cpp
  3. +2 −1 GPU/Common/DrawEngineCommon.h
View
@@ -1,7 +1,5 @@
#pragma once
#include <functional>
#include "ext/xxhash.h"
#include "Common/CommonFuncs.h"
@@ -33,7 +33,7 @@ enum {
TRANSFORMED_VERTEX_BUFFER_SIZE = VERTEX_BUFFER_MAX * sizeof(TransformedVertex)
};
DrawEngineCommon::DrawEngineCommon() {
DrawEngineCommon::DrawEngineCommon() : decoderMap_(16) {
quadIndices_ = new u16[6 * QUAD_INDICES_MAX];
decJitCache_ = new VertexDecoderJitCache();
transformed = (TransformedVertex *)AllocateMemoryPages(TRANSFORMED_VERTEX_BUFFER_SIZE, MEM_PROT_READ | MEM_PROT_WRITE);
@@ -45,9 +45,9 @@ DrawEngineCommon::~DrawEngineCommon() {
FreeMemoryPages(transformedExpanded, 3 * TRANSFORMED_VERTEX_BUFFER_SIZE);
delete[] quadIndices_;
delete decJitCache_;
for (auto iter = decoderMap_.begin(); iter != decoderMap_.end(); iter++) {
delete iter->second;
}
decoderMap_.Iterate([&](const uint32_t vtype, VertexDecoder *decoder) {
delete decoder;
});
}
void DrawEngineCommon::SetupVertexDecoder(u32 vertType) {
@@ -63,34 +63,31 @@ void DrawEngineCommon::SetupVertexDecoder(u32 vertType) {
}
VertexDecoder *DrawEngineCommon::GetVertexDecoder(u32 vtype) {
auto iter = decoderMap_.find(vtype);
if (iter != decoderMap_.end())
return iter->second;
VertexDecoder *dec = new VertexDecoder();
VertexDecoder *dec = decoderMap_.Get(vtype);
if (dec)
return dec;
dec = new VertexDecoder();
dec->SetVertexType(vtype, decOptions_, decJitCache_);
decoderMap_[vtype] = dec;
decoderMap_.Insert(vtype, dec);
return dec;
}
std::vector<std::string> DrawEngineCommon::DebugGetVertexLoaderIDs() {
std::vector<std::string> ids;
for (auto iter : decoderMap_) {
decoderMap_.Iterate([&](const uint32_t vtype, VertexDecoder *decoder) {
std::string id;
id.resize(sizeof(iter.first));
memcpy(&id[0], &iter.first, sizeof(iter.first));
id.resize(sizeof(vtype));
memcpy(&id[0], &vtype, sizeof(vtype));
ids.push_back(id);
}
});
return ids;
}
std::string DrawEngineCommon::DebugGetVertexLoaderString(std::string id, DebugShaderStringType stringType) {
u32 mapId;
memcpy(&mapId, &id[0], sizeof(mapId));
auto iter = decoderMap_.find(mapId);
if (iter == decoderMap_.end())
return "N/A";
else
return iter->second->GetString(stringType);
VertexDecoder *dec = decoderMap_.Get(mapId);
return dec ? dec->GetString(stringType) : "N/A";
}
struct Plane {
@@ -136,10 +133,10 @@ void DrawEngineCommon::Resized() {
decJitCache_->Clear();
lastVType_ = -1;
dec_ = nullptr;
for (auto iter = decoderMap_.begin(); iter != decoderMap_.end(); iter++) {
delete iter->second;
}
decoderMap_.clear();
decoderMap_.Iterate([&](const uint32_t vtype, VertexDecoder *decoder) {
delete decoder;
});
decoderMap_.Clear();
ClearTrackedVertexArrays();
}
@@ -21,6 +21,7 @@
#include <unordered_map>
#include "Common/CommonTypes.h"
#include "Common/Hashmaps.h"
#include "GPU/GPUState.h"
#include "GPU/Common/GPUDebugInterface.h"
@@ -104,7 +105,7 @@ class DrawEngineCommon {
// Cached vertex decoders
u32 lastVType_ = -1;
std::unordered_map<u32, VertexDecoder *> decoderMap_;
DenseHashMap<u32, VertexDecoder *, nullptr> decoderMap_;
VertexDecoder *dec_ = nullptr;
VertexDecoderJitCache *decJitCache_ = nullptr;
VertexDecoderOptions decOptions_{};

0 comments on commit 9c3549f

Please sign in to comment.