mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-15 08:06:19 +00:00
Replace DepthStencilState builder via DepthStencilState descriptor.
This change also removes DepthStencilState object. Bug=dawn:31 Change-Id: I7bb54ef4da527184bb2726c77d93d411d44c3956 Reviewed-on: https://dawn-review.googlesource.com/c/3541 Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Yunchao He <yunchao.he@intel.com>
This commit is contained in:
committed by
Commit Bot service account
parent
0b364067d0
commit
ea56333c1e
@@ -1,116 +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/DepthStencilStateGL.h"
|
||||
|
||||
#include "common/Assert.h"
|
||||
#include "dawn_native/opengl/PersistentPipelineStateGL.h"
|
||||
|
||||
namespace dawn_native { namespace opengl {
|
||||
|
||||
namespace {
|
||||
GLuint OpenGLCompareFunction(dawn::CompareFunction compareFunction) {
|
||||
switch (compareFunction) {
|
||||
case dawn::CompareFunction::Never:
|
||||
return GL_NEVER;
|
||||
case dawn::CompareFunction::Less:
|
||||
return GL_LESS;
|
||||
case dawn::CompareFunction::LessEqual:
|
||||
return GL_LEQUAL;
|
||||
case dawn::CompareFunction::Greater:
|
||||
return GL_GREATER;
|
||||
case dawn::CompareFunction::GreaterEqual:
|
||||
return GL_GEQUAL;
|
||||
case dawn::CompareFunction::NotEqual:
|
||||
return GL_NOTEQUAL;
|
||||
case dawn::CompareFunction::Equal:
|
||||
return GL_EQUAL;
|
||||
case dawn::CompareFunction::Always:
|
||||
return GL_ALWAYS;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
GLuint OpenGLStencilOperation(dawn::StencilOperation stencilOperation) {
|
||||
switch (stencilOperation) {
|
||||
case dawn::StencilOperation::Keep:
|
||||
return GL_KEEP;
|
||||
case dawn::StencilOperation::Zero:
|
||||
return GL_ZERO;
|
||||
case dawn::StencilOperation::Replace:
|
||||
return GL_REPLACE;
|
||||
case dawn::StencilOperation::Invert:
|
||||
return GL_INVERT;
|
||||
case dawn::StencilOperation::IncrementClamp:
|
||||
return GL_INCR;
|
||||
case dawn::StencilOperation::DecrementClamp:
|
||||
return GL_DECR;
|
||||
case dawn::StencilOperation::IncrementWrap:
|
||||
return GL_INCR_WRAP;
|
||||
case dawn::StencilOperation::DecrementWrap:
|
||||
return GL_DECR_WRAP;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
DepthStencilState::DepthStencilState(DepthStencilStateBuilder* builder)
|
||||
: DepthStencilStateBase(builder) {
|
||||
}
|
||||
|
||||
void DepthStencilState::ApplyNow(PersistentPipelineState& persistentPipelineState) const {
|
||||
auto& depthInfo = GetDepth();
|
||||
|
||||
// Depth writes only occur if depth is enabled
|
||||
if (depthInfo.compareFunction == dawn::CompareFunction::Always &&
|
||||
!depthInfo.depthWriteEnabled) {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
} else {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
if (depthInfo.depthWriteEnabled) {
|
||||
glDepthMask(GL_TRUE);
|
||||
} else {
|
||||
glDepthMask(GL_FALSE);
|
||||
}
|
||||
|
||||
glDepthFunc(OpenGLCompareFunction(depthInfo.compareFunction));
|
||||
|
||||
if (StencilTestEnabled()) {
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
} else {
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
|
||||
auto& stencilInfo = GetStencil();
|
||||
|
||||
GLenum backCompareFunction = OpenGLCompareFunction(stencilInfo.back.compare);
|
||||
GLenum frontCompareFunction = OpenGLCompareFunction(stencilInfo.front.compare);
|
||||
persistentPipelineState.SetStencilFuncsAndMask(backCompareFunction, frontCompareFunction,
|
||||
stencilInfo.readMask);
|
||||
|
||||
glStencilOpSeparate(GL_BACK, OpenGLStencilOperation(stencilInfo.back.stencilFailOp),
|
||||
OpenGLStencilOperation(stencilInfo.back.depthFailOp),
|
||||
OpenGLStencilOperation(stencilInfo.back.passOp));
|
||||
glStencilOpSeparate(GL_FRONT, OpenGLStencilOperation(stencilInfo.front.stencilFailOp),
|
||||
OpenGLStencilOperation(stencilInfo.front.depthFailOp),
|
||||
OpenGLStencilOperation(stencilInfo.front.passOp));
|
||||
|
||||
glStencilMask(stencilInfo.writeMask);
|
||||
}
|
||||
|
||||
}} // namespace dawn_native::opengl
|
||||
@@ -1,34 +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_DEPTHSTENCILSTATEGL_H_
|
||||
#define DAWNNATIVE_OPENGL_DEPTHSTENCILSTATEGL_H_
|
||||
|
||||
#include "dawn_native/DepthStencilState.h"
|
||||
|
||||
namespace dawn_native { namespace opengl {
|
||||
|
||||
class Device;
|
||||
class PersistentPipelineState;
|
||||
|
||||
class DepthStencilState : public DepthStencilStateBase {
|
||||
public:
|
||||
DepthStencilState(DepthStencilStateBuilder* builder);
|
||||
|
||||
void ApplyNow(PersistentPipelineState& persistentPipelineState) const;
|
||||
};
|
||||
|
||||
}} // namespace dawn_native::opengl
|
||||
|
||||
#endif // DAWNNATIVE_OPENGL_DEPTHSTENCILSTATEGL_H_
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "dawn_native/opengl/BufferGL.h"
|
||||
#include "dawn_native/opengl/CommandBufferGL.h"
|
||||
#include "dawn_native/opengl/ComputePipelineGL.h"
|
||||
#include "dawn_native/opengl/DepthStencilStateGL.h"
|
||||
#include "dawn_native/opengl/InputStateGL.h"
|
||||
#include "dawn_native/opengl/PipelineLayoutGL.h"
|
||||
#include "dawn_native/opengl/QueueGL.h"
|
||||
@@ -78,9 +77,6 @@ namespace dawn_native { namespace opengl {
|
||||
const ComputePipelineDescriptor* descriptor) {
|
||||
return new ComputePipeline(this, descriptor);
|
||||
}
|
||||
DepthStencilStateBase* Device::CreateDepthStencilState(DepthStencilStateBuilder* builder) {
|
||||
return new DepthStencilState(builder);
|
||||
}
|
||||
InputStateBase* Device::CreateInputState(InputStateBuilder* builder) {
|
||||
return new InputState(builder);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ namespace dawn_native { namespace opengl {
|
||||
|
||||
// Dawn API
|
||||
CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override;
|
||||
DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override;
|
||||
InputStateBase* CreateInputState(InputStateBuilder* builder) override;
|
||||
RenderPassDescriptorBase* CreateRenderPassDescriptor(
|
||||
RenderPassDescriptorBuilder* builder) override;
|
||||
|
||||
@@ -30,7 +30,6 @@ namespace dawn_native { namespace opengl {
|
||||
class Buffer;
|
||||
class CommandBuffer;
|
||||
class ComputePipeline;
|
||||
class DepthStencilState;
|
||||
class Device;
|
||||
class InputState;
|
||||
class PersistentPipelineState;
|
||||
@@ -50,7 +49,6 @@ namespace dawn_native { namespace opengl {
|
||||
using BufferType = Buffer;
|
||||
using CommandBufferType = CommandBuffer;
|
||||
using ComputePipelineType = ComputePipeline;
|
||||
using DepthStencilStateType = DepthStencilState;
|
||||
using DeviceType = Device;
|
||||
using InputStateType = InputState;
|
||||
using PipelineLayoutType = PipelineLayout;
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
#include "dawn_native/opengl/RenderPipelineGL.h"
|
||||
|
||||
#include "dawn_native/opengl/DepthStencilStateGL.h"
|
||||
#include "dawn_native/opengl/DeviceGL.h"
|
||||
#include "dawn_native/opengl/Forward.h"
|
||||
#include "dawn_native/opengl/InputStateGL.h"
|
||||
@@ -109,7 +108,92 @@ namespace dawn_native { namespace opengl {
|
||||
descriptor->colorWriteMask & dawn::ColorWriteMask::Alpha);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
GLuint OpenGLCompareFunction(dawn::CompareFunction compareFunction) {
|
||||
switch (compareFunction) {
|
||||
case dawn::CompareFunction::Never:
|
||||
return GL_NEVER;
|
||||
case dawn::CompareFunction::Less:
|
||||
return GL_LESS;
|
||||
case dawn::CompareFunction::LessEqual:
|
||||
return GL_LEQUAL;
|
||||
case dawn::CompareFunction::Greater:
|
||||
return GL_GREATER;
|
||||
case dawn::CompareFunction::GreaterEqual:
|
||||
return GL_GEQUAL;
|
||||
case dawn::CompareFunction::NotEqual:
|
||||
return GL_NOTEQUAL;
|
||||
case dawn::CompareFunction::Equal:
|
||||
return GL_EQUAL;
|
||||
case dawn::CompareFunction::Always:
|
||||
return GL_ALWAYS;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
GLuint OpenGLStencilOperation(dawn::StencilOperation stencilOperation) {
|
||||
switch (stencilOperation) {
|
||||
case dawn::StencilOperation::Keep:
|
||||
return GL_KEEP;
|
||||
case dawn::StencilOperation::Zero:
|
||||
return GL_ZERO;
|
||||
case dawn::StencilOperation::Replace:
|
||||
return GL_REPLACE;
|
||||
case dawn::StencilOperation::Invert:
|
||||
return GL_INVERT;
|
||||
case dawn::StencilOperation::IncrementClamp:
|
||||
return GL_INCR;
|
||||
case dawn::StencilOperation::DecrementClamp:
|
||||
return GL_DECR;
|
||||
case dawn::StencilOperation::IncrementWrap:
|
||||
return GL_INCR_WRAP;
|
||||
case dawn::StencilOperation::DecrementWrap:
|
||||
return GL_DECR_WRAP;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void ApplyDepthStencilState(const DepthStencilStateDescriptor* descriptor,
|
||||
PersistentPipelineState* persistentPipelineState) {
|
||||
// Depth writes only occur if depth is enabled
|
||||
if (descriptor->depthCompare == dawn::CompareFunction::Always &&
|
||||
!descriptor->depthWriteEnabled) {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
} else {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
if (descriptor->depthWriteEnabled) {
|
||||
glDepthMask(GL_TRUE);
|
||||
} else {
|
||||
glDepthMask(GL_FALSE);
|
||||
}
|
||||
|
||||
glDepthFunc(OpenGLCompareFunction(descriptor->depthCompare));
|
||||
|
||||
if (StencilTestEnabled(descriptor)) {
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
} else {
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
|
||||
GLenum backCompareFunction = OpenGLCompareFunction(descriptor->back.compare);
|
||||
GLenum frontCompareFunction = OpenGLCompareFunction(descriptor->front.compare);
|
||||
persistentPipelineState->SetStencilFuncsAndMask(
|
||||
backCompareFunction, frontCompareFunction, descriptor->stencilReadMask);
|
||||
|
||||
glStencilOpSeparate(GL_BACK, OpenGLStencilOperation(descriptor->back.stencilFailOp),
|
||||
OpenGLStencilOperation(descriptor->back.depthFailOp),
|
||||
OpenGLStencilOperation(descriptor->back.passOp));
|
||||
glStencilOpSeparate(GL_FRONT, OpenGLStencilOperation(descriptor->front.stencilFailOp),
|
||||
OpenGLStencilOperation(descriptor->front.depthFailOp),
|
||||
OpenGLStencilOperation(descriptor->front.passOp));
|
||||
|
||||
glStencilMask(descriptor->stencilWriteMask);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
RenderPipeline::RenderPipeline(Device* device, const RenderPipelineDescriptor* descriptor)
|
||||
: RenderPipelineBase(device, descriptor),
|
||||
@@ -131,8 +215,7 @@ namespace dawn_native { namespace opengl {
|
||||
auto inputState = ToBackend(GetInputState());
|
||||
glBindVertexArray(inputState->GetVAO());
|
||||
|
||||
auto depthStencilState = ToBackend(GetDepthStencilState());
|
||||
depthStencilState->ApplyNow(persistentPipelineState);
|
||||
ApplyDepthStencilState(GetDepthStencilStateDescriptor(), &persistentPipelineState);
|
||||
|
||||
for (uint32_t attachmentSlot : IterateBitSet(GetColorAttachmentsMask())) {
|
||||
ApplyBlendState(attachmentSlot, GetBlendStateDescriptor(attachmentSlot));
|
||||
|
||||
Reference in New Issue
Block a user