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

@@ -15,6 +15,7 @@
#include "common/Assert.h"
#include "common/Constants.h"
#include "tests/DawnTest.h"
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/DawnHelpers.h"
constexpr static unsigned int kRTSize = 8;
@@ -114,13 +115,15 @@ TEST_P(BindGroupTests, ReusedUBO) {
);
dawn::PipelineLayout pipelineLayout = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::RenderPipeline pipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, renderPass.colorFormat)
.SetLayout(pipelineLayout)
.SetPrimitiveTopology(dawn::PrimitiveTopology::TriangleList)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.GetResult();
utils::ComboRenderPipelineDescriptor textureDescriptor(device);
textureDescriptor.layout = pipelineLayout;
textureDescriptor.cVertexStage.module = vsModule;
textureDescriptor.cFragmentStage.module = fsModule;
textureDescriptor.cColorAttachments[0].format =
renderPass.colorFormat;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&textureDescriptor);
struct Data {
float transform[8];
char padding[256 - 8 * sizeof(float)];
@@ -198,13 +201,15 @@ TEST_P(BindGroupTests, UBOSamplerAndTexture) {
);
dawn::PipelineLayout pipelineLayout = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::RenderPipeline pipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, renderPass.colorFormat)
.SetLayout(pipelineLayout)
.SetPrimitiveTopology(dawn::PrimitiveTopology::TriangleList)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.GetResult();
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
pipelineDescriptor.layout = pipelineLayout;
pipelineDescriptor.cVertexStage.module = vsModule;
pipelineDescriptor.cFragmentStage.module = fsModule;
pipelineDescriptor.cColorAttachments[0].format =
renderPass.colorFormat;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&pipelineDescriptor);
constexpr float dummy = 0.0f;
constexpr float transform[] = { 1.f, 0.f, dummy, dummy, 0.f, 1.f, dummy, dummy };
dawn::Buffer buffer = utils::CreateBufferFromData(device, &transform, sizeof(transform), dawn::BufferUsageBit::Uniform);

View File

