Some descriptor binding fixes

This commit is contained in:
Henrik Rydgard committed 2016-03-20 19:30:11 +01:00
1 parent 906b259a85
commit ddb36a35a0
5 files changed
+47 -24

No files matched your search

+21 -16
View File
@@ -93,12 +93,13 @@ DrawEngineVulkan::DrawEngineVulkan(VulkanContext *vulkan)
indexGen.Setup(decIndex);
// All resources we need for PSP drawing. Usually only bindings 0 and 2-4 are populated.
VkDescriptorSetLayoutBinding bindings[5];
bindings[0].descriptorCount = 1;
bindings[0].pImmutableSamplers = nullptr;
bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
bindings[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
bindings[0].binding = 1;
bindings[0].binding = 0;
bindings[1].descriptorCount = 1;
bindings[1].pImmutableSamplers = nullptr;
bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
@@ -118,7 +119,7 @@ DrawEngineVulkan::DrawEngineVulkan(VulkanContext *vulkan)
bindings[4].pImmutableSamplers = nullptr;
bindings[4].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
bindings[4].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
bindings[4].binding = 3;
bindings[4].binding = 4;
VkDevice device = vulkan_->GetDevice();
@@ -152,6 +153,7 @@ DrawEngineVulkan::DrawEngineVulkan(VulkanContext *vulkan)
for (int i = 0; i < 2; i++) {
VkResult res = vkCreateDescriptorPool(vulkan_->GetDevice(), &dp, nullptr, &frame_[i].descPool);
assert(VK_SUCCESS == res);
frame_[i].pushData = new VulkanPushBuffer(vulkan_, 4 * 1024 * 1024); // TODO: Do something more dynamic
}
VkPipelineLayoutCreateInfo pl;
@@ -166,6 +168,12 @@ DrawEngineVulkan::DrawEngineVulkan(VulkanContext *vulkan)
assert(VK_SUCCESS == res);
}
void DrawEngineVulkan::BeginFrame() {
FrameData *frame = &frame_[curFrame_ & 1];
vkResetDescriptorPool(vulkan_->GetDevice(), frame->descPool, 0);
frame->pushData->Reset();
}
void DrawEngineVulkan::EndFrame() {
curFrame_++;
}
@@ -176,6 +184,11 @@ DrawEngineVulkan::~DrawEngineVulkan() {
FreeMemoryPages(splineBuffer, SPLINE_BUFFER_SIZE);
FreeMemoryPages(transformed, TRANSFORMED_VERTEX_BUFFER_SIZE);
FreeMemoryPages(transformedExpanded, 3 * TRANSFORMED_VERTEX_BUFFER_SIZE);
for (int i = 0; i < 2; i++) {
vulkan_->QueueDelete(frame_[i].descPool);
delete frame_[i].pushData;
}
}
VertexDecoder *DrawEngineVulkan::GetVertexDecoder(u32 vtype) {
@@ -350,20 +363,11 @@ inline u32 ComputeMiniHashRange(const void *ptr, size_t sz) {
}
}
/*
struct DescriptorSetKey {
void *texture_;
void *secondaryTexture_;
bool operator < (const DescriptorSetKey &other) const {
if (texture_ < other.texture_) return true; else if (texture_ > other.texture_) return false;
if (secondaryTexture_ < other.secondaryTexture_) return true; else if (secondaryTexture_ > other.secondaryTexture_) return false;
return false;
}
};
*/
VkDescriptorSet DrawEngineVulkan::GetDescriptorSet(CachedTextureVulkan *texture) {
DescriptorSetKey key;
key.texture_ = texture;
key.secondaryTexture_ = nullptr;
VkDescriptorSet DrawEngineVulkan::GetDescriptorSet() {
return nullptr;
}
@@ -373,9 +377,10 @@ void DrawEngineVulkan::DoFlush(VkCommandBuffer cmd) {
FrameData *frame = &frame_[curFrame_ & 1];
CachedTextureVulkan *tex = nullptr;
// This is not done on every drawcall, we should collect vertex data
// until critical state changes. That's when we draw (flush).
VkDescriptorSet ds = GetDescriptorSet();
VkDescriptorSet ds = GetDescriptorSet(tex);
GEPrimitiveType prim = prevPrim_;
// ApplyDrawState(prim);
+17 -2
View File
@@ -29,7 +29,7 @@
// The format of the various uniform buffers may vary though - vertex shaders that don't skin
// won't get any bone data, etc.
#include <map>
#include <unordered_map>
#include "GPU/Vulkan/VulkanUtil.h"
@@ -48,6 +48,7 @@ class ShaderManagerVulkan;
class PipelineManagerVulkan;
class TextureCacheVulkan;
class FramebufferManagerVulkan;
class CachedTextureVulkan;
// Avoiding the full include of TextureDecoder.h.
#if (defined(_M_SSE) && defined(_M_X64)) || defined(ARM64)
@@ -140,6 +141,7 @@ public:
return pipelineLayout_;
}
void BeginFrame();
void EndFrame();
private:
@@ -147,7 +149,7 @@ private:
void DecodeVertsStep();
void DoFlush(VkCommandBuffer cmd);
VkDescriptorSet GetDescriptorSet();
VkDescriptorSet GetDescriptorSet(CachedTextureVulkan *texture);
VertexDecoder *GetVertexDecoder(u32 vtype);
@@ -157,10 +159,23 @@ private:
VkDescriptorSetLayout descriptorSetLayout_;
VkPipelineLayout pipelineLayout_;
struct DescriptorSetKey {
void *texture_;
void *secondaryTexture_;
bool operator < (const DescriptorSetKey &other) const {
if (texture_ < other.texture_) return true; else if (texture_ > other.texture_) return false;
if (secondaryTexture_ < other.secondaryTexture_) return true; else if (secondaryTexture_ > other.secondaryTexture_) return false;
return false;
}
};
// We alternate between these.
struct FrameData {
VkDescriptorPool descPool;
VulkanPushBuffer *pushData;
// We do rolling allocation and reset instead of caching across frames. That we might do later.
std::map<DescriptorSetKey, VkDescriptorSet> descSets;
};
int curFrame_;
+1 -1
View File
@@ -92,7 +92,7 @@ bool GenerateVulkanGLSLFragmentShader(const ShaderID &id, char *buffer) {
const char *shading = doFlatShading ? "flat" : "";
WRITE(p, "layout (std140, set = 0, binding = 3) uniform baseUBO {\n%s} base;\n", ub_baseStr);
WRITE(p, "layout (std140, set = 0, binding = 2) uniform baseUBO {\n%s} base;\n", ub_baseStr);
if (doTexture) {
WRITE(p, "layout (binding = 0) uniform sampler2D tex;\n");
}
+3 -3
View File
@@ -138,11 +138,11 @@ bool GenerateVulkanGLSLVertexShader(const ShaderID &id, char *buffer) {
// are present and what parts aren't, but we will not be ultra detailed about it.
WRITE(p, "\n");
WRITE(p, "layout (std140, set = 0, binding = 3) uniform baseVars {\n%s\n} base;\n", ub_baseStr);
WRITE(p, "layout (std140, set = 0, binding = 2) uniform baseVars {\n%s\n} base;\n", ub_baseStr);
if (enableLighting)
WRITE(p, "layout (std140, set = 0, binding = 4) uniform lightVars {\n%s\n} light;\n", ub_vs_lightsStr);
WRITE(p, "layout (std140, set = 0, binding = 3) uniform lightVars {\n%s\n} light;\n", ub_vs_lightsStr);
if (enableBones)
WRITE(p, "layout (std140, set = 0, binding = 5) uniform boneVars {\n%s\n} bone;\n", ub_vs_bonesStr);
WRITE(p, "layout (std140, set = 0, binding = 4) uniform boneVars {\n%s\n} bone;\n", ub_vs_bonesStr);
const char *shading = doFlatShading ? "flat " : "";
+5 -2
View File
@@ -68,6 +68,7 @@ struct layer_properties {
// This is a bit repetitive...
class VulkanDeleteList {
public:
void QueueDelete(VkDescriptorPool pool) { descPools_.push_back(pool); }
void QueueDelete(VkShaderModule module) { modules_.push_back(module); }
void QueueDelete(VkBuffer buffer) { buffers_.push_back(buffer); }
void QueueDelete(VkBufferView bufferView) { bufferViews_.push_back(bufferView); }
@@ -76,6 +77,7 @@ public:
void QueueDelete(VkDeviceMemory deviceMemory) { memory_.push_back(deviceMemory); }
void Ingest(VulkanDeleteList &del) {
descPools_ = std::move(del.descPools_);
modules_ = std::move(del.modules_);
buffers_ = std::move(del.buffers_);
bufferViews_ = std::move(del.bufferViews_);
@@ -85,8 +87,8 @@ public:
}
void PerformDeletes(VkDevice device) {
for (auto &module : modules_) {
vkDestroyShaderModule(device, module, nullptr);
for (auto &descPool : descPools_) {
vkDestroyDescriptorPool(device, descPool, nullptr);
}
modules_.clear();
for (auto &buf : buffers_) {
@@ -112,6 +114,7 @@ public:
}
private:
std::vector<VkDescriptorPool> descPools_;
std::vector<VkShaderModule> modules_;
std::vector<VkBuffer> buffers_;
std::vector<VkBufferView> bufferViews_;