Replace BlendState builder via BlendState descriptor.

This change also removes BlendState object.

Bug=dawn:32

Change-Id: I8bf4ff7531e7504efb17b6bae3ca01f1f2b4131e
Reviewed-on: https://dawn-review.googlesource.com/c/3042
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Yunchao He <yunchao.he@intel.com>
This commit is contained in:
Yunchao He
2018-12-27 06:32:31 +00:00
committed by Commit Bot service account
parent cb71ba7b3a
commit 92700bfccd
43 changed files with 489 additions and 1043 deletions

View File

@@ -1,96 +0,0 @@
// Copyright 2017 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/opengl/BlendStateGL.h"
#include "common/Assert.h"
namespace dawn_native { namespace opengl {
namespace {
GLenum GLBlendFactor(dawn::BlendFactor factor, bool alpha) {
switch (factor) {
case dawn::BlendFactor::Zero:
return GL_ZERO;
case dawn::BlendFactor::One:
return GL_ONE;
case dawn::BlendFactor::SrcColor:
return GL_SRC_COLOR;
case dawn::BlendFactor::OneMinusSrcColor:
return GL_ONE_MINUS_SRC_COLOR;
case dawn::BlendFactor::SrcAlpha:
return GL_SRC_ALPHA;
case dawn::BlendFactor::OneMinusSrcAlpha:
return GL_ONE_MINUS_SRC_ALPHA;
case dawn::BlendFactor::DstColor:
return GL_DST_COLOR;
case dawn::BlendFactor::OneMinusDstColor:
return GL_ONE_MINUS_DST_COLOR;
case dawn::BlendFactor::DstAlpha:
return GL_DST_ALPHA;
case dawn::BlendFactor::OneMinusDstAlpha:
return GL_ONE_MINUS_DST_ALPHA;
case dawn::BlendFactor::SrcAlphaSaturated:
return GL_SRC_ALPHA_SATURATE;
case dawn::BlendFactor::BlendColor:
return alpha ? GL_CONSTANT_ALPHA : GL_CONSTANT_COLOR;
case dawn::BlendFactor::OneMinusBlendColor:
return alpha ? GL_ONE_MINUS_CONSTANT_ALPHA : GL_ONE_MINUS_CONSTANT_COLOR;
default:
UNREACHABLE();
}
}
GLenum GLBlendMode(dawn::BlendOperation operation) {
switch (operation) {
case dawn::BlendOperation::Add:
return GL_FUNC_ADD;
case dawn::BlendOperation::Subtract:
return GL_FUNC_SUBTRACT;
case dawn::BlendOperation::ReverseSubtract:
return GL_FUNC_REVERSE_SUBTRACT;
case dawn::BlendOperation::Min:
return GL_MIN;
case dawn::BlendOperation::Max:
return GL_MAX;
default:
UNREACHABLE();
}
}
} // namespace
BlendState::BlendState(BlendStateBuilder* builder) : BlendStateBase(builder) {
}
void BlendState::ApplyNow(uint32_t attachment) {
const auto& info = GetBlendInfo();
if (info.blendEnabled) {
glEnablei(GL_BLEND, attachment);
glBlendEquationSeparatei(attachment, GLBlendMode(info.colorBlend.operation),
GLBlendMode(info.alphaBlend.operation));
glBlendFuncSeparatei(attachment, GLBlendFactor(info.colorBlend.srcFactor, false),
GLBlendFactor(info.colorBlend.dstFactor, false),
GLBlendFactor(info.alphaBlend.srcFactor, true),
GLBlendFactor(info.alphaBlend.dstFactor, true));
} else {
glDisablei(GL_BLEND, attachment);
}
glColorMaski(attachment, info.colorWriteMask & dawn::ColorWriteMask::Red,
info.colorWriteMask & dawn::ColorWriteMask::Green,
info.colorWriteMask & dawn::ColorWriteMask::Blue,
info.colorWriteMask & dawn::ColorWriteMask::Alpha);
}
}} // namespace dawn_native::opengl

View File

@@ -1,33 +0,0 @@
// Copyright 2017 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_OPENGL_BLENDSTATEGL_H_
#define DAWNNATIVE_OPENGL_BLENDSTATEGL_H_
#include "dawn_native/BlendState.h"
#include "glad/glad.h"
namespace dawn_native { namespace opengl {
class BlendState : public BlendStateBase {
public:
BlendState(BlendStateBuilder* builder);
void ApplyNow(uint32_t attachment);
};
}} // namespace dawn_native::opengl
#endif // DAWNNATIVE_OPENGL_BLENDSTATEGL_H_

View File

@@ -18,7 +18,6 @@
#include "dawn_native/BindGroupLayout.h"
#include "dawn_native/OpenGLBackend.h"
#include "dawn_native/RenderPassDescriptor.h"
#include "dawn_native/opengl/BlendStateGL.h"
#include "dawn_native/opengl/BufferGL.h"
#include "dawn_native/opengl/CommandBufferGL.h"
#include "dawn_native/opengl/ComputePipelineGL.h"
@@ -69,9 +68,6 @@ namespace dawn_native { namespace opengl {
const BindGroupLayoutDescriptor* descriptor) {
return new BindGroupLayout(this, descriptor);
}
BlendStateBase* Device::CreateBlendState(BlendStateBuilder* builder) {
return new BlendState(builder);
}
ResultOrError<BufferBase*> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
return new Buffer(this, descriptor);
}