@@ -19,6 +19,7 @@
#include "common/Assert.h"
#include "common/Constants.h"
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/DawnHelpers.h"
constexpr static unsigned int kRTSize = 64;
@@ -66,20 +67,24 @@ class BlendStateTest : public DawnTest {
}
)");
basePipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, renderPass.colorFormat)
.SetLayout(pipelineLayout)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.GetResult();
utils::ComboRenderPipelineDescriptor baseDescriptor(device);
baseDescriptor.layout = pipelineLayout;
baseDescriptor.cVertexStage.module = vsModule;
baseDescriptor.cFragmentStage.module = fsModule;
baseDescriptor.cColorAttachments[0].format =
renderPass.colorFormat;
testPipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, renderPass.colorFormat)
.SetLayout(pipelineLayout)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetColorAttachmentBlendState(0, blendState)
.GetResult();
basePipeline = device.CreateRenderPipeline(&baseDescriptor);
utils::ComboRenderPipelineDescriptor testDescriptor(device);
testDescriptor.layout = pipelineLayout;
testDescriptor.cVertexStage.module = vsModule;
testDescriptor.cFragmentStage.module = fsModule;
testDescriptor.cColorAttachments[0].format =
renderPass.colorFormat;
testDescriptor.cBlendStates[0] = blendState;
testPipeline = device.CreateRenderPipeline(&testDescriptor);
}
// Create a bind group to set the colors as a uniform buffer
@@ -766,7 +771,7 @@ TEST_P(BlendStateTest, IndependentBlendState) {
blend3.srcFactor = dawn::BlendFactor::One;
blend3.dstFactor = dawn::BlendFactor::One;
std::array<dawn::BlendState, 3> blendStates = { {
std::array<dawn::BlendState, 4> blendStates = { {
device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(&blend1)
@@ -777,6 +782,7 @@ TEST_P(BlendStateTest, IndependentBlendState) {
.SetColorBlend(&blend2)
.SetAlphaBlend(&blend2)
.GetResult(),
device.CreateBlendStateBuilder().GetResult(),
device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(&blend3)
@@ -784,30 +790,24 @@ TEST_P(BlendStateTest, IndependentBlendState) {
.GetResult(),
} };
basePipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, dawn::TextureFormat::R8G8B8A8Unorm)
.SetColorAttachmentFormat(1, dawn::TextureFormat::R8G8B8A8Unorm)
.SetColorAttachmentFormat(2, dawn::TextureFormat::R8G8B8A8Unorm)
.SetColorAttachmentFormat(3, dawn::TextureFormat::R8G8B8A8Unorm)
.SetLayout(pipelineLayout)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.GetResult();
utils::ComboRenderPipelineDescriptor baseDescriptor(device);
baseDescriptor.layout = pipelineLayout;
baseDescriptor.cVertexStage.module = vsModule;
baseDescriptor.cFragmentStage.module = fsModule;
baseDescriptor.cAttachmentsState.numColorAttachments = 4;
baseDescriptor.numBlendStates = 4;
testPipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, dawn::TextureFormat::R8G8B8A8Unorm)
.SetColorAttachmentFormat(1, dawn::TextureFormat::R8G8B8A8Unorm)
.SetColorAttachmentFormat(2, dawn::TextureFormat::R8G8B8A8Unorm)
.SetColorAttachmentFormat(3, dawn::TextureFormat::R8G8B8A8Unorm)
.SetLayout(pipelineLayout)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetColorAttachmentBlendState(0, blendStates[0])
.SetColorAttachmentBlendState(1, blendStates[1])
// Blend state not set on third color attachment. It should be default
.SetColorAttachmentBlendState(3, blendStates[2])
.GetResult();
basePipeline = device.CreateRenderPipeline(&baseDescriptor);
utils::ComboRenderPipelineDescriptor testDescriptor(device);
testDescriptor.layout = pipelineLayout;
testDescriptor.cVertexStage.module = vsModule;
testDescriptor.cFragmentStage.module = fsModule;
testDescriptor.cAttachmentsState.numColorAttachments = 4;
testDescriptor.numBlendStates = 4;
testDescriptor.blendStates = blendStates.data();
testPipeline = device.CreateRenderPipeline(&testDescriptor);
for (unsigned int c = 0; c < kColors.size(); ++c) {
RGBA8 base = kColors[((c + 31) * 29) % kColors.size()];
@@ -870,20 +870,24 @@ TEST_P(BlendStateTest, DefaultBlendColor) {
}
)");
basePipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, renderPass.colorFormat)
.SetLayout(pipelineLayout)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.GetResult();
utils::ComboRenderPipelineDescriptor baseDescriptor(device);
baseDescriptor.layout = pipelineLayout;
baseDescriptor.cVertexStage.module = vsModule;
baseDescriptor.cFragmentStage.module = fsModule;
baseDescriptor.cColorAttachments[0].format =
renderPass.colorFormat;
testPipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, renderPass.colorFormat)
.SetLayout(pipelineLayout)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetColorAttachmentBlendState(0, blendState)
.GetResult();
basePipeline = device.CreateRenderPipeline(&baseDescriptor);
utils::ComboRenderPipelineDescriptor testDescriptor(device);
testDescriptor.layout = pipelineLayout;
testDescriptor.cVertexStage.module = vsModule;
testDescriptor.cFragmentStage.module = fsModule;
testDescriptor.cColorAttachments[0].format =
renderPass.colorFormat;
testDescriptor.cBlendStates[0] = blendState;
testPipeline = device.CreateRenderPipeline(&testDescriptor);
// Check that the initial blend color is (0,0,0,0)
{

View File

@@ -15,6 +15,7 @@
#include "tests/DawnTest.h"
#include "common/Assert.h"
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/DawnHelpers.h"
constexpr static unsigned int kRTSize = 64;
@@ -213,14 +214,16 @@ class DepthStencilStateTest : public DawnTest {
dawn::BindGroup bindGroup = utils::MakeBindGroup(device, bindGroupLayout, {{0, buffer, 0, sizeof(TriangleData)}});
// Create a pipeline for the triangles with the test spec's depth stencil state
dawn::RenderPipeline pipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, dawn::TextureFormat::R8G8B8A8Unorm)
.SetDepthStencilAttachmentFormat(dawn::TextureFormat::D32FloatS8Uint)
.SetLayout(pipelineLayout)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetDepthStencilState(test.depthStencilState)
.GetResult();
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.layout = pipelineLayout;
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.cAttachmentsState.hasDepthStencilAttachment = true;
descriptor.cDepthStencilAttachment.format = dawn::TextureFormat::D32FloatS8Uint;
descriptor.depthStencilState = test.depthStencilState;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
pass.SetRenderPipeline(pipeline);
pass.SetStencilReference(test.stencil); // Set the stencil reference

View File

@@ -14,6 +14,7 @@
#include "tests/DawnTest.h"
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/DawnHelpers.h"
constexpr uint32_t kRTSize = 4;
@@ -46,14 +47,16 @@ class DrawElementsTest : public DawnTest {
})"
);
pipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, renderPass.colorFormat)
.SetPrimitiveTopology(dawn::PrimitiveTopology::TriangleStrip)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetIndexFormat(dawn::IndexFormat::Uint32)
.SetInputState(inputState)
.GetResult();
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
descriptor.indexFormat = dawn::IndexFormat::Uint32;
descriptor.inputState = inputState;
descriptor.cColorAttachments[0].format =
renderPass.colorFormat;
pipeline = device.CreateRenderPipeline(&descriptor);
vertexBuffer = utils::CreateBufferFromData<float>(device, dawn::BufferUsageBit::Vertex, {
-1.0f, -1.0f, 0.0f, 1.0f,

View File

@@ -15,6 +15,7 @@
#include "tests/DawnTest.h"
#include "common/Assert.h"
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/DawnHelpers.h"
constexpr uint32_t kRTSize = 400;
@@ -51,14 +52,16 @@ class IndexFormatTest : public DawnTest {
})"
);
return device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, renderPass.colorFormat)
.SetPrimitiveTopology(dawn::PrimitiveTopology::TriangleStrip)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetIndexFormat(format)
.SetInputState(inputState)
.GetResult();
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
descriptor.indexFormat = format;
descriptor.inputState = inputState;
descriptor.cColorAttachments[0].format =
renderPass.colorFormat;
return device.CreateRenderPipeline(&descriptor);
}
};

