Update samples to the new RenderPipelineDescriptor

Also does some updates for the new BindGroupLayoutEntry and
VertexFormats that were missed previously.

Bug: chromium:1177501
Change-Id: Icb336590673158538a1586a1f8d5ace398fb381e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/45282
Reviewed-by: Brandon Jones <bajones@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez
2021-03-18 16:46:58 +00:00
committed by Commit Bot service account
parent 8ce8271c34
commit 9895c273d6
6 changed files with 147 additions and 140 deletions

View File

@@ -143,20 +143,23 @@ void init() {
return;
})");
utils::ComboVertexStateDescriptor vertexState;
vertexState.cVertexBuffers[0].attributeCount = 2;
vertexState.cAttributes[0].format = wgpu::VertexFormat::Float3;
vertexState.cAttributes[1].shaderLocation = 1;
vertexState.cAttributes[1].offset = 3 * sizeof(float);
vertexState.cAttributes[1].format = wgpu::VertexFormat::Float3;
wgpu::VertexAttribute attributes[2];
attributes[0].shaderLocation = 0;
attributes[0].offset = 0;
attributes[0].format = wgpu::VertexFormat::Float32x3;
attributes[1].shaderLocation = 1;
attributes[1].offset = 3 * sizeof(float);
attributes[1].format = wgpu::VertexFormat::Float32x3;
vertexState.vertexBufferCount = 1;
vertexState.cVertexBuffers[0].arrayStride = 6 * sizeof(float);
wgpu::VertexBufferLayout vertexBufferLayout;
vertexBufferLayout.attributeCount = 2;
vertexBufferLayout.attributes = attributes;
vertexBufferLayout.arrayStride = 6 * sizeof(float);
auto bgl = utils::MakeBindGroupLayout(
device, {
{0, wgpu::ShaderStage::Vertex, wgpu::BindingType::UniformBuffer},
{1, wgpu::ShaderStage::Vertex, wgpu::BindingType::UniformBuffer},
{0, wgpu::ShaderStage::Vertex, wgpu::BufferBindingType::Uniform},
{1, wgpu::ShaderStage::Vertex, wgpu::BufferBindingType::Uniform},
});
wgpu::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
@@ -184,49 +187,64 @@ void init() {
depthStencilView = CreateDefaultDepthStencilView(device);
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.layout = pl;
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.vertexState = &vertexState;
descriptor.depthStencilState = &descriptor.cDepthStencilState;
descriptor.cDepthStencilState.format = wgpu::TextureFormat::Depth24PlusStencil8;
descriptor.cColorStates[0].format = GetPreferredSwapChainTextureFormat();
descriptor.cDepthStencilState.depthWriteEnabled = true;
descriptor.cDepthStencilState.depthCompare = wgpu::CompareFunction::Less;
{
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = vsModule;
descriptor.vertex.bufferCount = 1;
descriptor.vertex.buffers = &vertexBufferLayout;
pipeline = device.CreateRenderPipeline(&descriptor);
descriptor.layout = pl;
descriptor.cFragment.module = fsModule;
descriptor.cTargets[0].format = GetPreferredSwapChainTextureFormat();
utils::ComboRenderPipelineDescriptor pDescriptor(device);
pDescriptor.layout = pl;
pDescriptor.vertexStage.module = vsModule;
pDescriptor.cFragmentStage.module = fsModule;
pDescriptor.vertexState = &vertexState;
pDescriptor.depthStencilState = &pDescriptor.cDepthStencilState;
pDescriptor.cDepthStencilState.format = wgpu::TextureFormat::Depth24PlusStencil8;
pDescriptor.cColorStates[0].format = GetPreferredSwapChainTextureFormat();
pDescriptor.cDepthStencilState.stencilFront.passOp = wgpu::StencilOperation::Replace;
pDescriptor.cDepthStencilState.stencilBack.passOp = wgpu::StencilOperation::Replace;
pDescriptor.cDepthStencilState.depthCompare = wgpu::CompareFunction::Less;
wgpu::DepthStencilState* depthStencil =
descriptor.EnableDepthStencil(wgpu::TextureFormat::Depth24PlusStencil8);
depthStencil->depthWriteEnabled = true;
depthStencil->depthCompare = wgpu::CompareFunction::Less;
planePipeline = device.CreateRenderPipeline(&pDescriptor);
pipeline = device.CreateRenderPipeline2(&descriptor);
}
utils::ComboRenderPipelineDescriptor rfDescriptor(device);
rfDescriptor.layout = pl;
rfDescriptor.vertexStage.module = vsModule;
rfDescriptor.cFragmentStage.module = fsReflectionModule;
rfDescriptor.vertexState = &vertexState;
rfDescriptor.depthStencilState = &rfDescriptor.cDepthStencilState;
rfDescriptor.cDepthStencilState.format = wgpu::TextureFormat::Depth24PlusStencil8;
rfDescriptor.cColorStates[0].format = GetPreferredSwapChainTextureFormat();
rfDescriptor.cDepthStencilState.stencilFront.compare = wgpu::CompareFunction::Equal;
rfDescriptor.cDepthStencilState.stencilBack.compare = wgpu::CompareFunction::Equal;
rfDescriptor.cDepthStencilState.stencilFront.passOp = wgpu::StencilOperation::Replace;
rfDescriptor.cDepthStencilState.stencilBack.passOp = wgpu::StencilOperation::Replace;
rfDescriptor.cDepthStencilState.depthWriteEnabled = true;
rfDescriptor.cDepthStencilState.depthCompare = wgpu::CompareFunction::Less;
{
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = vsModule;
descriptor.vertex.bufferCount = 1;
descriptor.vertex.buffers = &vertexBufferLayout;
reflectionPipeline = device.CreateRenderPipeline(&rfDescriptor);
descriptor.layout = pl;
descriptor.cFragment.module = fsModule;
descriptor.cTargets[0].format = GetPreferredSwapChainTextureFormat();
wgpu::DepthStencilState* depthStencil =
descriptor.EnableDepthStencil(wgpu::TextureFormat::Depth24PlusStencil8);
depthStencil->stencilFront.passOp = wgpu::StencilOperation::Replace;
depthStencil->stencilBack.passOp = wgpu::StencilOperation::Replace;
depthStencil->depthCompare = wgpu::CompareFunction::Less;
planePipeline = device.CreateRenderPipeline2(&descriptor);
}
{
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = vsModule;
descriptor.vertex.bufferCount = 1;
descriptor.vertex.buffers = &vertexBufferLayout;
descriptor.layout = pl;
descriptor.cFragment.module = fsReflectionModule;
descriptor.cTargets[0].format = GetPreferredSwapChainTextureFormat();
wgpu::DepthStencilState* depthStencil =
descriptor.EnableDepthStencil(wgpu::TextureFormat::Depth24PlusStencil8);
depthStencil->stencilFront.compare = wgpu::CompareFunction::Equal;
depthStencil->stencilBack.compare = wgpu::CompareFunction::Equal;
depthStencil->stencilFront.passOp = wgpu::StencilOperation::Replace;
depthStencil->stencilBack.passOp = wgpu::StencilOperation::Replace;
depthStencil->depthWriteEnabled = true;
depthStencil->depthCompare = wgpu::CompareFunction::Less;
reflectionPipeline = device.CreateRenderPipeline2(&descriptor);
}
cameraData.proj = glm::perspective(glm::radians(45.0f), 1.f, 1.0f, 100.0f);
}