Updating RenderPipelineDescriptor to the newest layout

Currently normalizes anything using the new layout to the old one for
the sake of getting things working as quickly as possible. Follow up
changes will gradually push the new layout through more of the stack.

Bug: dawn:642
Change-Id: Ie92fa9dde21174f62ceba1a1f4866cbc24c5fc6f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/38600
Commit-Queue: Brandon Jones <bajones@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Brandon Jones
2021-03-11 21:19:00 +00:00
committed by Commit Bot service account
parent c506385531
commit 0702b70469
6 changed files with 474 additions and 136 deletions

View File

@@ -797,6 +797,22 @@ namespace dawn_native {
const RenderPipelineDescriptor* descriptor) {
RenderPipelineBase* result = nullptr;
// TODO: Enable this warning once the tests have been converted to either use the new
// format or expect the deprecation warning.
/*EmitDeprecationWarning(
"The format of RenderPipelineDescriptor has changed, and will soon require the "
"new structure. Please begin using CreateRenderPipeline2() instead.");*/
if (ConsumedError(CreateRenderPipelineInternal(&result, descriptor))) {
return RenderPipelineBase::MakeError(this);
}
return result;
}
RenderPipelineBase* DeviceBase::CreateRenderPipeline2(
const RenderPipelineDescriptor2* descriptor) {
RenderPipelineBase* result = nullptr;
if (ConsumedError(CreateRenderPipelineInternal(&result, descriptor))) {
return RenderPipelineBase::MakeError(this);
}
@@ -1056,10 +1072,93 @@ namespace dawn_native {
return {};
}
MaybeError DeviceBase::CreateRenderPipelineInternal(
RenderPipelineBase** result,
const RenderPipelineDescriptor2* descriptor) {
// Convert descriptor to the older format it before proceeding.
// TODO: Convert the rest of the code to operate on the newer format.
RenderPipelineDescriptor normalizedDescriptor;
VertexStateDescriptor vertexState;
normalizedDescriptor.vertexState = &vertexState;
RasterizationStateDescriptor rasterizationState;
normalizedDescriptor.rasterizationState = &rasterizationState;
normalizedDescriptor.label = descriptor->label;
normalizedDescriptor.layout = descriptor->layout;
normalizedDescriptor.vertexStage.module = descriptor->vertex.module;
normalizedDescriptor.vertexStage.entryPoint = descriptor->vertex.entryPoint;
normalizedDescriptor.primitiveTopology = descriptor->primitive.topology;
normalizedDescriptor.sampleCount = descriptor->multisample.count;
normalizedDescriptor.sampleMask = descriptor->multisample.mask;
normalizedDescriptor.alphaToCoverageEnabled =
descriptor->multisample.alphaToCoverageEnabled;
vertexState.vertexBufferCount = descriptor->vertex.bufferCount;
vertexState.vertexBuffers = descriptor->vertex.buffers;
vertexState.indexFormat = descriptor->primitive.stripIndexFormat;
rasterizationState.frontFace = descriptor->primitive.frontFace;
rasterizationState.cullMode = descriptor->primitive.cullMode;
DepthStencilStateDescriptor depthStencilState;
if (descriptor->depthStencil) {
const DepthStencilState* depthStencil = descriptor->depthStencil;
normalizedDescriptor.depthStencilState = &depthStencilState;
depthStencilState.format = depthStencil->format;
depthStencilState.depthWriteEnabled = depthStencil->depthWriteEnabled;
depthStencilState.depthCompare = depthStencil->depthCompare;
depthStencilState.stencilFront = depthStencil->stencilFront;
depthStencilState.stencilBack = depthStencil->stencilBack;
depthStencilState.stencilReadMask = depthStencil->stencilReadMask;
depthStencilState.stencilWriteMask = depthStencil->stencilWriteMask;
rasterizationState.depthBias = depthStencil->depthBias;
rasterizationState.depthBiasSlopeScale = depthStencil->depthBiasSlopeScale;
rasterizationState.depthBiasClamp = depthStencil->depthBiasClamp;
}
ProgrammableStageDescriptor fragmentStage;
std::vector<ColorStateDescriptor> colorStates;
if (descriptor->fragment) {
const FragmentState* fragment = descriptor->fragment;
normalizedDescriptor.fragmentStage = &fragmentStage;
fragmentStage.module = fragment->module;
fragmentStage.entryPoint = fragment->entryPoint;
for (uint32_t i = 0; i < fragment->targetCount; ++i) {
const ColorTargetState& target = fragment->targets[i];
ColorStateDescriptor colorState;
colorState.format = target.format;
colorState.writeMask = target.writeMask;
if (target.blend) {
const BlendState* blend = target.blend;
colorState.colorBlend.srcFactor = blend->color.srcFactor;
colorState.colorBlend.dstFactor = blend->color.dstFactor;
colorState.colorBlend.operation = blend->color.operation;
colorState.alphaBlend.srcFactor = blend->alpha.srcFactor;
colorState.alphaBlend.dstFactor = blend->alpha.dstFactor;
colorState.alphaBlend.operation = blend->alpha.operation;
}
colorStates.push_back(colorState);
}
normalizedDescriptor.colorStateCount = fragment->targetCount;
normalizedDescriptor.colorStates = colorStates.data();
}
return CreateRenderPipelineInternal(result, &normalizedDescriptor);
}
MaybeError DeviceBase::CreateRenderPipelineInternal(
RenderPipelineBase** result,
const RenderPipelineDescriptor* descriptor) {
DAWN_TRY(ValidateIsAlive());
if (IsValidationEnabled()) {
DAWN_TRY(ValidateRenderPipelineDescriptor(this, descriptor));
}

View File

@@ -155,6 +155,7 @@ namespace dawn_native {
RenderBundleEncoder* CreateRenderBundleEncoder(
const RenderBundleEncoderDescriptor* descriptor);
RenderPipelineBase* CreateRenderPipeline(const RenderPipelineDescriptor* descriptor);
RenderPipelineBase* CreateRenderPipeline2(const RenderPipelineDescriptor2* descriptor);
SamplerBase* CreateSampler(const SamplerDescriptor* descriptor);
ShaderModuleBase* CreateShaderModule(const ShaderModuleDescriptor* descriptor);
SwapChainBase* CreateSwapChain(Surface* surface, const SwapChainDescriptor* descriptor);
@@ -307,6 +308,8 @@ namespace dawn_native {
MaybeError CreateRenderBundleEncoderInternal(
RenderBundleEncoder** result,
const RenderBundleEncoderDescriptor* descriptor);
MaybeError CreateRenderPipelineInternal(RenderPipelineBase** result,
const RenderPipelineDescriptor2* descriptor);
MaybeError CreateRenderPipelineInternal(RenderPipelineBase** result,
const RenderPipelineDescriptor* descriptor);
MaybeError CreateSamplerInternal(SamplerBase** result, const SamplerDescriptor* descriptor);

View File

@@ -46,6 +46,15 @@ class RenderPipelineValidationTest : public ValidationTest {
// Test cases where creation should succeed
TEST_F(RenderPipelineValidationTest, CreationSuccess) {
{
// New format
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModule;
device.CreateRenderPipeline2(&descriptor);
}
{
// Deprecated format
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
@@ -75,66 +84,71 @@ TEST_F(RenderPipelineValidationTest, CreationSuccess) {
TEST_F(RenderPipelineValidationTest, DepthBiasParameterNotBeNaN) {
// Control case, depth bias parameters in ComboRenderPipeline default to 0 which is finite
{
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
device.CreateRenderPipeline(&descriptor);
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModule;
descriptor.depthStencil = &descriptor.cDepthStencil;
device.CreateRenderPipeline2(&descriptor);
}
// Infinite depth bias clamp is valid
{
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.cRasterizationState.depthBiasClamp = INFINITY;
device.CreateRenderPipeline(&descriptor);
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModule;
descriptor.cDepthStencil.depthBiasClamp = INFINITY;
descriptor.depthStencil = &descriptor.cDepthStencil;
device.CreateRenderPipeline2(&descriptor);
}
// NAN depth bias clamp is invalid
{
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.cRasterizationState.depthBiasClamp = NAN;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModule;
descriptor.cDepthStencil.depthBiasClamp = NAN;
descriptor.depthStencil = &descriptor.cDepthStencil;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline2(&descriptor));
}
// Infinite depth bias slope is valid
{
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.cRasterizationState.depthBiasSlopeScale = INFINITY;
device.CreateRenderPipeline(&descriptor);
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModule;
descriptor.cDepthStencil.depthBiasSlopeScale = INFINITY;
descriptor.depthStencil = &descriptor.cDepthStencil;
device.CreateRenderPipeline2(&descriptor);
}
// NAN depth bias slope is invalid
{
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.cRasterizationState.depthBiasSlopeScale = NAN;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModule;
descriptor.cDepthStencil.depthBiasSlopeScale = NAN;
descriptor.depthStencil = &descriptor.cDepthStencil;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline2(&descriptor));
}
}
// Tests that at least one color state is required.
TEST_F(RenderPipelineValidationTest, ColorStateRequired) {
// Tests that at least one color target state is required.
TEST_F(RenderPipelineValidationTest, ColorTargetStateRequired) {
{
// This one succeeds because attachment 0 is the color attachment
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.colorStateCount = 1;
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModule;
descriptor.cFragment.targetCount = 1;
device.CreateRenderPipeline(&descriptor);
device.CreateRenderPipeline2(&descriptor);
}
{ // Fail because lack of color states (and depth/stencil state)
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.colorStateCount = 0;
{ // Fail because lack of color target states (and depth/stencil state)
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModule;
descriptor.cFragment.targetCount = 0;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline2(&descriptor));
}
}
@@ -142,22 +156,22 @@ TEST_F(RenderPipelineValidationTest, ColorStateRequired) {
TEST_F(RenderPipelineValidationTest, NonRenderableFormat) {
{
// Succeeds because RGBA8Unorm is renderable
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.cColorStates[0].format = wgpu::TextureFormat::RGBA8Unorm;
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModule;
descriptor.cTargets[0].format = wgpu::TextureFormat::RGBA8Unorm;
device.CreateRenderPipeline(&descriptor);
device.CreateRenderPipeline2(&descriptor);
}
{
// Fails because RG11B10Ufloat is non-renderable
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.cColorStates[0].format = wgpu::TextureFormat::RG11B10Ufloat;
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModule;
descriptor.cTargets[0].format = wgpu::TextureFormat::RG11B10Ufloat;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline2(&descriptor));
}
}
@@ -196,21 +210,21 @@ TEST_F(RenderPipelineValidationTest, FragmentOutputFormatCompatibility) {
/// Tests that the sample count of the render pipeline must be valid.
TEST_F(RenderPipelineValidationTest, SampleCount) {
{
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.sampleCount = 4;
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModule;
descriptor.multisample.count = 4;
device.CreateRenderPipeline(&descriptor);
device.CreateRenderPipeline2(&descriptor);
}
{
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.sampleCount = 3;
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModule;
descriptor.multisample.count = 3;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline2(&descriptor));
}
}
@@ -360,23 +374,23 @@ TEST_F(RenderPipelineValidationTest, SampleCountCompatibilityWithRenderPass) {
// when the alphaToCoverage mode is enabled.
TEST_F(RenderPipelineValidationTest, AlphaToCoverageAndSampleCount) {
{
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.sampleCount = 4;
descriptor.alphaToCoverageEnabled = true;
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModule;
descriptor.multisample.count = 4;
descriptor.multisample.alphaToCoverageEnabled = true;
device.CreateRenderPipeline(&descriptor);
device.CreateRenderPipeline2(&descriptor);
}
{
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.sampleCount = 1;
descriptor.alphaToCoverageEnabled = true;
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModule;
descriptor.multisample.count = 1;
descriptor.multisample.alphaToCoverageEnabled = true;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline2(&descriptor));
}
}
@@ -586,37 +600,37 @@ TEST_F(RenderPipelineValidationTest, EntryPointNameValidation) {
}
)");
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = module;
descriptor.vertexStage.entryPoint = "vertex_main";
descriptor.cFragmentStage.module = module;
descriptor.cFragmentStage.entryPoint = "fragment_main";
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = module;
descriptor.vertex.entryPoint = "vertex_main";
descriptor.cFragment.module = module;
descriptor.cFragment.entryPoint = "fragment_main";
// Success case.
device.CreateRenderPipeline(&descriptor);
device.CreateRenderPipeline2(&descriptor);
// Test for the vertex stage entryPoint name.
{
// The entryPoint name doesn't exist in the module.
descriptor.vertexStage.entryPoint = "main";
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
descriptor.vertex.entryPoint = "main";
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline2(&descriptor));
// The entryPoint name exists, but not for the correct stage.
descriptor.vertexStage.entryPoint = "fragment_main";
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
descriptor.vertex.entryPoint = "fragment_main";
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline2(&descriptor));
}
descriptor.vertexStage.entryPoint = "vertex_main";
descriptor.vertex.entryPoint = "vertex_main";
// Test for the fragment stage entryPoint name.
{
// The entryPoint name doesn't exist in the module.
descriptor.cFragmentStage.entryPoint = "main";
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
descriptor.cFragment.entryPoint = "main";
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline2(&descriptor));
// The entryPoint name exists, but not for the correct stage.
descriptor.cFragmentStage.entryPoint = "vertex_main";
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
descriptor.cFragment.entryPoint = "vertex_main";
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline2(&descriptor));
}
}
@@ -639,33 +653,33 @@ TEST_F(RenderPipelineValidationTest, VertexAttribCorrectEntryPoint) {
}
)");
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = module;
descriptor.cFragmentStage.module = fsModule;
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = module;
descriptor.cFragment.module = fsModule;
descriptor.cVertexState.vertexBufferCount = 1;
descriptor.cVertexState.cVertexBuffers[0].attributeCount = 1;
descriptor.cVertexState.cVertexBuffers[0].arrayStride = 16;
descriptor.cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float32x4;
descriptor.cVertexState.cAttributes[0].offset = 0;
descriptor.vertex.bufferCount = 1;
descriptor.cBuffers[0].attributeCount = 1;
descriptor.cBuffers[0].arrayStride = 16;
descriptor.cAttributes[0].format = wgpu::VertexFormat::Float32x4;
descriptor.cAttributes[0].offset = 0;
// Success cases, the attribute used by the entryPoint is declared in the pipeline.
descriptor.vertexStage.entryPoint = "vertex0";
descriptor.cVertexState.cAttributes[0].shaderLocation = 0;
device.CreateRenderPipeline(&descriptor);
descriptor.vertex.entryPoint = "vertex0";
descriptor.cAttributes[0].shaderLocation = 0;
device.CreateRenderPipeline2(&descriptor);
descriptor.vertexStage.entryPoint = "vertex1";
descriptor.cVertexState.cAttributes[0].shaderLocation = 1;
device.CreateRenderPipeline(&descriptor);
descriptor.vertex.entryPoint = "vertex1";
descriptor.cAttributes[0].shaderLocation = 1;
device.CreateRenderPipeline2(&descriptor);
// Error cases, the attribute used by the entryPoint isn't declared in the pipeline.
descriptor.vertexStage.entryPoint = "vertex1";
descriptor.cVertexState.cAttributes[0].shaderLocation = 0;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
descriptor.vertex.entryPoint = "vertex1";
descriptor.cAttributes[0].shaderLocation = 0;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline2(&descriptor));
descriptor.vertexStage.entryPoint = "vertex0";
descriptor.cVertexState.cAttributes[0].shaderLocation = 1;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
descriptor.vertex.entryPoint = "vertex0";
descriptor.cAttributes[0].shaderLocation = 1;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline2(&descriptor));
}
// Test that fragment output validation is for the correct entryPoint
@@ -686,27 +700,27 @@ TEST_F(RenderPipelineValidationTest, FragmentOutputCorrectEntryPoint) {
}
)");
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = module;
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = module;
// Success case, the component type matches between the pipeline and the entryPoint
descriptor.cFragmentStage.entryPoint = "fragmentFloat";
descriptor.cColorStates[0].format = wgpu::TextureFormat::RGBA32Float;
device.CreateRenderPipeline(&descriptor);
descriptor.cFragment.entryPoint = "fragmentFloat";
descriptor.cTargets[0].format = wgpu::TextureFormat::RGBA32Float;
device.CreateRenderPipeline2(&descriptor);
descriptor.cFragmentStage.entryPoint = "fragmentUint";
descriptor.cColorStates[0].format = wgpu::TextureFormat::RGBA32Uint;
device.CreateRenderPipeline(&descriptor);
descriptor.cFragment.entryPoint = "fragmentUint";
descriptor.cTargets[0].format = wgpu::TextureFormat::RGBA32Uint;
device.CreateRenderPipeline2(&descriptor);
// Error case, the component type doesn't match between the pipeline and the entryPoint
descriptor.cFragmentStage.entryPoint = "fragmentUint";
descriptor.cColorStates[0].format = wgpu::TextureFormat::RGBA32Float;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
descriptor.cFragment.entryPoint = "fragmentUint";
descriptor.cTargets[0].format = wgpu::TextureFormat::RGBA32Float;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline2(&descriptor));
descriptor.cFragmentStage.entryPoint = "fragmentFloat";
descriptor.cColorStates[0].format = wgpu::TextureFormat::RGBA32Uint;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
descriptor.cFragment.entryPoint = "fragmentFloat";
descriptor.cTargets[0].format = wgpu::TextureFormat::RGBA32Uint;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline2(&descriptor));
}
// Test that fragment output validation is for the correct entryPoint
@@ -743,25 +757,25 @@ TEST_F(RenderPipelineValidationTest, DISABLED_BindingsFromCorrectEntryPoint) {
device, {{1, wgpu::ShaderStage::Vertex, wgpu::BufferBindingType::Uniform}});
wgpu::PipelineLayout layout1 = utils::MakeBasicPipelineLayout(device, &bgl1);
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = module;
descriptor.cFragmentStage.module = fsModule;
utils::ComboRenderPipelineDescriptor2 descriptor;
descriptor.vertex.module = module;
descriptor.cFragment.module = fsModule;
// Success case, the BGL matches the bindings used by the entryPoint
descriptor.vertexStage.entryPoint = "vertex0";
descriptor.vertex.entryPoint = "vertex0";
descriptor.layout = layout0;
device.CreateRenderPipeline(&descriptor);
device.CreateRenderPipeline2(&descriptor);
descriptor.vertexStage.entryPoint = "vertex1";
descriptor.vertex.entryPoint = "vertex1";
descriptor.layout = layout1;
device.CreateRenderPipeline(&descriptor);
device.CreateRenderPipeline2(&descriptor);
// Error case, the BGL doesn't match the bindings used by the entryPoint
descriptor.vertexStage.entryPoint = "vertex1";
descriptor.vertex.entryPoint = "vertex1";
descriptor.layout = layout0;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline2(&descriptor));
descriptor.vertexStage.entryPoint = "vertex0";
descriptor.vertex.entryPoint = "vertex0";
descriptor.layout = layout1;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline2(&descriptor));
}