View File

@@ -15,6 +15,7 @@
#include "tests/DawnTest.h"
#include "common/Assert.h"
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/DawnHelpers.h"
using dawn::InputStepMode;
@@ -120,12 +121,14 @@ class InputStateTest : public DawnTest {
})"
);
return device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, renderPass.colorFormat)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetInputState(inputState)
.GetResult();
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.inputState = inputState;
descriptor.cColorAttachments[0].format =
renderPass.colorFormat;
return device.CreateRenderPipeline(&descriptor);
}
struct InputSpec {

View File

@@ -15,6 +15,7 @@
#include "tests/DawnTest.h"
#include "common/Assert.h"
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/DawnHelpers.h"
// Primitive topology tests work by drawing the following vertices with all the different primitive topology states:
@@ -185,13 +186,16 @@ class PrimitiveTopologyTest : public DawnTest {
// Draw the vertices with the given primitive topology and check the pixel values of the test locations
void DoTest(dawn::PrimitiveTopology primitiveTopology, const std::vector<LocationSpec> &locationSpecs) {
dawn::RenderPipeline pipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, renderPass.colorFormat)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetInputState(inputState)
.SetPrimitiveTopology(primitiveTopology)
.GetResult();
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = primitiveTopology;
descriptor.inputState = inputState;
descriptor.cColorAttachments[0].format =
renderPass.colorFormat;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
static const uint32_t zeroOffset = 0;
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();

View File

@@ -16,6 +16,7 @@
#include "common/Assert.h"
#include "common/Constants.h"
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/DawnHelpers.h"
#include <array>
@@ -189,20 +190,18 @@ class PushConstantTest: public DawnTest {
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::One;
dawn::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(&blend)
.SetAlphaBlend(&blend)
.GetResult();
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.layout = layout;
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::PointList;
descriptor.cBlendStates[0] = device.CreateBlendStateBuilder()
.SetBlendEnabled(true)
.SetColorBlend(&blend)
.SetAlphaBlend(&blend)
.GetResult();
return device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, dawn::TextureFormat::R8G8B8A8Unorm)
.SetLayout(layout)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetPrimitiveTopology(dawn::PrimitiveTopology::PointList)
.SetColorAttachmentBlendState(0, blendState)
.GetResult();
return device.CreateRenderPipeline(&descriptor);
}
};

