Split Pipeline in Render and Compute, examples part

This commit is contained in:
Corentin Wallez 2017-07-14 11:32:57 -04:00 committed by Corentin Wallez
parent b085eecb31
commit 66ff447216
12 changed files with 56 additions and 56 deletions

View File

@ -22,7 +22,7 @@
nxt::Device device;
nxt::Queue queue;
nxt::Pipeline pipeline;
nxt::RenderPipeline pipeline;
nxt::RenderPass renderpass;
nxt::Framebuffer framebuffer;
@ -105,7 +105,7 @@ void init() {
);
utils::CreateDefaultRenderPass(device, &renderpass, &framebuffer);
pipeline = device.CreatePipelineBuilder()
pipeline = device.CreateRenderPipelineBuilder()
.SetSubpass(renderpass, 0)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
@ -134,7 +134,7 @@ void frame() {
nxt::CommandBufferBuilder builder = device.CreateCommandBufferBuilder()
.BeginRenderPass(renderpass, framebuffer)
.BeginRenderSubpass()
.SetPipeline(pipeline)
.SetRenderPipeline(pipeline)
.Clone();
for (int k = 0; k < 200; k++) {

View File

@ -18,7 +18,7 @@
nxtDevice device;
nxtQueue queue;
nxtPipeline pipeline;
nxtRenderPipeline pipeline;
nxtRenderPass renderpass;
nxtFramebuffer framebuffer;
@ -64,12 +64,12 @@ void init() {
nxtFramebufferBuilderRelease(builder);
}
{
nxtPipelineBuilder builder = nxtDeviceCreatePipelineBuilder(device);
nxtPipelineBuilderSetSubpass(builder, renderpass, 0);
nxtPipelineBuilderSetStage(builder, NXT_SHADER_STAGE_VERTEX, vsModule, "main");
nxtPipelineBuilderSetStage(builder, NXT_SHADER_STAGE_FRAGMENT, fsModule, "main");
pipeline = nxtPipelineBuilderGetResult(builder);
nxtPipelineBuilderRelease(builder);
nxtRenderPipelineBuilder builder = nxtDeviceCreateRenderPipelineBuilder(device);
nxtRenderPipelineBuilderSetSubpass(builder, renderpass, 0);
nxtRenderPipelineBuilderSetStage(builder, NXT_SHADER_STAGE_VERTEX, vsModule, "main");
nxtRenderPipelineBuilderSetStage(builder, NXT_SHADER_STAGE_FRAGMENT, fsModule, "main");
pipeline = nxtRenderPipelineBuilderGetResult(builder);
nxtRenderPipelineBuilderRelease(builder);
}
nxtShaderModuleRelease(vsModule);
@ -82,7 +82,7 @@ void frame() {
nxtCommandBufferBuilder builder = nxtDeviceCreateCommandBufferBuilder(device);
nxtCommandBufferBuilderBeginRenderPass(builder, renderpass, framebuffer);
nxtCommandBufferBuilderBeginRenderSubpass(builder);
nxtCommandBufferBuilderSetPipeline(builder, pipeline);
nxtCommandBufferBuilderSetRenderPipeline(builder, pipeline);
nxtCommandBufferBuilderDrawArrays(builder, 3, 1, 0, 0);
nxtCommandBufferBuilderEndRenderSubpass(builder);
nxtCommandBufferBuilderEndRenderPass(builder);

View File

@ -28,12 +28,12 @@ nxt::Queue queue;
nxt::Buffer modelBuffer;
std::array<nxt::Buffer, 2> particleBuffers;
nxt::Pipeline renderPipeline;
nxt::RenderPipeline renderPipeline;
nxt::RenderPass renderpass;
nxt::Framebuffer framebuffer;
nxt::Buffer updateParams;
nxt::Pipeline updatePipeline;
nxt::ComputePipeline updatePipeline;
std::array<nxt::BindGroup, 2> updateBGs;
std::array<nxt::CommandBuffer, 2> commandBuffers;
@ -124,7 +124,7 @@ void initRender() {
.GetResult();
utils::CreateDefaultRenderPass(device, &renderpass, &framebuffer);
renderPipeline = device.CreatePipelineBuilder()
renderPipeline = device.CreateRenderPipelineBuilder()
.SetSubpass(renderpass, 0)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
@ -231,7 +231,7 @@ void initSim() {
.SetBindGroupLayout(0, bgl)
.GetResult();
updatePipeline = device.CreatePipelineBuilder()
updatePipeline = device.CreateComputePipelineBuilder()
.SetLayout(pl)
.SetStage(nxt::ShaderStage::Compute, module, "main")
.GetResult();
@ -265,7 +265,7 @@ void initCommandBuffers() {
auto& bufferDst = particleBuffers[(i + 1) % 2];
commandBuffers[i] = device.CreateCommandBufferBuilder()
.BeginComputePass()
.SetPipeline(updatePipeline)
.SetComputePipeline(updatePipeline)
.TransitionBufferUsage(bufferSrc, nxt::BufferUsageBit::Storage)
.TransitionBufferUsage(bufferDst, nxt::BufferUsageBit::Storage)
.SetBindGroup(0, updateBGs[i])
@ -274,7 +274,7 @@ void initCommandBuffers() {
.BeginRenderPass(renderpass, framebuffer)
.BeginRenderSubpass()
.SetPipeline(renderPipeline)
.SetRenderPipeline(renderPipeline)
.TransitionBufferUsage(bufferDst, nxt::BufferUsageBit::Vertex)
.SetVertexBuffers(0, 1, &bufferDst, zeroOffsets)
.SetVertexBuffers(1, 1, &modelBuffer, zeroOffsets)

View File

@ -21,11 +21,11 @@
nxt::Device device;
nxt::Queue queue;
nxt::Buffer buffer;
nxt::Pipeline renderPipeline;
nxt::RenderPipeline renderPipeline;
nxt::BindGroup renderBindGroup;
nxt::RenderPass renderpass;
nxt::Framebuffer framebuffer;
nxt::Pipeline computePipeline;
nxt::ComputePipeline computePipeline;
nxt::BindGroup computeBindGroup;
void init() {
@ -67,7 +67,7 @@ void init() {
.SetBindGroupLayout(0, bgl)
.GetResult();
computePipeline = device.CreatePipelineBuilder()
computePipeline = device.CreateComputePipelineBuilder()
.SetLayout(pl)
.SetStage(nxt::ShaderStage::Compute, module, "main")
.GetResult();
@ -109,7 +109,7 @@ void init() {
.GetResult();
utils::CreateDefaultRenderPass(device, &renderpass, &framebuffer);
renderPipeline = device.CreatePipelineBuilder()
renderPipeline = device.CreateRenderPipelineBuilder()
.SetSubpass(renderpass, 0)
.SetLayout(pl)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
@ -127,7 +127,7 @@ void init() {
void frame() {
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.BeginComputePass()
.SetPipeline(computePipeline)
.SetComputePipeline(computePipeline)
.TransitionBufferUsage(buffer, nxt::BufferUsageBit::Storage)
.SetBindGroup(0, computeBindGroup)
.Dispatch(1, 1, 1)
@ -135,7 +135,7 @@ void frame() {
.BeginRenderPass(renderpass, framebuffer)
.BeginRenderSubpass()
.SetPipeline(renderPipeline)
.SetRenderPipeline(renderPipeline)
.TransitionBufferUsage(buffer, nxt::BufferUsageBit::Uniform)
.SetBindGroup(0, renderBindGroup)
.DrawArrays(3, 1, 0, 0)

View File

@ -34,9 +34,9 @@ nxt::BindGroup bindGroup[2];
nxt::BindGroup cubeTransformBindGroup[2];
nxt::Queue queue;
nxt::Pipeline pipeline;
nxt::Pipeline planePipeline;
nxt::Pipeline reflectionPipeline;
nxt::RenderPipeline pipeline;
nxt::RenderPipeline planePipeline;
nxt::RenderPipeline reflectionPipeline;
nxt::RenderPass renderpass;
nxt::Framebuffer framebuffer;
@ -212,7 +212,7 @@ void init() {
.SetDepthWriteEnabled(true)
.GetResult();
pipeline = device.CreatePipelineBuilder()
pipeline = device.CreateRenderPipelineBuilder()
.SetSubpass(renderpass, 0)
.SetLayout(pl)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
@ -227,7 +227,7 @@ void init() {
.SetStencilFunction(nxt::Face::Both, nxt::CompareFunction::Always, nxt::StencilOperation::Keep, nxt::StencilOperation::Keep, nxt::StencilOperation::Replace)
.GetResult();
planePipeline = device.CreatePipelineBuilder()
planePipeline = device.CreateRenderPipelineBuilder()
.SetSubpass(renderpass, 0)
.SetLayout(pl)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
@ -242,7 +242,7 @@ void init() {
.SetStencilFunction(nxt::Face::Both, nxt::CompareFunction::Equal, nxt::StencilOperation::Keep, nxt::StencilOperation::Keep, nxt::StencilOperation::Replace)
.GetResult();
reflectionPipeline = device.CreatePipelineBuilder()
reflectionPipeline = device.CreateRenderPipelineBuilder()
.SetSubpass(renderpass, 0)
.SetLayout(pl)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
@ -273,7 +273,7 @@ void frame() {
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.BeginRenderPass(renderpass, framebuffer)
.BeginRenderSubpass()
.SetPipeline(pipeline)
.SetRenderPipeline(pipeline)
.TransitionBufferUsage(cameraBuffer, nxt::BufferUsageBit::Uniform)
.SetBindGroup(0, bindGroup[0])
.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets)
@ -281,11 +281,11 @@ void frame() {
.DrawElements(36, 1, 0, 0)
.SetStencilReference(0x1)
.SetPipeline(planePipeline)
.SetRenderPipeline(planePipeline)
.SetVertexBuffers(0, 1, &planeBuffer, vertexBufferOffsets)
.DrawElements(6, 1, 0, 0)
.SetPipeline(reflectionPipeline)
.SetRenderPipeline(reflectionPipeline)
.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets)
.SetBindGroup(0, bindGroup[1])
.DrawElements(36, 1, 0, 0)

View File

@ -24,7 +24,7 @@ nxt::Buffer indexBuffer;
nxt::Buffer vertexBuffer;
nxt::Queue queue;
nxt::Pipeline pipeline;
nxt::RenderPipeline pipeline;
nxt::RenderPass renderpass;
nxt::Framebuffer framebuffer;
@ -71,7 +71,7 @@ void init() {
.GetResult();
utils::CreateDefaultRenderPass(device, &renderpass, &framebuffer);
pipeline = device.CreatePipelineBuilder()
pipeline = device.CreateRenderPipelineBuilder()
.SetSubpass(renderpass, 0)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
@ -84,7 +84,7 @@ void frame() {
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.BeginRenderPass(renderpass, framebuffer)
.BeginRenderSubpass()
.SetPipeline(pipeline)
.SetRenderPipeline(pipeline)
.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets)
.SetIndexBuffer(indexBuffer, 0, nxt::IndexFormat::Uint32)
.DrawElements(3, 1, 0, 0)

View File

@ -24,7 +24,7 @@ nxt::Buffer vertexBuffer;
nxt::Buffer instanceBuffer;
nxt::Queue queue;
nxt::Pipeline pipeline;
nxt::RenderPipeline pipeline;
nxt::RenderPass renderpass;
nxt::Framebuffer framebuffer;
@ -77,7 +77,7 @@ void init() {
.GetResult();
utils::CreateDefaultRenderPass(device, &renderpass, &framebuffer);
pipeline = device.CreatePipelineBuilder()
pipeline = device.CreateRenderPipelineBuilder()
.SetSubpass(renderpass, 0)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
@ -90,7 +90,7 @@ void frame() {
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.BeginRenderPass(renderpass, framebuffer)
.BeginRenderSubpass()
.SetPipeline(pipeline)
.SetRenderPipeline(pipeline)
.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets)
.SetVertexBuffers(1, 1, &instanceBuffer, vertexBufferOffsets)
.DrawArrays(3, 4, 0, 0)

View File

@ -27,7 +27,7 @@ nxt::Texture texture;
nxt::Sampler sampler;
nxt::Queue queue;
nxt::Pipeline pipeline;
nxt::RenderPipeline pipeline;
nxt::RenderPass renderpass;
nxt::Framebuffer framebuffer;
nxt::BindGroup bindGroup;
@ -118,7 +118,7 @@ void init() {
.GetResult();
utils::CreateDefaultRenderPass(device, &renderpass, &framebuffer);
pipeline = device.CreatePipelineBuilder()
pipeline = device.CreateRenderPipelineBuilder()
.SetSubpass(renderpass, 0)
.SetLayout(pl)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
@ -145,7 +145,7 @@ void frame() {
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.BeginRenderPass(renderpass, framebuffer)
.BeginRenderSubpass()
.SetPipeline(pipeline)
.SetRenderPipeline(pipeline)
.SetBindGroup(0, bindGroup)
.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets)
.SetIndexBuffer(indexBuffer, 0, nxt::IndexFormat::Uint32)

View File

@ -18,7 +18,7 @@
nxt::Device device;
nxt::Queue queue;
nxt::Pipeline pipeline;
nxt::RenderPipeline pipeline;
nxt::RenderPass renderpass;
nxt::Framebuffer framebuffer;
nxt::Buffer buffer;
@ -60,7 +60,7 @@ void init() {
.GetResult();
utils::CreateDefaultRenderPass(device, &renderpass, &framebuffer);
pipeline = device.CreatePipelineBuilder()
pipeline = device.CreateRenderPipelineBuilder()
.SetSubpass(renderpass, 0)
.SetLayout(pl)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
@ -95,7 +95,7 @@ void frame() {
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.BeginRenderPass(renderpass, framebuffer)
.BeginRenderSubpass()
.SetPipeline(pipeline)
.SetRenderPipeline(pipeline)
.TransitionBufferUsage(buffer, nxt::BufferUsageBit::Uniform)
.SetBindGroup(0, bindGroup)
.DrawArrays(3, 1, 0, 0)

View File

@ -23,7 +23,7 @@ nxt::Device device;
nxt::Buffer vertexBuffer;
nxt::Queue queue;
nxt::Pipeline pipeline;
nxt::RenderPipeline pipeline;
nxt::RenderPass renderpass;
nxt::Framebuffer framebuffer;
@ -65,7 +65,7 @@ void init() {
.GetResult();
utils::CreateDefaultRenderPass(device, &renderpass, &framebuffer);
pipeline = device.CreatePipelineBuilder()
pipeline = device.CreateRenderPipelineBuilder()
.SetSubpass(renderpass, 0)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
@ -78,7 +78,7 @@ void frame() {
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.BeginRenderPass(renderpass, framebuffer)
.BeginRenderSubpass()
.SetPipeline(pipeline)
.SetRenderPipeline(pipeline)
.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets)
.DrawArrays(3, 1, 0, 0)
.EndRenderSubpass()

View File

@ -28,8 +28,8 @@ nxt::TextureView renderTargetView;
nxt::Sampler samplerPost;
nxt::Queue queue;
nxt::Pipeline pipeline;
nxt::Pipeline pipelinePost;
nxt::RenderPipeline pipeline;
nxt::RenderPipeline pipelinePost;
nxt::BindGroup bindGroup;
nxt::RenderPass renderpass;
nxt::Framebuffer framebuffer;
@ -112,7 +112,7 @@ void initPipeline() {
.SetInput(0, 4 * sizeof(float), nxt::InputStepMode::Vertex)
.GetResult();
pipeline = device.CreatePipelineBuilder()
pipeline = device.CreateRenderPipelineBuilder()
.SetSubpass(renderpass, 0)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
@ -153,7 +153,7 @@ void initPipelinePost() {
.SetBindGroupLayout(0, bgl)
.GetResult();
pipelinePost = device.CreatePipelineBuilder()
pipelinePost = device.CreateRenderPipelineBuilder()
.SetSubpass(renderpass, 1)
.SetLayout(pl)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
@ -187,13 +187,13 @@ void frame() {
.BeginRenderPass(renderpass, framebuffer)
.BeginRenderSubpass()
// renderTarget implicitly locked to to Attachment usage (if not already frozen)
.SetPipeline(pipeline)
.SetRenderPipeline(pipeline)
.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets)
.DrawArrays(3, 1, 0, 0)
.EndRenderSubpass()
// renderTarget usage unlocked, but left in Attachment usage
.BeginRenderSubpass()
.SetPipeline(pipelinePost)
.SetRenderPipeline(pipelinePost)
.SetVertexBuffers(0, 1, &vertexBufferQuad, vertexBufferOffsets)
.TransitionTextureUsage(renderTarget, nxt::TextureUsageBit::Sampled)
.SetBindGroup(0, bindGroup)

View File

@ -62,7 +62,7 @@ namespace gl {
struct MaterialInfo {
nxt::Buffer uniformBuffer;
nxt::Pipeline pipeline;
nxt::RenderPipeline pipeline;
nxt::BindGroup bindGroup0;
std::map<uint32_t, std::string> slotSemantics;
};
@ -257,7 +257,7 @@ namespace {
auto pipelineLayout = device.CreatePipelineLayoutBuilder()
.SetBindGroupLayout(0, bindGroupLayout)
.GetResult();
auto pipeline = device.CreatePipelineBuilder()
auto pipeline = device.CreateRenderPipelineBuilder()
.SetSubpass(renderpass, 0)
.SetLayout(pipelineLayout)
.SetStage(nxt::ShaderStage::Vertex, oVSModule, "main")
@ -486,7 +486,7 @@ namespace {
reinterpret_cast<const uint32_t*>(&transforms));
cmd.BeginRenderPass(renderpass, framebuffer);
cmd.BeginRenderSubpass();
cmd.SetPipeline(material.pipeline);
cmd.SetRenderPipeline(material.pipeline);
cmd.TransitionBufferUsage(material.uniformBuffer, nxt::BufferUsageBit::Uniform);
cmd.SetBindGroup(0, material.bindGroup0);