View File

@@ -18,6 +18,8 @@
namespace utils {
// For creating deprecated render pipeline descriptors
ComboVertexStateDescriptor::ComboVertexStateDescriptor() {
wgpu::VertexStateDescriptor* descriptor = this;
@@ -114,4 +116,96 @@ namespace utils {
}
}
ComboRenderPipelineDescriptor2::ComboRenderPipelineDescriptor2() {
wgpu::RenderPipelineDescriptor2* descriptor = this;
// Set defaults for the vertex state.
{
wgpu::VertexState* vertex = &descriptor->vertex;
vertex->module = nullptr;
vertex->entryPoint = "main";
vertex->bufferCount = 0;
// Fill the default values for vertexBuffers and vertexAttributes in buffers.
for (uint32_t i = 0; i < kMaxVertexAttributes; ++i) {
cAttributes[i].shaderLocation = 0;
cAttributes[i].offset = 0;
cAttributes[i].format = wgpu::VertexFormat::Float32;
}
for (uint32_t i = 0; i < kMaxVertexBuffers; ++i) {
cBuffers[i].arrayStride = 0;
cBuffers[i].stepMode = wgpu::InputStepMode::Vertex;
cBuffers[i].attributeCount = 0;
cBuffers[i].attributes = nullptr;
}
// cBuffers[i].attributes points to somewhere in cAttributes.
// cBuffers[0].attributes points to &cAttributes[0] by default. Assuming
// cBuffers[0] has two attributes, then cBuffers[1].attributes should point to
// &cAttributes[2]. Likewise, if cBuffers[1] has 3 attributes, then
// cBuffers[2].attributes should point to &cAttributes[5].
cBuffers[0].attributes = &cAttributes[0];
vertex->buffers = &cBuffers[0];
}
// Set the defaults for the primitive state
{
wgpu::PrimitiveState* primitive = &descriptor->primitive;
primitive->topology = wgpu::PrimitiveTopology::TriangleList;
primitive->stripIndexFormat = wgpu::IndexFormat::Undefined;
primitive->frontFace = wgpu::FrontFace::CCW;
primitive->cullMode = wgpu::CullMode::None;
}
// Set the defaults for the depth-stencil state
{
wgpu::StencilFaceState stencilFace;
stencilFace.compare = wgpu::CompareFunction::Always;
stencilFace.failOp = wgpu::StencilOperation::Keep;
stencilFace.depthFailOp = wgpu::StencilOperation::Keep;
stencilFace.passOp = wgpu::StencilOperation::Keep;
cDepthStencil.format = wgpu::TextureFormat::Depth24PlusStencil8;
cDepthStencil.depthWriteEnabled = false;
cDepthStencil.depthCompare = wgpu::CompareFunction::Always;
cDepthStencil.stencilBack = stencilFace;
cDepthStencil.stencilFront = stencilFace;
cDepthStencil.stencilReadMask = 0xff;
cDepthStencil.stencilWriteMask = 0xff;
cDepthStencil.depthBias = 0;
cDepthStencil.depthBiasSlopeScale = 0.0;
cDepthStencil.depthBiasClamp = 0.0;
}
// Set the defaults for the multisample state
{
wgpu::MultisampleState* multisample = &descriptor->multisample;
multisample->count = 1;
multisample->mask = 0xFFFFFFFF;
multisample->alphaToCoverageEnabled = false;
}
// Set the defaults for the fragment state
{
cFragment.module = nullptr;
cFragment.entryPoint = "main";
cFragment.targetCount = 1;
cFragment.targets = &cTargets[0];
descriptor->fragment = &cFragment;
wgpu::BlendComponent blendComponent;
blendComponent.srcFactor = wgpu::BlendFactor::One;
blendComponent.dstFactor = wgpu::BlendFactor::Zero;
blendComponent.operation = wgpu::BlendOperation::Add;
for (uint32_t i = 0; i < kMaxColorAttachments; ++i) {
cTargets[i].format = wgpu::TextureFormat::RGBA8Unorm;
cTargets[i].blend = nullptr;
cTargets[i].writeMask = wgpu::ColorWriteMask::All;
cBlends[i].color = blendComponent;
cBlends[i].alpha = blendComponent;
}
}
}
} // namespace utils

