From fb4265387c6140d0c900f8c8f06fce5b971ec4b0 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Tue, 1 Aug 2017 14:22:52 -0400 Subject: [PATCH] Add SetBlendColor command --- next.json | 12 ++++++++++ src/backend/CommandBuffer.cpp | 29 ++++++++++++++++++++++++ src/backend/CommandBuffer.h | 1 + src/backend/Commands.h | 5 ++++ src/backend/d3d12/CommandBufferD3D12.cpp | 8 +++++++ src/backend/metal/CommandBufferMTL.mm | 14 ++++++++++++ src/backend/opengl/CommandBufferGL.cpp | 6 +++++ 7 files changed, 75 insertions(+) diff --git a/next.json b/next.json index a967b7dd94..95deacad4e 100644 --- a/next.json +++ b/next.json @@ -441,6 +441,15 @@ {"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": [ @@ -688,6 +697,9 @@ {"value": 1, "name":"linear"} ] }, + "float": { + "category": "native" + }, "framebuffer": { "category": "object" }, diff --git a/src/backend/CommandBuffer.cpp b/src/backend/CommandBuffer.cpp index 407ca37506..5159c2f5b2 100644 --- a/src/backend/CommandBuffer.cpp +++ b/src/backend/CommandBuffer.cpp @@ -236,6 +236,12 @@ namespace backend { cmd->~SetStencilReferenceCmd(); } break; + case Command::SetBlendColor: + { + SetBlendColorCmd* cmd = commands->NextCommand(); + cmd->~SetBlendColorCmd(); + } + break; case Command::SetBindGroup: { SetBindGroupCmd* cmd = commands->NextCommand(); @@ -345,6 +351,10 @@ namespace backend { commands->NextCommand(); break; + case Command::SetBlendColor: + commands->NextCommand(); + break; + case Command::SetBindGroup: commands->NextCommand(); break; @@ -570,6 +580,16 @@ namespace backend { } break; + case Command::SetBlendColor: + { + iterator.NextCommand(); + if (!state->HaveRenderPass()) { + HandleError("Can't set blend color without an active render pass"); + return false; + } + } + break; + case Command::SetBindGroup: { SetBindGroupCmd* cmd = iterator.NextCommand(); @@ -779,6 +799,15 @@ namespace backend { cmd->reference = reference; } + void CommandBufferBuilder::SetBlendColor(float r, float g, float b, float a) { + SetBlendColorCmd* cmd = allocator.Allocate(Command::SetBlendColor); + new(cmd) SetBlendColorCmd; + cmd->r = r; + cmd->g = g; + cmd->b = b; + cmd->a = a; + } + void CommandBufferBuilder::SetBindGroup(uint32_t groupIndex, BindGroupBase* group) { if (groupIndex >= kMaxBindGroups) { HandleError("Setting bind group over the max"); diff --git a/src/backend/CommandBuffer.h b/src/backend/CommandBuffer.h index 1790d0e2a8..cf3ed3db27 100644 --- a/src/backend/CommandBuffer.h +++ b/src/backend/CommandBuffer.h @@ -81,6 +81,7 @@ namespace backend { void SetComputePipeline(ComputePipelineBase* pipeline); void SetRenderPipeline(RenderPipelineBase* pipeline); void SetStencilReference(uint32_t reference); + void SetBlendColor(float r, float g, float b, float a); void SetBindGroup(uint32_t groupIndex, BindGroupBase* group); void SetIndexBuffer(BufferBase* buffer, uint32_t offset, nxt::IndexFormat format); diff --git a/src/backend/Commands.h b/src/backend/Commands.h index 0efb093a51..e386995cbe 100644 --- a/src/backend/Commands.h +++ b/src/backend/Commands.h @@ -44,6 +44,7 @@ namespace backend { SetRenderPipeline, SetPushConstants, SetStencilReference, + SetBlendColor, SetBindGroup, SetIndexBuffer, SetVertexBuffers, @@ -139,6 +140,10 @@ namespace backend { uint32_t reference; }; + struct SetBlendColorCmd { + float r, g, b, a; + }; + struct SetBindGroupCmd { uint32_t index; Ref group; diff --git a/src/backend/d3d12/CommandBufferD3D12.cpp b/src/backend/d3d12/CommandBufferD3D12.cpp index d1ce6a449f..5629d3fde7 100644 --- a/src/backend/d3d12/CommandBufferD3D12.cpp +++ b/src/backend/d3d12/CommandBufferD3D12.cpp @@ -485,6 +485,14 @@ namespace d3d12 { } break; + case Command::SetBlendColor: + { + SetBlendColorCmd* cmd = commands.NextCommand(); + ASSERT(lastRenderPipeline); + commandList->OMSetBlendFactor(static_cast(&cmd->r)); + } + break; + case Command::SetBindGroup: { SetBindGroupCmd* cmd = commands.NextCommand(); diff --git a/src/backend/metal/CommandBufferMTL.mm b/src/backend/metal/CommandBufferMTL.mm index efad9ae6ef..0012e20c01 100644 --- a/src/backend/metal/CommandBufferMTL.mm +++ b/src/backend/metal/CommandBufferMTL.mm @@ -402,6 +402,20 @@ namespace metal { } break; + case Command::SetBlendColor: + { + SetBlendColorCmd* cmd = commands.NextCommand(); + + ASSERT(encoders.render); + + [encoders.render + setBlendColorRed:cmd->r + green:cmd->g + blue:cmd->b + alpha:cmd->a ]; + } + break; + case Command::SetBindGroup: { SetBindGroupCmd* cmd = commands.NextCommand(); diff --git a/src/backend/opengl/CommandBufferGL.cpp b/src/backend/opengl/CommandBufferGL.cpp index f977ff16aa..b3f91eb5e0 100644 --- a/src/backend/opengl/CommandBufferGL.cpp +++ b/src/backend/opengl/CommandBufferGL.cpp @@ -336,6 +336,12 @@ namespace opengl { } break; + case Command::SetBlendColor: + { + commands.NextCommand(); + } + break; + case Command::SetBindGroup: { SetBindGroupCmd* cmd = commands.NextCommand();