View File

@@ -14,6 +14,7 @@
#include "tests/DawnTest.h"
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/DawnHelpers.h"
#include <array>
@@ -23,28 +24,29 @@ constexpr static unsigned int kRTSize = 16;
class DrawQuad {
public:
DrawQuad() {}
DrawQuad(dawn::Device* device, const char* vsSource, const char* fsSource)
DrawQuad(dawn::Device device, const char* vsSource, const char* fsSource)
: device(device) {
vsModule = utils::CreateShaderModule(*device, dawn::ShaderStage::Vertex, vsSource);
fsModule = utils::CreateShaderModule(*device, dawn::ShaderStage::Fragment, fsSource);
vsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Vertex, vsSource);
fsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, fsSource);
pipelineLayout = utils::MakeBasicPipelineLayout(*device, nullptr);
pipelineLayout = utils::MakeBasicPipelineLayout(device, nullptr);
}
void Draw(dawn::RenderPassEncoder* pass) {
auto renderPipeline = device->CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, dawn::TextureFormat::R8G8B8A8Unorm)
.SetLayout(pipelineLayout)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.GetResult();
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.layout = pipelineLayout;
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
auto renderPipeline = device.CreateRenderPipeline(&descriptor);
pass->SetRenderPipeline(renderPipeline);
pass->Draw(6, 1, 0, 0);
}
private:
dawn::Device* device = nullptr;
dawn::Device device;
dawn::ShaderModule vsModule = {};
dawn::ShaderModule fsModule = {};
dawn::PipelineLayout pipelineLayout = {};
@@ -94,7 +96,7 @@ class RenderPassLoadOpTests : public DawnTest {
color = vec4(0.f, 0.f, 1.f, 1.f);
}
)";
blueQuad = DrawQuad(&device, vsSource, fsSource);
blueQuad = DrawQuad(device, vsSource, fsSource);
}
dawn::Texture renderTarget;

View File

@@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <array>
#include <cmath>
#include "tests/DawnTest.h"
#include "common/Assert.h"
#include "common/Constants.h"
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/DawnHelpers.h"
constexpr static unsigned int kRTSize = 64;
@@ -73,12 +73,14 @@ protected:
}
)");
mPipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, mRenderPass.colorFormat)
.SetLayout(pipelineLayout)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.GetResult();
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
pipelineDescriptor.layout = pipelineLayout;
pipelineDescriptor.cVertexStage.module = vsModule;
pipelineDescriptor.cFragmentStage.module = fsModule;
pipelineDescriptor.cColorAttachments[0].format =
mRenderPass.colorFormat;
mPipeline = device.CreateRenderPipeline(&pipelineDescriptor);
dawn::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D;

View File

@@ -14,6 +14,7 @@
#include "tests/DawnTest.h"
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/DawnHelpers.h"
class ScissorTest: public DawnTest {
@@ -36,13 +37,13 @@ class ScissorTest: public DawnTest {
fragColor = vec4(0.0f, 1.0f, 0.0f, 1.0f);
})");
dawn::RenderPipeline pipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, format)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.GetResult();
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.cColorAttachments[0].format =
format;
return pipeline;
return device.CreateRenderPipeline(&descriptor);
}
};

View File

