Change render passes from multi to single pass.

This as an API change to get closer to the direction in which WebGPU is
headed. The API change in next.json caused a ton of files to be changed
in the same commit to keep things compiling.

API: the Framebuffer and RenderPass objects are now merged in a single
RenderPassInfo that contains the attachments, loadOps and clear values
for a BeginRenderPass command. The concept of subpass is removed.
The RenderPass creation argument to RenderPipelines is replaced by
explicitly setting the format of attachments for RenderPipeline.

Validation: SetPipeline checks are changed to check that the attachments
info set on a RenderPipeline matches the attachments of the render pass.

Backends: Most changes are simplifications of the backends that no
longer require and indirection to query the current subpass out of the
render pass in BeginSubpass, and don't need to get the attachment info
from a RenderPass when creating RenderPipelines. In the Vulkan backend,
a VkRenderPass cache is added to reuse VkRenderPasses between
RenderPassInfos and RenderPipelines.

Tests and examples: they are updated with the simplified API. Tests
specific to the Framebuffer and RenderPass objects were removed and
validation tests for RenderPassInfo were added.

Tested by running CppHelloTriangle on all backends, end2end tests on all
platforms and all examples on the GL backend.
This commit is contained in:
Corentin Wallez
2018-05-02 18:10:13 -04:00
committed by Corentin Wallez
parent 87ec361cc2
commit 6f7749cce9
92 changed files with 1869 additions and 3168 deletions

View File

@@ -32,7 +32,6 @@ nxt::Buffer modelBuffer;
std::array<nxt::Buffer, 2> particleBuffers;
nxt::RenderPipeline renderPipeline;
nxt::RenderPass renderpass;
nxt::Buffer updateParams;
nxt::ComputePipeline updatePipeline;
@@ -123,11 +122,11 @@ void initRender() {
.SetInput(1, sizeof(glm::vec2), nxt::InputStepMode::Vertex)
.GetResult();
renderpass = CreateDefaultRenderPass(device);
depthStencilView = CreateDefaultDepthStencilView(device);
renderPipeline = device.CreateRenderPipelineBuilder()
.SetSubpass(renderpass, 0)
.SetColorAttachmentFormat(0, GetPreferredSwapChainTextureFormat())
.SetDepthStencilAttachmentFormat(nxt::TextureFormat::D32FloatS8Uint)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
.SetInputState(inputState)
@@ -260,7 +259,7 @@ void initSim() {
}
}
nxt::CommandBuffer createCommandBuffer(const nxt::Framebuffer& framebuffer, size_t i) {
nxt::CommandBuffer createCommandBuffer(const nxt::RenderPassInfo& renderPass, size_t i) {
static const uint32_t zeroOffsets[1] = {0};
auto& bufferSrc = particleBuffers[i];
auto& bufferDst = particleBuffers[(i + 1) % 2];
@@ -273,14 +272,12 @@ nxt::CommandBuffer createCommandBuffer(const nxt::Framebuffer& framebuffer, size
.Dispatch(kNumParticles, 1, 1)
.EndComputePass()
.BeginRenderPass(renderpass, framebuffer)
.BeginRenderSubpass()
.BeginRenderPass(renderPass)
.SetRenderPipeline(renderPipeline)
.TransitionBufferUsage(bufferDst, nxt::BufferUsageBit::Vertex)
.SetVertexBuffers(0, 1, &bufferDst, zeroOffsets)
.SetVertexBuffers(1, 1, &modelBuffer, zeroOffsets)
.DrawArrays(3, kNumParticles, 0, 0)
.EndRenderSubpass()
.EndRenderPass()
.GetResult();
@@ -301,10 +298,10 @@ void init() {
void frame() {
nxt::Texture backbuffer;
nxt::Framebuffer framebuffer;
GetNextFramebuffer(device, renderpass, swapchain, depthStencilView, &backbuffer, &framebuffer);
nxt::RenderPassInfo renderPass;
GetNextRenderPassInfo(device, swapchain, depthStencilView, &backbuffer, &renderPass);
nxt::CommandBuffer commandBuffer = createCommandBuffer(framebuffer, pingpong);
nxt::CommandBuffer commandBuffer = createCommandBuffer(renderPass, pingpong);
queue.Submit(1, &commandBuffer);
backbuffer.TransitionUsage(nxt::TextureUsageBit::Present);
swapchain.Present(backbuffer);