Commit 823d8973 by Shahbaz Youssefi Committed by Commit Bot

Vulkan: Internal Compute support

While this is not exposed to the front end yet, this commit adds support for creating Compute pipelines for internal usage. Bug: angleproject:2959 Change-Id: I976eae1ce0f736c257b7b4ae0d1c3b2d9f4da5bb Reviewed-on: https://chromium-review.googlesource.com/c/1333972 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent df066e9c
......@@ -513,10 +513,11 @@ angle::Result RendererVk::initialize(DisplayVk *displayVk,
size_t graphicsQueueFamilyCount = false;
uint32_t firstGraphicsQueueFamily = 0;
constexpr VkQueueFlags kGraphicsAndCompute = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT;
for (uint32_t familyIndex = 0; familyIndex < queueCount; ++familyIndex)
{
const auto &queueInfo = mQueueFamilyProperties[familyIndex];
if ((queueInfo.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0)
if ((queueInfo.queueFlags & kGraphicsAndCompute) == kGraphicsAndCompute)
{
ASSERT(queueInfo.queueCount > 0);
graphicsQueueFamilyCount++;
......@@ -691,10 +692,11 @@ angle::Result RendererVk::selectPresentQueueForSurface(DisplayVk *displayVk,
// Find a graphics and present queue.
Optional<uint32_t> newPresentQueue;
uint32_t queueCount = static_cast<uint32_t>(mQueueFamilyProperties.size());
constexpr VkQueueFlags kGraphicsAndCompute = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT;
for (uint32_t queueIndex = 0; queueIndex < queueCount; ++queueIndex)
{
const auto &queueInfo = mQueueFamilyProperties[queueIndex];
if ((queueInfo.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0)
if ((queueInfo.queueFlags & kGraphicsAndCompute) == kGraphicsAndCompute)
{
VkBool32 supportsPresent = VK_FALSE;
ANGLE_VK_TRY(displayVk, vkGetPhysicalDeviceSurfaceSupportKHR(
......
......@@ -1003,7 +1003,8 @@ void PipelineLayoutDesc::updatePushConstantRange(gl::ShaderType shaderType,
uint32_t offset,
uint32_t size)
{
ASSERT(shaderType == gl::ShaderType::Vertex || shaderType == gl::ShaderType::Fragment);
ASSERT(shaderType == gl::ShaderType::Vertex || shaderType == gl::ShaderType::Fragment ||
shaderType == gl::ShaderType::Compute);
PackedPushConstantRange &packed = mPushConstantRanges[static_cast<size_t>(shaderType)];
packed.offset = offset;
packed.size = size;
......
......@@ -1486,6 +1486,7 @@ bool ShaderProgramHelper::valid() const
void ShaderProgramHelper::destroy(VkDevice device)
{
mGraphicsPipelines.destroy(device);
mComputePipeline.destroy(device);
for (BindingPointer<ShaderAndSerial> &shader : mShaders)
{
shader.reset();
......@@ -1495,6 +1496,7 @@ void ShaderProgramHelper::destroy(VkDevice device)
void ShaderProgramHelper::release(RendererVk *renderer)
{
mGraphicsPipelines.release(renderer);
renderer->releaseObject(mComputePipeline.getSerial(), &mComputePipeline.get());
for (BindingPointer<ShaderAndSerial> &shader : mShaders)
{
shader.reset();
......@@ -1526,5 +1528,41 @@ angle::Result ShaderProgramHelper::getGraphicsPipeline(
mShaders[gl::ShaderType::Fragment].get().get(), pipelineDesc, pipelineOut);
}
angle::Result ShaderProgramHelper::getComputePipeline(Context *context,
const PipelineLayout &pipelineLayout,
PipelineAndSerial **pipelineOut)
{
if (mComputePipeline.valid())
{
*pipelineOut = &mComputePipeline;
return angle::Result::Continue();
}
RendererVk *renderer = context->getRenderer();
VkPipelineShaderStageCreateInfo shaderStage = {};
VkComputePipelineCreateInfo createInfo = {};
shaderStage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
shaderStage.flags = 0;
shaderStage.stage = VK_SHADER_STAGE_COMPUTE_BIT;
shaderStage.module = mShaders[gl::ShaderType::Compute].get().get().getHandle();
shaderStage.pName = "main";
shaderStage.pSpecializationInfo = nullptr;
createInfo.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO;
createInfo.flags = 0;
createInfo.stage = shaderStage;
createInfo.layout = pipelineLayout.getHandle();
createInfo.basePipelineHandle = VK_NULL_HANDLE;
createInfo.basePipelineIndex = 0;
ANGLE_VK_TRY(context, mComputePipeline.get().initCompute(context->getDevice(), createInfo,
renderer->getPipelineCache()));
*pipelineOut = &mComputePipeline;
return angle::Result::Continue();
}
} // namespace vk
} // namespace rx
......@@ -574,10 +574,14 @@ class ShaderProgramHelper : angle::NonCopyable
const GraphicsPipelineDesc &pipelineDesc,
const gl::AttributesMask &activeAttribLocationsMask,
PipelineAndSerial **pipelineOut);
angle::Result getComputePipeline(Context *context,
const PipelineLayout &pipelineLayout,
PipelineAndSerial **pipelineOut);
private:
gl::ShaderMap<BindingPointer<ShaderAndSerial>> mShaders;
GraphicsPipelineCache mGraphicsPipelines;
PipelineAndSerial mComputePipeline;
};
} // namespace vk
} // namespace rx
......
......@@ -949,6 +949,15 @@ VkResult Pipeline::initGraphics(VkDevice device,
&mHandle);
}
VkResult Pipeline::initCompute(VkDevice device,
const VkComputePipelineCreateInfo &createInfo,
const PipelineCache &pipelineCacheVk)
{
ASSERT(!valid());
return vkCreateComputePipelines(device, pipelineCacheVk.getHandle(), 1, &createInfo, nullptr,
&mHandle);
}
// DescriptorSetLayout implementation.
DescriptorSetLayout::DescriptorSetLayout()
{
......
......@@ -582,6 +582,9 @@ class Pipeline final : public WrappedObject<Pipeline, VkPipeline>
VkResult initGraphics(VkDevice device,
const VkGraphicsPipelineCreateInfo &createInfo,
const PipelineCache &pipelineCacheVk);
VkResult initCompute(VkDevice device,
const VkComputePipelineCreateInfo &createInfo,
const PipelineCache &pipelineCacheVk);
};
class DescriptorSetLayout final : public WrappedObject<DescriptorSetLayout, VkDescriptorSetLayout>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment