Add and Implement CommandBuffer::SetScissorRect

This commit is contained in:
Corentin Wallez 2018-02-13 14:57:13 -05:00 committed by Corentin Wallez
parent 234111c379
commit a3c89cc27a
9 changed files with 85 additions and 2 deletions

View File

@ -485,6 +485,15 @@
{"name": "pipeline", "type": "render pipeline"}
]
},
{
"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": [

View File

@ -219,6 +219,10 @@ namespace backend {
SetStencilReferenceCmd* cmd = commands->NextCommand<SetStencilReferenceCmd>();
cmd->~SetStencilReferenceCmd();
} break;
case Command::SetScissorRect: {
SetScissorRectCmd* cmd = commands->NextCommand<SetScissorRectCmd>();
cmd->~SetScissorRectCmd();
} break;
case Command::SetBlendColor: {
SetBlendColorCmd* cmd = commands->NextCommand<SetBlendColorCmd>();
cmd->~SetBlendColorCmd();
@ -322,6 +326,10 @@ namespace backend {
commands->NextCommand<SetStencilReferenceCmd>();
break;
case Command::SetScissorRect:
commands->NextCommand<SetScissorRectCmd>();
break;
case Command::SetBlendColor:
commands->NextCommand<SetBlendColorCmd>();
break;
@ -537,6 +545,14 @@ namespace backend {
}
} break;
case Command::SetScissorRect: {
mIterator.NextCommand<SetScissorRectCmd>();
if (!mState->HaveRenderSubpass()) {
HandleError("Can't set scissor rect without an active render subpass");
return false;
}
} break;
case Command::SetBindGroup: {
SetBindGroupCmd* cmd = mIterator.NextCommand<SetBindGroupCmd>();
if (!mState->SetBindGroup(cmd->index, cmd->group.Get())) {
@ -784,6 +800,18 @@ namespace backend {
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");

View File

@ -111,6 +111,7 @@ namespace backend {
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);

View File

@ -44,6 +44,7 @@ namespace backend {
SetRenderPipeline,
SetPushConstants,
SetStencilReference,
SetScissorRect,
SetBlendColor,
SetBindGroup,
SetIndexBuffer,
@ -135,6 +136,10 @@ namespace backend {
uint32_t reference;
};
struct SetScissorRectCmd {
uint32_t x, y, width, height;
};
struct SetBlendColorCmd {
float r, g, b, a;
};

View File

@ -528,6 +528,17 @@ namespace backend { namespace d3d12 {
commandList->OMSetStencilRef(cmd->reference);
} break;
case Command::SetScissorRect: {
SetScissorRectCmd* cmd = mCommands.NextCommand<SetScissorRectCmd>();
D3D12_RECT rect;
rect.left = cmd->x;
rect.bottom = cmd->y;
rect.right = cmd->x + cmd->width;
rect.top = cmd->y + cmd->height;
commandList->RSSetScissorRects(1, &rect);
} break;
case Command::SetBlendColor: {
SetBlendColorCmd* cmd = mCommands.NextCommand<SetBlendColorCmd>();
ASSERT(lastRenderPipeline);

View File

@ -392,15 +392,25 @@ namespace backend { namespace metal {
SetStencilReferenceCmd* cmd = mCommands.NextCommand<SetStencilReferenceCmd>();
ASSERT(encoders.render);
[encoders.render setStencilReferenceValue:cmd->reference];
} break;
case Command::SetScissorRect: {
SetScissorRectCmd* cmd = mCommands.NextCommand<SetScissorRectCmd>();
MTLScissorRect rect;
rect.x = cmd->x;
rect.y = cmd->y;
rect.width = cmd->width;
rect.height = cmd->height;
ASSERT(encoders.render);
[encoders.render setScissorRect:rect];
} break;
case Command::SetBlendColor: {
SetBlendColorCmd* cmd = mCommands.NextCommand<SetBlendColorCmd>();
ASSERT(encoders.render);
[encoders.render setBlendColorRed:cmd->r green:cmd->g blue:cmd->b alpha:cmd->a];
} break;

View File

@ -370,6 +370,8 @@ namespace backend { namespace opengl {
glBlendColor(0, 0, 0, 0);
glViewport(0, 0, currentFramebuffer->GetWidth(),
currentFramebuffer->GetHeight());
glScissor(0, 0, currentFramebuffer->GetWidth(),
currentFramebuffer->GetHeight());
} break;
case Command::CopyBufferToBuffer: {
@ -539,6 +541,11 @@ namespace backend { namespace opengl {
persistentPipelineState.SetStencilReference(cmd->reference);
} break;
case Command::SetScissorRect: {
SetScissorRectCmd* cmd = mCommands.NextCommand<SetScissorRectCmd>();
glScissor(cmd->x, cmd->y, cmd->width, cmd->height);
} break;
case Command::SetBlendColor: {
SetBlendColorCmd* cmd = mCommands.NextCommand<SetBlendColorCmd>();
glBlendColor(cmd->r, cmd->g, cmd->b, cmd->a);

View File

@ -40,6 +40,7 @@ namespace backend { namespace opengl {
*device = reinterpret_cast<nxtDevice>(new Device);
glEnable(GL_DEPTH_TEST);
glEnable(GL_SCISSOR_TEST);
glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
}

View File

@ -275,6 +275,17 @@ namespace backend { namespace vulkan {
cmd->reference);
} break;
case Command::SetScissorRect: {
SetScissorRectCmd* cmd = mCommands.NextCommand<SetScissorRectCmd>();
VkRect2D rect;
rect.offset.x = cmd->x;
rect.offset.y = cmd->y;
rect.extent.width = cmd->width;
rect.extent.height = cmd->height;
device->fn.CmdSetScissor(commands, 0, 1, &rect);
} break;
case Command::SetVertexBuffers: {
SetVertexBuffersCmd* cmd = mCommands.NextCommand<SetVertexBuffersCmd>();
auto buffers = mCommands.NextData<Ref<BufferBase>>(cmd->count);