[Vulkan] Robustify error handling during initialization

This commit is contained in:
DrChat
2017-12-16 15:14:48 -06:00
parent 293878cd14
commit 49287579ff
13 changed files with 339 additions and 136 deletions

View File

@@ -510,7 +510,11 @@ bool CachedRenderPass::IsCompatible(
RenderCache::RenderCache(RegisterFile* register_file,
ui::vulkan::VulkanDevice* device)
: register_file_(register_file), device_(device) {
: register_file_(register_file), device_(device) {}
RenderCache::~RenderCache() { Shutdown(); }
VkResult RenderCache::Initialize() {
VkResult status = VK_SUCCESS;
// Create the buffer we'll bind to our memory.
@@ -524,8 +528,11 @@ RenderCache::RenderCache(RegisterFile* register_file,
buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
buffer_info.queueFamilyIndexCount = 0;
buffer_info.pQueueFamilyIndices = nullptr;
status = vkCreateBuffer(*device, &buffer_info, nullptr, &edram_buffer_);
status = vkCreateBuffer(*device_, &buffer_info, nullptr, &edram_buffer_);
CheckResult(status, "vkCreateBuffer");
if (status != VK_SUCCESS) {
return status;
}
// Query requirements for the buffer.
// It should be 1:1.
@@ -535,19 +542,24 @@ RenderCache::RenderCache(RegisterFile* register_file,
// Allocate EDRAM memory.
// TODO(benvanik): do we need it host visible?
edram_memory_ = device->AllocateMemory(buffer_requirements);
edram_memory_ = device_->AllocateMemory(buffer_requirements);
assert_not_null(edram_memory_);
if (!edram_memory_) {
return VK_ERROR_INITIALIZATION_FAILED;
}
// Bind buffer to map our entire memory.
status = vkBindBufferMemory(*device_, edram_buffer_, edram_memory_, 0);
CheckResult(status, "vkBindBufferMemory");
if (status != VK_SUCCESS) {
return status;
}
if (status == VK_SUCCESS) {
// For debugging, upload a grid into the EDRAM buffer.
uint32_t* gpu_data = nullptr;
status = vkMapMemory(*device_, edram_memory_, 0, buffer_requirements.size,
0, reinterpret_cast<void**>(&gpu_data));
CheckResult(status, "vkMapMemory");
if (status == VK_SUCCESS) {
for (int i = 0; i < kEdramBufferCapacity / 4; i++) {
@@ -557,9 +569,11 @@ RenderCache::RenderCache(RegisterFile* register_file,
vkUnmapMemory(*device_, edram_memory_);
}
}
return VK_SUCCESS;
}
RenderCache::~RenderCache() {
void RenderCache::Shutdown() {
// TODO(benvanik): wait for idle.
// Dispose all render passes (and their framebuffers).
@@ -575,8 +589,14 @@ RenderCache::~RenderCache() {
cached_tile_views_.clear();
// Release underlying EDRAM memory.
vkDestroyBuffer(*device_, edram_buffer_, nullptr);
vkFreeMemory(*device_, edram_memory_, nullptr);
if (edram_buffer_) {
vkDestroyBuffer(*device_, edram_buffer_, nullptr);
edram_buffer_ = nullptr;
}
if (edram_memory_) {
vkFreeMemory(*device_, edram_memory_, nullptr);
edram_memory_ = nullptr;
}
}
bool RenderCache::dirty() const {