Permalink
Browse files

Vulkan: Remove duplicate depalShaderCache, fix a number of instances …

…where we didn't use the deleter properly.

Plus more logging, of course.
  • Loading branch information...
hrydgard committed Nov 9, 2017
1 parent 6eb58b1 commit 8b42d8312373b6ae19a04b1630ece769fd6ed50d
@@ -219,6 +219,7 @@ bool VulkanContext::InitObjects() {
}
void VulkanContext::DestroyObjects() {
ILOG("VulkanContext::DestroyObjects (including swapchain)");
if (swapchain_ != VK_NULL_HANDLE)
vkDestroySwapchainKHR(device_, swapchain_, nullptr);
swapchain_ = VK_NULL_HANDLE;
@@ -584,6 +585,7 @@ void VulkanContext::InitSurfaceAndroid(ANativeWindow *wnd, int width, int height
}
void VulkanContext::ReinitSurfaceAndroid(int width, int height) {
ILOG("Destroying and reiniting Android Vulkan surface");
if (surface_ != VK_NULL_HANDLE) {
vkDestroySurfaceKHR(instance_, surface_, nullptr);
surface_ = VK_NULL_HANDLE;
@@ -71,6 +71,7 @@ class VulkanDeleteList {
};
public:
// NOTE: These all take reference handles so they can zero the input value.
void QueueDeleteCommandPool(VkCommandPool &pool) { cmdPools_.push_back(pool); pool = VK_NULL_HANDLE; }
void QueueDeleteDescriptorPool(VkDescriptorPool &pool) { descPools_.push_back(pool); pool = VK_NULL_HANDLE; }
void QueueDeleteShaderModule(VkShaderModule &module) { modules_.push_back(module); module = VK_NULL_HANDLE; }
@@ -122,6 +123,7 @@ class VulkanDeleteList {
}
void PerformDeletes(VkDevice device) {
ILOG("PerformDeletes");
for (auto &cmdPool : cmdPools_) {
vkDestroyCommandPool(device, cmdPool, nullptr);
}
@@ -78,7 +78,6 @@ void VulkanPushBuffer::Destroy(VulkanContext *vulkan) {
vulkan->Delete().QueueDeleteBuffer(info.buffer);
vulkan->Delete().QueueDeleteDeviceMemory(info.deviceMemory);
}
buffers_.clear();
}
@@ -60,19 +60,27 @@ static VkFormat GetClutDestFormat(GEPaletteFormat format, VkComponentMapping *co
DepalShaderCacheVulkan::DepalShaderCacheVulkan(Draw::DrawContext *draw, VulkanContext *vulkan)
: draw_(draw), vulkan_(vulkan) {
std::string errors;
vshader_ = CompileShaderModule(vulkan_, VK_SHADER_STAGE_VERTEX_BIT, depal_vs, &errors);
assert(vshader_ != VK_NULL_HANDLE);
DeviceRestore(draw, vulkan);
}
DepalShaderCacheVulkan::~DepalShaderCacheVulkan() {
DeviceLost();
}
void DepalShaderCacheVulkan::DeviceLost() {
Clear();
vulkan_->Delete().QueueDeleteShaderModule(vshader_);
vshader_ = nullptr;
draw_ = nullptr;
vulkan_ = nullptr;
}
void DepalShaderCacheVulkan::DeviceRestore(Draw::DrawContext *draw, VulkanContext *vulkan) {
draw_ = draw;
vulkan_ = vulkan;
std::string errors;
vshader_ = CompileShaderModule(vulkan_, VK_SHADER_STAGE_VERTEX_BIT, depal_vs, &errors);
assert(vshader_ != VK_NULL_HANDLE);
}
DepalShaderVulkan *DepalShaderCacheVulkan::GetDepalettizeShader(uint32_t clutMode, GEBufferFormat pixelFormat) {
@@ -52,6 +52,7 @@ class DepalShaderCacheVulkan : public DepalShaderCacheCommon {
public:
DepalShaderCacheVulkan(Draw::DrawContext *draw, VulkanContext *vulkan);
~DepalShaderCacheVulkan();
void DeviceLost();
void DeviceRestore(Draw::DrawContext *draw, VulkanContext *vulkan);
// This also uploads the palette and binds the correct texture.
@@ -249,10 +249,10 @@ void DrawEngineVulkan::DestroyDeviceObjects() {
if (nullSampler_ != VK_NULL_HANDLE)
vulkan_->Delete().QueueDeleteSampler(nullSampler_);
if (pipelineLayout_ != VK_NULL_HANDLE)
vkDestroyPipelineLayout(vulkan_->GetDevice(), pipelineLayout_, nullptr);
vulkan_->Delete().QueueDeletePipelineLayout(pipelineLayout_);
pipelineLayout_ = VK_NULL_HANDLE;
if (descriptorSetLayout_ != VK_NULL_HANDLE)
vkDestroyDescriptorSetLayout(vulkan_->GetDevice(), descriptorSetLayout_, nullptr);
vulkan_->Delete().QueueDeleteDescriptorSetLayout(descriptorSetLayout_);
descriptorSetLayout_ = VK_NULL_HANDLE;
if (nullTexture_) {
nullTexture_->Destroy();
@@ -88,8 +88,7 @@ FramebufferManagerVulkan::FramebufferManagerVulkan(Draw::DrawContext *draw, Vulk
convBufSize_(0),
textureCacheVulkan_(nullptr),
shaderManagerVulkan_(nullptr),
pipelinePostShader_(VK_NULL_HANDLE),
depalVulkan_(draw, vulkan) {
pipelinePostShader_(VK_NULL_HANDLE) {
InitDeviceObjects();
@@ -120,7 +120,6 @@ class FramebufferManagerVulkan : public FramebufferManagerCommon {
DrawEngineVulkan *drawEngineVulkan_;
VulkanPushBuffer *push_;
DepalShaderCacheVulkan depalVulkan_;
enum {
MAX_COMMAND_BUFFERS = 32,
};
@@ -807,7 +807,7 @@ void GPU_Vulkan::DeviceLost() {
drawEngine_.DeviceLost();
pipelineManager_->DeviceLost();
textureCacheVulkan_->DeviceLost();
depalShaderCache_.Clear();
depalShaderCache_.DeviceLost();
shaderManagerVulkan_->ClearShaders();
}
@@ -46,11 +46,11 @@ void Vulkan2D::DestroyDeviceObjects() {
VkDevice device = vulkan_->GetDevice();
if (descriptorSetLayout_ != VK_NULL_HANDLE) {
vkDestroyDescriptorSetLayout(device, descriptorSetLayout_, nullptr);
vulkan_->Delete().QueueDeleteDescriptorSetLayout(descriptorSetLayout_);
descriptorSetLayout_ = VK_NULL_HANDLE;
}
if (pipelineLayout_ != VK_NULL_HANDLE) {
vkDestroyPipelineLayout(device, pipelineLayout_, nullptr);
vulkan_->Delete().QueueDeletePipelineLayout(pipelineLayout_);
pipelineLayout_ = VK_NULL_HANDLE;
}
@@ -39,18 +39,19 @@ void VulkanQueueRunner::CreateDeviceObjects() {
void VulkanQueueRunner::DestroyDeviceObjects() {
ILOG("VulkanQueueRuner::DestroyDeviceObjects");
VkDevice device = vulkan_->GetDevice();
vulkan_->Delete().QueueDeleteDeviceMemory(readbackMemory_);
vkFreeMemory(device, readbackMemory_, nullptr);
readbackMemory_ = VK_NULL_HANDLE;
vulkan_->Delete().QueueDeleteBuffer(readbackBuffer_);
readbackBuffer_ = VK_NULL_HANDLE;
for (int i = 0; i < ARRAY_SIZE(renderPasses_); i++) {
assert(renderPasses_[i] != VK_NULL_HANDLE);
vkDestroyRenderPass(device, renderPasses_[i], nullptr);
vulkan_->Delete().QueueDeleteRenderPass(renderPasses_[i]);
renderPasses_[i] = VK_NULL_HANDLE;
}
assert(backbufferRenderPass_ != VK_NULL_HANDLE);
vkDestroyRenderPass(device, backbufferRenderPass_, nullptr);
vulkan_->Delete().QueueDeleteRenderPass(backbufferRenderPass_);
backbufferRenderPass_ = VK_NULL_HANDLE;
}
@@ -425,8 +426,8 @@ void VulkanQueueRunner::PerformRenderPass(const VKRStep &step, VkCommandBuffer c
VkClearRect rc{};
rc.baseArrayLayer = 0;
rc.layerCount = 1;
rc.rect.extent.width = curWidth;
rc.rect.extent.height = curHeight;
rc.rect.extent.width = (uint32_t)curWidth;
rc.rect.extent.height = (uint32_t)curHeight;
VkClearAttachment attachments[2];
if (c.clear.clearMask & VK_IMAGE_ASPECT_COLOR_BIT) {
VkClearAttachment &attachment = attachments[numAttachments++];
@@ -442,7 +443,7 @@ void VulkanQueueRunner::PerformRenderPass(const VKRStep &step, VkCommandBuffer c
attachment.aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT;
}
if (c.clear.clearMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
attachment.clearValue.depthStencil.stencil = c.clear.clearStencil;
attachment.clearValue.depthStencil.stencil = (uint32_t)c.clear.clearStencil;
attachment.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
}
}
@@ -194,7 +194,7 @@ void VulkanRenderManager::CreateBackbuffers() {
run_ = true;
// Won't necessarily be 0.
threadInitFrame_ = vulkan_->GetCurFrame();
VLOG("starting thread");
ILOG("Starting Vulkan submission thread");
thread_ = std::thread(&VulkanRenderManager::ThreadFunc, this);
}
}
@@ -215,7 +215,7 @@ void VulkanRenderManager::StopThread() {
}
}
thread_.join();
VLOG("thread joined.");
ILOG("Vulkan submission thread joined.");
// Wait for any fences to finish and be resignaled, so we don't have sync issues.
for (int i = 0; i < vulkan_->GetInflightFrames(); i++) {
@@ -228,6 +228,8 @@ void VulkanRenderManager::StopThread() {
frameData.push_condVar.wait(lock);
}
}
} else {
ILOG("Vulkan submission thread was already stopped.");
}
}
@@ -331,6 +333,9 @@ void VulkanRenderManager::BeginFrame() {
// Must be after the fence - this performs deletes.
VLOG("PUSH: BeginFrame %d", curFrame);
if (!run_) {
WLOG("BeginFrame while !run_!");
}
vulkan_->BeginFrame();
insideFrame_ = true;
@@ -193,7 +193,7 @@ class VKShaderModule : public ShaderModule {
const std::string &GetSource() const { return source_; }
~VKShaderModule() {
if (module_) {
vkDestroyShaderModule(device_, module_, nullptr);
vulkan_->Delete().QueueDeleteShaderModule(module_);
}
}
VkShaderModule Get() const { return module_; }
@@ -202,7 +202,7 @@ class VKShaderModule : public ShaderModule {
}
private:
VkDevice device_;
VulkanContext *vulkan_;
VkShaderModule module_;
VkShaderStageFlagBits vkstage_;
bool ok_;
@@ -211,9 +211,9 @@ class VKShaderModule : public ShaderModule {
};
bool VKShaderModule::Compile(VulkanContext *vulkan, ShaderLanguage language, const uint8_t *data, size_t size) {
vulkan_ = vulkan;
// We'll need this to free it later.
device_ = vulkan->GetDevice();
this->source_ = (const char *)data;
source_ = (const char *)data;
std::vector<uint32_t> spirv;
if (!GLSLtoSPV(vkstage_, source_.c_str(), spirv)) {
return false;
@@ -31,7 +31,9 @@ void PrioritizedWorkQueue::Flush() {
flush_count++;
}
queue_.clear();
ILOG("Flushed %d un-executed tasks", flush_count);
if (flush_count > 0) {
ILOG("PrioritizedWorkQueue: Flushed %d un-executed tasks", flush_count);
}
}
bool PrioritizedWorkQueue::WaitUntilDone(bool all) {

0 comments on commit 8b42d83

Please sign in to comment.