@@ -17,6 +17,7 @@
#include "common/Assert.h"
#include "common/Constants.h"
#include "common/Math.h"
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/DawnHelpers.h"
#include <array>
@@ -163,12 +164,14 @@ protected:
dawn::ShaderModule fsModule =
utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, fragmentShader);
dawn::RenderPipeline pipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, mRenderPass.colorFormat)
.SetLayout(mPipelineLayout)
.SetStage(dawn::ShaderStage::Vertex, mVSModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.GetResult();
utils::ComboRenderPipelineDescriptor textureDescriptor(device);
textureDescriptor.cVertexStage.module = mVSModule;
textureDescriptor.cFragmentStage.module = fsModule;
textureDescriptor.layout = mPipelineLayout;
textureDescriptor.cColorAttachments[0].format =
mRenderPass.colorFormat;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&textureDescriptor);
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
{
@@ -502,11 +505,13 @@ class TextureViewRenderingTest : public DawnTest {
dawn::ShaderModule oneColorFsModule =
utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, oneColorFragmentShader);
dawn::RenderPipeline oneColorPipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, kDefaultFormat)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, oneColorFsModule, "main")
.GetResult();
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
pipelineDescriptor.cVertexStage.module = vsModule;
pipelineDescriptor.cFragmentStage.module = oneColorFsModule;
pipelineDescriptor.cColorAttachments[0].format = kDefaultFormat;
dawn::RenderPipeline oneColorPipeline = device.CreateRenderPipeline(&pipelineDescriptor);
dawn::CommandBufferBuilder commandBufferBuilder = device.CreateCommandBufferBuilder();
{
dawn::RenderPassEncoder pass =

View File

@@ -14,6 +14,7 @@
#include "tests/DawnTest.h"
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/DawnHelpers.h"
class ViewportOrientationTests : public DawnTest {};
@@ -35,12 +36,14 @@ TEST_P(ViewportOrientationTests, OriginAt0x0) {
fragColor = vec4(0.0f, 1.0f, 0.0f, 1.0f);
})");
dawn::RenderPipeline pipeline = device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, renderPass.colorFormat)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetPrimitiveTopology(dawn::PrimitiveTopology::PointList)
.GetResult();
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::PointList;
descriptor.cColorAttachments[0].format =
renderPass.colorFormat;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
{

View File

@@ -318,24 +318,99 @@ TEST_F(WireTests, ValueArrayArgument) {
// Test that the wire is able to send C strings
TEST_F(WireTests, CStringArgument) {
// Create shader module
dawnShaderModuleDescriptor descriptor;
descriptor.nextInChain = nullptr;
descriptor.codeSize = 0;
dawnShaderModule shaderModule = dawnDeviceCreateShaderModule(device, &descriptor);
dawnShaderModule apiShaderModule = api.GetNewShaderModule();
dawnShaderModuleDescriptor vertexDescriptor;
vertexDescriptor.nextInChain = nullptr;
vertexDescriptor.codeSize = 0;
dawnShaderModule vsModule = dawnDeviceCreateShaderModule(device, &vertexDescriptor);
dawnShaderModule apiVsModule = api.GetNewShaderModule();
EXPECT_CALL(api, DeviceCreateShaderModule(apiDevice, _))
.WillOnce(Return(apiShaderModule));
.WillOnce(Return(apiVsModule));
// Create the blend state
dawnBlendStateBuilder blendStateBuilder = dawnDeviceCreateBlendStateBuilder(device);
dawnBlendStateBuilder apiBlendStateBuilder = api.GetNewBlendStateBuilder();
EXPECT_CALL(api, DeviceCreateBlendStateBuilder(apiDevice))
.WillOnce(Return(apiBlendStateBuilder));
dawnBlendState blendState = dawnBlendStateBuilderGetResult(blendStateBuilder);
dawnBlendState apiBlendState = api.GetNewBlendState();
EXPECT_CALL(api, BlendStateBuilderGetResult(apiBlendStateBuilder))
.WillOnce(Return(apiBlendState));
// Create the input state
dawnInputStateBuilder inputStateBuilder = dawnDeviceCreateInputStateBuilder(device);
dawnInputStateBuilder apiInputStateBuilder = api.GetNewInputStateBuilder();
EXPECT_CALL(api, DeviceCreateInputStateBuilder(apiDevice))
.WillOnce(Return(apiInputStateBuilder));
dawnInputState inputState = dawnInputStateBuilderGetResult(inputStateBuilder);
dawnInputState apiInputState = api.GetNewInputState();
EXPECT_CALL(api, InputStateBuilderGetResult(apiInputStateBuilder))
.WillOnce(Return(apiInputState));
// Create the depth-stencil state
dawnDepthStencilStateBuilder depthStencilStateBuilder = dawnDeviceCreateDepthStencilStateBuilder(device);
dawnDepthStencilStateBuilder apiDepthStencilStateBuilder = api.GetNewDepthStencilStateBuilder();
EXPECT_CALL(api, DeviceCreateDepthStencilStateBuilder(apiDevice))
.WillOnce(Return(apiDepthStencilStateBuilder));
dawnDepthStencilState depthStencilState = dawnDepthStencilStateBuilderGetResult(depthStencilStateBuilder);
dawnDepthStencilState apiDepthStencilState = api.GetNewDepthStencilState();
EXPECT_CALL(api, DepthStencilStateBuilderGetResult(apiDepthStencilStateBuilder))
.WillOnce(Return(apiDepthStencilState));
// Create the pipeline layout
dawnPipelineLayoutDescriptor layoutDescriptor;
layoutDescriptor.nextInChain = nullptr;
layoutDescriptor.numBindGroupLayouts = 0;
layoutDescriptor.bindGroupLayouts = nullptr;
dawnPipelineLayout layout = dawnDeviceCreatePipelineLayout(device, &layoutDescriptor);
dawnPipelineLayout apiLayout = api.GetNewPipelineLayout();
EXPECT_CALL(api, DeviceCreatePipelineLayout(apiDevice, _))
.WillOnce(Return(apiLayout));
// Create pipeline
dawnRenderPipelineBuilder pipelineBuilder = dawnDeviceCreateRenderPipelineBuilder(device);
dawnRenderPipelineBuilderSetStage(pipelineBuilder, DAWN_SHADER_STAGE_FRAGMENT, shaderModule, "my entry point");
dawnRenderPipelineDescriptor pipelineDescriptor;
pipelineDescriptor.nextInChain = nullptr;
dawnRenderPipelineBuilder apiPipelineBuilder = api.GetNewRenderPipelineBuilder();
EXPECT_CALL(api, DeviceCreateRenderPipelineBuilder(apiDevice))
.WillOnce(Return(apiPipelineBuilder));
dawnPipelineStageDescriptor vertexStage;
vertexStage.nextInChain = nullptr;
vertexStage.module = vsModule;
vertexStage.entryPoint = "main";
pipelineDescriptor.vertexStage = &vertexStage;
EXPECT_CALL(api, RenderPipelineBuilderSetStage(apiPipelineBuilder, DAWN_SHADER_STAGE_FRAGMENT, apiShaderModule, StrEq("my entry point")));
dawnPipelineStageDescriptor fragmentStage;
fragmentStage.nextInChain = nullptr;
fragmentStage.module = vsModule;
fragmentStage.entryPoint = "main";
pipelineDescriptor.fragmentStage = &fragmentStage;
dawnAttachmentsStateDescriptor attachmentsState;
attachmentsState.nextInChain = nullptr;
attachmentsState.numColorAttachments = 1;
dawnAttachmentDescriptor colorAttachment = {nullptr, DAWN_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM};
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;
pipelineDescriptor.attachmentsState = &attachmentsState;
pipelineDescriptor.numBlendStates = 1;
pipelineDescriptor.blendStates = &blendState;
pipelineDescriptor.sampleCount = 1;
pipelineDescriptor.layout = layout;
pipelineDescriptor.inputState = inputState;
pipelineDescriptor.indexFormat = DAWN_INDEX_FORMAT_UINT32;
pipelineDescriptor.primitiveTopology = DAWN_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
pipelineDescriptor.depthStencilState = depthStencilState;
dawnDeviceCreateRenderPipeline(device, &pipelineDescriptor);
EXPECT_CALL(api, DeviceCreateRenderPipeline(apiDevice, MatchesLambda([](const dawnRenderPipelineDescriptor* desc) -> bool {
return desc->vertexStage->entryPoint == std::string("main");
})))
.WillOnce(Return(nullptr));
FlushClient();
}

View File

@@ -14,15 +14,12 @@
#include "tests/unittests/validation/ValidationTest.h"
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/DawnHelpers.h"
// Maximums for Dawn, tests will start failing when this changes
static constexpr uint32_t kMaxVertexAttributes = 16u;
static constexpr uint32_t kMaxVertexInputs = 16u;
class InputStateTest : public ValidationTest {
protected:
dawn::RenderPipeline CreatePipeline(bool success, const dawn::InputState& inputState, std::string vertexSource) {
void CreatePipeline(bool success, const dawn::InputState& inputState, std::string vertexSource) {
DummyRenderPass renderpassData = CreateDummyRenderPass();
dawn::ShaderModule vsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Vertex, vertexSource.c_str());
@@ -34,18 +31,18 @@ class InputStateTest : public ValidationTest {
}
)");
dawn::RenderPipelineBuilder builder;
if (success) {
builder = AssertWillBeSuccess(device.CreateRenderPipelineBuilder());
} else {
builder = AssertWillBeError(device.CreateRenderPipelineBuilder());
}
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.inputState = inputState;
descriptor.cColorAttachments[0].format =
renderpassData.attachmentFormat;
return builder.SetColorAttachmentFormat(0, renderpassData.attachmentFormat)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetInputState(inputState)
.GetResult();
if (!success) {
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
} else {
device.CreateRenderPipeline(&descriptor);
}
}
};

View File

@@ -15,6 +15,7 @@
#include "tests/unittests/validation/ValidationTest.h"
#include "common/Constants.h"
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/DawnHelpers.h"
class RenderPipelineValidationTest : public ValidationTest {
@@ -24,12 +25,6 @@ class RenderPipelineValidationTest : public ValidationTest {
renderpass = CreateSimpleRenderPass();
pipelineLayout = utils::MakeBasicPipelineLayout(device, nullptr);
inputState = device.CreateInputStateBuilder().GetResult();
blendState = device.CreateBlendStateBuilder().GetResult();
vsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Vertex, R"(
#version 450
void main() {
@@ -45,167 +40,49 @@ class RenderPipelineValidationTest : public ValidationTest {
})");
}
dawn::RenderPipelineBuilder& AddDefaultStates(dawn::RenderPipelineBuilder&& builder) {
builder.SetColorAttachmentFormat(0, dawn::TextureFormat::R8G8B8A8Unorm)
.SetLayout(pipelineLayout)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetPrimitiveTopology(dawn::PrimitiveTopology::TriangleList);
return builder;
}
dawn::RenderPassDescriptor renderpass;
dawn::ShaderModule vsModule;
dawn::ShaderModule fsModule;
dawn::InputState inputState;
dawn::BlendState blendState;
dawn::PipelineLayout pipelineLayout;
};
// Test cases where creation should succeed
TEST_F(RenderPipelineValidationTest, CreationSuccess) {
AddDefaultStates(AssertWillBeSuccess(device.CreateRenderPipelineBuilder()))
.GetResult();
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
AddDefaultStates(AssertWillBeSuccess(device.CreateRenderPipelineBuilder()))
.SetInputState(inputState)
.GetResult();
AddDefaultStates(AssertWillBeSuccess(device.CreateRenderPipelineBuilder()))
.SetColorAttachmentBlendState(0, blendState)
.GetResult();
}
// Test creation failure when properties are missing
TEST_F(RenderPipelineValidationTest, CreationMissingProperty) {
// Vertex stage not set
{
AssertWillBeError(device.CreateRenderPipelineBuilder())
.SetColorAttachmentFormat(0, dawn::TextureFormat::R8G8B8A8Unorm)
.SetLayout(pipelineLayout)
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetPrimitiveTopology(dawn::PrimitiveTopology::TriangleList)
.GetResult();
}
// Fragment stage not set
{
AssertWillBeError(device.CreateRenderPipelineBuilder())
.SetColorAttachmentFormat(0, dawn::TextureFormat::R8G8B8A8Unorm)
.SetLayout(pipelineLayout)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetPrimitiveTopology(dawn::PrimitiveTopology::TriangleList)
.GetResult();
}
// No attachment set
{
AssertWillBeError(device.CreateRenderPipelineBuilder())
.SetLayout(pipelineLayout)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetPrimitiveTopology(dawn::PrimitiveTopology::TriangleList)
.GetResult();
}
device.CreateRenderPipeline(&descriptor);
}
TEST_F(RenderPipelineValidationTest, BlendState) {
// Fails because blend state is set on a nonexistent color attachment
{
// This one succeeds because attachment 0 is the color attachment
AssertWillBeSuccess(device.CreateRenderPipelineBuilder())
.SetColorAttachmentFormat(0, dawn::TextureFormat::R8G8B8A8Unorm)
.SetLayout(pipelineLayout)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetPrimitiveTopology(dawn::PrimitiveTopology::TriangleList)
.SetColorAttachmentBlendState(0, blendState)
.GetResult();
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.numBlendStates = 1;
// This fails because attachment 1 is not one of the color attachments
AssertWillBeError(device.CreateRenderPipelineBuilder())
.SetColorAttachmentFormat(0, dawn::TextureFormat::R8G8B8A8Unorm)
.SetLayout(pipelineLayout)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetPrimitiveTopology(dawn::PrimitiveTopology::TriangleList)
.SetColorAttachmentBlendState(1, blendState)
.GetResult();
device.CreateRenderPipeline(&descriptor);
}
// Fails because color attachment is out of bounds
{
AddDefaultStates(AssertWillBeError(device.CreateRenderPipelineBuilder()))
.SetColorAttachmentBlendState(kMaxColorAttachments, blendState)
.GetResult();
{ // Fail because lack of blend states for color attachments
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.numBlendStates = 0;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
}
// Fails because color attachment blend state is set twice
{
AddDefaultStates(AssertWillBeError(device.CreateRenderPipelineBuilder()))
.SetColorAttachmentBlendState(0, blendState)
.SetColorAttachmentBlendState(0, blendState)
.GetResult();
// Fail because set blend states for empty color attachments
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.numBlendStates = 2;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
}
}
// TODO(enga@google.com): These should be added to the test above when validation is implemented
TEST_F(RenderPipelineValidationTest, DISABLED_TodoCreationMissingProperty) {
// Fails because pipeline layout is not set
{
AssertWillBeError(device.CreateRenderPipelineBuilder())
.SetColorAttachmentFormat(0, dawn::TextureFormat::R8G8B8A8Unorm)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetPrimitiveTopology(dawn::PrimitiveTopology::TriangleList)
.GetResult();
}
// Fails because primitive topology is not set
{
AssertWillBeError(device.CreateRenderPipelineBuilder())
.SetColorAttachmentFormat(0, dawn::TextureFormat::R8G8B8A8Unorm)
.SetLayout(pipelineLayout)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.GetResult();
}
}
// Test creation failure when specifying properties multiple times
TEST_F(RenderPipelineValidationTest, DISABLED_CreationDuplicates) {
// Fails because input state is set twice
{
AddDefaultStates(AssertWillBeError(device.CreateRenderPipelineBuilder()))
.SetInputState(inputState)
.GetResult();
}
// Fails because primitive topology is set twice
{
AddDefaultStates(AssertWillBeError(device.CreateRenderPipelineBuilder()))
.SetPrimitiveTopology(dawn::PrimitiveTopology::TriangleList)
.GetResult();
}
// Fails because vertex stage is set twice
{
AddDefaultStates(AssertWillBeError(device.CreateRenderPipelineBuilder()))
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.GetResult();
}
// Fails because fragment stage is set twice
{
AddDefaultStates(AssertWillBeError(device.CreateRenderPipelineBuilder()))
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.GetResult();
}
// Fails because the layout is set twice
{
AddDefaultStates(AssertWillBeError(device.CreateRenderPipelineBuilder()))
.SetLayout(pipelineLayout)
.GetResult();
}
}

View File

@@ -16,6 +16,7 @@
#include "tests/unittests/validation/ValidationTest.h"
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/DawnHelpers.h"
class VertexBufferValidationTest : public ValidationTest {
@@ -78,12 +79,13 @@ class VertexBufferValidationTest : public ValidationTest {
}
dawn::RenderPipeline MakeRenderPipeline(const dawn::ShaderModule& vsModule, const dawn::InputState& inputState) {
return device.CreateRenderPipelineBuilder()
.SetColorAttachmentFormat(0, dawn::TextureFormat::R8G8B8A8Unorm)
.SetStage(dawn::ShaderStage::Vertex, vsModule, "main")
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
.SetInputState(inputState)
.GetResult();
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.inputState = inputState;
return device.CreateRenderPipeline(&descriptor);
}
dawn::RenderPassDescriptor renderpass;