Skip to content

Commit

Permalink
Merge branch 'master' into TemporaryHackishBranch
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaMoo committed Apr 15, 2018
2 parents 8a829c3 + fb377b0 commit a16a7f0
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 26 deletions.
3 changes: 1 addition & 2 deletions Common/Vulkan/VulkanMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,15 +450,14 @@ void VulkanDeviceAllocator::ReportOldUsage() {
}

if (hasOldAllocs) {
NOTICE_LOG(G3D, "Slab %d usage:", i);
NOTICE_LOG(G3D, "Slab %d usage:", (int)i);
for (auto it : slab.tags) {
const auto info = it.second;

float createAge = now - info.created;
float touchedAge = now - info.touched;
NOTICE_LOG(G3D, " * %s (created %fs ago, used %fs ago)", info.tag.c_str(), createAge, touchedAge);
}
NOTICE_LOG(G3D, "");
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions GPU/Vulkan/GPU_Vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,11 @@ void GPU_Vulkan::DestroyDeviceObjects() {
}

// Need to turn off hacks when shutting down the GPU. Don't want them running in the menu.
VulkanRenderManager *rm = (VulkanRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
rm->GetQueueRunner()->EnableHacks(0);
if (draw_) {
VulkanRenderManager *rm = (VulkanRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
if (rm)
rm->GetQueueRunner()->EnableHacks(0);
}
}

void GPU_Vulkan::DeviceLost() {
Expand Down
35 changes: 23 additions & 12 deletions GPU/Vulkan/PipelineManagerVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ void PipelineManagerVulkan::SaveCache(FILE *file, bool saveRawPipelineCache, Sha
size_t seekPosOnFailure = ftell(file);

bool failed = false;
bool writeFailed = false;
int count = 0;
// Since we don't include the full pipeline key, there can be duplicates,
// caused by things like switching from buffered to non-buffered rendering.
Expand Down Expand Up @@ -630,22 +631,29 @@ void PipelineManagerVulkan::SaveCache(FILE *file, bool saveRawPipelineCache, Sha

// Write the number of pipelines.
size = (uint32_t)keys.size();
fwrite(&size, sizeof(size), 1, file);
writeFailed = writeFailed || fwrite(&size, sizeof(size), 1, file) != 1;

// Write the pipelines.
for (auto &key : keys) {
fwrite(&key, sizeof(key), 1, file);
writeFailed = writeFailed || fwrite(&key, sizeof(key), 1, file) != 1;
}

if (failed) {
ERROR_LOG(G3D, "Failed to write pipeline cache, some shader was missing");
// Write a zero in the right place so it doesn't try to load the pipelines next time.
size = 0;
fseek(file, (long)seekPosOnFailure, SEEK_SET);
fwrite(&size, sizeof(size), 1, file);
writeFailed = fwrite(&size, sizeof(size), 1, file) != 1;
if (writeFailed) {
ERROR_LOG(G3D, "Failed to write pipeline cache, disk full?");
}
return;
}
NOTICE_LOG(G3D, "Saved Vulkan pipeline ID cache (%d unique pipelines/%d).", (int)keys.size(), (int)pipelines_.size());
if (writeFailed) {
ERROR_LOG(G3D, "Failed to write pipeline cache, disk full?");
} else {
NOTICE_LOG(G3D, "Saved Vulkan pipeline ID cache (%d unique pipelines/%d).", (int)keys.size(), (int)pipelines_.size());
}
}

bool PipelineManagerVulkan::LoadCache(FILE *file, bool loadRawPipelineCache, ShaderManagerVulkan *shaderManager, Draw::DrawContext *drawContext, VkPipelineLayout layout) {
Expand All @@ -654,16 +662,16 @@ bool PipelineManagerVulkan::LoadCache(FILE *file, bool loadRawPipelineCache, Sha

uint32_t size = 0;
if (loadRawPipelineCache) {
fread(&size, sizeof(size), 1, file);
if (!size) {
bool success = fread(&size, sizeof(size), 1, file) == 1;
if (!size || !success) {
WARN_LOG(G3D, "Zero-sized Vulkan pipeline cache.");
return true;
}
std::unique_ptr<uint8_t[]> buffer(new uint8_t[size]);
fread(buffer.get(), 1, size, file);
success = fread(buffer.get(), 1, size, file) == size;
// Verify header.
VkPipelineCacheHeader *header = (VkPipelineCacheHeader *)buffer.get();
if (header->version != VK_PIPELINE_CACHE_HEADER_VERSION_ONE) {
if (!success || header->version != VK_PIPELINE_CACHE_HEADER_VERSION_ONE) {
// Bad header, don't do anything.
WARN_LOG(G3D, "Bad Vulkan pipeline cache header - ignoring");
return false;
Expand Down Expand Up @@ -697,16 +705,19 @@ bool PipelineManagerVulkan::LoadCache(FILE *file, bool loadRawPipelineCache, Sha
}

// Read the number of pipelines.
fread(&size, sizeof(size), 1, file);
bool failed = fread(&size, sizeof(size), 1, file) != 1;

NOTICE_LOG(G3D, "Creating %d pipelines...", size);
bool failed = false;
for (uint32_t i = 0; i < size; i++) {
if (failed) {
continue;
break;
}
StoredVulkanPipelineKey key;
fread(&key, sizeof(key), 1, file);
failed = failed || fread(&key, sizeof(key), 1, file) != 1;
if (failed) {
ERROR_LOG(G3D, "Truncated Vulkan pipeline cache file");
continue;
}
VulkanVertexShader *vs = shaderManager->GetVertexShaderFromID(key.vShaderID);
VulkanFragmentShader *fs = shaderManager->GetFragmentShaderFromID(key.fShaderID);
if (!vs || !fs) {
Expand Down
26 changes: 18 additions & 8 deletions GPU/Vulkan/ShaderManagerVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ struct VulkanCacheHeader {

bool ShaderManagerVulkan::LoadCache(FILE *f) {
VulkanCacheHeader header{};
fread(&header, sizeof(header), 1, f);
if (header.magic != CACHE_HEADER_MAGIC)
bool success = fread(&header, sizeof(header), 1, f) == 1;
if (!success || header.magic != CACHE_HEADER_MAGIC)
return false;
if (header.version != CACHE_VERSION)
return false;
Expand All @@ -380,15 +380,21 @@ bool ShaderManagerVulkan::LoadCache(FILE *f) {

for (int i = 0; i < header.numVertexShaders; i++) {
VShaderID id;
fread(&id, sizeof(id), 1, f);
if (fread(&id, sizeof(id), 1, f) != 1) {
ERROR_LOG(G3D, "Vulkan shader cache truncated");
break;
}
bool useHWTransform = id.Bit(VS_BIT_USE_HW_TRANSFORM);
GenerateVulkanGLSLVertexShader(id, codeBuffer_);
VulkanVertexShader *vs = new VulkanVertexShader(vulkan_, id, codeBuffer_, useHWTransform);
vsCache_.Insert(id, vs);
}
for (int i = 0; i < header.numFragmentShaders; i++) {
FShaderID id;
fread(&id, sizeof(id), 1, f);
if (fread(&id, sizeof(id), 1, f) != 1) {
ERROR_LOG(G3D, "Vulkan shader cache truncated");
break;
}
GenerateVulkanGLSLFragmentShader(id, codeBuffer_);
VulkanFragmentShader *fs = new VulkanFragmentShader(vulkan_, id, codeBuffer_);
fsCache_.Insert(id, fs);
Expand All @@ -406,12 +412,16 @@ void ShaderManagerVulkan::SaveCache(FILE *f) {
header.reserved = 0;
header.numVertexShaders = (int)vsCache_.size();
header.numFragmentShaders = (int)fsCache_.size();
fwrite(&header, sizeof(header), 1, f);
bool writeFailed = fwrite(&header, sizeof(header), 1, f) != 1;
vsCache_.Iterate([&](const VShaderID &id, VulkanVertexShader *vs) {
fwrite(&id, sizeof(id), 1, f);
writeFailed = writeFailed || fwrite(&id, sizeof(id), 1, f) != 1;
});
fsCache_.Iterate([&](const FShaderID &id, VulkanFragmentShader *fs) {
fwrite(&id, sizeof(id), 1, f);
writeFailed = writeFailed || fwrite(&id, sizeof(id), 1, f) != 1;
});
NOTICE_LOG(G3D, "Saved %d vertex and %d fragment shaders", header.numVertexShaders, header.numFragmentShaders);
if (writeFailed) {
ERROR_LOG(G3D, "Failed to write Vulkan shader cache, disk full?");
} else {
NOTICE_LOG(G3D, "Saved %d vertex and %d fragment shaders", header.numVertexShaders, header.numFragmentShaders);
}
}
3 changes: 3 additions & 0 deletions android/jni/AndroidGraphicsContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ class AndroidGraphicsContext : public GraphicsContext {
// Android (EGL, Vulkan) we do have all this info on the render thread.
virtual bool InitFromRenderThread(ANativeWindow *wnd, int desiredBackbufferSizeX, int desiredBackbufferSizeY, int backbufferFormat, int androidVersion) = 0;
virtual bool Initialized() = 0;

private:
using GraphicsContext::InitFromRenderThread;
};
2 changes: 0 additions & 2 deletions ext/native/thin3d/GLRenderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,6 @@ class GLPushBuffer {
uint8_t *writePtr_ = nullptr;
GLuint target_;
GLBufferStrategy strategy_ = GLBufferStrategy::SUBDATA;

friend class GLRenderManager;
};

enum class GLRRunType {
Expand Down
6 changes: 6 additions & 0 deletions ext/native/thin3d/VulkanQueueRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,12 @@ void VulkanQueueRunner::ApplyMGSHack(std::vector<VKRStep *> &steps) {
case VKRStepType::RENDER:
if (steps[j]->render.numDraws > 1)
last = j - 1;
// should really also check descriptor sets...
if (steps[j]->commands.size()) {
VkRenderData &cmd = steps[j]->commands.back();
if (cmd.cmd == VKRRenderCommand::DRAW_INDEXED && cmd.draw.count != 6)
last = j - 1;
}
break;
case VKRStepType::COPY:
if (steps[j]->copy.dst != steps[i]->copy.dst)
Expand Down

0 comments on commit a16a7f0

Please sign in to comment.