Introduce [Render|Compute]PassEncoder.
This splits off part of CommandBufferBuilder in separate RenderPassEncoder and ComputePassEncoder objects. To match the WebGPU IDL and factor some code, both these encoders inherit from ProgrammablePassEncoder. These encoders are pure frontend objects and record into the CommandBufferBuilder command allocator objects, so no changes to the backends were needed. Error handling is still ew, because the "builder" mechanism we had doesn't allow for "split builders". Nicer error handling will have to wait on Dawn matching WebGPU. All the tests and samples were updated to the new structure. BUG=dawn:5 Change-Id: I5f5d4ad866e2c07fedd1ba7a122258c6610941f1 Reviewed-on: https://dawn-review.googlesource.com/1543 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
31d1e78d57
commit
82fbccbd78
6
BUILD.gn
6
BUILD.gn
|
@ -348,6 +348,8 @@ source_set("libdawn_native_sources") {
|
||||||
"src/dawn_native/CommandBufferStateTracker.h",
|
"src/dawn_native/CommandBufferStateTracker.h",
|
||||||
"src/dawn_native/Commands.cpp",
|
"src/dawn_native/Commands.cpp",
|
||||||
"src/dawn_native/Commands.h",
|
"src/dawn_native/Commands.h",
|
||||||
|
"src/dawn_native/ComputePassEncoder.cpp",
|
||||||
|
"src/dawn_native/ComputePassEncoder.h",
|
||||||
"src/dawn_native/ComputePipeline.cpp",
|
"src/dawn_native/ComputePipeline.cpp",
|
||||||
"src/dawn_native/ComputePipeline.h",
|
"src/dawn_native/ComputePipeline.h",
|
||||||
"src/dawn_native/DawnNative.cpp",
|
"src/dawn_native/DawnNative.cpp",
|
||||||
|
@ -369,12 +371,16 @@ source_set("libdawn_native_sources") {
|
||||||
"src/dawn_native/Pipeline.h",
|
"src/dawn_native/Pipeline.h",
|
||||||
"src/dawn_native/PipelineLayout.cpp",
|
"src/dawn_native/PipelineLayout.cpp",
|
||||||
"src/dawn_native/PipelineLayout.h",
|
"src/dawn_native/PipelineLayout.h",
|
||||||
|
"src/dawn_native/ProgrammablePassEncoder.cpp",
|
||||||
|
"src/dawn_native/ProgrammablePassEncoder.h",
|
||||||
"src/dawn_native/Queue.cpp",
|
"src/dawn_native/Queue.cpp",
|
||||||
"src/dawn_native/Queue.h",
|
"src/dawn_native/Queue.h",
|
||||||
"src/dawn_native/RefCounted.cpp",
|
"src/dawn_native/RefCounted.cpp",
|
||||||
"src/dawn_native/RefCounted.h",
|
"src/dawn_native/RefCounted.h",
|
||||||
"src/dawn_native/RenderPassDescriptor.cpp",
|
"src/dawn_native/RenderPassDescriptor.cpp",
|
||||||
"src/dawn_native/RenderPassDescriptor.h",
|
"src/dawn_native/RenderPassDescriptor.h",
|
||||||
|
"src/dawn_native/RenderPassEncoder.cpp",
|
||||||
|
"src/dawn_native/RenderPassEncoder.h",
|
||||||
"src/dawn_native/RenderPipeline.cpp",
|
"src/dawn_native/RenderPipeline.cpp",
|
||||||
"src/dawn_native/RenderPipeline.h",
|
"src/dawn_native/RenderPipeline.h",
|
||||||
"src/dawn_native/Sampler.cpp",
|
"src/dawn_native/Sampler.cpp",
|
||||||
|
|
218
dawn.json
218
dawn.json
|
@ -319,13 +319,15 @@
|
||||||
"returns": "command buffer"
|
"returns": "command buffer"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "begin compute pass"
|
"name": "begin compute pass",
|
||||||
|
"returns": "compute pass encoder"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "begin render pass",
|
"name": "begin render pass",
|
||||||
"args": [
|
"args": [
|
||||||
{"name": "info", "type": "render pass descriptor"}
|
{"name": "info", "type": "render pass descriptor"}
|
||||||
]
|
],
|
||||||
|
"returns": "render pass encoder"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "copy buffer to buffer",
|
"name": "copy buffer to buffer",
|
||||||
|
@ -385,66 +387,30 @@
|
||||||
"Add these arguments too",
|
"Add these arguments too",
|
||||||
{"name": "image height", "type": "uint32_t"}
|
{"name": "image height", "type": "uint32_t"}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"compare function": {
|
||||||
|
"category": "enum",
|
||||||
|
"values": [
|
||||||
|
{"value": 0, "name": "never"},
|
||||||
|
{"value": 1, "name": "less"},
|
||||||
|
{"value": 2, "name": "less equal"},
|
||||||
|
{"value": 3, "name": "greater"},
|
||||||
|
{"value": 4, "name": "greater equal"},
|
||||||
|
{"value": 5, "name": "equal"},
|
||||||
|
{"value": 6, "name": "not equal"},
|
||||||
|
{"value": 7, "name": "always"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"compute pass encoder": {
|
||||||
|
"category": "object",
|
||||||
|
"methods": [
|
||||||
{
|
{
|
||||||
"name": "dispatch",
|
"name": "set compute pipeline",
|
||||||
|
"TODO": "This is called setPipeline in the WebGPU IDL",
|
||||||
"args": [
|
"args": [
|
||||||
{"name": "x", "type": "uint32_t"},
|
{"name": "pipeline", "type": "compute pipeline"}
|
||||||
{"name": "y", "type": "uint32_t"},
|
|
||||||
{"name": "z", "type": "uint32_t"}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "draw arrays",
|
|
||||||
"args": [
|
|
||||||
{"name": "vertex count", "type": "uint32_t"},
|
|
||||||
{"name": "instance count", "type": "uint32_t"},
|
|
||||||
{"name": "first vertex", "type": "uint32_t"},
|
|
||||||
{"name": "first instance", "type": "uint32_t"}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "draw elements",
|
|
||||||
"args": [
|
|
||||||
{"name": "index count", "type": "uint32_t"},
|
|
||||||
{"name": "instance count", "type": "uint32_t"},
|
|
||||||
{"name": "first index", "type": "uint32_t"},
|
|
||||||
{"name": "first instance", "type": "uint32_t"}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "end compute pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "end render pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "set stencil reference",
|
|
||||||
"args": [
|
|
||||||
{"name": "reference", "type": "uint32_t"}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "set blend color",
|
|
||||||
"args": [
|
|
||||||
{"name": "r", "type": "float"},
|
|
||||||
{"name": "g", "type": "float"},
|
|
||||||
{"name": "b", "type": "float"},
|
|
||||||
{"name": "a", "type": "float"}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "set bind group",
|
|
||||||
"args": [
|
|
||||||
{"name": "group index", "type": "uint32_t"},
|
|
||||||
{"name": "group", "type": "bind group"}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "set index buffer",
|
|
||||||
"args": [
|
|
||||||
{"name": "buffer", "type": "buffer"},
|
|
||||||
{"name": "offset", "type": "uint32_t"}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -461,50 +427,26 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "set compute pipeline",
|
"name": "set bind group",
|
||||||
"args": [
|
"args": [
|
||||||
{"name": "pipeline", "type": "compute pipeline"}
|
{"name": "group index", "type": "uint32_t"},
|
||||||
|
{"name": "group", "type": "bind group"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "set render pipeline",
|
"name": "dispatch",
|
||||||
"args": [
|
|
||||||
{"name": "pipeline", "type": "render pipeline"}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "set scissor rect",
|
|
||||||
"args": [
|
"args": [
|
||||||
{"name": "x", "type": "uint32_t"},
|
{"name": "x", "type": "uint32_t"},
|
||||||
{"name": "y", "type": "uint32_t"},
|
{"name": "y", "type": "uint32_t"},
|
||||||
{"name": "width", "type": "uint32_t"},
|
{"name": "z", "type": "uint32_t"}
|
||||||
{"name": "height", "type": "uint32_t"}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "set vertex buffers",
|
"name": "end pass",
|
||||||
"args": [
|
"TODO": "This returns the top-level encoder in the WebGPU IDL"
|
||||||
{"name": "start slot", "type": "uint32_t"},
|
|
||||||
{"name": "count", "type": "uint32_t"},
|
|
||||||
{"name": "buffers", "type": "buffer", "annotation": "const*", "length": "count"},
|
|
||||||
{"name": "offsets", "type": "uint32_t", "annotation": "const*", "length": "count"}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"compare function": {
|
|
||||||
"category": "enum",
|
|
||||||
"values": [
|
|
||||||
{"value": 0, "name": "never"},
|
|
||||||
{"value": 1, "name": "less"},
|
|
||||||
{"value": 2, "name": "less equal"},
|
|
||||||
{"value": 3, "name": "greater"},
|
|
||||||
{"value": 4, "name": "greater equal"},
|
|
||||||
{"value": 5, "name": "equal"},
|
|
||||||
{"value": 6, "name": "not equal"},
|
|
||||||
{"value": 7, "name": "always"}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"compute pipeline": {
|
"compute pipeline": {
|
||||||
"category": "object"
|
"category": "object"
|
||||||
},
|
},
|
||||||
|
@ -822,6 +764,100 @@
|
||||||
"render pass descriptor": {
|
"render pass descriptor": {
|
||||||
"category": "object"
|
"category": "object"
|
||||||
},
|
},
|
||||||
|
"render pass encoder": {
|
||||||
|
"category": "object",
|
||||||
|
"methods": [
|
||||||
|
{
|
||||||
|
"name": "set render pipeline",
|
||||||
|
"TODO": "This is called setPipeline in the WebGPU IDL",
|
||||||
|
"args": [
|
||||||
|
{"name": "pipeline", "type": "render pipeline"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "set push constants",
|
||||||
|
"TODO": [
|
||||||
|
"data should be void*",
|
||||||
|
"TODO Vulkan has an additional stage mask"
|
||||||
|
],
|
||||||
|
"args": [
|
||||||
|
{"name": "stages", "type": "shader stage bit"},
|
||||||
|
{"name": "offset", "type": "uint32_t"},
|
||||||
|
{"name": "count", "type": "uint32_t"},
|
||||||
|
{"name": "data", "type": "uint32_t", "annotation": "const*", "length": "count"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "set bind group",
|
||||||
|
"args": [
|
||||||
|
{"name": "group index", "type": "uint32_t"},
|
||||||
|
{"name": "group", "type": "bind group"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "draw arrays",
|
||||||
|
"args": [
|
||||||
|
{"name": "vertex count", "type": "uint32_t"},
|
||||||
|
{"name": "instance count", "type": "uint32_t"},
|
||||||
|
{"name": "first vertex", "type": "uint32_t"},
|
||||||
|
{"name": "first instance", "type": "uint32_t"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "draw elements",
|
||||||
|
"args": [
|
||||||
|
{"name": "index count", "type": "uint32_t"},
|
||||||
|
{"name": "instance count", "type": "uint32_t"},
|
||||||
|
{"name": "first index", "type": "uint32_t"},
|
||||||
|
{"name": "first instance", "type": "uint32_t"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "set stencil reference",
|
||||||
|
"args": [
|
||||||
|
{"name": "reference", "type": "uint32_t"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "set blend color",
|
||||||
|
"args": [
|
||||||
|
{"name": "r", "type": "float"},
|
||||||
|
{"name": "g", "type": "float"},
|
||||||
|
{"name": "b", "type": "float"},
|
||||||
|
{"name": "a", "type": "float"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "set scissor rect",
|
||||||
|
"args": [
|
||||||
|
{"name": "x", "type": "uint32_t"},
|
||||||
|
{"name": "y", "type": "uint32_t"},
|
||||||
|
{"name": "width", "type": "uint32_t"},
|
||||||
|
{"name": "height", "type": "uint32_t"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "set vertex buffers",
|
||||||
|
"args": [
|
||||||
|
{"name": "start slot", "type": "uint32_t"},
|
||||||
|
{"name": "count", "type": "uint32_t"},
|
||||||
|
{"name": "buffers", "type": "buffer", "annotation": "const*", "length": "count"},
|
||||||
|
{"name": "offsets", "type": "uint32_t", "annotation": "const*", "length": "count"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "set index buffer",
|
||||||
|
"args": [
|
||||||
|
{"name": "buffer", "type": "buffer"},
|
||||||
|
{"name": "offset", "type": "uint32_t"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "end pass",
|
||||||
|
"TODO": "This returns the top-level encoder in the WebGPU IDL"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"render pipeline": {
|
"render pipeline": {
|
||||||
"category": "object"
|
"category": "object"
|
||||||
},
|
},
|
||||||
|
|
|
@ -137,24 +137,22 @@ void frame() {
|
||||||
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
dawn::CommandBuffer commands;
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
{
|
{
|
||||||
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder()
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass);
|
||||||
.BeginRenderPass(renderPass)
|
pass.SetRenderPipeline(pipeline);
|
||||||
.SetRenderPipeline(pipeline)
|
|
||||||
.Clone();
|
|
||||||
|
|
||||||
for (int k = 0; k < 10000; k++) {
|
for (int k = 0; k < 10000; k++) {
|
||||||
shaderData[i].time = f / 60.0f;
|
shaderData[i].time = f / 60.0f;
|
||||||
builder.SetPushConstants(dawn::ShaderStageBit::Vertex, 0, 6, reinterpret_cast<uint32_t*>(&shaderData[i]))
|
pass.SetPushConstants(dawn::ShaderStageBit::Vertex, 0, 6, reinterpret_cast<uint32_t*>(&shaderData[i]));
|
||||||
.DrawArrays(3, 1, 0, 0);
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.EndRenderPass();
|
pass.EndPass();
|
||||||
commands = builder.GetResult();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
swapchain.Present(backbuffer);
|
swapchain.Present(backbuffer);
|
||||||
DoFlush();
|
DoFlush();
|
||||||
|
|
|
@ -84,10 +84,13 @@ void frame() {
|
||||||
dawnCommandBuffer commands;
|
dawnCommandBuffer commands;
|
||||||
{
|
{
|
||||||
dawnCommandBufferBuilder builder = dawnDeviceCreateCommandBufferBuilder(device);
|
dawnCommandBufferBuilder builder = dawnDeviceCreateCommandBufferBuilder(device);
|
||||||
dawnCommandBufferBuilderBeginRenderPass(builder, renderpassInfo);
|
|
||||||
dawnCommandBufferBuilderSetRenderPipeline(builder, pipeline);
|
dawnRenderPassEncoder pass = dawnCommandBufferBuilderBeginRenderPass(builder, renderpassInfo);
|
||||||
dawnCommandBufferBuilderDrawArrays(builder, 3, 1, 0, 0);
|
dawnRenderPassEncoderSetRenderPipeline(pass, pipeline);
|
||||||
dawnCommandBufferBuilderEndRenderPass(builder);
|
dawnRenderPassEncoderDrawArrays(pass, 3, 1, 0, 0);
|
||||||
|
dawnRenderPassEncoderEndPass(pass);
|
||||||
|
dawnRenderPassEncoderRelease(pass);
|
||||||
|
|
||||||
commands = dawnCommandBufferBuilderGetResult(builder);
|
commands = dawnCommandBufferBuilderGetResult(builder);
|
||||||
dawnCommandBufferBuilderRelease(builder);
|
dawnCommandBufferBuilderRelease(builder);
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,21 +261,26 @@ void initSim() {
|
||||||
dawn::CommandBuffer createCommandBuffer(const dawn::RenderPassDescriptor& renderPass, size_t i) {
|
dawn::CommandBuffer createCommandBuffer(const dawn::RenderPassDescriptor& renderPass, size_t i) {
|
||||||
static const uint32_t zeroOffsets[1] = {0};
|
static const uint32_t zeroOffsets[1] = {0};
|
||||||
auto& bufferDst = particleBuffers[(i + 1) % 2];
|
auto& bufferDst = particleBuffers[(i + 1) % 2];
|
||||||
return device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginComputePass()
|
|
||||||
.SetComputePipeline(updatePipeline)
|
|
||||||
.SetBindGroup(0, updateBGs[i])
|
|
||||||
.Dispatch(kNumParticles, 1, 1)
|
|
||||||
.EndComputePass()
|
|
||||||
|
|
||||||
.BeginRenderPass(renderPass)
|
{
|
||||||
.SetRenderPipeline(renderPipeline)
|
dawn::ComputePassEncoder pass = builder.BeginComputePass();
|
||||||
.SetVertexBuffers(0, 1, &bufferDst, zeroOffsets)
|
pass.SetComputePipeline(updatePipeline);
|
||||||
.SetVertexBuffers(1, 1, &modelBuffer, zeroOffsets)
|
pass.SetBindGroup(0, updateBGs[i]);
|
||||||
.DrawArrays(3, kNumParticles, 0, 0)
|
pass.Dispatch(kNumParticles, 1, 1);
|
||||||
.EndRenderPass()
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
.GetResult();
|
{
|
||||||
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass);
|
||||||
|
pass.SetRenderPipeline(renderPipeline);
|
||||||
|
pass.SetVertexBuffers(0, 1, &bufferDst, zeroOffsets);
|
||||||
|
pass.SetVertexBuffers(1, 1, &modelBuffer, zeroOffsets);
|
||||||
|
pass.DrawArrays(3, kNumParticles, 0, 0);
|
||||||
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
|
|
|
@ -151,16 +151,18 @@ void frame() {
|
||||||
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
|
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
|
||||||
|
|
||||||
static const uint32_t vertexBufferOffsets[1] = {0};
|
static const uint32_t vertexBufferOffsets[1] = {0};
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass)
|
{
|
||||||
.SetRenderPipeline(pipeline)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass);
|
||||||
.SetBindGroup(0, bindGroup)
|
pass.SetRenderPipeline(pipeline);
|
||||||
.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets)
|
pass.SetBindGroup(0, bindGroup);
|
||||||
.SetIndexBuffer(indexBuffer, 0)
|
pass.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets);
|
||||||
.DrawElements(3, 1, 0, 0)
|
pass.SetIndexBuffer(indexBuffer, 0);
|
||||||
.EndRenderPass()
|
pass.DrawElements(3, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
swapchain.Present(backbuffer);
|
swapchain.Present(backbuffer);
|
||||||
DoFlush();
|
DoFlush();
|
||||||
|
|
|
@ -277,27 +277,30 @@ void frame() {
|
||||||
dawn::RenderPassDescriptor renderPass;
|
dawn::RenderPassDescriptor renderPass;
|
||||||
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
|
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
|
||||||
|
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass)
|
{
|
||||||
.SetRenderPipeline(pipeline)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass);
|
||||||
.SetBindGroup(0, bindGroup[0])
|
pass.SetRenderPipeline(pipeline);
|
||||||
.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets)
|
pass.SetBindGroup(0, bindGroup[0]);
|
||||||
.SetIndexBuffer(indexBuffer, 0)
|
pass.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets);
|
||||||
.DrawElements(36, 1, 0, 0)
|
pass.SetIndexBuffer(indexBuffer, 0);
|
||||||
|
pass.DrawElements(36, 1, 0, 0);
|
||||||
|
|
||||||
.SetStencilReference(0x1)
|
pass.SetStencilReference(0x1);
|
||||||
.SetRenderPipeline(planePipeline)
|
pass.SetRenderPipeline(planePipeline);
|
||||||
.SetBindGroup(0, bindGroup[0])
|
pass.SetBindGroup(0, bindGroup[0]);
|
||||||
.SetVertexBuffers(0, 1, &planeBuffer, vertexBufferOffsets)
|
pass.SetVertexBuffers(0, 1, &planeBuffer, vertexBufferOffsets);
|
||||||
.DrawElements(6, 1, 0, 0)
|
pass.DrawElements(6, 1, 0, 0);
|
||||||
|
|
||||||
.SetRenderPipeline(reflectionPipeline)
|
pass.SetRenderPipeline(reflectionPipeline);
|
||||||
.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets)
|
pass.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets);
|
||||||
.SetBindGroup(0, bindGroup[1])
|
pass.SetBindGroup(0, bindGroup[1]);
|
||||||
.DrawElements(36, 1, 0, 0)
|
pass.DrawElements(36, 1, 0, 0);
|
||||||
.EndRenderPass()
|
|
||||||
.GetResult();
|
|
||||||
|
|
||||||
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
swapchain.Present(backbuffer);
|
swapchain.Present(backbuffer);
|
||||||
DoFlush();
|
DoFlush();
|
||||||
|
|
|
@ -460,7 +460,7 @@ namespace {
|
||||||
|
|
||||||
// Drawing
|
// Drawing
|
||||||
namespace {
|
namespace {
|
||||||
void drawMesh(dawn::CommandBufferBuilder& cmd, const tinygltf::Mesh& iMesh, const glm::mat4& model) {
|
void drawMesh(dawn::RenderPassEncoder& pass, const tinygltf::Mesh& iMesh, const glm::mat4& model) {
|
||||||
for (const auto& iPrim : iMesh.primitives) {
|
for (const auto& iPrim : iMesh.primitives) {
|
||||||
if (iPrim.mode != gl::Triangles) {
|
if (iPrim.mode != gl::Triangles) {
|
||||||
fprintf(stderr, "unsupported primitive mode %d\n", iPrim.mode);
|
fprintf(stderr, "unsupported primitive mode %d\n", iPrim.mode);
|
||||||
|
@ -484,9 +484,9 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const MaterialInfo& material = getMaterial(iPrim.material, strides[0], strides[1], strides[2]);
|
const MaterialInfo& material = getMaterial(iPrim.material, strides[0], strides[1], strides[2]);
|
||||||
cmd.SetRenderPipeline(material.pipeline);
|
pass.SetRenderPipeline(material.pipeline);
|
||||||
cmd.SetBindGroup(0, material.bindGroup0);
|
pass.SetBindGroup(0, material.bindGroup0);
|
||||||
cmd.SetPushConstants(dawn::ShaderStageBit::Vertex,
|
pass.SetPushConstants(dawn::ShaderStageBit::Vertex,
|
||||||
0, sizeof(u_transform_block) / sizeof(uint32_t),
|
0, sizeof(u_transform_block) / sizeof(uint32_t),
|
||||||
reinterpret_cast<const uint32_t*>(&transforms));
|
reinterpret_cast<const uint32_t*>(&transforms));
|
||||||
|
|
||||||
|
@ -496,7 +496,7 @@ namespace {
|
||||||
auto it = iPrim.attributes.find(s.second);
|
auto it = iPrim.attributes.find(s.second);
|
||||||
if (it == iPrim.attributes.end()) {
|
if (it == iPrim.attributes.end()) {
|
||||||
uint32_t zero = 0;
|
uint32_t zero = 0;
|
||||||
cmd.SetVertexBuffers(slot, 1, &defaultBuffer, &zero);
|
pass.SetVertexBuffers(slot, 1, &defaultBuffer, &zero);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const auto& iAccessor = scene.accessors.at(it->second);
|
const auto& iAccessor = scene.accessors.at(it->second);
|
||||||
|
@ -511,7 +511,7 @@ namespace {
|
||||||
}
|
}
|
||||||
const auto& oBuffer = buffers.at(iAccessor.bufferView);
|
const auto& oBuffer = buffers.at(iAccessor.bufferView);
|
||||||
uint32_t iBufferOffset = static_cast<uint32_t>(iAccessor.byteOffset);
|
uint32_t iBufferOffset = static_cast<uint32_t>(iAccessor.byteOffset);
|
||||||
cmd.SetVertexBuffers(slot, 1, &oBuffer, &iBufferOffset);
|
pass.SetVertexBuffers(slot, 1, &oBuffer, &iBufferOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!iPrim.indices.empty()) {
|
if (!iPrim.indices.empty()) {
|
||||||
|
@ -522,16 +522,16 @@ namespace {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const auto& oIndicesBuffer = buffers.at(iIndices.bufferView);
|
const auto& oIndicesBuffer = buffers.at(iIndices.bufferView);
|
||||||
cmd.SetIndexBuffer(oIndicesBuffer, static_cast<uint32_t>(iIndices.byteOffset));
|
pass.SetIndexBuffer(oIndicesBuffer, static_cast<uint32_t>(iIndices.byteOffset));
|
||||||
cmd.DrawElements(static_cast<uint32_t>(iIndices.count), 1, 0, 0);
|
pass.DrawElements(static_cast<uint32_t>(iIndices.count), 1, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
// DrawArrays
|
// DrawArrays
|
||||||
cmd.DrawArrays(vertexCount, 1, 0, 0);
|
pass.DrawArrays(vertexCount, 1, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawNode(dawn::CommandBufferBuilder& cmd, const tinygltf::Node& node, const glm::mat4& parent = glm::mat4()) {
|
void drawNode(dawn::RenderPassEncoder& pass, const tinygltf::Node& node, const glm::mat4& parent = glm::mat4()) {
|
||||||
glm::mat4 model;
|
glm::mat4 model;
|
||||||
if (node.matrix.size() == 16) {
|
if (node.matrix.size() == 16) {
|
||||||
model = glm::make_mat4(node.matrix.data());
|
model = glm::make_mat4(node.matrix.data());
|
||||||
|
@ -552,10 +552,10 @@ namespace {
|
||||||
model = parent * model;
|
model = parent * model;
|
||||||
|
|
||||||
for (const auto& meshID : node.meshes) {
|
for (const auto& meshID : node.meshes) {
|
||||||
drawMesh(cmd, scene.meshes[meshID], model);
|
drawMesh(pass, scene.meshes[meshID], model);
|
||||||
}
|
}
|
||||||
for (const auto& child : node.children) {
|
for (const auto& child : node.children) {
|
||||||
drawNode(cmd, scene.nodes.at(child), model);
|
drawNode(pass, scene.nodes.at(child), model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -565,15 +565,17 @@ namespace {
|
||||||
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
|
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
|
||||||
|
|
||||||
const auto& defaultSceneNodes = scene.scenes.at(scene.defaultScene);
|
const auto& defaultSceneNodes = scene.scenes.at(scene.defaultScene);
|
||||||
dawn::CommandBufferBuilder cmd = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass)
|
{
|
||||||
.Clone();
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass);
|
||||||
for (const auto& n : defaultSceneNodes) {
|
for (const auto& n : defaultSceneNodes) {
|
||||||
const auto& node = scene.nodes.at(n);
|
const auto& node = scene.nodes.at(n);
|
||||||
drawNode(cmd, node);
|
drawNode(pass, node);
|
||||||
|
}
|
||||||
|
pass.EndPass();
|
||||||
}
|
}
|
||||||
auto commands = cmd.EndRenderPass()
|
|
||||||
.GetResult();
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
swapchain.Present(backbuffer);
|
swapchain.Present(backbuffer);
|
||||||
|
|
|
@ -333,6 +333,8 @@ list(APPEND DAWN_NATIVE_SOURCES
|
||||||
${DAWN_NATIVE_DIR}/CommandAllocator.h
|
${DAWN_NATIVE_DIR}/CommandAllocator.h
|
||||||
${DAWN_NATIVE_DIR}/CommandBuffer.cpp
|
${DAWN_NATIVE_DIR}/CommandBuffer.cpp
|
||||||
${DAWN_NATIVE_DIR}/CommandBuffer.h
|
${DAWN_NATIVE_DIR}/CommandBuffer.h
|
||||||
|
${DAWN_NATIVE_DIR}/ComputePassEncoder.cpp
|
||||||
|
${DAWN_NATIVE_DIR}/ComputePassEncoder.h
|
||||||
${DAWN_NATIVE_DIR}/ComputePipeline.cpp
|
${DAWN_NATIVE_DIR}/ComputePipeline.cpp
|
||||||
${DAWN_NATIVE_DIR}/ComputePipeline.h
|
${DAWN_NATIVE_DIR}/ComputePipeline.h
|
||||||
${DAWN_NATIVE_DIR}/CommandBufferStateTracker.cpp
|
${DAWN_NATIVE_DIR}/CommandBufferStateTracker.cpp
|
||||||
|
@ -358,10 +360,14 @@ list(APPEND DAWN_NATIVE_SOURCES
|
||||||
${DAWN_NATIVE_DIR}/Pipeline.h
|
${DAWN_NATIVE_DIR}/Pipeline.h
|
||||||
${DAWN_NATIVE_DIR}/PipelineLayout.cpp
|
${DAWN_NATIVE_DIR}/PipelineLayout.cpp
|
||||||
${DAWN_NATIVE_DIR}/PipelineLayout.h
|
${DAWN_NATIVE_DIR}/PipelineLayout.h
|
||||||
|
${DAWN_NATIVE_DIR}/ProgrammablePassEncoder.cpp
|
||||||
|
${DAWN_NATIVE_DIR}/ProgrammablePassEncoder.h
|
||||||
${DAWN_NATIVE_DIR}/Queue.cpp
|
${DAWN_NATIVE_DIR}/Queue.cpp
|
||||||
${DAWN_NATIVE_DIR}/Queue.h
|
${DAWN_NATIVE_DIR}/Queue.h
|
||||||
${DAWN_NATIVE_DIR}/RenderPassDescriptor.cpp
|
${DAWN_NATIVE_DIR}/RenderPassDescriptor.cpp
|
||||||
${DAWN_NATIVE_DIR}/RenderPassDescriptor.h
|
${DAWN_NATIVE_DIR}/RenderPassDescriptor.h
|
||||||
|
${DAWN_NATIVE_DIR}/RenderPassEncoder.cpp
|
||||||
|
${DAWN_NATIVE_DIR}/RenderPassEncoder.h
|
||||||
${DAWN_NATIVE_DIR}/RefCounted.cpp
|
${DAWN_NATIVE_DIR}/RefCounted.cpp
|
||||||
${DAWN_NATIVE_DIR}/RefCounted.h
|
${DAWN_NATIVE_DIR}/RefCounted.h
|
||||||
${DAWN_NATIVE_DIR}/Sampler.cpp
|
${DAWN_NATIVE_DIR}/Sampler.cpp
|
||||||
|
|
|
@ -18,10 +18,13 @@
|
||||||
#include "dawn_native/Buffer.h"
|
#include "dawn_native/Buffer.h"
|
||||||
#include "dawn_native/CommandBufferStateTracker.h"
|
#include "dawn_native/CommandBufferStateTracker.h"
|
||||||
#include "dawn_native/Commands.h"
|
#include "dawn_native/Commands.h"
|
||||||
|
#include "dawn_native/ComputePassEncoder.h"
|
||||||
#include "dawn_native/ComputePipeline.h"
|
#include "dawn_native/ComputePipeline.h"
|
||||||
#include "dawn_native/Device.h"
|
#include "dawn_native/Device.h"
|
||||||
|
#include "dawn_native/ErrorData.h"
|
||||||
#include "dawn_native/InputState.h"
|
#include "dawn_native/InputState.h"
|
||||||
#include "dawn_native/PipelineLayout.h"
|
#include "dawn_native/PipelineLayout.h"
|
||||||
|
#include "dawn_native/RenderPassEncoder.h"
|
||||||
#include "dawn_native/RenderPipeline.h"
|
#include "dawn_native/RenderPipeline.h"
|
||||||
#include "dawn_native/Texture.h"
|
#include "dawn_native/Texture.h"
|
||||||
|
|
||||||
|
@ -273,6 +276,13 @@ namespace dawn_native {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
enum class CommandBufferBuilder::EncodingState : uint8_t {
|
||||||
|
TopLevel,
|
||||||
|
ComputePass,
|
||||||
|
RenderPass,
|
||||||
|
Finished
|
||||||
|
};
|
||||||
|
|
||||||
// CommandBuffer
|
// CommandBuffer
|
||||||
|
|
||||||
CommandBufferBase::CommandBufferBase(CommandBufferBuilder* builder)
|
CommandBufferBase::CommandBufferBase(CommandBufferBuilder* builder)
|
||||||
|
@ -285,7 +295,8 @@ namespace dawn_native {
|
||||||
|
|
||||||
// CommandBufferBuilder
|
// CommandBufferBuilder
|
||||||
|
|
||||||
CommandBufferBuilder::CommandBufferBuilder(DeviceBase* device) : Builder(device) {
|
CommandBufferBuilder::CommandBufferBuilder(DeviceBase* device)
|
||||||
|
: Builder(device), mEncodingState(EncodingState::TopLevel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandBufferBuilder::~CommandBufferBuilder() {
|
CommandBufferBuilder::~CommandBufferBuilder() {
|
||||||
|
@ -308,6 +319,8 @@ namespace dawn_native {
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandBufferBase* CommandBufferBuilder::GetResultImpl() {
|
CommandBufferBase* CommandBufferBuilder::GetResultImpl() {
|
||||||
|
mEncodingState = EncodingState::Finished;
|
||||||
|
|
||||||
MoveToIterator();
|
MoveToIterator();
|
||||||
return mDevice->CreateCommandBuffer(this);
|
return mDevice->CreateCommandBuffer(this);
|
||||||
}
|
}
|
||||||
|
@ -319,6 +332,21 @@ namespace dawn_native {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CommandBufferBuilder::PassEnded() {
|
||||||
|
if (mEncodingState == EncodingState::ComputePass) {
|
||||||
|
mAllocator.Allocate<EndComputePassCmd>(Command::EndComputePass);
|
||||||
|
} else {
|
||||||
|
ASSERT(mEncodingState == EncodingState::RenderPass);
|
||||||
|
mAllocator.Allocate<EndRenderPassCmd>(Command::EndRenderPass);
|
||||||
|
}
|
||||||
|
mEncodingState = EncodingState::TopLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommandBufferBuilder::ConsumeError(ErrorData* error) {
|
||||||
|
HandleError(error->GetMessage().c_str());
|
||||||
|
delete error;
|
||||||
|
}
|
||||||
|
|
||||||
// Implementation of the command buffer validation that can be precomputed before submit
|
// Implementation of the command buffer validation that can be precomputed before submit
|
||||||
|
|
||||||
MaybeError CommandBufferBuilder::ValidateGetResult() {
|
MaybeError CommandBufferBuilder::ValidateGetResult() {
|
||||||
|
@ -558,14 +586,20 @@ namespace dawn_native {
|
||||||
|
|
||||||
// Implementation of the API's command recording methods
|
// Implementation of the API's command recording methods
|
||||||
|
|
||||||
void CommandBufferBuilder::BeginComputePass() {
|
ComputePassEncoderBase* CommandBufferBuilder::BeginComputePass() {
|
||||||
mAllocator.Allocate<BeginComputePassCmd>(Command::BeginComputePass);
|
mAllocator.Allocate<BeginComputePassCmd>(Command::BeginComputePass);
|
||||||
|
|
||||||
|
mEncodingState = EncodingState::ComputePass;
|
||||||
|
return new ComputePassEncoderBase(mDevice, this, &mAllocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandBufferBuilder::BeginRenderPass(RenderPassDescriptorBase* info) {
|
RenderPassEncoderBase* CommandBufferBuilder::BeginRenderPass(RenderPassDescriptorBase* info) {
|
||||||
BeginRenderPassCmd* cmd = mAllocator.Allocate<BeginRenderPassCmd>(Command::BeginRenderPass);
|
BeginRenderPassCmd* cmd = mAllocator.Allocate<BeginRenderPassCmd>(Command::BeginRenderPass);
|
||||||
new (cmd) BeginRenderPassCmd;
|
new (cmd) BeginRenderPassCmd;
|
||||||
cmd->info = info;
|
cmd->info = info;
|
||||||
|
|
||||||
|
mEncodingState = EncodingState::RenderPass;
|
||||||
|
return new RenderPassEncoderBase(mDevice, this, &mAllocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandBufferBuilder::CopyBufferToBuffer(BufferBase* source,
|
void CommandBufferBuilder::CopyBufferToBuffer(BufferBase* source,
|
||||||
|
@ -647,149 +681,4 @@ namespace dawn_native {
|
||||||
copy->rowPitch = rowPitch;
|
copy->rowPitch = rowPitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandBufferBuilder::Dispatch(uint32_t x, uint32_t y, uint32_t z) {
|
|
||||||
DispatchCmd* dispatch = mAllocator.Allocate<DispatchCmd>(Command::Dispatch);
|
|
||||||
new (dispatch) DispatchCmd;
|
|
||||||
dispatch->x = x;
|
|
||||||
dispatch->y = y;
|
|
||||||
dispatch->z = z;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandBufferBuilder::DrawArrays(uint32_t vertexCount,
|
|
||||||
uint32_t instanceCount,
|
|
||||||
uint32_t firstVertex,
|
|
||||||
uint32_t firstInstance) {
|
|
||||||
DrawArraysCmd* draw = mAllocator.Allocate<DrawArraysCmd>(Command::DrawArrays);
|
|
||||||
new (draw) DrawArraysCmd;
|
|
||||||
draw->vertexCount = vertexCount;
|
|
||||||
draw->instanceCount = instanceCount;
|
|
||||||
draw->firstVertex = firstVertex;
|
|
||||||
draw->firstInstance = firstInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandBufferBuilder::DrawElements(uint32_t indexCount,
|
|
||||||
uint32_t instanceCount,
|
|
||||||
uint32_t firstIndex,
|
|
||||||
uint32_t firstInstance) {
|
|
||||||
DrawElementsCmd* draw = mAllocator.Allocate<DrawElementsCmd>(Command::DrawElements);
|
|
||||||
new (draw) DrawElementsCmd;
|
|
||||||
draw->indexCount = indexCount;
|
|
||||||
draw->instanceCount = instanceCount;
|
|
||||||
draw->firstIndex = firstIndex;
|
|
||||||
draw->firstInstance = firstInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandBufferBuilder::EndComputePass() {
|
|
||||||
mAllocator.Allocate<EndComputePassCmd>(Command::EndComputePass);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandBufferBuilder::EndRenderPass() {
|
|
||||||
mAllocator.Allocate<EndRenderPassCmd>(Command::EndRenderPass);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandBufferBuilder::SetComputePipeline(ComputePipelineBase* pipeline) {
|
|
||||||
SetComputePipelineCmd* cmd =
|
|
||||||
mAllocator.Allocate<SetComputePipelineCmd>(Command::SetComputePipeline);
|
|
||||||
new (cmd) SetComputePipelineCmd;
|
|
||||||
cmd->pipeline = pipeline;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandBufferBuilder::SetRenderPipeline(RenderPipelineBase* pipeline) {
|
|
||||||
SetRenderPipelineCmd* cmd =
|
|
||||||
mAllocator.Allocate<SetRenderPipelineCmd>(Command::SetRenderPipeline);
|
|
||||||
new (cmd) SetRenderPipelineCmd;
|
|
||||||
cmd->pipeline = pipeline;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandBufferBuilder::SetPushConstants(dawn::ShaderStageBit stages,
|
|
||||||
uint32_t offset,
|
|
||||||
uint32_t count,
|
|
||||||
const void* data) {
|
|
||||||
// TODO(cwallez@chromium.org): check for overflows
|
|
||||||
if (offset + count > kMaxPushConstants) {
|
|
||||||
HandleError("Setting too many push constants");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SetPushConstantsCmd* cmd =
|
|
||||||
mAllocator.Allocate<SetPushConstantsCmd>(Command::SetPushConstants);
|
|
||||||
new (cmd) SetPushConstantsCmd;
|
|
||||||
cmd->stages = stages;
|
|
||||||
cmd->offset = offset;
|
|
||||||
cmd->count = count;
|
|
||||||
|
|
||||||
uint32_t* values = mAllocator.AllocateData<uint32_t>(count);
|
|
||||||
memcpy(values, data, count * sizeof(uint32_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandBufferBuilder::SetStencilReference(uint32_t reference) {
|
|
||||||
SetStencilReferenceCmd* cmd =
|
|
||||||
mAllocator.Allocate<SetStencilReferenceCmd>(Command::SetStencilReference);
|
|
||||||
new (cmd) SetStencilReferenceCmd;
|
|
||||||
cmd->reference = reference;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandBufferBuilder::SetBlendColor(float r, float g, float b, float a) {
|
|
||||||
SetBlendColorCmd* cmd = mAllocator.Allocate<SetBlendColorCmd>(Command::SetBlendColor);
|
|
||||||
new (cmd) SetBlendColorCmd;
|
|
||||||
cmd->r = r;
|
|
||||||
cmd->g = g;
|
|
||||||
cmd->b = b;
|
|
||||||
cmd->a = a;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandBufferBuilder::SetScissorRect(uint32_t x,
|
|
||||||
uint32_t y,
|
|
||||||
uint32_t width,
|
|
||||||
uint32_t height) {
|
|
||||||
SetScissorRectCmd* cmd = mAllocator.Allocate<SetScissorRectCmd>(Command::SetScissorRect);
|
|
||||||
new (cmd) SetScissorRectCmd;
|
|
||||||
cmd->x = x;
|
|
||||||
cmd->y = y;
|
|
||||||
cmd->width = width;
|
|
||||||
cmd->height = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandBufferBuilder::SetBindGroup(uint32_t groupIndex, BindGroupBase* group) {
|
|
||||||
if (groupIndex >= kMaxBindGroups) {
|
|
||||||
HandleError("Setting bind group over the max");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SetBindGroupCmd* cmd = mAllocator.Allocate<SetBindGroupCmd>(Command::SetBindGroup);
|
|
||||||
new (cmd) SetBindGroupCmd;
|
|
||||||
cmd->index = groupIndex;
|
|
||||||
cmd->group = group;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandBufferBuilder::SetIndexBuffer(BufferBase* buffer, uint32_t offset) {
|
|
||||||
// TODO(kainino@chromium.org): validation
|
|
||||||
|
|
||||||
SetIndexBufferCmd* cmd = mAllocator.Allocate<SetIndexBufferCmd>(Command::SetIndexBuffer);
|
|
||||||
new (cmd) SetIndexBufferCmd;
|
|
||||||
cmd->buffer = buffer;
|
|
||||||
cmd->offset = offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandBufferBuilder::SetVertexBuffers(uint32_t startSlot,
|
|
||||||
uint32_t count,
|
|
||||||
BufferBase* const* buffers,
|
|
||||||
uint32_t const* offsets) {
|
|
||||||
// TODO(kainino@chromium.org): validation
|
|
||||||
|
|
||||||
SetVertexBuffersCmd* cmd =
|
|
||||||
mAllocator.Allocate<SetVertexBuffersCmd>(Command::SetVertexBuffers);
|
|
||||||
new (cmd) SetVertexBuffersCmd;
|
|
||||||
cmd->startSlot = startSlot;
|
|
||||||
cmd->count = count;
|
|
||||||
|
|
||||||
Ref<BufferBase>* cmdBuffers = mAllocator.AllocateData<Ref<BufferBase>>(count);
|
|
||||||
for (size_t i = 0; i < count; ++i) {
|
|
||||||
new (&cmdBuffers[i]) Ref<BufferBase>(buffers[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t* cmdOffsets = mAllocator.AllocateData<uint32_t>(count);
|
|
||||||
memcpy(cmdOffsets, offsets, count * sizeof(uint32_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace dawn_native
|
} // namespace dawn_native
|
||||||
|
|
|
@ -60,8 +60,8 @@ namespace dawn_native {
|
||||||
std::vector<PassResourceUsage> AcquirePassResourceUsage();
|
std::vector<PassResourceUsage> AcquirePassResourceUsage();
|
||||||
|
|
||||||
// Dawn API
|
// Dawn API
|
||||||
void BeginComputePass();
|
ComputePassEncoderBase* BeginComputePass();
|
||||||
void BeginRenderPass(RenderPassDescriptorBase* info);
|
RenderPassEncoderBase* BeginRenderPass(RenderPassDescriptorBase* info);
|
||||||
void CopyBufferToBuffer(BufferBase* source,
|
void CopyBufferToBuffer(BufferBase* source,
|
||||||
uint32_t sourceOffset,
|
uint32_t sourceOffset,
|
||||||
BufferBase* destination,
|
BufferBase* destination,
|
||||||
|
@ -91,54 +91,32 @@ namespace dawn_native {
|
||||||
BufferBase* buffer,
|
BufferBase* buffer,
|
||||||
uint32_t bufferOffset,
|
uint32_t bufferOffset,
|
||||||
uint32_t rowPitch);
|
uint32_t rowPitch);
|
||||||
void Dispatch(uint32_t x, uint32_t y, uint32_t z);
|
|
||||||
void DrawArrays(uint32_t vertexCount,
|
|
||||||
uint32_t instanceCount,
|
|
||||||
uint32_t firstVertex,
|
|
||||||
uint32_t firstInstance);
|
|
||||||
void DrawElements(uint32_t vertexCount,
|
|
||||||
uint32_t instanceCount,
|
|
||||||
uint32_t firstIndex,
|
|
||||||
uint32_t firstInstance);
|
|
||||||
void EndComputePass();
|
|
||||||
void EndRenderPass();
|
|
||||||
void SetPushConstants(dawn::ShaderStageBit stages,
|
|
||||||
uint32_t offset,
|
|
||||||
uint32_t count,
|
|
||||||
const void* data);
|
|
||||||
void SetComputePipeline(ComputePipelineBase* pipeline);
|
|
||||||
void SetRenderPipeline(RenderPipelineBase* pipeline);
|
|
||||||
void SetStencilReference(uint32_t reference);
|
|
||||||
void SetBlendColor(float r, float g, float b, float a);
|
|
||||||
void SetScissorRect(uint32_t x, uint32_t y, uint32_t width, uint32_t height);
|
|
||||||
void SetBindGroup(uint32_t groupIndex, BindGroupBase* group);
|
|
||||||
void SetIndexBuffer(BufferBase* buffer, uint32_t offset);
|
|
||||||
|
|
||||||
template <typename T>
|
// Functions to interact with the encoders
|
||||||
void SetVertexBuffers(uint32_t startSlot,
|
bool ConsumedError(MaybeError maybeError) {
|
||||||
uint32_t count,
|
if (DAWN_UNLIKELY(maybeError.IsError())) {
|
||||||
T* const* buffers,
|
ConsumeError(maybeError.AcquireError());
|
||||||
uint32_t const* offsets) {
|
return true;
|
||||||
static_assert(std::is_base_of<BufferBase, T>::value, "");
|
}
|
||||||
SetVertexBuffers(startSlot, count, reinterpret_cast<BufferBase* const*>(buffers),
|
return false;
|
||||||
offsets);
|
|
||||||
}
|
}
|
||||||
void SetVertexBuffers(uint32_t startSlot,
|
|
||||||
uint32_t count,
|
|
||||||
BufferBase* const* buffers,
|
|
||||||
uint32_t const* offsets);
|
|
||||||
|
|
||||||
void TransitionBufferUsage(BufferBase* buffer, dawn::BufferUsageBit usage);
|
void PassEnded();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class CommandBufferBase;
|
friend class CommandBufferBase;
|
||||||
|
|
||||||
|
enum class EncodingState : uint8_t;
|
||||||
|
EncodingState mEncodingState;
|
||||||
|
|
||||||
CommandBufferBase* GetResultImpl() override;
|
CommandBufferBase* GetResultImpl() override;
|
||||||
void MoveToIterator();
|
void MoveToIterator();
|
||||||
|
|
||||||
MaybeError ValidateComputePass();
|
MaybeError ValidateComputePass();
|
||||||
MaybeError ValidateRenderPass(RenderPassDescriptorBase* renderPass);
|
MaybeError ValidateRenderPass(RenderPassDescriptorBase* renderPass);
|
||||||
|
|
||||||
|
void ConsumeError(ErrorData* error);
|
||||||
|
|
||||||
CommandAllocator mAllocator;
|
CommandAllocator mAllocator;
|
||||||
CommandIterator mIterator;
|
CommandIterator mIterator;
|
||||||
bool mWasMovedToIterator = false;
|
bool mWasMovedToIterator = false;
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
// Copyright 2018 The Dawn Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include "dawn_native/ComputePassEncoder.h"
|
||||||
|
|
||||||
|
#include "dawn_native/CommandBuffer.h"
|
||||||
|
#include "dawn_native/Commands.h"
|
||||||
|
#include "dawn_native/ComputePipeline.h"
|
||||||
|
|
||||||
|
namespace dawn_native {
|
||||||
|
|
||||||
|
ComputePassEncoderBase::ComputePassEncoderBase(DeviceBase* device,
|
||||||
|
CommandBufferBuilder* topLevelBuilder,
|
||||||
|
CommandAllocator* allocator)
|
||||||
|
: ProgrammablePassEncoder(device, topLevelBuilder, allocator) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComputePassEncoderBase::Dispatch(uint32_t x, uint32_t y, uint32_t z) {
|
||||||
|
if (mTopLevelBuilder->ConsumedError(ValidateCanRecordCommands())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DispatchCmd* dispatch = mAllocator->Allocate<DispatchCmd>(Command::Dispatch);
|
||||||
|
new (dispatch) DispatchCmd;
|
||||||
|
dispatch->x = x;
|
||||||
|
dispatch->y = y;
|
||||||
|
dispatch->z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComputePassEncoderBase::SetComputePipeline(ComputePipelineBase* pipeline) {
|
||||||
|
if (mTopLevelBuilder->ConsumedError(ValidateCanRecordCommands())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetComputePipelineCmd* cmd =
|
||||||
|
mAllocator->Allocate<SetComputePipelineCmd>(Command::SetComputePipeline);
|
||||||
|
new (cmd) SetComputePipelineCmd;
|
||||||
|
cmd->pipeline = pipeline;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace dawn_native
|
|
@ -0,0 +1,39 @@
|
||||||
|
// Copyright 2018 The Dawn Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#ifndef DAWNNATIVE_COMPUTEPASSENCODER_H_
|
||||||
|
#define DAWNNATIVE_COMPUTEPASSENCODER_H_
|
||||||
|
|
||||||
|
#include "dawn_native/Error.h"
|
||||||
|
#include "dawn_native/ProgrammablePassEncoder.h"
|
||||||
|
|
||||||
|
namespace dawn_native {
|
||||||
|
|
||||||
|
// This is called ComputePassEncoderBase to match the code generator expectations. Note that it
|
||||||
|
// is a pure frontend type to record in its parent CommandBufferBuilder and never has a backend
|
||||||
|
// implementation.
|
||||||
|
// TODO(cwallez@chromium.org): Remove that generator limitation and rename to ComputePassEncoder
|
||||||
|
class ComputePassEncoderBase : public ProgrammablePassEncoder {
|
||||||
|
public:
|
||||||
|
ComputePassEncoderBase(DeviceBase* device,
|
||||||
|
CommandBufferBuilder* topLevelBuilder,
|
||||||
|
CommandAllocator* allocator);
|
||||||
|
|
||||||
|
void Dispatch(uint32_t x, uint32_t y, uint32_t z);
|
||||||
|
void SetComputePipeline(ComputePipelineBase* pipeline);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace dawn_native
|
||||||
|
|
||||||
|
#endif // DAWNNATIVE_COMPUTEPASSENCODER_H_
|
|
@ -33,6 +33,7 @@ namespace dawn_native {
|
||||||
class ComputePipelineBuilder;
|
class ComputePipelineBuilder;
|
||||||
class CommandBufferBase;
|
class CommandBufferBase;
|
||||||
class CommandBufferBuilder;
|
class CommandBufferBuilder;
|
||||||
|
class ComputePassEncoderBase;
|
||||||
class DepthStencilStateBase;
|
class DepthStencilStateBase;
|
||||||
class DepthStencilStateBuilder;
|
class DepthStencilStateBuilder;
|
||||||
class InputStateBase;
|
class InputStateBase;
|
||||||
|
@ -42,6 +43,7 @@ namespace dawn_native {
|
||||||
class QueueBase;
|
class QueueBase;
|
||||||
class RenderPassDescriptorBase;
|
class RenderPassDescriptorBase;
|
||||||
class RenderPassDescriptorBuilder;
|
class RenderPassDescriptorBuilder;
|
||||||
|
class RenderPassEncoderBase;
|
||||||
class RenderPipelineBase;
|
class RenderPipelineBase;
|
||||||
class RenderPipelineBuilder;
|
class RenderPipelineBuilder;
|
||||||
class SamplerBase;
|
class SamplerBase;
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
// Copyright 2018 The Dawn Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include "dawn_native/ProgrammablePassEncoder.h"
|
||||||
|
|
||||||
|
#include "dawn_native/BindGroup.h"
|
||||||
|
#include "dawn_native/CommandBuffer.h"
|
||||||
|
#include "dawn_native/Commands.h"
|
||||||
|
|
||||||
|
namespace dawn_native {
|
||||||
|
|
||||||
|
ProgrammablePassEncoder::ProgrammablePassEncoder(DeviceBase* device,
|
||||||
|
CommandBufferBuilder* topLevelBuilder,
|
||||||
|
CommandAllocator* allocator)
|
||||||
|
: mDevice(device), mTopLevelBuilder(topLevelBuilder), mAllocator(allocator) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgrammablePassEncoder::EndPass() {
|
||||||
|
mTopLevelBuilder->PassEnded();
|
||||||
|
mAllocator = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgrammablePassEncoder::SetBindGroup(uint32_t groupIndex, BindGroupBase* group) {
|
||||||
|
if (mTopLevelBuilder->ConsumedError(ValidateCanRecordCommands())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (groupIndex >= kMaxBindGroups) {
|
||||||
|
mTopLevelBuilder->HandleError("Setting bind group over the max");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetBindGroupCmd* cmd = mAllocator->Allocate<SetBindGroupCmd>(Command::SetBindGroup);
|
||||||
|
new (cmd) SetBindGroupCmd;
|
||||||
|
cmd->index = groupIndex;
|
||||||
|
cmd->group = group;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgrammablePassEncoder::SetPushConstants(dawn::ShaderStageBit stages,
|
||||||
|
uint32_t offset,
|
||||||
|
uint32_t count,
|
||||||
|
const void* data) {
|
||||||
|
if (mTopLevelBuilder->ConsumedError(ValidateCanRecordCommands())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(cwallez@chromium.org): check for overflows
|
||||||
|
if (offset + count > kMaxPushConstants) {
|
||||||
|
mTopLevelBuilder->HandleError("Setting too many push constants");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetPushConstantsCmd* cmd =
|
||||||
|
mAllocator->Allocate<SetPushConstantsCmd>(Command::SetPushConstants);
|
||||||
|
new (cmd) SetPushConstantsCmd;
|
||||||
|
cmd->stages = stages;
|
||||||
|
cmd->offset = offset;
|
||||||
|
cmd->count = count;
|
||||||
|
|
||||||
|
uint32_t* values = mAllocator->AllocateData<uint32_t>(count);
|
||||||
|
memcpy(values, data, count * sizeof(uint32_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceBase* ProgrammablePassEncoder::GetDevice() const {
|
||||||
|
return mDevice;
|
||||||
|
}
|
||||||
|
|
||||||
|
MaybeError ProgrammablePassEncoder::ValidateCanRecordCommands() const {
|
||||||
|
if (mAllocator == nullptr) {
|
||||||
|
return DAWN_VALIDATION_ERROR("Recording in an already ended computePassEncoder");
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace dawn_native
|
|
@ -0,0 +1,59 @@
|
||||||
|
// Copyright 2018 The Dawn Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#ifndef DAWNNATIVE_PROGRAMMABLEPASSENCODER_H_
|
||||||
|
#define DAWNNATIVE_PROGRAMMABLEPASSENCODER_H_
|
||||||
|
|
||||||
|
#include "dawn_native/Error.h"
|
||||||
|
#include "dawn_native/RefCounted.h"
|
||||||
|
|
||||||
|
#include "dawn_native/dawn_platform.h"
|
||||||
|
|
||||||
|
namespace dawn_native {
|
||||||
|
|
||||||
|
class CommandAllocator;
|
||||||
|
class DeviceBase;
|
||||||
|
|
||||||
|
// Base class for shared functionality between ComputePassEncoder and RenderPassEncoder.
|
||||||
|
class ProgrammablePassEncoder : public RefCounted {
|
||||||
|
public:
|
||||||
|
ProgrammablePassEncoder(DeviceBase* device,
|
||||||
|
CommandBufferBuilder* topLevelBuilder,
|
||||||
|
CommandAllocator* allocator);
|
||||||
|
|
||||||
|
void EndPass();
|
||||||
|
|
||||||
|
void SetBindGroup(uint32_t groupIndex, BindGroupBase* group);
|
||||||
|
void SetPushConstants(dawn::ShaderStageBit stages,
|
||||||
|
uint32_t offset,
|
||||||
|
uint32_t count,
|
||||||
|
const void* data);
|
||||||
|
|
||||||
|
DeviceBase* GetDevice() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
MaybeError ValidateCanRecordCommands() const;
|
||||||
|
|
||||||
|
DeviceBase* mDevice;
|
||||||
|
|
||||||
|
// The allocator is borrowed from the top level builder. Keep a reference to the builder
|
||||||
|
// to make sure the allocator isn't freed.
|
||||||
|
Ref<CommandBufferBuilder> mTopLevelBuilder = nullptr;
|
||||||
|
// mAllocator is cleared at the end of the pass so it acts as a tag that EndPass was called
|
||||||
|
CommandAllocator* mAllocator = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace dawn_native
|
||||||
|
|
||||||
|
#endif // DAWNNATIVE_PROGRAMMABLEPASSENCODER_H_
|
|
@ -0,0 +1,123 @@
|
||||||
|
// Copyright 2018 The Dawn Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include "dawn_native/RenderPassEncoder.h"
|
||||||
|
|
||||||
|
#include "dawn_native/Buffer.h"
|
||||||
|
#include "dawn_native/CommandBuffer.h"
|
||||||
|
#include "dawn_native/Commands.h"
|
||||||
|
#include "dawn_native/RenderPipeline.h"
|
||||||
|
|
||||||
|
namespace dawn_native {
|
||||||
|
|
||||||
|
RenderPassEncoderBase::RenderPassEncoderBase(DeviceBase* device,
|
||||||
|
CommandBufferBuilder* topLevelBuilder,
|
||||||
|
CommandAllocator* allocator)
|
||||||
|
: ProgrammablePassEncoder(device, topLevelBuilder, allocator) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderPassEncoderBase::DrawArrays(uint32_t vertexCount,
|
||||||
|
uint32_t instanceCount,
|
||||||
|
uint32_t firstVertex,
|
||||||
|
uint32_t firstInstance) {
|
||||||
|
DrawArraysCmd* draw = mAllocator->Allocate<DrawArraysCmd>(Command::DrawArrays);
|
||||||
|
new (draw) DrawArraysCmd;
|
||||||
|
draw->vertexCount = vertexCount;
|
||||||
|
draw->instanceCount = instanceCount;
|
||||||
|
draw->firstVertex = firstVertex;
|
||||||
|
draw->firstInstance = firstInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderPassEncoderBase::DrawElements(uint32_t indexCount,
|
||||||
|
uint32_t instanceCount,
|
||||||
|
uint32_t firstIndex,
|
||||||
|
uint32_t firstInstance) {
|
||||||
|
DrawElementsCmd* draw = mAllocator->Allocate<DrawElementsCmd>(Command::DrawElements);
|
||||||
|
new (draw) DrawElementsCmd;
|
||||||
|
draw->indexCount = indexCount;
|
||||||
|
draw->instanceCount = instanceCount;
|
||||||
|
draw->firstIndex = firstIndex;
|
||||||
|
draw->firstInstance = firstInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderPassEncoderBase::SetRenderPipeline(RenderPipelineBase* pipeline) {
|
||||||
|
if (mTopLevelBuilder->ConsumedError(ValidateCanRecordCommands())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetRenderPipelineCmd* cmd =
|
||||||
|
mAllocator->Allocate<SetRenderPipelineCmd>(Command::SetRenderPipeline);
|
||||||
|
new (cmd) SetRenderPipelineCmd;
|
||||||
|
cmd->pipeline = pipeline;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderPassEncoderBase::SetStencilReference(uint32_t reference) {
|
||||||
|
SetStencilReferenceCmd* cmd =
|
||||||
|
mAllocator->Allocate<SetStencilReferenceCmd>(Command::SetStencilReference);
|
||||||
|
new (cmd) SetStencilReferenceCmd;
|
||||||
|
cmd->reference = reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderPassEncoderBase::SetBlendColor(float r, float g, float b, float a) {
|
||||||
|
SetBlendColorCmd* cmd = mAllocator->Allocate<SetBlendColorCmd>(Command::SetBlendColor);
|
||||||
|
new (cmd) SetBlendColorCmd;
|
||||||
|
cmd->r = r;
|
||||||
|
cmd->g = g;
|
||||||
|
cmd->b = b;
|
||||||
|
cmd->a = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderPassEncoderBase::SetScissorRect(uint32_t x,
|
||||||
|
uint32_t y,
|
||||||
|
uint32_t width,
|
||||||
|
uint32_t height) {
|
||||||
|
SetScissorRectCmd* cmd = mAllocator->Allocate<SetScissorRectCmd>(Command::SetScissorRect);
|
||||||
|
new (cmd) SetScissorRectCmd;
|
||||||
|
cmd->x = x;
|
||||||
|
cmd->y = y;
|
||||||
|
cmd->width = width;
|
||||||
|
cmd->height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderPassEncoderBase::SetIndexBuffer(BufferBase* buffer, uint32_t offset) {
|
||||||
|
// TODO(kainino@chromium.org): validation
|
||||||
|
|
||||||
|
SetIndexBufferCmd* cmd = mAllocator->Allocate<SetIndexBufferCmd>(Command::SetIndexBuffer);
|
||||||
|
new (cmd) SetIndexBufferCmd;
|
||||||
|
cmd->buffer = buffer;
|
||||||
|
cmd->offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderPassEncoderBase::SetVertexBuffers(uint32_t startSlot,
|
||||||
|
uint32_t count,
|
||||||
|
BufferBase* const* buffers,
|
||||||
|
uint32_t const* offsets) {
|
||||||
|
// TODO(kainino@chromium.org): validation
|
||||||
|
|
||||||
|
SetVertexBuffersCmd* cmd =
|
||||||
|
mAllocator->Allocate<SetVertexBuffersCmd>(Command::SetVertexBuffers);
|
||||||
|
new (cmd) SetVertexBuffersCmd;
|
||||||
|
cmd->startSlot = startSlot;
|
||||||
|
cmd->count = count;
|
||||||
|
|
||||||
|
Ref<BufferBase>* cmdBuffers = mAllocator->AllocateData<Ref<BufferBase>>(count);
|
||||||
|
for (size_t i = 0; i < count; ++i) {
|
||||||
|
new (&cmdBuffers[i]) Ref<BufferBase>(buffers[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t* cmdOffsets = mAllocator->AllocateData<uint32_t>(count);
|
||||||
|
memcpy(cmdOffsets, offsets, count * sizeof(uint32_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace dawn_native
|
|
@ -0,0 +1,66 @@
|
||||||
|
// Copyright 2018 The Dawn Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#ifndef DAWNNATIVE_RENDERPASSENCODER_H_
|
||||||
|
#define DAWNNATIVE_RENDERPASSENCODER_H_
|
||||||
|
|
||||||
|
#include "dawn_native/Error.h"
|
||||||
|
#include "dawn_native/ProgrammablePassEncoder.h"
|
||||||
|
|
||||||
|
namespace dawn_native {
|
||||||
|
|
||||||
|
// This is called RenderPassEncoderBase to match the code generator expectations. Note that it
|
||||||
|
// is a pure frontend type to record in its parent CommandBufferBuilder and never has a backend
|
||||||
|
// implementation.
|
||||||
|
// TODO(cwallez@chromium.org): Remove that generator limitation and rename to ComputePassEncoder
|
||||||
|
class RenderPassEncoderBase : public ProgrammablePassEncoder {
|
||||||
|
public:
|
||||||
|
RenderPassEncoderBase(DeviceBase* device,
|
||||||
|
CommandBufferBuilder* topLevelBuilder,
|
||||||
|
CommandAllocator* allocator);
|
||||||
|
|
||||||
|
void DrawArrays(uint32_t vertexCount,
|
||||||
|
uint32_t instanceCount,
|
||||||
|
uint32_t firstVertex,
|
||||||
|
uint32_t firstInstance);
|
||||||
|
void DrawElements(uint32_t vertexCount,
|
||||||
|
uint32_t instanceCount,
|
||||||
|
uint32_t firstIndex,
|
||||||
|
uint32_t firstInstance);
|
||||||
|
|
||||||
|
void SetRenderPipeline(RenderPipelineBase* pipeline);
|
||||||
|
|
||||||
|
void SetStencilReference(uint32_t reference);
|
||||||
|
void SetBlendColor(float r, float g, float b, float a);
|
||||||
|
void SetScissorRect(uint32_t x, uint32_t y, uint32_t width, uint32_t height);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void SetVertexBuffers(uint32_t startSlot,
|
||||||
|
uint32_t count,
|
||||||
|
T* const* buffers,
|
||||||
|
uint32_t const* offsets) {
|
||||||
|
static_assert(std::is_base_of<BufferBase, T>::value, "");
|
||||||
|
SetVertexBuffers(startSlot, count, reinterpret_cast<BufferBase* const*>(buffers),
|
||||||
|
offsets);
|
||||||
|
}
|
||||||
|
void SetVertexBuffers(uint32_t startSlot,
|
||||||
|
uint32_t count,
|
||||||
|
BufferBase* const* buffers,
|
||||||
|
uint32_t const* offsets);
|
||||||
|
void SetIndexBuffer(BufferBase* buffer, uint32_t offset);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace dawn_native
|
||||||
|
|
||||||
|
#endif // DAWNNATIVE_RENDERPASSENCODER_H_
|
|
@ -109,22 +109,23 @@ class BlendStateTest : public DawnTest {
|
||||||
|
|
||||||
// Test that after drawing a triangle with the base color, and then the given triangle spec, the color is as expected
|
// Test that after drawing a triangle with the base color, and then the given triangle spec, the color is as expected
|
||||||
void DoSingleSourceTest(RGBA8 base, const TriangleSpec& triangle, const RGBA8& expected) {
|
void DoSingleSourceTest(RGBA8 base, const TriangleSpec& triangle, const RGBA8& expected) {
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
// First use the base pipeline to draw a triangle with no blending
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetRenderPipeline(basePipeline)
|
// First use the base pipeline to draw a triangle with no blending
|
||||||
.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { base } })))
|
pass.SetRenderPipeline(basePipeline);
|
||||||
.DrawArrays(3, 1, 0, 0)
|
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { base } })));
|
||||||
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
// Then use the test pipeline to draw the test triangle with blending
|
|
||||||
.SetRenderPipeline(testPipeline)
|
|
||||||
.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { triangle.color } })))
|
|
||||||
.SetBlendColor(triangle.blendFactor[0], triangle.blendFactor[1], triangle.blendFactor[2], triangle.blendFactor[3])
|
|
||||||
.DrawArrays(3, 1, 0, 0)
|
|
||||||
.EndRenderPass()
|
|
||||||
.GetResult();
|
|
||||||
|
|
||||||
|
// Then use the test pipeline to draw the test triangle with blending
|
||||||
|
pass.SetRenderPipeline(testPipeline);
|
||||||
|
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { triangle.color } })));
|
||||||
|
pass.SetBlendColor(triangle.blendFactor[0], triangle.blendFactor[1], triangle.blendFactor[2], triangle.blendFactor[3]);
|
||||||
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(expected, renderPass.color, kRTSize / 2, kRTSize / 2);
|
EXPECT_PIXEL_RGBA8_EQ(expected, renderPass.color, kRTSize / 2, kRTSize / 2);
|
||||||
|
@ -671,14 +672,17 @@ TEST_P(BlendStateTest, ColorWriteMaskBlendingDisabled) {
|
||||||
|
|
||||||
RGBA8 base(32, 64, 128, 192);
|
RGBA8 base(32, 64, 128, 192);
|
||||||
RGBA8 expected(32, 0, 0, 0);
|
RGBA8 expected(32, 0, 0, 0);
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
|
||||||
.SetRenderPipeline(testPipeline)
|
|
||||||
.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { base } })))
|
|
||||||
.DrawArrays(3, 1, 0, 0)
|
|
||||||
.EndRenderPass()
|
|
||||||
.GetResult();
|
|
||||||
|
|
||||||
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
|
{
|
||||||
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
|
pass.SetRenderPipeline(testPipeline);
|
||||||
|
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { base } })));
|
||||||
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
EXPECT_PIXEL_RGBA8_EQ(expected, renderPass.color, kRTSize / 2, kRTSize / 2);
|
EXPECT_PIXEL_RGBA8_EQ(expected, renderPass.color, kRTSize / 2, kRTSize / 2);
|
||||||
}
|
}
|
||||||
|
@ -790,18 +794,20 @@ TEST_P(BlendStateTest, IndependentBlendState) {
|
||||||
RGBA8 expected2 = color2;
|
RGBA8 expected2 = color2;
|
||||||
RGBA8 expected3 = min(color3, base);
|
RGBA8 expected3 = min(color3, base);
|
||||||
|
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderpass)
|
{
|
||||||
.SetRenderPipeline(basePipeline)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderpass);
|
||||||
.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 4>({ { base, base, base, base } })))
|
pass.SetRenderPipeline(basePipeline);
|
||||||
.DrawArrays(3, 1, 0, 0)
|
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 4>({ { base, base, base, base } })));
|
||||||
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
|
|
||||||
.SetRenderPipeline(testPipeline)
|
pass.SetRenderPipeline(testPipeline);
|
||||||
.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 4>({ { color0, color1, color2, color3 } })))
|
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 4>({ { color0, color1, color2, color3 } })));
|
||||||
.DrawArrays(3, 1, 0, 0)
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
.EndRenderPass()
|
pass.EndPass();
|
||||||
.GetResult();
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(expected0, renderTargets[0], kRTSize / 2, kRTSize / 2) << "Attachment slot 0 should have been " << color0 << " + " << base << " = " << expected0;
|
EXPECT_PIXEL_RGBA8_EQ(expected0, renderTargets[0], kRTSize / 2, kRTSize / 2) << "Attachment slot 0 should have been " << color0 << " + " << base << " = " << expected0;
|
||||||
|
@ -849,17 +855,19 @@ TEST_P(BlendStateTest, DefaultBlendColor) {
|
||||||
|
|
||||||
// Check that the initial blend color is (0,0,0,0)
|
// Check that the initial blend color is (0,0,0,0)
|
||||||
{
|
{
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetRenderPipeline(basePipeline)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { RGBA8(0, 0, 0, 0) } })))
|
pass.SetRenderPipeline(basePipeline);
|
||||||
.DrawArrays(3, 1, 0, 0)
|
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { RGBA8(0, 0, 0, 0) } })));
|
||||||
.SetRenderPipeline(testPipeline)
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { RGBA8(255, 255, 255, 255) } })))
|
pass.SetRenderPipeline(testPipeline);
|
||||||
.DrawArrays(3, 1, 0, 0)
|
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { RGBA8(255, 255, 255, 255) } })));
|
||||||
.EndRenderPass()
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, kRTSize / 2, kRTSize / 2);
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, kRTSize / 2, kRTSize / 2);
|
||||||
|
@ -867,18 +875,20 @@ TEST_P(BlendStateTest, DefaultBlendColor) {
|
||||||
|
|
||||||
// Check that setting the blend color works
|
// Check that setting the blend color works
|
||||||
{
|
{
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetRenderPipeline(basePipeline)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { RGBA8(0, 0, 0, 0) } })))
|
pass.SetRenderPipeline(basePipeline);
|
||||||
.DrawArrays(3, 1, 0, 0)
|
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { RGBA8(0, 0, 0, 0) } })));
|
||||||
.SetRenderPipeline(testPipeline)
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
.SetBlendColor(1, 1, 1, 1)
|
pass.SetRenderPipeline(testPipeline);
|
||||||
.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { RGBA8(255, 255, 255, 255) } })))
|
pass.SetBlendColor(1, 1, 1, 1);
|
||||||
.DrawArrays(3, 1, 0, 0)
|
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { RGBA8(255, 255, 255, 255) } })));
|
||||||
.EndRenderPass()
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(255, 255, 255, 255), renderPass.color, kRTSize / 2, kRTSize / 2);
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(255, 255, 255, 255), renderPass.color, kRTSize / 2, kRTSize / 2);
|
||||||
|
@ -886,26 +896,30 @@ TEST_P(BlendStateTest, DefaultBlendColor) {
|
||||||
|
|
||||||
// Check that the blend color is not inherited between render passes
|
// Check that the blend color is not inherited between render passes
|
||||||
{
|
{
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetRenderPipeline(basePipeline)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { RGBA8(0, 0, 0, 0) } })))
|
pass.SetRenderPipeline(basePipeline);
|
||||||
.DrawArrays(3, 1, 0, 0)
|
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { RGBA8(0, 0, 0, 0) } })));
|
||||||
.SetRenderPipeline(testPipeline)
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
.SetBlendColor(1, 1, 1, 1)
|
pass.SetRenderPipeline(testPipeline);
|
||||||
.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { RGBA8(255, 255, 255, 255) } })))
|
pass.SetBlendColor(1, 1, 1, 1);
|
||||||
.DrawArrays(3, 1, 0, 0)
|
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { RGBA8(255, 255, 255, 255) } })));
|
||||||
.EndRenderPass()
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
pass.EndPass();
|
||||||
.SetRenderPipeline(basePipeline)
|
}
|
||||||
.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { RGBA8(0, 0, 0, 0) } })))
|
{
|
||||||
.DrawArrays(3, 1, 0, 0)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetRenderPipeline(testPipeline)
|
pass.SetRenderPipeline(basePipeline);
|
||||||
.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { RGBA8(255, 255, 255, 255) } })))
|
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { RGBA8(0, 0, 0, 0) } })));
|
||||||
.DrawArrays(3, 1, 0, 0)
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
.EndRenderPass()
|
pass.SetRenderPipeline(testPipeline);
|
||||||
.GetResult();
|
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { RGBA8(255, 255, 255, 255) } })));
|
||||||
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, kRTSize / 2, kRTSize / 2);
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, kRTSize / 2, kRTSize / 2);
|
||||||
|
|
|
@ -78,13 +78,18 @@ void ComputeCopyStorageBufferTests::BasicTest(const char* shader) {
|
||||||
.SetBufferViews(0, 1, &srcView)
|
.SetBufferViews(0, 1, &srcView)
|
||||||
.SetBufferViews(1, 1, &dstView)
|
.SetBufferViews(1, 1, &dstView)
|
||||||
.GetResult();
|
.GetResult();
|
||||||
auto commands = device.CreateCommandBufferBuilder()
|
|
||||||
.BeginComputePass()
|
dawn::CommandBuffer commands;
|
||||||
.SetComputePipeline(pipeline)
|
{
|
||||||
.SetBindGroup(0, bindGroup)
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.Dispatch(kInstances, 1, 1)
|
dawn::ComputePassEncoder pass = builder.BeginComputePass();
|
||||||
.EndComputePass()
|
pass.SetComputePipeline(pipeline);
|
||||||
.GetResult();
|
pass.SetBindGroup(0, bindGroup);
|
||||||
|
pass.Dispatch(kInstances, 1, 1);
|
||||||
|
pass.EndPass();
|
||||||
|
|
||||||
|
commands = builder.GetResult();
|
||||||
|
}
|
||||||
|
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
|
|
|
@ -197,7 +197,7 @@ class DepthStencilStateTest : public DawnTest {
|
||||||
float depth;
|
float depth;
|
||||||
};
|
};
|
||||||
|
|
||||||
builder.BeginRenderPass(renderpass);
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderpass);
|
||||||
|
|
||||||
for (size_t i = 0; i < testParams.size(); ++i) {
|
for (size_t i = 0; i < testParams.size(); ++i) {
|
||||||
const TestSpec& test = testParams[i];
|
const TestSpec& test = testParams[i];
|
||||||
|
@ -229,16 +229,14 @@ class DepthStencilStateTest : public DawnTest {
|
||||||
.SetDepthStencilState(test.depthStencilState)
|
.SetDepthStencilState(test.depthStencilState)
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
builder.SetRenderPipeline(pipeline)
|
pass.SetRenderPipeline(pipeline);
|
||||||
.SetStencilReference(test.stencil) // Set the stencil reference
|
pass.SetStencilReference(test.stencil); // Set the stencil reference
|
||||||
.SetBindGroup(0, bindGroup) // Set the bind group which contains color and depth data
|
pass.SetBindGroup(0, bindGroup); // Set the bind group which contains color and depth data
|
||||||
.DrawArrays(6, 1, 0, 0);
|
pass.DrawArrays(6, 1, 0, 0);
|
||||||
}
|
}
|
||||||
|
pass.EndPass();
|
||||||
|
|
||||||
dawn::CommandBuffer commands = builder
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
.EndRenderPass()
|
|
||||||
.GetResult();
|
|
||||||
|
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(expectedFront, renderTarget, kRTSize / 4, kRTSize / 2) << "Front face check failed";
|
EXPECT_PIXEL_RGBA8_EQ(expectedFront, renderTarget, kRTSize / 4, kRTSize / 2) << "Front face check failed";
|
||||||
|
|
|
@ -74,15 +74,17 @@ class DrawElementsTest : public DawnTest {
|
||||||
void Test(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex,
|
void Test(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex,
|
||||||
uint32_t firstInstance, RGBA8 bottomLeftExpected, RGBA8 topRightExpected) {
|
uint32_t firstInstance, RGBA8 bottomLeftExpected, RGBA8 topRightExpected) {
|
||||||
uint32_t zeroOffset = 0;
|
uint32_t zeroOffset = 0;
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetRenderPipeline(pipeline)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetVertexBuffers(0, 1, &vertexBuffer, &zeroOffset)
|
pass.SetRenderPipeline(pipeline);
|
||||||
.SetIndexBuffer(indexBuffer, 0)
|
pass.SetVertexBuffers(0, 1, &vertexBuffer, &zeroOffset);
|
||||||
.DrawElements(indexCount, instanceCount, firstIndex, firstInstance)
|
pass.SetIndexBuffer(indexBuffer, 0);
|
||||||
.EndRenderPass()
|
pass.DrawElements(indexCount, instanceCount, firstIndex, firstInstance);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(bottomLeftExpected, renderPass.color, 1, 3);
|
EXPECT_PIXEL_RGBA8_EQ(bottomLeftExpected, renderPass.color, 1, 3);
|
||||||
|
|
|
@ -78,15 +78,17 @@ TEST_P(IndexFormatTest, Uint32) {
|
||||||
});
|
});
|
||||||
|
|
||||||
uint32_t zeroOffset = 0;
|
uint32_t zeroOffset = 0;
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetRenderPipeline(pipeline)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetVertexBuffers(0, 1, &vertexBuffer, &zeroOffset)
|
pass.SetRenderPipeline(pipeline);
|
||||||
.SetIndexBuffer(indexBuffer, 0)
|
pass.SetVertexBuffers(0, 1, &vertexBuffer, &zeroOffset);
|
||||||
.DrawElements(3, 1, 0, 0)
|
pass.SetIndexBuffer(indexBuffer, 0);
|
||||||
.EndRenderPass()
|
pass.DrawElements(3, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
|
||||||
|
@ -107,15 +109,17 @@ TEST_P(IndexFormatTest, Uint16) {
|
||||||
});
|
});
|
||||||
|
|
||||||
uint32_t zeroOffset = 0;
|
uint32_t zeroOffset = 0;
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetRenderPipeline(pipeline)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetVertexBuffers(0, 1, &vertexBuffer, &zeroOffset)
|
pass.SetRenderPipeline(pipeline);
|
||||||
.SetIndexBuffer(indexBuffer, 0)
|
pass.SetVertexBuffers(0, 1, &vertexBuffer, &zeroOffset);
|
||||||
.DrawElements(3, 1, 0, 0)
|
pass.SetIndexBuffer(indexBuffer, 0);
|
||||||
.EndRenderPass()
|
pass.DrawElements(3, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
|
||||||
|
@ -149,15 +153,17 @@ TEST_P(IndexFormatTest, Uint32PrimitiveRestart) {
|
||||||
});
|
});
|
||||||
|
|
||||||
uint32_t zeroOffset = 0;
|
uint32_t zeroOffset = 0;
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetRenderPipeline(pipeline)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetVertexBuffers(0, 1, &vertexBuffer, &zeroOffset)
|
pass.SetRenderPipeline(pipeline);
|
||||||
.SetIndexBuffer(indexBuffer, 0)
|
pass.SetVertexBuffers(0, 1, &vertexBuffer, &zeroOffset);
|
||||||
.DrawElements(7, 1, 0, 0)
|
pass.SetIndexBuffer(indexBuffer, 0);
|
||||||
.EndRenderPass()
|
pass.DrawElements(7, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 190, 190); // A
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 190, 190); // A
|
||||||
|
@ -181,15 +187,17 @@ TEST_P(IndexFormatTest, Uint16PrimitiveRestart) {
|
||||||
});
|
});
|
||||||
|
|
||||||
uint32_t zeroOffset = 0;
|
uint32_t zeroOffset = 0;
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetRenderPipeline(pipeline)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetVertexBuffers(0, 1, &vertexBuffer, &zeroOffset)
|
pass.SetRenderPipeline(pipeline);
|
||||||
.SetIndexBuffer(indexBuffer, 0)
|
pass.SetVertexBuffers(0, 1, &vertexBuffer, &zeroOffset);
|
||||||
.DrawElements(7, 1, 0, 0)
|
pass.SetIndexBuffer(indexBuffer, 0);
|
||||||
.EndRenderPass()
|
pass.DrawElements(7, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 190, 190); // A
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 190, 190); // A
|
||||||
|
@ -218,16 +226,18 @@ TEST_P(IndexFormatTest, ChangePipelineAfterSetIndexBuffer) {
|
||||||
});
|
});
|
||||||
|
|
||||||
uint32_t zeroOffset = 0;
|
uint32_t zeroOffset = 0;
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetRenderPipeline(pipeline16)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetVertexBuffers(0, 1, &vertexBuffer, &zeroOffset)
|
pass.SetRenderPipeline(pipeline16);
|
||||||
.SetIndexBuffer(indexBuffer, 0)
|
pass.SetVertexBuffers(0, 1, &vertexBuffer, &zeroOffset);
|
||||||
.SetRenderPipeline(pipeline32)
|
pass.SetIndexBuffer(indexBuffer, 0);
|
||||||
.DrawElements(3, 1, 0, 0)
|
pass.SetRenderPipeline(pipeline32);
|
||||||
.EndRenderPass()
|
pass.DrawElements(3, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
|
||||||
|
@ -251,15 +261,17 @@ TEST_P(IndexFormatTest, DISABLED_SetIndexBufferBeforeSetPipeline) {
|
||||||
});
|
});
|
||||||
|
|
||||||
uint32_t zeroOffset = 0;
|
uint32_t zeroOffset = 0;
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetIndexBuffer(indexBuffer, 0)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetRenderPipeline(pipeline)
|
pass.SetIndexBuffer(indexBuffer, 0);
|
||||||
.SetVertexBuffers(0, 1, &vertexBuffer, &zeroOffset)
|
pass.SetRenderPipeline(pipeline);
|
||||||
.DrawElements(3, 1, 0, 0)
|
pass.SetVertexBuffers(0, 1, &vertexBuffer, &zeroOffset);
|
||||||
.EndRenderPass()
|
pass.DrawElements(3, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
|
||||||
|
|
|
@ -168,19 +168,18 @@ class InputStateTest : public DawnTest {
|
||||||
|
|
||||||
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
|
|
||||||
builder.BeginRenderPass(renderPass.renderPassInfo)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetRenderPipeline(pipeline);
|
pass.SetRenderPipeline(pipeline);
|
||||||
|
|
||||||
uint32_t zeroOffset = 0;
|
uint32_t zeroOffset = 0;
|
||||||
for (const auto& buffer : vertexBuffers) {
|
for (const auto& buffer : vertexBuffers) {
|
||||||
builder.SetVertexBuffers(buffer.location, 1, buffer.buffer, &zeroOffset);
|
pass.SetVertexBuffers(buffer.location, 1, buffer.buffer, &zeroOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
dawn::CommandBuffer commands = builder
|
pass.DrawArrays(triangles * 3, instances, 0, 0);
|
||||||
.DrawArrays(triangles * 3, instances, 0, 0)
|
pass.EndPass();
|
||||||
.EndRenderPass()
|
|
||||||
.GetResult();
|
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
// Check that the center of each triangle is pure green, so that if a single vertex shader
|
// Check that the center of each triangle is pure green, so that if a single vertex shader
|
||||||
|
|
|
@ -194,14 +194,16 @@ class PrimitiveTopologyTest : public DawnTest {
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
static const uint32_t zeroOffset = 0;
|
static const uint32_t zeroOffset = 0;
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetRenderPipeline(pipeline)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetVertexBuffers(0, 1, &vertexBuffer, &zeroOffset)
|
pass.SetRenderPipeline(pipeline);
|
||||||
.DrawArrays(6, 1, 0, 0)
|
pass.SetVertexBuffers(0, 1, &vertexBuffer, &zeroOffset);
|
||||||
.EndRenderPass()
|
pass.DrawArrays(6, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
for (auto& locationSpec : locationSpecs) {
|
for (auto& locationSpec : locationSpecs) {
|
||||||
|
|
|
@ -207,23 +207,31 @@ TEST_P(PushConstantTest, ComputePassDefaultsToZero) {
|
||||||
dawn::ComputePipeline pipeline = MakeTestComputePipeline(binding.layout, MakeAllZeroSpec());
|
dawn::ComputePipeline pipeline = MakeTestComputePipeline(binding.layout, MakeAllZeroSpec());
|
||||||
|
|
||||||
uint32_t notZero = 42;
|
uint32_t notZero = 42;
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginComputePass()
|
{
|
||||||
// Test compute push constants are set to zero by default.
|
dawn::ComputePassEncoder pass = builder.BeginComputePass();
|
||||||
.SetComputePipeline(pipeline)
|
|
||||||
.SetBindGroup(0, binding.bindGroup)
|
|
||||||
.Dispatch(1, 1, 1)
|
|
||||||
// Set push constants to non-zero value to check they will be reset to zero
|
|
||||||
// on the next BeginComputePass
|
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Compute, 0, 1, ¬Zero)
|
|
||||||
.EndComputePass()
|
|
||||||
.BeginComputePass()
|
|
||||||
.SetComputePipeline(pipeline)
|
|
||||||
.SetBindGroup(0, binding.bindGroup)
|
|
||||||
.Dispatch(1, 1, 1)
|
|
||||||
.EndComputePass()
|
|
||||||
.GetResult();
|
|
||||||
|
|
||||||
|
// Test compute push constants are set to zero by default.
|
||||||
|
pass.SetComputePipeline(pipeline);
|
||||||
|
pass.SetBindGroup(0, binding.bindGroup);
|
||||||
|
pass.Dispatch(1, 1, 1);
|
||||||
|
// Set push constants to non-zero value to check they will be reset to zero
|
||||||
|
// on the next BeginComputePass
|
||||||
|
pass.SetPushConstants(dawn::ShaderStageBit::Compute, 0, 1, ¬Zero);
|
||||||
|
|
||||||
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
dawn::ComputePassEncoder pass = builder.BeginComputePass();
|
||||||
|
|
||||||
|
pass.SetComputePipeline(pipeline);
|
||||||
|
pass.SetBindGroup(0, binding.bindGroup);
|
||||||
|
pass.Dispatch(1, 1, 1);
|
||||||
|
|
||||||
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_BUFFER_U32_EQ(1, binding.resultBuffer, 0);
|
EXPECT_BUFFER_U32_EQ(1, binding.resultBuffer, 0);
|
||||||
|
@ -238,14 +246,16 @@ TEST_P(PushConstantTest, RenderPassDefaultsToZero) {
|
||||||
dawn::PipelineLayout layout = MakeEmptyLayout();
|
dawn::PipelineLayout layout = MakeEmptyLayout();
|
||||||
dawn::RenderPipeline pipeline = MakeTestRenderPipeline(layout, MakeAllZeroSpec(), MakeAllZeroSpec());
|
dawn::RenderPipeline pipeline = MakeTestRenderPipeline(layout, MakeAllZeroSpec(), MakeAllZeroSpec());
|
||||||
|
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
// Test render push constants are set to zero by default.
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetRenderPipeline(pipeline)
|
// Test render push constants are set to zero by default.
|
||||||
.DrawArrays(1, 1, 0, 0)
|
pass.SetRenderPipeline(pipeline);
|
||||||
.EndRenderPass()
|
pass.DrawArrays(1, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(1, 1, 0, 0), renderPass.color, 0, 0);
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(1, 1, 0, 0), renderPass.color, 0, 0);
|
||||||
|
@ -266,15 +276,19 @@ TEST_P(PushConstantTest, VariousConstantTypes) {
|
||||||
dawn::ComputePipeline pipeline = MakeTestComputePipeline(binding.layout, spec);
|
dawn::ComputePipeline pipeline = MakeTestComputePipeline(binding.layout, spec);
|
||||||
|
|
||||||
|
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginComputePass()
|
{
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Compute, 0, 3, reinterpret_cast<uint32_t*>(&values))
|
dawn::ComputePassEncoder pass = builder.BeginComputePass();
|
||||||
.SetComputePipeline(pipeline)
|
|
||||||
.SetBindGroup(0, binding.bindGroup)
|
|
||||||
.Dispatch(1, 1, 1)
|
|
||||||
.EndComputePass()
|
|
||||||
.GetResult();
|
|
||||||
|
|
||||||
|
pass.SetPushConstants(dawn::ShaderStageBit::Compute, 0, 3, reinterpret_cast<uint32_t*>(&values));
|
||||||
|
pass.SetComputePipeline(pipeline);
|
||||||
|
pass.SetBindGroup(0, binding.bindGroup);
|
||||||
|
pass.Dispatch(1, 1, 1);
|
||||||
|
|
||||||
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_BUFFER_U32_EQ(1, binding.resultBuffer, 0);
|
EXPECT_BUFFER_U32_EQ(1, binding.resultBuffer, 0);
|
||||||
|
@ -292,21 +306,25 @@ TEST_P(PushConstantTest, InheritThroughPipelineLayoutChange) {
|
||||||
|
|
||||||
uint32_t one = 1;
|
uint32_t one = 1;
|
||||||
uint32_t two = 2;
|
uint32_t two = 2;
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginComputePass()
|
{
|
||||||
// Set Push constant before there is a pipeline set
|
dawn::ComputePassEncoder pass = builder.BeginComputePass();
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Compute, 0, 1, &one)
|
|
||||||
.SetComputePipeline(pipeline1)
|
|
||||||
.SetBindGroup(0, binding1.bindGroup)
|
|
||||||
.Dispatch(1, 1, 1)
|
|
||||||
// Change the push constant before changing pipeline layout
|
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Compute, 0, 1, &two)
|
|
||||||
.SetComputePipeline(pipeline2)
|
|
||||||
.SetBindGroup(0, binding2.bindGroup)
|
|
||||||
.Dispatch(1, 1, 1)
|
|
||||||
.EndComputePass()
|
|
||||||
.GetResult();
|
|
||||||
|
|
||||||
|
// Set Push constant before there is a pipeline set
|
||||||
|
pass.SetPushConstants(dawn::ShaderStageBit::Compute, 0, 1, &one);
|
||||||
|
pass.SetComputePipeline(pipeline1);
|
||||||
|
pass.SetBindGroup(0, binding1.bindGroup);
|
||||||
|
pass.Dispatch(1, 1, 1);
|
||||||
|
// Change the push constant before changing pipeline layout
|
||||||
|
pass.SetPushConstants(dawn::ShaderStageBit::Compute, 0, 1, &two);
|
||||||
|
pass.SetComputePipeline(pipeline2);
|
||||||
|
pass.SetBindGroup(0, binding2.bindGroup);
|
||||||
|
pass.Dispatch(1, 1, 1);
|
||||||
|
|
||||||
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_BUFFER_U32_EQ(1, binding1.resultBuffer, 0);
|
EXPECT_BUFFER_U32_EQ(1, binding1.resultBuffer, 0);
|
||||||
|
@ -325,15 +343,19 @@ TEST_P(PushConstantTest, SetAllConstantsToNonZero) {
|
||||||
auto binding = MakeTestBindings(false);
|
auto binding = MakeTestBindings(false);
|
||||||
dawn::ComputePipeline pipeline = MakeTestComputePipeline(binding.layout, spec);
|
dawn::ComputePipeline pipeline = MakeTestComputePipeline(binding.layout, spec);
|
||||||
|
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginComputePass()
|
{
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Compute, 0, kMaxPushConstants, &values[0])
|
dawn::ComputePassEncoder pass = builder.BeginComputePass();
|
||||||
.SetComputePipeline(pipeline)
|
|
||||||
.SetBindGroup(0, binding.bindGroup)
|
|
||||||
.Dispatch(1, 1, 1)
|
|
||||||
.EndComputePass()
|
|
||||||
.GetResult();
|
|
||||||
|
|
||||||
|
pass.SetPushConstants(dawn::ShaderStageBit::Compute, 0, kMaxPushConstants, &values[0]);
|
||||||
|
pass.SetComputePipeline(pipeline);
|
||||||
|
pass.SetBindGroup(0, binding.bindGroup);
|
||||||
|
pass.Dispatch(1, 1, 1);
|
||||||
|
|
||||||
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_BUFFER_U32_EQ(1, binding.resultBuffer, 0);
|
EXPECT_BUFFER_U32_EQ(1, binding.resultBuffer, 0);
|
||||||
|
@ -351,15 +373,17 @@ TEST_P(PushConstantTest, SeparateVertexAndFragmentConstants) {
|
||||||
|
|
||||||
uint32_t one = 1;
|
uint32_t one = 1;
|
||||||
uint32_t two = 2;
|
uint32_t two = 2;
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Vertex, 0, 1, &one)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Fragment, 0, 1, &two)
|
pass.SetPushConstants(dawn::ShaderStageBit::Vertex, 0, 1, &one);
|
||||||
.SetRenderPipeline(pipeline)
|
pass.SetPushConstants(dawn::ShaderStageBit::Fragment, 0, 1, &two);
|
||||||
.DrawArrays(1, 1, 0, 0)
|
pass.SetRenderPipeline(pipeline);
|
||||||
.EndRenderPass()
|
pass.DrawArrays(1, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(1, 1, 0, 0), renderPass.color, 0, 0);
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(1, 1, 0, 0), renderPass.color, 0, 0);
|
||||||
|
@ -375,14 +399,16 @@ TEST_P(PushConstantTest, SimultaneousVertexAndFragmentConstants) {
|
||||||
dawn::RenderPipeline pipeline = MakeTestRenderPipeline(layout, spec, spec);
|
dawn::RenderPipeline pipeline = MakeTestRenderPipeline(layout, spec, spec);
|
||||||
|
|
||||||
uint32_t two = 2;
|
uint32_t two = 2;
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Vertex | dawn::ShaderStageBit::Fragment, 0, 1, &two)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetRenderPipeline(pipeline)
|
pass.SetPushConstants(dawn::ShaderStageBit::Vertex | dawn::ShaderStageBit::Fragment, 0, 1, &two);
|
||||||
.DrawArrays(1, 1, 0, 0)
|
pass.SetRenderPipeline(pipeline);
|
||||||
.EndRenderPass()
|
pass.DrawArrays(1, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(1, 1, 0, 0), renderPass.color, 0, 0);
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(1, 1, 0, 0), renderPass.color, 0, 0);
|
||||||
|
|
|
@ -31,7 +31,7 @@ class DrawQuad {
|
||||||
pipelineLayout = utils::MakeBasicPipelineLayout(*device, nullptr);
|
pipelineLayout = utils::MakeBasicPipelineLayout(*device, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Draw(dawn::CommandBufferBuilder* builder) {
|
void Draw(dawn::RenderPassEncoder* pass) {
|
||||||
auto renderPipeline = device->CreateRenderPipelineBuilder()
|
auto renderPipeline = device->CreateRenderPipelineBuilder()
|
||||||
.SetColorAttachmentFormat(0, dawn::TextureFormat::R8G8B8A8Unorm)
|
.SetColorAttachmentFormat(0, dawn::TextureFormat::R8G8B8A8Unorm)
|
||||||
.SetLayout(pipelineLayout)
|
.SetLayout(pipelineLayout)
|
||||||
|
@ -39,8 +39,8 @@ class DrawQuad {
|
||||||
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
|
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
builder->SetRenderPipeline(renderPipeline);
|
pass->SetRenderPipeline(renderPipeline);
|
||||||
builder->DrawArrays(6, 1, 0, 0);
|
pass->DrawArrays(6, 1, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -117,24 +117,20 @@ TEST_P(RenderPassLoadOpTests, ColorClearThenLoadAndDraw) {
|
||||||
.SetColorAttachmentClearColor(0, 0.0f, 0.0f, 0.0f, 0.0f)
|
.SetColorAttachmentClearColor(0, 0.0f, 0.0f, 0.0f, 0.0f)
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
auto commandsClearZero = device.CreateCommandBufferBuilder()
|
auto commandsClearZeroBuilder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPassClearZero)
|
auto clearZeroPass = commandsClearZeroBuilder.BeginRenderPass(renderPassClearZero);
|
||||||
// Clear should occur implicitly
|
clearZeroPass.EndPass();
|
||||||
// Store should occur implicitly
|
auto commandsClearZero = commandsClearZeroBuilder.GetResult();
|
||||||
.EndRenderPass()
|
|
||||||
.GetResult();
|
|
||||||
|
|
||||||
auto renderPassClearGreen = device.CreateRenderPassDescriptorBuilder()
|
auto renderPassClearGreen = device.CreateRenderPassDescriptorBuilder()
|
||||||
.SetColorAttachment(0, renderTargetView, dawn::LoadOp::Clear)
|
.SetColorAttachment(0, renderTargetView, dawn::LoadOp::Clear)
|
||||||
.SetColorAttachmentClearColor(0, 0.0f, 1.0f, 0.0f, 1.0f)
|
.SetColorAttachmentClearColor(0, 0.0f, 1.0f, 0.0f, 1.0f)
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
auto commandsClearGreen = device.CreateCommandBufferBuilder()
|
auto commandsClearGreenBuilder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPassClearGreen)
|
auto clearGreenPass = commandsClearGreenBuilder.BeginRenderPass(renderPassClearGreen);
|
||||||
// Clear should occur implicitly
|
clearGreenPass.EndPass();
|
||||||
// Store should occur implicitly
|
auto commandsClearGreen = commandsClearGreenBuilder.GetResult();
|
||||||
.EndRenderPass()
|
|
||||||
.GetResult();
|
|
||||||
|
|
||||||
queue.Submit(1, &commandsClearZero);
|
queue.Submit(1, &commandsClearZero);
|
||||||
EXPECT_TEXTURE_RGBA8_EQ(expectZero.data(), renderTarget, 0, 0, kRTSize, kRTSize, 0);
|
EXPECT_TEXTURE_RGBA8_EQ(expectZero.data(), renderTarget, 0, 0, kRTSize, kRTSize, 0);
|
||||||
|
@ -150,15 +146,11 @@ TEST_P(RenderPassLoadOpTests, ColorClearThenLoadAndDraw) {
|
||||||
|
|
||||||
dawn::CommandBuffer commandsLoad;
|
dawn::CommandBuffer commandsLoad;
|
||||||
{
|
{
|
||||||
auto builder = device.CreateCommandBufferBuilder()
|
auto builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPassLoad)
|
auto pass = builder.BeginRenderPass(renderPassLoad);
|
||||||
// Load should occur implicitly
|
blueQuad.Draw(&pass);
|
||||||
.Clone();
|
pass.EndPass();
|
||||||
blueQuad.Draw(&builder);
|
commandsLoad = builder.GetResult();
|
||||||
commandsLoad = builder
|
|
||||||
// Store should occur implicitly
|
|
||||||
.EndRenderPass()
|
|
||||||
.GetResult();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
queue.Submit(1, &commandsLoad);
|
queue.Submit(1, &commandsLoad);
|
||||||
|
|
|
@ -127,14 +127,16 @@ protected:
|
||||||
.SetTextureViews(1, 1, &mTextureView)
|
.SetTextureViews(1, 1, &mTextureView)
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(mRenderPass.renderPassInfo)
|
{
|
||||||
.SetRenderPipeline(mPipeline)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(mRenderPass.renderPassInfo);
|
||||||
.SetBindGroup(0, bindGroup)
|
pass.SetRenderPipeline(mPipeline);
|
||||||
.DrawArrays(6, 1, 0, 0)
|
pass.SetBindGroup(0, bindGroup);
|
||||||
.EndRenderPass()
|
pass.DrawArrays(6, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
RGBA8 expectedU2(u.mExpected2, u.mExpected2, u.mExpected2, 255);
|
RGBA8 expectedU2(u.mExpected2, u.mExpected2, u.mExpected2, 255);
|
||||||
|
|
|
@ -51,13 +51,15 @@ TEST_P(ScissorTest, DefaultsToWholeRenderTarget) {
|
||||||
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 100, 100);
|
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 100, 100);
|
||||||
dawn::RenderPipeline pipeline = CreateQuadPipeline(renderPass.colorFormat);
|
dawn::RenderPipeline pipeline = CreateQuadPipeline(renderPass.colorFormat);
|
||||||
|
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetRenderPipeline(pipeline)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.DrawArrays(6, 1, 0, 0)
|
pass.SetRenderPipeline(pipeline);
|
||||||
.EndRenderPass()
|
pass.DrawArrays(6, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0);
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0);
|
||||||
|
@ -71,14 +73,16 @@ TEST_P(ScissorTest, LargerThanAttachment) {
|
||||||
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 100, 100);
|
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 100, 100);
|
||||||
dawn::RenderPipeline pipeline = CreateQuadPipeline(renderPass.colorFormat);
|
dawn::RenderPipeline pipeline = CreateQuadPipeline(renderPass.colorFormat);
|
||||||
|
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetRenderPipeline(pipeline)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetScissorRect(0, 0, 200, 200)
|
pass.SetRenderPipeline(pipeline);
|
||||||
.DrawArrays(6, 1, 0, 0)
|
pass.SetScissorRect(0, 0, 200, 200);
|
||||||
.EndRenderPass()
|
pass.DrawArrays(6, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0);
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0);
|
||||||
|
@ -95,14 +99,16 @@ TEST_P(ScissorTest, EmptyRect) {
|
||||||
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 2, 2);
|
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 2, 2);
|
||||||
dawn::RenderPipeline pipeline = CreateQuadPipeline(renderPass.colorFormat);
|
dawn::RenderPipeline pipeline = CreateQuadPipeline(renderPass.colorFormat);
|
||||||
|
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetRenderPipeline(pipeline)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetScissorRect(0, 0, 0, 0)
|
pass.SetRenderPipeline(pipeline);
|
||||||
.DrawArrays(6, 1, 0, 0)
|
pass.SetScissorRect(0, 0, 0, 0);
|
||||||
.EndRenderPass()
|
pass.DrawArrays(6, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, 0, 0);
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, 0, 0);
|
||||||
|
@ -121,14 +127,16 @@ TEST_P(ScissorTest, PartialRect) {
|
||||||
constexpr uint32_t kW = 5;
|
constexpr uint32_t kW = 5;
|
||||||
constexpr uint32_t kH = 13;
|
constexpr uint32_t kH = 13;
|
||||||
|
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetRenderPipeline(pipeline)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.SetScissorRect(kX, kY, kW, kH)
|
pass.SetRenderPipeline(pipeline);
|
||||||
.DrawArrays(6, 1, 0, 0)
|
pass.SetScissorRect(kX, kY, kW, kH);
|
||||||
.EndRenderPass()
|
pass.DrawArrays(6, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
// Test the two opposite corners of the scissor box. With one pixel inside and on outside
|
// Test the two opposite corners of the scissor box. With one pixel inside and on outside
|
||||||
|
@ -144,18 +152,22 @@ TEST_P(ScissorTest, NoInheritanceBetweenRenderPass) {
|
||||||
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 100, 100);
|
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 100, 100);
|
||||||
dawn::RenderPipeline pipeline = CreateQuadPipeline(renderPass.colorFormat);
|
dawn::RenderPipeline pipeline = CreateQuadPipeline(renderPass.colorFormat);
|
||||||
|
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
// RenderPass 1 set the scissor
|
// RenderPass 1 set the scissor
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetScissorRect(0, 0, 0, 0)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.EndRenderPass()
|
pass.SetScissorRect(0, 0, 0, 0);
|
||||||
// RenderPass 2 draw a full quad, it shouldn't be scissored
|
pass.EndPass();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
}
|
||||||
.SetRenderPipeline(pipeline)
|
// RenderPass 2 draw a full quad, it shouldn't be scissored
|
||||||
.DrawArrays(6, 1, 0, 0)
|
{
|
||||||
.EndRenderPass()
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.GetResult();
|
pass.SetRenderPipeline(pipeline);
|
||||||
|
pass.DrawArrays(6, 1, 0, 0);
|
||||||
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0);
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0);
|
||||||
|
|
|
@ -42,13 +42,15 @@ TEST_P(ViewportOrientationTests, OriginAt0x0) {
|
||||||
.SetPrimitiveTopology(dawn::PrimitiveTopology::PointList)
|
.SetPrimitiveTopology(dawn::PrimitiveTopology::PointList)
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
dawn::CommandBuffer commands = device.CreateCommandBufferBuilder()
|
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||||
.BeginRenderPass(renderPass.renderPassInfo)
|
{
|
||||||
.SetRenderPipeline(pipeline)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
|
||||||
.DrawArrays(1, 1, 0, 0)
|
pass.SetRenderPipeline(pipeline);
|
||||||
.EndRenderPass()
|
pass.DrawArrays(1, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
dawn::CommandBuffer commands = builder.GetResult();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0);
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0);
|
||||||
|
|
|
@ -250,13 +250,18 @@ TEST_F(WireTests, ReleaseCalledOnRefCount0) {
|
||||||
// Test that the wire is able to send numerical values
|
// Test that the wire is able to send numerical values
|
||||||
TEST_F(WireTests, ValueArgument) {
|
TEST_F(WireTests, ValueArgument) {
|
||||||
dawnCommandBufferBuilder builder = dawnDeviceCreateCommandBufferBuilder(device);
|
dawnCommandBufferBuilder builder = dawnDeviceCreateCommandBufferBuilder(device);
|
||||||
dawnCommandBufferBuilderDispatch(builder, 1, 2, 3);
|
dawnComputePassEncoder pass = dawnCommandBufferBuilderBeginComputePass(builder);
|
||||||
|
dawnComputePassEncoderDispatch(pass, 1, 2, 3);
|
||||||
|
|
||||||
dawnCommandBufferBuilder apiBuilder = api.GetNewCommandBufferBuilder();
|
dawnCommandBufferBuilder apiBuilder = api.GetNewCommandBufferBuilder();
|
||||||
EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
|
EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
|
||||||
.WillOnce(Return(apiBuilder));
|
.WillOnce(Return(apiBuilder));
|
||||||
|
|
||||||
EXPECT_CALL(api, CommandBufferBuilderDispatch(apiBuilder, 1, 2, 3))
|
dawnComputePassEncoder apiPass = api.GetNewComputePassEncoder();
|
||||||
|
EXPECT_CALL(api, CommandBufferBuilderBeginComputePass(apiBuilder))
|
||||||
|
.WillOnce(Return(apiPass));
|
||||||
|
|
||||||
|
EXPECT_CALL(api, ComputePassEncoderDispatch(apiPass, 1, 2, 3))
|
||||||
.Times(1);
|
.Times(1);
|
||||||
|
|
||||||
FlushClient();
|
FlushClient();
|
||||||
|
@ -281,13 +286,18 @@ bool CheckPushConstantValues(const uint32_t* values) {
|
||||||
|
|
||||||
TEST_F(WireTests, ValueArrayArgument) {
|
TEST_F(WireTests, ValueArrayArgument) {
|
||||||
dawnCommandBufferBuilder builder = dawnDeviceCreateCommandBufferBuilder(device);
|
dawnCommandBufferBuilder builder = dawnDeviceCreateCommandBufferBuilder(device);
|
||||||
dawnCommandBufferBuilderSetPushConstants(builder, DAWN_SHADER_STAGE_BIT_VERTEX, 0, 4, testPushConstantValues);
|
dawnComputePassEncoder pass = dawnCommandBufferBuilderBeginComputePass(builder);
|
||||||
|
dawnComputePassEncoderSetPushConstants(pass, DAWN_SHADER_STAGE_BIT_VERTEX, 0, 4, testPushConstantValues);
|
||||||
|
|
||||||
dawnCommandBufferBuilder apiBuilder = api.GetNewCommandBufferBuilder();
|
dawnCommandBufferBuilder apiBuilder = api.GetNewCommandBufferBuilder();
|
||||||
EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
|
EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
|
||||||
.WillOnce(Return(apiBuilder));
|
.WillOnce(Return(apiBuilder));
|
||||||
|
|
||||||
EXPECT_CALL(api, CommandBufferBuilderSetPushConstants(apiBuilder, DAWN_SHADER_STAGE_BIT_VERTEX, 0, 4, ResultOf(CheckPushConstantValues, Eq(true))));
|
dawnComputePassEncoder apiPass = api.GetNewComputePassEncoder();
|
||||||
|
EXPECT_CALL(api, CommandBufferBuilderBeginComputePass(apiBuilder))
|
||||||
|
.WillOnce(Return(apiPass));
|
||||||
|
|
||||||
|
EXPECT_CALL(api, ComputePassEncoderSetPushConstants(apiPass, DAWN_SHADER_STAGE_BIT_VERTEX, 0, 4, ResultOf(CheckPushConstantValues, Eq(true))));
|
||||||
|
|
||||||
FlushClient();
|
FlushClient();
|
||||||
}
|
}
|
||||||
|
@ -318,28 +328,33 @@ TEST_F(WireTests, CStringArgument) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test that the wire is able to send objects as value arguments
|
// Test that the wire is able to send objects as value arguments
|
||||||
TEST_F(WireTests, ObjectAsValueArgument) {
|
TEST_F(WireTests, DISABLED_ObjectAsValueArgument) {
|
||||||
// Create pipeline
|
// Create pipeline
|
||||||
dawnRenderPipelineBuilder pipelineBuilder = dawnDeviceCreateRenderPipelineBuilder(device);
|
dawnComputePipelineDescriptor pipelineDesc;
|
||||||
dawnRenderPipeline pipeline = dawnRenderPipelineBuilderGetResult(pipelineBuilder);
|
pipelineDesc.nextInChain = nullptr;
|
||||||
|
pipelineDesc.layout = nullptr;
|
||||||
|
pipelineDesc.entryPoint = "main";
|
||||||
|
pipelineDesc.module = nullptr;
|
||||||
|
dawnComputePipeline pipeline = dawnDeviceCreateComputePipeline(device, &pipelineDesc);
|
||||||
|
|
||||||
dawnRenderPipelineBuilder apiPipelineBuilder = api.GetNewRenderPipelineBuilder();
|
dawnComputePipeline apiPipeline = api.GetNewComputePipeline();
|
||||||
EXPECT_CALL(api, DeviceCreateRenderPipelineBuilder(apiDevice))
|
EXPECT_CALL(api, DeviceCreateComputePipeline(apiDevice, _))
|
||||||
.WillOnce(Return(apiPipelineBuilder));
|
|
||||||
|
|
||||||
dawnRenderPipeline apiPipeline = api.GetNewRenderPipeline();
|
|
||||||
EXPECT_CALL(api, RenderPipelineBuilderGetResult(apiPipelineBuilder))
|
|
||||||
.WillOnce(Return(apiPipeline));
|
.WillOnce(Return(apiPipeline));
|
||||||
|
|
||||||
// Create command buffer builder, setting pipeline
|
// Create command buffer builder, setting pipeline
|
||||||
dawnCommandBufferBuilder cmdBufBuilder = dawnDeviceCreateCommandBufferBuilder(device);
|
dawnCommandBufferBuilder cmdBufBuilder = dawnDeviceCreateCommandBufferBuilder(device);
|
||||||
dawnCommandBufferBuilderSetRenderPipeline(cmdBufBuilder, pipeline);
|
dawnComputePassEncoder pass = dawnCommandBufferBuilderBeginComputePass(cmdBufBuilder);
|
||||||
|
dawnComputePassEncoderSetComputePipeline(pass, pipeline);
|
||||||
|
|
||||||
dawnCommandBufferBuilder apiCmdBufBuilder = api.GetNewCommandBufferBuilder();
|
dawnCommandBufferBuilder apiCmdBufBuilder = api.GetNewCommandBufferBuilder();
|
||||||
EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
|
EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
|
||||||
.WillOnce(Return(apiCmdBufBuilder));
|
.WillOnce(Return(apiCmdBufBuilder));
|
||||||
|
|
||||||
EXPECT_CALL(api, CommandBufferBuilderSetRenderPipeline(apiCmdBufBuilder, apiPipeline));
|
dawnComputePassEncoder apiPass = api.GetNewComputePassEncoder();
|
||||||
|
EXPECT_CALL(api, CommandBufferBuilderBeginComputePass(apiCmdBufBuilder))
|
||||||
|
.WillOnce(Return(apiPass));
|
||||||
|
|
||||||
|
EXPECT_CALL(api, ComputePassEncoderSetComputePipeline(apiPass, apiPipeline));
|
||||||
|
|
||||||
FlushClient();
|
FlushClient();
|
||||||
}
|
}
|
||||||
|
@ -472,23 +487,33 @@ TEST_F(WireTests, StructureOfStructureArrayArgument) {
|
||||||
|
|
||||||
// Test that the server doesn't forward calls to error objects or with error objects
|
// Test that the server doesn't forward calls to error objects or with error objects
|
||||||
// Also test that when GetResult is called on an error builder, the error callback is fired
|
// Also test that when GetResult is called on an error builder, the error callback is fired
|
||||||
TEST_F(WireTests, CallsSkippedAfterBuilderError) {
|
// TODO(cwallez@chromium.org): This test is disabled because the introduction of encoders breaks
|
||||||
|
// the assumptions of the "builder error" handling that a builder is self-contained. We need to
|
||||||
|
// revisit this once the new error handling is in place.
|
||||||
|
TEST_F(WireTests, DISABLED_CallsSkippedAfterBuilderError) {
|
||||||
dawnCommandBufferBuilder cmdBufBuilder = dawnDeviceCreateCommandBufferBuilder(device);
|
dawnCommandBufferBuilder cmdBufBuilder = dawnDeviceCreateCommandBufferBuilder(device);
|
||||||
dawnCommandBufferBuilderSetErrorCallback(cmdBufBuilder, ToMockBuilderErrorCallback, 1, 2);
|
dawnCommandBufferBuilderSetErrorCallback(cmdBufBuilder, ToMockBuilderErrorCallback, 1, 2);
|
||||||
|
|
||||||
|
dawnRenderPassEncoder pass = dawnCommandBufferBuilderBeginRenderPass(cmdBufBuilder, nullptr);
|
||||||
|
|
||||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
|
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
|
||||||
dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 3, 4);
|
dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 3, 4);
|
||||||
dawnBuffer buffer = dawnBufferBuilderGetResult(bufferBuilder); // Hey look an error!
|
dawnBuffer buffer = dawnBufferBuilderGetResult(bufferBuilder); // Hey look an error!
|
||||||
|
|
||||||
// These calls will be skipped because of the error
|
// These calls will be skipped because of the error
|
||||||
dawnBufferSetSubData(buffer, 0, 0, nullptr);
|
dawnBufferSetSubData(buffer, 0, 0, nullptr);
|
||||||
dawnCommandBufferBuilderSetIndexBuffer(cmdBufBuilder, buffer, 0);
|
dawnRenderPassEncoderSetIndexBuffer(pass, buffer, 0);
|
||||||
|
dawnRenderPassEncoderEndPass(pass);
|
||||||
dawnCommandBufferBuilderGetResult(cmdBufBuilder);
|
dawnCommandBufferBuilderGetResult(cmdBufBuilder);
|
||||||
|
|
||||||
dawnCommandBufferBuilder apiCmdBufBuilder = api.GetNewCommandBufferBuilder();
|
dawnCommandBufferBuilder apiCmdBufBuilder = api.GetNewCommandBufferBuilder();
|
||||||
EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
|
EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
|
||||||
.WillOnce(Return(apiCmdBufBuilder));
|
.WillOnce(Return(apiCmdBufBuilder));
|
||||||
|
|
||||||
|
dawnRenderPassEncoder apiPass = api.GetNewRenderPassEncoder();
|
||||||
|
EXPECT_CALL(api, CommandBufferBuilderBeginRenderPass(apiCmdBufBuilder, _))
|
||||||
|
.WillOnce(Return(apiPass));
|
||||||
|
|
||||||
dawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
|
dawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
|
||||||
EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
|
EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
|
||||||
.WillOnce(Return(apiBufferBuilder));
|
.WillOnce(Return(apiBufferBuilder));
|
||||||
|
@ -501,7 +526,7 @@ TEST_F(WireTests, CallsSkippedAfterBuilderError) {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
EXPECT_CALL(api, BufferSetSubData(_, _, _, _)).Times(0);
|
EXPECT_CALL(api, BufferSetSubData(_, _, _, _)).Times(0);
|
||||||
EXPECT_CALL(api, CommandBufferBuilderSetIndexBuffer(_, _, _)).Times(0);
|
EXPECT_CALL(api, RenderPassEncoderSetIndexBuffer(_, _, _)).Times(0);
|
||||||
EXPECT_CALL(api, CommandBufferBuilderGetResult(_)).Times(0);
|
EXPECT_CALL(api, CommandBufferBuilderGetResult(_)).Times(0);
|
||||||
|
|
||||||
FlushClient();
|
FlushClient();
|
||||||
|
|
|
@ -27,11 +27,16 @@ TEST_F(CommandBufferValidationTest, Empty) {
|
||||||
TEST_F(CommandBufferValidationTest, RenderPass) {
|
TEST_F(CommandBufferValidationTest, RenderPass) {
|
||||||
auto renderpass = CreateSimpleRenderPass();
|
auto renderpass = CreateSimpleRenderPass();
|
||||||
|
|
||||||
AssertWillBeSuccess(device.CreateCommandBufferBuilder())
|
{
|
||||||
.BeginRenderPass(renderpass)
|
dawn::CommandBufferBuilder builder = AssertWillBeSuccess(device.CreateCommandBufferBuilder());
|
||||||
.EndRenderPass()
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderpass);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
AssertWillBeError(device.CreateCommandBufferBuilder())
|
builder.GetResult();
|
||||||
.BeginRenderPass(renderpass)
|
}
|
||||||
.GetResult();
|
|
||||||
|
{
|
||||||
|
dawn::CommandBufferBuilder builder = AssertWillBeError(device.CreateCommandBufferBuilder());
|
||||||
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderpass);
|
||||||
|
builder.GetResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,36 +17,30 @@
|
||||||
class SetScissorRectTest : public ValidationTest {
|
class SetScissorRectTest : public ValidationTest {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Test to check that SetScissor can only be used inside render passes
|
// Test to check basic use of SetScissor
|
||||||
TEST_F(SetScissorRectTest, AllowedOnlyInRenderPass) {
|
TEST_F(SetScissorRectTest, Success) {
|
||||||
DummyRenderPass renderPass = CreateDummyRenderPass();
|
DummyRenderPass renderPass = CreateDummyRenderPass();
|
||||||
|
|
||||||
AssertWillBeSuccess(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeSuccess(device.CreateCommandBufferBuilder());
|
||||||
.BeginRenderPass(renderPass.renderPass)
|
{
|
||||||
.SetScissorRect(0, 0, 1, 1)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPass);
|
||||||
.EndRenderPass()
|
pass.SetScissorRect(0, 0, 1, 1);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
AssertWillBeError(device.CreateCommandBufferBuilder())
|
builder.GetResult();
|
||||||
.SetScissorRect(0, 0, 1, 1)
|
|
||||||
.GetResult();
|
|
||||||
|
|
||||||
AssertWillBeError(device.CreateCommandBufferBuilder())
|
|
||||||
.BeginComputePass()
|
|
||||||
.SetScissorRect(0, 0, 1, 1)
|
|
||||||
.EndComputePass()
|
|
||||||
.GetResult();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test to check that an empty scissor is allowed
|
// Test to check that an empty scissor is allowed
|
||||||
TEST_F(SetScissorRectTest, EmptyScissor) {
|
TEST_F(SetScissorRectTest, EmptyScissor) {
|
||||||
DummyRenderPass renderPass = CreateDummyRenderPass();
|
DummyRenderPass renderPass = CreateDummyRenderPass();
|
||||||
|
|
||||||
AssertWillBeSuccess(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeSuccess(device.CreateCommandBufferBuilder());
|
||||||
.BeginRenderPass(renderPass.renderPass)
|
{
|
||||||
.SetScissorRect(0, 0, 0, 0)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPass);
|
||||||
.EndRenderPass()
|
pass.SetScissorRect(0, 0, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
builder.GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test to check that a scissor larger than the framebuffer is allowed
|
// Test to check that a scissor larger than the framebuffer is allowed
|
||||||
|
@ -55,79 +49,69 @@ TEST_F(SetScissorRectTest, EmptyScissor) {
|
||||||
TEST_F(SetScissorRectTest, ScissorLargerThanFramebuffer) {
|
TEST_F(SetScissorRectTest, ScissorLargerThanFramebuffer) {
|
||||||
DummyRenderPass renderPass = CreateDummyRenderPass();
|
DummyRenderPass renderPass = CreateDummyRenderPass();
|
||||||
|
|
||||||
AssertWillBeSuccess(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeSuccess(device.CreateCommandBufferBuilder());
|
||||||
.BeginRenderPass(renderPass.renderPass)
|
{
|
||||||
.SetScissorRect(0, 0, renderPass.width + 1, renderPass.height + 1)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPass);
|
||||||
.EndRenderPass()
|
pass.SetScissorRect(0, 0, renderPass.width + 1, renderPass.height + 1);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
builder.GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
class SetBlendColorTest : public ValidationTest {
|
class SetBlendColorTest : public ValidationTest {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Test to check that SetBlendColor can only be used inside render passes
|
// Test to check basic use of SetBlendColor
|
||||||
TEST_F(SetBlendColorTest, AllowedOnlyInRenderPass) {
|
TEST_F(SetBlendColorTest, Success) {
|
||||||
DummyRenderPass renderPass = CreateDummyRenderPass();
|
DummyRenderPass renderPass = CreateDummyRenderPass();
|
||||||
|
|
||||||
AssertWillBeSuccess(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeSuccess(device.CreateCommandBufferBuilder());
|
||||||
.BeginRenderPass(renderPass.renderPass)
|
{
|
||||||
.SetBlendColor(0.0f, 0.0f, 0.0f, 0.0f)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPass);
|
||||||
.EndRenderPass()
|
pass.SetBlendColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
AssertWillBeError(device.CreateCommandBufferBuilder())
|
builder.GetResult();
|
||||||
.SetBlendColor(0.0f, 0.0f, 0.0f, 0.0f)
|
|
||||||
.GetResult();
|
|
||||||
|
|
||||||
AssertWillBeError(device.CreateCommandBufferBuilder())
|
|
||||||
.BeginComputePass()
|
|
||||||
.SetBlendColor(0.0f, 0.0f, 0.0f, 0.0f)
|
|
||||||
.EndComputePass()
|
|
||||||
.GetResult();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test that SetBlendColor allows any value, large, small or negative
|
// Test that SetBlendColor allows any value, large, small or negative
|
||||||
TEST_F(SetBlendColorTest, AnyValueAllowed) {
|
TEST_F(SetBlendColorTest, AnyValueAllowed) {
|
||||||
DummyRenderPass renderPass = CreateDummyRenderPass();
|
DummyRenderPass renderPass = CreateDummyRenderPass();
|
||||||
|
|
||||||
AssertWillBeSuccess(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeSuccess(device.CreateCommandBufferBuilder());
|
||||||
.BeginRenderPass(renderPass.renderPass)
|
{
|
||||||
.SetBlendColor(-1.0f, 42.0f, -0.0f, 0.0f)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPass);
|
||||||
.EndRenderPass()
|
pass.SetBlendColor(-1.0f, 42.0f, -0.0f, 0.0f);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
builder.GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
class SetStencilReferenceTest : public ValidationTest {
|
class SetStencilReferenceTest : public ValidationTest {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Test to check that SetStencilReference can only be used inside render passes
|
// Test to check basic use of SetBlendColor
|
||||||
TEST_F(SetStencilReferenceTest, AllowedOnlyInRenderPass) {
|
TEST_F(SetStencilReferenceTest, Success) {
|
||||||
DummyRenderPass renderPass = CreateDummyRenderPass();
|
DummyRenderPass renderPass = CreateDummyRenderPass();
|
||||||
|
|
||||||
AssertWillBeSuccess(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeSuccess(device.CreateCommandBufferBuilder());
|
||||||
.BeginRenderPass(renderPass.renderPass)
|
{
|
||||||
.SetStencilReference(0)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPass);
|
||||||
.EndRenderPass()
|
pass.SetStencilReference(0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
AssertWillBeError(device.CreateCommandBufferBuilder())
|
builder.GetResult();
|
||||||
.SetStencilReference(0)
|
|
||||||
.GetResult();
|
|
||||||
|
|
||||||
AssertWillBeError(device.CreateCommandBufferBuilder())
|
|
||||||
.BeginComputePass()
|
|
||||||
.SetStencilReference(0)
|
|
||||||
.EndComputePass()
|
|
||||||
.GetResult();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test that SetStencilReference allows any bit to be set
|
// Test that SetStencilReference allows any bit to be set
|
||||||
TEST_F(SetStencilReferenceTest, AllBitsAllowed) {
|
TEST_F(SetStencilReferenceTest, AllBitsAllowed) {
|
||||||
DummyRenderPass renderPass = CreateDummyRenderPass();
|
DummyRenderPass renderPass = CreateDummyRenderPass();
|
||||||
|
|
||||||
AssertWillBeSuccess(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeSuccess(device.CreateCommandBufferBuilder());
|
||||||
.BeginRenderPass(renderPass.renderPass)
|
{
|
||||||
.SetStencilReference(0xFFFFFFFF)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPass);
|
||||||
.EndRenderPass()
|
pass.SetStencilReference(0xFFFFFFFF);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
builder.GetResult();
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,28 +46,36 @@ class PushConstantTest : public ValidationTest {
|
||||||
TEST_F(PushConstantTest, Success) {
|
TEST_F(PushConstantTest, Success) {
|
||||||
DummyRenderPass renderpassData = CreateDummyRenderPass();
|
DummyRenderPass renderpassData = CreateDummyRenderPass();
|
||||||
|
|
||||||
AssertWillBeSuccess(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeSuccess(device.CreateCommandBufferBuilder());
|
||||||
// PushConstants in a compute pass
|
// PushConstants in a compute pass
|
||||||
.BeginComputePass()
|
{
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Compute, 0, 1, constants)
|
dawn::ComputePassEncoder pass = builder.BeginComputePass();
|
||||||
.EndComputePass()
|
pass.SetPushConstants(dawn::ShaderStageBit::Compute, 0, 1, constants);
|
||||||
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
// PushConstants in a render pass
|
// PushConstants in a render pass
|
||||||
.BeginRenderPass(renderpassData.renderPass)
|
{
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Vertex | dawn::ShaderStageBit::Fragment, 0, 1, constants)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderpassData.renderPass);
|
||||||
.EndRenderPass()
|
pass.SetPushConstants(dawn::ShaderStageBit::Vertex | dawn::ShaderStageBit::Fragment, 0, 1, constants);
|
||||||
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
// Setting all constants
|
// Setting all constants
|
||||||
.BeginComputePass()
|
{
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Compute, 0, kMaxPushConstants, constants)
|
dawn::ComputePassEncoder pass = builder.BeginComputePass();
|
||||||
.EndComputePass()
|
pass.SetPushConstants(dawn::ShaderStageBit::Compute, 0, kMaxPushConstants, constants);
|
||||||
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
// Setting constants at an offset
|
// Setting constants at an offset
|
||||||
.BeginComputePass()
|
{
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Compute, kMaxPushConstants - 1, 1, constants)
|
dawn::ComputePassEncoder pass = builder.BeginComputePass();
|
||||||
.EndComputePass()
|
pass.SetPushConstants(dawn::ShaderStageBit::Compute, kMaxPushConstants - 1, 1, constants);
|
||||||
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
.GetResult();
|
builder.GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test check for constants being set out of bounds
|
// Test check for constants being set out of bounds
|
||||||
|
@ -76,45 +84,29 @@ TEST_F(PushConstantTest, SetPushConstantsOOB) {
|
||||||
|
|
||||||
// Control case: setting all constants
|
// Control case: setting all constants
|
||||||
{
|
{
|
||||||
AssertWillBeSuccess(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeSuccess(device.CreateCommandBufferBuilder());
|
||||||
.BeginComputePass()
|
dawn::ComputePassEncoder pass = builder.BeginComputePass();
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Compute, 0, kMaxPushConstants, constants)
|
pass.SetPushConstants(dawn::ShaderStageBit::Compute, 0, kMaxPushConstants, constants);
|
||||||
.EndComputePass()
|
pass.EndPass();
|
||||||
.GetResult();
|
builder.GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
// OOB because count is too big.
|
// OOB because count is too big.
|
||||||
{
|
{
|
||||||
AssertWillBeError(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeError(device.CreateCommandBufferBuilder());
|
||||||
.BeginComputePass()
|
dawn::ComputePassEncoder pass = builder.BeginComputePass();
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Compute, 0, kMaxPushConstants + 1, constants)
|
pass.SetPushConstants(dawn::ShaderStageBit::Compute, 0, kMaxPushConstants + 1, constants);
|
||||||
.EndComputePass()
|
pass.EndPass();
|
||||||
.GetResult();
|
builder.GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
// OOB because of the offset.
|
// OOB because of the offset.
|
||||||
{
|
{
|
||||||
AssertWillBeError(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeError(device.CreateCommandBufferBuilder());
|
||||||
.BeginComputePass()
|
dawn::ComputePassEncoder pass = builder.BeginComputePass();
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Compute, 1, kMaxPushConstants, constants)
|
pass.SetPushConstants(dawn::ShaderStageBit::Compute, 1, kMaxPushConstants, constants);
|
||||||
.EndComputePass()
|
pass.EndPass();
|
||||||
.GetResult();
|
builder.GetResult();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test which places push constants can be set
|
|
||||||
TEST_F(PushConstantTest, NotInPass) {
|
|
||||||
DummyRenderPass renderpassData = CreateDummyRenderPass();
|
|
||||||
|
|
||||||
// Setting outside of any pass is invalid.
|
|
||||||
{
|
|
||||||
AssertWillBeError(device.CreateCommandBufferBuilder())
|
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Compute, 0, 1, constants)
|
|
||||||
.GetResult();
|
|
||||||
|
|
||||||
AssertWillBeError(device.CreateCommandBufferBuilder())
|
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Vertex, 0, 1, constants)
|
|
||||||
.GetResult();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,29 +114,29 @@ TEST_F(PushConstantTest, NotInPass) {
|
||||||
TEST_F(PushConstantTest, StageForComputePass) {
|
TEST_F(PushConstantTest, StageForComputePass) {
|
||||||
// Control case: setting to the compute stage in compute passes
|
// Control case: setting to the compute stage in compute passes
|
||||||
{
|
{
|
||||||
AssertWillBeSuccess(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeSuccess(device.CreateCommandBufferBuilder());
|
||||||
.BeginComputePass()
|
dawn::ComputePassEncoder pass = builder.BeginComputePass();
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Compute, 0, 1, constants)
|
pass.SetPushConstants(dawn::ShaderStageBit::Compute, 0, 1, constants);
|
||||||
.EndComputePass()
|
pass.EndPass();
|
||||||
.GetResult();
|
builder.GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Graphics stages are disallowed
|
// Graphics stages are disallowed
|
||||||
{
|
{
|
||||||
AssertWillBeError(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeError(device.CreateCommandBufferBuilder());
|
||||||
.BeginComputePass()
|
dawn::ComputePassEncoder pass = builder.BeginComputePass();
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Vertex, 0, 1, constants)
|
pass.SetPushConstants(dawn::ShaderStageBit::Vertex, 0, 1, constants);
|
||||||
.EndComputePass()
|
pass.EndPass();
|
||||||
.GetResult();
|
builder.GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
// A None shader stage mask is valid.
|
// A None shader stage mask is valid.
|
||||||
{
|
{
|
||||||
AssertWillBeSuccess(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeSuccess(device.CreateCommandBufferBuilder());
|
||||||
.BeginComputePass()
|
dawn::ComputePassEncoder pass = builder.BeginComputePass();
|
||||||
.SetPushConstants(dawn::ShaderStageBit::None, 0, 1, constants)
|
pass.SetPushConstants(dawn::ShaderStageBit::None, 0, 1, constants);
|
||||||
.EndComputePass()
|
pass.EndPass();
|
||||||
.GetResult();
|
builder.GetResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,29 +146,29 @@ TEST_F(PushConstantTest, StageForRenderPass) {
|
||||||
|
|
||||||
// Control case: setting to vertex and fragment in render pass
|
// Control case: setting to vertex and fragment in render pass
|
||||||
{
|
{
|
||||||
AssertWillBeSuccess(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeSuccess(device.CreateCommandBufferBuilder());
|
||||||
.BeginRenderPass(renderpassData.renderPass)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderpassData.renderPass);
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Vertex | dawn::ShaderStageBit::Fragment, 0, 1, constants)
|
pass.SetPushConstants(dawn::ShaderStageBit::Vertex | dawn::ShaderStageBit::Fragment, 0, 1, constants);
|
||||||
.EndRenderPass()
|
pass.EndPass();
|
||||||
.GetResult();
|
builder.GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute stage is disallowed
|
// Compute stage is disallowed
|
||||||
{
|
{
|
||||||
AssertWillBeError(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeError(device.CreateCommandBufferBuilder());
|
||||||
.BeginRenderPass(renderpassData.renderPass)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderpassData.renderPass);
|
||||||
.SetPushConstants(dawn::ShaderStageBit::Compute, 0, 1, constants)
|
pass.SetPushConstants(dawn::ShaderStageBit::Compute, 0, 1, constants);
|
||||||
.EndRenderPass()
|
pass.EndPass();
|
||||||
.GetResult();
|
builder.GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
// A None shader stage mask is valid.
|
// A None shader stage mask is valid.
|
||||||
{
|
{
|
||||||
AssertWillBeSuccess(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeSuccess(device.CreateCommandBufferBuilder());
|
||||||
.BeginRenderPass(renderpassData.renderPass)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderpassData.renderPass);
|
||||||
.SetPushConstants(dawn::ShaderStageBit::None, 0, 1, constants)
|
pass.SetPushConstants(dawn::ShaderStageBit::None, 0, 1, constants);
|
||||||
.EndRenderPass()
|
pass.EndPass();
|
||||||
.GetResult();
|
builder.GetResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,23 +104,27 @@ TEST_F(VertexBufferValidationTest, VertexInputsInheritedBetweenPipelines) {
|
||||||
uint32_t offsets[] = { 0, 0 };
|
uint32_t offsets[] = { 0, 0 };
|
||||||
|
|
||||||
// Check failure when vertex buffer is not set
|
// Check failure when vertex buffer is not set
|
||||||
AssertWillBeError(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeError(device.CreateCommandBufferBuilder());
|
||||||
.BeginRenderPass(renderpass)
|
{
|
||||||
.SetRenderPipeline(pipeline1)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderpass);
|
||||||
.DrawArrays(3, 1, 0, 0)
|
pass.SetRenderPipeline(pipeline1);
|
||||||
.EndRenderPass()
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
builder.GetResult();
|
||||||
|
|
||||||
// Check success when vertex buffer is inherited from previous pipeline
|
// Check success when vertex buffer is inherited from previous pipeline
|
||||||
AssertWillBeSuccess(device.CreateCommandBufferBuilder())
|
builder = AssertWillBeSuccess(device.CreateCommandBufferBuilder());
|
||||||
.BeginRenderPass(renderpass)
|
{
|
||||||
.SetRenderPipeline(pipeline2)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderpass);
|
||||||
.SetVertexBuffers(0, 2, vertexBuffers.data(), offsets)
|
pass.SetRenderPipeline(pipeline2);
|
||||||
.DrawArrays(3, 1, 0, 0)
|
pass.SetVertexBuffers(0, 2, vertexBuffers.data(), offsets);
|
||||||
.SetRenderPipeline(pipeline1)
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
.DrawArrays(3, 1, 0, 0)
|
pass.SetRenderPipeline(pipeline1);
|
||||||
.EndRenderPass()
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
.GetResult();
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
builder.GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(VertexBufferValidationTest, VertexInputsNotInheritedBetweenRendePasses) {
|
TEST_F(VertexBufferValidationTest, VertexInputsNotInheritedBetweenRendePasses) {
|
||||||
|
@ -137,29 +141,37 @@ TEST_F(VertexBufferValidationTest, VertexInputsNotInheritedBetweenRendePasses) {
|
||||||
uint32_t offsets[] = { 0, 0 };
|
uint32_t offsets[] = { 0, 0 };
|
||||||
|
|
||||||
// Check success when vertex buffer is set for each render pass
|
// Check success when vertex buffer is set for each render pass
|
||||||
AssertWillBeSuccess(device.CreateCommandBufferBuilder())
|
dawn::CommandBufferBuilder builder = AssertWillBeSuccess(device.CreateCommandBufferBuilder());
|
||||||
.BeginRenderPass(renderpass)
|
{
|
||||||
.SetRenderPipeline(pipeline2)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderpass);
|
||||||
.SetVertexBuffers(0, 2, vertexBuffers.data(), offsets)
|
pass.SetRenderPipeline(pipeline2);
|
||||||
.DrawArrays(3, 1, 0, 0)
|
pass.SetVertexBuffers(0, 2, vertexBuffers.data(), offsets);
|
||||||
.EndRenderPass()
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
.BeginRenderPass(renderpass)
|
pass.EndPass();
|
||||||
.SetRenderPipeline(pipeline1)
|
}
|
||||||
.SetVertexBuffers(0, 1, vertexBuffers.data(), offsets)
|
{
|
||||||
.DrawArrays(3, 1, 0, 0)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderpass);
|
||||||
.EndRenderPass()
|
pass.SetRenderPipeline(pipeline1);
|
||||||
.GetResult();
|
pass.SetVertexBuffers(0, 1, vertexBuffers.data(), offsets);
|
||||||
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
builder.GetResult();
|
||||||
|
|
||||||
// Check failure because vertex buffer is not inherited in second subpass
|
// Check failure because vertex buffer is not inherited in second subpass
|
||||||
AssertWillBeError(device.CreateCommandBufferBuilder())
|
builder = AssertWillBeError(device.CreateCommandBufferBuilder());
|
||||||
.BeginRenderPass(renderpass)
|
{
|
||||||
.SetRenderPipeline(pipeline2)
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderpass);
|
||||||
.SetVertexBuffers(0, 2, vertexBuffers.data(), offsets)
|
pass.SetRenderPipeline(pipeline2);
|
||||||
.DrawArrays(3, 1, 0, 0)
|
pass.SetVertexBuffers(0, 2, vertexBuffers.data(), offsets);
|
||||||
.EndRenderPass()
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
.BeginRenderPass(renderpass)
|
pass.EndPass();
|
||||||
.SetRenderPipeline(pipeline1)
|
}
|
||||||
.DrawArrays(3, 1, 0, 0)
|
{
|
||||||
.EndRenderPass()
|
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderpass);
|
||||||
.GetResult();
|
pass.SetRenderPipeline(pipeline1);
|
||||||
|
pass.DrawArrays(3, 1, 0, 0);
|
||||||
|
pass.EndPass();
|
||||||
|
}
|
||||||
|
builder.GetResult();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue