Commit 895df0dd by Ben Clayton Committed by Chris Forbes

Migrate ComputeProgram to using Coroutines

This is a smallest-change migration: • The yield type is a dummy int. Nothing currently yields. • There's no handling of coroutine resumes. Bug: b/131672705 Change-Id: I238b1fa65c62ded7148816d87000103245373e33 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/30849 Presubmit-Ready: Ben Clayton <bclayton@google.com> Tested-by: 's avatarChris Forbes <chrisforbes@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 13dcbece
......@@ -198,14 +198,11 @@ namespace sw
}
void ComputeProgram::run(
Routine *routine, SpirvShader const *shader,
vk::DescriptorSet::Bindings const &descriptorSets,
vk::DescriptorSet::DynamicOffsets const &descriptorDynamicOffsets,
PushConstantStorage const &pushConstants,
uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ)
{
auto runWorkgroup = (void(*)(void*, int, int, int, int, int))(routine->getEntry());
auto &modes = shader->getModes();
auto invocationsPerSubgroup = SIMD::Width;
......@@ -242,7 +239,7 @@ namespace sw
{
for (uint32_t groupX = 0; groupX < groupCountX; groupX++)
{
runWorkgroup(&data, groupX, groupY, groupZ, 0, subgroupsPerWorkgroup);
(*this)(&data, groupX, groupY, groupZ, 0, subgroupsPerWorkgroup);
}
}
}
......
......@@ -17,7 +17,7 @@
#include "SpirvShader.hpp"
#include "Reactor/Reactor.hpp"
#include "Reactor/Coroutine.hpp"
#include "Device/Context.hpp"
#include "Vulkan/VkDescriptorSet.hpp"
......@@ -37,13 +37,13 @@ namespace sw
struct Constants;
// ComputeProgram builds a SPIR-V compute shader.
class ComputeProgram : public Function<Void(
Pointer<Byte> data,
Int workgroupX,
Int workgroupY,
Int workgroupZ,
Int firstSubgroup,
Int subgroupCount)>
class ComputeProgram : public Coroutine<int(
void* data,
int32_t workgroupX,
int32_t workgroupY,
int32_t workgroupZ,
int32_t firstSubgroup,
int32_t subgroupCount)>
{
public:
ComputeProgram(SpirvShader const *spirvShader, vk::PipelineLayout const *pipelineLayout, const vk::DescriptorSet::Bindings &descriptorSets);
......@@ -54,9 +54,7 @@ namespace sw
void generate();
// run executes the compute shader routine for all workgroups.
// TODO(bclayton): This probably does not belong here. Consider moving.
static void run(
Routine *routine, SpirvShader const *shader,
void run(
vk::DescriptorSet::Bindings const &descriptorSetBindings,
vk::DescriptorSet::DynamicOffsets const &descriptorDynamicOffsets,
PushConstantStorage const &pushConstants,
......
......@@ -533,6 +533,7 @@ ComputePipeline::ComputePipeline(const VkComputePipelineCreateInfo* pCreateInfo,
void ComputePipeline::destroyPipeline(const VkAllocationCallbacks* pAllocator)
{
delete shader;
delete program;
}
size_t ComputePipeline::ComputeRequiredAllocationSize(const VkComputePipelineCreateInfo* pCreateInfo)
......@@ -553,12 +554,9 @@ void ComputePipeline::compileShaders(const VkAllocationCallbacks* pAllocator, co
// FIXME(b/119409619): use allocator.
shader = new sw::SpirvShader(code, nullptr, 0);
vk::DescriptorSet::Bindings descriptorSets; // FIXME(b/129523279): Delay code generation until invoke time.
sw::ComputeProgram program(shader, layout, descriptorSets);
program.generate();
// TODO(bclayton): Cache program
routine = program("ComputeRoutine");
program = new sw::ComputeProgram(shader, layout, descriptorSets);
program->generate();
program->finalize();
}
void ComputePipeline::run(uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ,
......@@ -566,9 +564,8 @@ void ComputePipeline::run(uint32_t groupCountX, uint32_t groupCountY, uint32_t g
vk::DescriptorSet::DynamicOffsets const &descriptorDynamicOffsets,
sw::PushConstantStorage const &pushConstants)
{
ASSERT_OR_RETURN(routine != nullptr);
sw::ComputeProgram::run(
routine, shader,
ASSERT_OR_RETURN(program != nullptr);
program->run(
descriptorSets, descriptorDynamicOffsets, pushConstants,
groupCountX, groupCountY, groupCountZ);
}
......
......@@ -19,7 +19,11 @@
#include "Vulkan/VkDescriptorSet.hpp"
#include "Device/Renderer.hpp"
namespace sw { class SpirvShader; }
namespace sw
{
class ComputeProgram;
class SpirvShader;
}
namespace vk
{
......@@ -113,7 +117,7 @@ public:
protected:
sw::SpirvShader *shader = nullptr;
rr::Routine *routine = nullptr;
sw::ComputeProgram *program = nullptr;
};
static inline Pipeline* Cast(VkPipeline object)
......
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