Add support for getting vulkan descriptor sets without a GrVkUniformHandler.

This change allows us to use the current descriptor set system for doing
copies as draws. This is a step towards being able to track resources for draws
that don't go through out normal pipeline.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2275633002

Review-Url: https://codereview.chromium.org/2275633002
This commit is contained in:
egdaniel 2016-08-25 13:52:00 -07:00 committed by Commit bot
parent 1c9f55b468
commit 4d866dfc46
4 changed files with 105 additions and 7 deletions

View File

@ -31,6 +31,26 @@ GrVkDescriptorSetManager::GrVkDescriptorSetManager(GrVkGpu* gpu,
}
}
GrVkDescriptorSetManager::GrVkDescriptorSetManager(GrVkGpu* gpu,
VkDescriptorType type,
const SkTArray<uint32_t>& visibilities)
: fPoolManager(type, gpu, visibilities) {
if (type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) {
for (int i = 0; i < visibilities.count(); ++i) {
fBindingVisibilities.push_back(visibilities[i]);
}
} else {
SkASSERT(type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
SkASSERT(2 == visibilities.count() &&
kVertex_GrShaderFlag == visibilities[0] &&
kFragment_GrShaderFlag == visibilities[1]);
// We set the visibility of the first binding to the vertex shader and the second to the
// fragment shader.
fBindingVisibilities.push_back(kVertex_GrShaderFlag);
fBindingVisibilities.push_back(kFragment_GrShaderFlag);
}
}
const GrVkDescriptorSet* GrVkDescriptorSetManager::getDescriptorSet(GrVkGpu* gpu,
const Handle& handle) {
const GrVkDescriptorSet* ds = nullptr;
@ -91,6 +111,25 @@ bool GrVkDescriptorSetManager::isCompatible(VkDescriptorType type,
return true;
}
bool GrVkDescriptorSetManager::isCompatible(VkDescriptorType type,
const SkTArray<uint32_t>& visibilities) const {
if (type != fPoolManager.fDescType) {
return false;
}
if (type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) {
if (fBindingVisibilities.count() != visibilities.count()) {
return false;
}
for (int i = 0; i < visibilities.count(); ++i) {
if (visibilities[i] != fBindingVisibilities[i]) {
return false;
}
}
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
VkShaderStageFlags visibility_to_vk_stage_flags(uint32_t visibility) {
@ -115,20 +154,48 @@ GrVkDescriptorSetManager::DescriptorPoolManager::DescriptorPoolManager(
: fDescType(type)
, fCurrentDescriptorCount(0)
, fPool(nullptr) {
this->init(gpu, type, uniformHandler, nullptr);
}
GrVkDescriptorSetManager::DescriptorPoolManager::DescriptorPoolManager(
VkDescriptorType type,
GrVkGpu* gpu,
const SkTArray<uint32_t>& visibilities)
: fDescType(type)
, fCurrentDescriptorCount(0)
, fPool(nullptr) {
this->init(gpu, type, nullptr, &visibilities);
}
void GrVkDescriptorSetManager::DescriptorPoolManager::init(GrVkGpu* gpu,
VkDescriptorType type,
const GrVkUniformHandler* uniformHandler,
const SkTArray<uint32_t>* visibilities) {
if (type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) {
SkASSERT(uniformHandler);
uint32_t numSamplers = (uint32_t)uniformHandler->numSamplers();
SkASSERT(SkToBool(uniformHandler) != SkToBool(visibilities));
uint32_t numSamplers;
if (uniformHandler) {
numSamplers = (uint32_t)uniformHandler->numSamplers();
} else {
numSamplers = (uint32_t)visibilities->count();
}
SkAutoTDeleteArray<VkDescriptorSetLayoutBinding> dsSamplerBindings(
new VkDescriptorSetLayoutBinding[numSamplers]);
new VkDescriptorSetLayoutBinding[numSamplers]);
for (uint32_t i = 0; i < numSamplers; ++i) {
const GrVkGLSLSampler& sampler =
uint32_t visibility;
if (uniformHandler) {
const GrVkGLSLSampler& sampler =
static_cast<const GrVkGLSLSampler&>(uniformHandler->getSampler(i));
SkASSERT(sampler.binding() == i);
dsSamplerBindings[i].binding = sampler.binding();
SkASSERT(sampler.binding() == i);
visibility = sampler.visibility();
} else {
visibility = (*visibilities)[i];
}
dsSamplerBindings[i].binding = i;
dsSamplerBindings[i].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
dsSamplerBindings[i].descriptorCount = 1;
dsSamplerBindings[i].stageFlags = visibility_to_vk_stage_flags(sampler.visibility());
dsSamplerBindings[i].stageFlags = visibility_to_vk_stage_flags(visibility);
dsSamplerBindings[i].pImmutableSamplers = nullptr;
}

View File

@ -29,6 +29,11 @@ public:
GrVkDescriptorSetManager(GrVkGpu* gpu,
VkDescriptorType,
const GrVkUniformHandler* handler = nullptr);
GrVkDescriptorSetManager(GrVkGpu* gpu,
VkDescriptorType,
const SkTArray<uint32_t>& visibilities);
~GrVkDescriptorSetManager() {}
void abandon();
@ -41,11 +46,16 @@ public:
void recycleDescriptorSet(const GrVkDescriptorSet*);
bool isCompatible(VkDescriptorType type, const GrVkUniformHandler*) const;
bool isCompatible(VkDescriptorType type,
const SkTArray<uint32_t>& visibilities) const;
private:
struct DescriptorPoolManager {
DescriptorPoolManager(VkDescriptorType type, GrVkGpu* gpu,
const GrVkUniformHandler* handler = nullptr);
DescriptorPoolManager(VkDescriptorType type, GrVkGpu* gpu,
const SkTArray<uint32_t>& visibilities);
~DescriptorPoolManager() {
SkASSERT(!fDescLayout);
@ -71,6 +81,9 @@ private:
kStartNumDescriptors = 16, // must be less than kMaxUniformDescriptors
};
void init(GrVkGpu* gpu, VkDescriptorType type, const GrVkUniformHandler* uniformHandler,
const SkTArray<uint32_t>* visibilities);
void getNewPool(GrVkGpu* gpu);
};

View File

@ -177,6 +177,22 @@ void GrVkResourceProvider::getSamplerDescriptorSetHandle(const GrVkUniformHandle
*handle = GrVkDescriptorSetManager::Handle(fDescriptorSetManagers.count() - 1);
}
void GrVkResourceProvider::getSamplerDescriptorSetHandle(const SkTArray<uint32_t>& visibilities,
GrVkDescriptorSetManager::Handle* handle) {
SkASSERT(handle);
for (int i = 0; i < fDescriptorSetManagers.count(); ++i) {
if (fDescriptorSetManagers[i].isCompatible(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
visibilities)) {
*handle = GrVkDescriptorSetManager::Handle(i);
return;
}
}
fDescriptorSetManagers.emplace_back(fGpu, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
visibilities);
*handle = GrVkDescriptorSetManager::Handle(fDescriptorSetManagers.count() - 1);
}
VkDescriptorSetLayout GrVkResourceProvider::getUniformDSLayout() const {
SkASSERT(fUniformDSHandle.isValid());
return fDescriptorSetManagers[fUniformDSHandle.toIndex()].layout();

View File

@ -104,6 +104,8 @@ public:
void getSamplerDescriptorSetHandle(const GrVkUniformHandler&,
GrVkDescriptorSetManager::Handle* handle);
void getSamplerDescriptorSetHandle(const SkTArray<uint32_t>& visibilities,
GrVkDescriptorSetManager::Handle* handle);
// Returns the compatible VkDescriptorSetLayout to use for uniform buffers. The caller does not
// own the VkDescriptorSetLayout and thus should not delete it. This function should be used