Render Pipeline Descriptorization -- Part I

This patch remove render pipeline builder and use descriptor to create render pipeline.
Sub-objects in descriptor will be removed in future.

Bug: dawn:4
Change-Id: I58dd569c7be42c2648311847b939c681189c2854
Reviewed-on: https://dawn-review.googlesource.com/c/2180
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Yan, Shaobo
2018-12-10 19:47:22 +00:00
committed by Commit Bot service account
parent 07df605a2b
commit a49242766a
51 changed files with 916 additions and 763 deletions

View File

@@ -56,12 +56,62 @@ void init() {
dawnShaderModule fsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, fs).Release();
{
dawnRenderPipelineBuilder builder = dawnDeviceCreateRenderPipelineBuilder(device);
dawnRenderPipelineBuilderSetColorAttachmentFormat(builder, 0, swapChainFormat);
dawnRenderPipelineBuilderSetStage(builder, DAWN_SHADER_STAGE_VERTEX, vsModule, "main");
dawnRenderPipelineBuilderSetStage(builder, DAWN_SHADER_STAGE_FRAGMENT, fsModule, "main");
pipeline = dawnRenderPipelineBuilderGetResult(builder);
dawnRenderPipelineBuilderRelease(builder);
dawnRenderPipelineDescriptor descriptor;
descriptor.nextInChain = nullptr;
dawnPipelineStageDescriptor vertexStage;
vertexStage.nextInChain = nullptr;
vertexStage.module = vsModule;
vertexStage.entryPoint = "main";
descriptor.vertexStage = &vertexStage;
dawnPipelineStageDescriptor fragmentStage;
fragmentStage.nextInChain = nullptr;
fragmentStage.module = fsModule;
fragmentStage.entryPoint = "main";
descriptor.fragmentStage = &fragmentStage;
dawnAttachmentsStateDescriptor attachmentsState;
attachmentsState.nextInChain = nullptr;
attachmentsState.numColorAttachments = 1;
dawnAttachmentDescriptor colorAttachment = {nullptr, swapChainFormat};
attachmentsState.colorAttachments = &colorAttachment;
attachmentsState.hasDepthStencilAttachment = false;
// Even with hasDepthStencilAttachment = false, depthStencilAttachment must point to valid
// data because we don't have optional substructures yet.
attachmentsState.depthStencilAttachment = &colorAttachment;
descriptor.attachmentsState = &attachmentsState;
descriptor.sampleCount = 1;
descriptor.numBlendStates = 1;
dawnBlendStateBuilder blendStateBuilder = dawnDeviceCreateBlendStateBuilder(device);
dawnBlendState blendState = dawnBlendStateBuilderGetResult(blendStateBuilder);
descriptor.blendStates = &blendState;
dawnBlendStateBuilderRelease(blendStateBuilder);
dawnPipelineLayoutDescriptor pl;
pl.nextInChain = nullptr;
pl.numBindGroupLayouts = 0;
pl.bindGroupLayouts = nullptr;
descriptor.layout = dawnDeviceCreatePipelineLayout(device, &pl);
dawnInputStateBuilder inputStateBuilder = dawnDeviceCreateInputStateBuilder(device);
descriptor.inputState = dawnInputStateBuilderGetResult(inputStateBuilder);
dawnInputStateBuilderRelease(inputStateBuilder);
descriptor.indexFormat = DAWN_INDEX_FORMAT_UINT32;
descriptor.primitiveTopology = DAWN_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
dawnDepthStencilStateBuilder depthStencilBuilder = dawnDeviceCreateDepthStencilStateBuilder(device);
descriptor.depthStencilState = dawnDepthStencilStateBuilderGetResult(depthStencilBuilder);
dawnDepthStencilStateBuilderRelease(depthStencilBuilder);
pipeline = dawnDeviceCreateRenderPipeline(device, &descriptor);
dawnBlendStateRelease(descriptor.blendStates[0]);
dawnDepthStencilStateRelease(descriptor.depthStencilState);
dawnInputStateRelease(descriptor.inputState);
}
dawnShaderModuleRelease(vsModule);