View File

@@ -23,6 +23,7 @@
namespace utils {
// For creating deprecated render pipeline descriptors
class ComboVertexStateDescriptor : public wgpu::VertexStateDescriptor {
public:
ComboVertexStateDescriptor();
@@ -53,6 +54,25 @@ namespace utils {
wgpu::DepthStencilStateDescriptor cDepthStencilState;
};
// For creating the new style of render pipeline descriptors
class ComboRenderPipelineDescriptor2 : public wgpu::RenderPipelineDescriptor2 {
public:
ComboRenderPipelineDescriptor2();
ComboRenderPipelineDescriptor2(const ComboRenderPipelineDescriptor2&) = delete;
ComboRenderPipelineDescriptor2& operator=(const ComboRenderPipelineDescriptor2&) = delete;
ComboRenderPipelineDescriptor2(ComboRenderPipelineDescriptor2&&) = delete;
ComboRenderPipelineDescriptor2& operator=(ComboRenderPipelineDescriptor2&&) = delete;
std::array<wgpu::VertexBufferLayout, kMaxVertexBuffers> cBuffers;
std::array<wgpu::VertexAttribute, kMaxVertexAttributes> cAttributes;
std::array<wgpu::ColorTargetState, kMaxColorAttachments> cTargets;
std::array<wgpu::BlendState, kMaxColorAttachments> cBlends;
wgpu::DepthStencilState cDepthStencil;
wgpu::FragmentState cFragment;
};
} // namespace utils
#endif // UTILS_COMBORENDERPIPELINEDESCRIPTOR_H_