View File

@@ -40,7 +40,6 @@ namespace dawn_native { namespace opengl {
void SubmitFenceSync();
// Dawn API
BlendStateBase* CreateBlendState(BlendStateBuilder* builder) override;
CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override;
DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override;
InputStateBase* CreateInputState(InputStateBuilder* builder) override;

View File

@@ -27,7 +27,6 @@ namespace dawn_native { namespace opengl {
using BindGroup = BindGroupBase;
using BindGroupLayout = BindGroupLayoutBase;
class BlendState;
class Buffer;
class CommandBuffer;
class ComputePipeline;
@@ -48,7 +47,6 @@ namespace dawn_native { namespace opengl {
struct OpenGLBackendTraits {
using BindGroupType = BindGroup;
using BindGroupLayoutType = BindGroupLayout;
using BlendStateType = BlendState;
using BufferType = Buffer;
using CommandBufferType = CommandBuffer;
using ComputePipelineType = ComputePipeline;

View File

@@ -14,7 +14,6 @@
#include "dawn_native/opengl/RenderPipelineGL.h"
#include "dawn_native/opengl/BlendStateGL.h"
#include "dawn_native/opengl/DepthStencilStateGL.h"
#include "dawn_native/opengl/DeviceGL.h"
#include "dawn_native/opengl/Forward.h"
@@ -40,6 +39,76 @@ namespace dawn_native { namespace opengl {
UNREACHABLE();
}
}
GLenum GLBlendFactor(dawn::BlendFactor factor, bool alpha) {
switch (factor) {
case dawn::BlendFactor::Zero:
return GL_ZERO;
case dawn::BlendFactor::One:
return GL_ONE;
case dawn::BlendFactor::SrcColor:
return GL_SRC_COLOR;
case dawn::BlendFactor::OneMinusSrcColor:
return GL_ONE_MINUS_SRC_COLOR;
case dawn::BlendFactor::SrcAlpha:
return GL_SRC_ALPHA;
case dawn::BlendFactor::OneMinusSrcAlpha:
return GL_ONE_MINUS_SRC_ALPHA;
case dawn::BlendFactor::DstColor:
return GL_DST_COLOR;
case dawn::BlendFactor::OneMinusDstColor:
return GL_ONE_MINUS_DST_COLOR;
case dawn::BlendFactor::DstAlpha:
return GL_DST_ALPHA;
case dawn::BlendFactor::OneMinusDstAlpha:
return GL_ONE_MINUS_DST_ALPHA;
case dawn::BlendFactor::SrcAlphaSaturated:
return GL_SRC_ALPHA_SATURATE;
case dawn::BlendFactor::BlendColor:
return alpha ? GL_CONSTANT_ALPHA : GL_CONSTANT_COLOR;
case dawn::BlendFactor::OneMinusBlendColor:
return alpha ? GL_ONE_MINUS_CONSTANT_ALPHA : GL_ONE_MINUS_CONSTANT_COLOR;
default:
UNREACHABLE();
}
}
GLenum GLBlendMode(dawn::BlendOperation operation) {
switch (operation) {
case dawn::BlendOperation::Add:
return GL_FUNC_ADD;
case dawn::BlendOperation::Subtract:
return GL_FUNC_SUBTRACT;
case dawn::BlendOperation::ReverseSubtract:
return GL_FUNC_REVERSE_SUBTRACT;
case dawn::BlendOperation::Min:
return GL_MIN;
case dawn::BlendOperation::Max:
return GL_MAX;
default:
UNREACHABLE();
}
}
void ApplyBlendState(uint32_t attachment, const BlendStateDescriptor* descriptor) {
if (descriptor->blendEnabled) {
glEnablei(GL_BLEND, attachment);
glBlendEquationSeparatei(attachment, GLBlendMode(descriptor->colorBlend.operation),
GLBlendMode(descriptor->alphaBlend.operation));
glBlendFuncSeparatei(attachment,
GLBlendFactor(descriptor->colorBlend.srcFactor, false),
GLBlendFactor(descriptor->colorBlend.dstFactor, false),
GLBlendFactor(descriptor->alphaBlend.srcFactor, true),
GLBlendFactor(descriptor->alphaBlend.dstFactor, true));
} else {
glDisablei(GL_BLEND, attachment);
}
glColorMaski(attachment, descriptor->colorWriteMask & dawn::ColorWriteMask::Red,
descriptor->colorWriteMask & dawn::ColorWriteMask::Green,
descriptor->colorWriteMask & dawn::ColorWriteMask::Blue,
descriptor->colorWriteMask & dawn::ColorWriteMask::Alpha);
}
} // namespace
RenderPipeline::RenderPipeline(Device* device, const RenderPipelineDescriptor* descriptor)
@@ -66,7 +135,7 @@ namespace dawn_native { namespace opengl {
depthStencilState->ApplyNow(persistentPipelineState);
for (uint32_t attachmentSlot : IterateBitSet(GetColorAttachmentsMask())) {
ToBackend(GetBlendState(attachmentSlot))->ApplyNow(attachmentSlot);
ApplyBlendState(attachmentSlot, GetBlendStateDescriptor(attachmentSlot));
}
}