Input State Descriptorization

This change also removes InputState object.

BUG=dawn:107

Change-Id: Ia3fd2d348658f5719de0279bfe7bb10a4f183523
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/5660
Commit-Queue: Yunchao He <yunchao.he@intel.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Yunchao He
2019-03-27 18:08:50 +00:00
committed by Commit Bot service account
parent 5490e9aca1
commit 889d743baa
63 changed files with 1141 additions and 1465 deletions

View File

@@ -21,7 +21,6 @@
#include "dawn_native/opengl/ComputePipelineGL.h"
#include "dawn_native/opengl/DeviceGL.h"
#include "dawn_native/opengl/Forward.h"
#include "dawn_native/opengl/InputStateGL.h"
#include "dawn_native/opengl/PersistentPipelineStateGL.h"
#include "dawn_native/opengl/PipelineLayoutGL.h"
#include "dawn_native/opengl/RenderPipelineGL.h"
@@ -212,15 +211,14 @@ namespace dawn_native { namespace opengl {
}
void OnSetPipeline(RenderPipelineBase* pipeline) {
InputStateBase* inputState = pipeline->GetInputState();
if (mLastInputState == inputState) {
if (mLastPipeline == pipeline) {
return;
}
mIndexBufferDirty = true;
mDirtyVertexBuffers |= inputState->GetInputsSetMask();
mDirtyVertexBuffers |= pipeline->GetInputsSetMask();
mLastInputState = ToBackend(inputState);
mLastPipeline = pipeline;
}
void Apply() {
@@ -230,15 +228,15 @@ namespace dawn_native { namespace opengl {
}
for (uint32_t slot :
IterateBitSet(mDirtyVertexBuffers & mLastInputState->GetInputsSetMask())) {
IterateBitSet(mDirtyVertexBuffers & mLastPipeline->GetInputsSetMask())) {
for (uint32_t location :
IterateBitSet(mLastInputState->GetAttributesUsingInput(slot))) {
auto attribute = mLastInputState->GetAttribute(location);
IterateBitSet(mLastPipeline->GetAttributesUsingInput(slot))) {
auto attribute = mLastPipeline->GetAttribute(location);
GLuint buffer = mVertexBuffers[slot]->GetHandle();
uint32_t offset = mVertexBufferOffsets[slot];
auto input = mLastInputState->GetInput(slot);
auto input = mLastPipeline->GetInput(slot);
auto components = VertexFormatNumComponents(attribute.format);
auto formatType = VertexFormatType(attribute.format);
@@ -262,7 +260,7 @@ namespace dawn_native { namespace opengl {
std::array<Buffer*, kMaxVertexInputs> mVertexBuffers;
std::array<uint32_t, kMaxVertexInputs> mVertexBufferOffsets;
InputState* mLastInputState = nullptr;
RenderPipelineBase* mLastPipeline = nullptr;
};
// Handles SetBindGroup commands with the specifics of translating to OpenGL texture and

View File

@@ -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/InputStateGL.h"
#include "dawn_native/opengl/PipelineLayoutGL.h"
#include "dawn_native/opengl/QueueGL.h"
#include "dawn_native/opengl/RenderPipelineGL.h"
@@ -67,9 +66,6 @@ namespace dawn_native { namespace opengl {
const ComputePipelineDescriptor* descriptor) {
return new ComputePipeline(this, descriptor);
}
InputStateBase* Device::CreateInputState(InputStateBuilder* builder) {
return new InputState(builder);
}
ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) {
return new PipelineLayout(this, descriptor);

View File

@@ -41,7 +41,6 @@ namespace dawn_native { namespace opengl {
// Dawn API
CommandBufferBase* CreateCommandBuffer(CommandEncoderBase* encoder) override;
InputStateBase* CreateInputState(InputStateBuilder* builder) override;
Serial GetCompletedCommandSerial() const final override;
Serial GetLastSubmittedCommandSerial() const final override;

View File

@@ -32,7 +32,6 @@ namespace dawn_native { namespace opengl {
class CommandBuffer;
class ComputePipeline;
class Device;
class InputState;
class PersistentPipelineState;
class PipelineLayout;
class Queue;
@@ -51,7 +50,6 @@ namespace dawn_native { namespace opengl {
using CommandBufferType = CommandBuffer;
using ComputePipelineType = ComputePipeline;
using DeviceType = Device;
using InputStateType = InputState;
using PipelineLayoutType = PipelineLayout;
using QueueType = Queue;
using RenderPipelineType = RenderPipeline;

View File

@@ -1,61 +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/InputStateGL.h"
#include "common/Assert.h"
namespace dawn_native { namespace opengl {
InputState::InputState(InputStateBuilder* builder) : InputStateBase(builder) {
glGenVertexArrays(1, &mVertexArrayObject);
glBindVertexArray(mVertexArrayObject);
auto& attributesSetMask = GetAttributesSetMask();
for (uint32_t location = 0; location < attributesSetMask.size(); ++location) {
if (!attributesSetMask[location]) {
continue;
}
auto attribute = GetAttribute(location);
glEnableVertexAttribArray(location);
attributesUsingInput[attribute.inputSlot][location] = true;
auto input = GetInput(attribute.inputSlot);
if (input.stride == 0) {
// Emulate a stride of zero (constant vertex attribute) by
// setting the attribute instance divisor to a huge number.
glVertexAttribDivisor(location, 0xffffffff);
} else {
switch (input.stepMode) {
case dawn::InputStepMode::Vertex:
break;
case dawn::InputStepMode::Instance:
glVertexAttribDivisor(location, 1);
break;
default:
UNREACHABLE();
}
}
}
}
std::bitset<kMaxVertexAttributes> InputState::GetAttributesUsingInput(uint32_t slot) const {
return attributesUsingInput[slot];
}
GLuint InputState::GetVAO() {
return mVertexArrayObject;
}
}} // namespace dawn_native::opengl

View File

@@ -1,40 +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_INPUTSTATEGL_H_
#define DAWNNATIVE_OPENGL_INPUTSTATEGL_H_
#include "dawn_native/InputState.h"
#include "glad/glad.h"
namespace dawn_native { namespace opengl {
class Device;
class InputState : public InputStateBase {
public:
InputState(InputStateBuilder* builder);
std::bitset<kMaxVertexAttributes> GetAttributesUsingInput(uint32_t slot) const;
GLuint GetVAO();
private:
GLuint mVertexArrayObject;
std::array<std::bitset<kMaxVertexAttributes>, kMaxVertexInputs> attributesUsingInput;
};
}} // namespace dawn_native::opengl
#endif // DAWNNATIVE_OPENGL_INPUTSTATEGL_H_

View File

@@ -16,13 +16,13 @@
#include "dawn_native/opengl/DeviceGL.h"
#include "dawn_native/opengl/Forward.h"
#include "dawn_native/opengl/InputStateGL.h"
#include "dawn_native/opengl/PersistentPipelineStateGL.h"
#include "dawn_native/opengl/UtilsGL.h"
namespace dawn_native { namespace opengl {
namespace {
GLenum GLPrimitiveTopology(dawn::PrimitiveTopology primitiveTopology) {
switch (primitiveTopology) {
case dawn::PrimitiveTopology::PointList:
@@ -175,23 +175,62 @@ namespace dawn_native { namespace opengl {
RenderPipeline::RenderPipeline(Device* device, const RenderPipelineDescriptor* descriptor)
: RenderPipelineBase(device, descriptor),
mVertexArrayObject(0),
mGlPrimitiveTopology(GLPrimitiveTopology(GetPrimitiveTopology())) {
PerStage<const ShaderModule*> modules(nullptr);
modules[dawn::ShaderStage::Vertex] = ToBackend(descriptor->vertexStage->module);
modules[dawn::ShaderStage::Fragment] = ToBackend(descriptor->fragmentStage->module);
PipelineGL::Initialize(ToBackend(GetLayout()), modules);
CreateVAOForInputState(descriptor->inputState);
}
RenderPipeline::~RenderPipeline() {
glDeleteVertexArrays(1, &mVertexArrayObject);
glBindVertexArray(0);
}
GLenum RenderPipeline::GetGLPrimitiveTopology() const {
return mGlPrimitiveTopology;
}
void RenderPipeline::CreateVAOForInputState(const InputStateDescriptor* inputState) {
glGenVertexArrays(1, &mVertexArrayObject);
glBindVertexArray(mVertexArrayObject);
auto& attributesSetMask = GetAttributesSetMask();
for (uint32_t location = 0; location < attributesSetMask.size(); ++location) {
if (!attributesSetMask[location]) {
continue;
}
auto attribute = GetAttribute(location);
glEnableVertexAttribArray(location);
attributesUsingInput[attribute.inputSlot][location] = true;
auto input = GetInput(attribute.inputSlot);
if (input.stride == 0) {
// Emulate a stride of zero (constant vertex attribute) by
// setting the attribute instance divisor to a huge number.
glVertexAttribDivisor(location, 0xffffffff);
} else {
switch (input.stepMode) {
case dawn::InputStepMode::Vertex:
break;
case dawn::InputStepMode::Instance:
glVertexAttribDivisor(location, 1);
break;
default:
UNREACHABLE();
}
}
}
}
void RenderPipeline::ApplyNow(PersistentPipelineState& persistentPipelineState) {
PipelineGL::ApplyNow();
auto inputState = ToBackend(GetInputState());
glBindVertexArray(inputState->GetVAO());
ASSERT(mVertexArrayObject);
glBindVertexArray(mVertexArrayObject);
ApplyDepthStencilState(GetDepthStencilStateDescriptor(), &persistentPipelineState);

View File

@@ -31,12 +31,17 @@ namespace dawn_native { namespace opengl {
class RenderPipeline : public RenderPipelineBase, public PipelineGL {
public:
RenderPipeline(Device* device, const RenderPipelineDescriptor* descriptor);
~RenderPipeline();
GLenum GetGLPrimitiveTopology() const;
void ApplyNow(PersistentPipelineState& persistentPipelineState);
private:
void CreateVAOForInputState(const InputStateDescriptor* inputState);
// TODO(yunchao.he@intel.com): vao need to be deduplicated between pipelines.
GLuint mVertexArrayObject;
GLenum mGlPrimitiveTopology;
};