Vulkan: Implement InputState

This commit is contained in:
Corentin Wallez 2018-01-09 07:26:52 -08:00 committed by Corentin Wallez
parent 3a11684e05
commit 2bd6143061
6 changed files with 139 additions and 2 deletions

View File

@ -297,6 +297,8 @@ if (NXT_ENABLE_VULKAN)
${VULKAN_DIR}/CommandBufferVk.h ${VULKAN_DIR}/CommandBufferVk.h
${VULKAN_DIR}/FencedDeleter.cpp ${VULKAN_DIR}/FencedDeleter.cpp
${VULKAN_DIR}/FencedDeleter.h ${VULKAN_DIR}/FencedDeleter.h
${VULKAN_DIR}/InputStateVk.cpp
${VULKAN_DIR}/InputStateVk.h
${VULKAN_DIR}/MemoryAllocator.cpp ${VULKAN_DIR}/MemoryAllocator.cpp
${VULKAN_DIR}/MemoryAllocator.h ${VULKAN_DIR}/MemoryAllocator.h
${VULKAN_DIR}/PipelineLayoutVk.cpp ${VULKAN_DIR}/PipelineLayoutVk.cpp

View File

@ -14,6 +14,7 @@
#include "backend/vulkan/BufferVk.h" #include "backend/vulkan/BufferVk.h"
#include "backend/vulkan/CommandBufferVk.h" #include "backend/vulkan/CommandBufferVk.h"
#include "backend/vulkan/InputStateVk.h"
#include "backend/vulkan/PipelineLayoutVk.h" #include "backend/vulkan/PipelineLayoutVk.h"
#include "backend/vulkan/RenderPassVk.h" #include "backend/vulkan/RenderPassVk.h"
#include "backend/vulkan/TextureVk.h" #include "backend/vulkan/TextureVk.h"

View File

@ -0,0 +1,93 @@
// Copyright 2018 The NXT 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 "backend/vulkan/InputStateVk.h"
#include "common/BitSetIterator.h"
namespace backend { namespace vulkan {
namespace {
VkVertexInputRate VulkanInputRate(nxt::InputStepMode stepMode) {
switch (stepMode) {
case nxt::InputStepMode::Vertex:
return VK_VERTEX_INPUT_RATE_VERTEX;
case nxt::InputStepMode::Instance:
return VK_VERTEX_INPUT_RATE_INSTANCE;
default:
UNREACHABLE();
}
}
VkFormat VulkanVertexFormat(nxt::VertexFormat format) {
switch (format) {
case nxt::VertexFormat::FloatR32G32B32A32:
return VK_FORMAT_R32G32B32A32_SFLOAT;
case nxt::VertexFormat::FloatR32G32B32:
return VK_FORMAT_R32G32B32_SFLOAT;
case nxt::VertexFormat::FloatR32G32:
return VK_FORMAT_R32G32_SFLOAT;
case nxt::VertexFormat::FloatR32:
return VK_FORMAT_R32_SFLOAT;
default:
UNREACHABLE();
}
}
} // anonymous namespace
InputState::InputState(InputStateBuilder* builder) : InputStateBase(builder) {
// Fill in the "binding info" that will be chained in the create info
uint32_t bindingCount = 0;
for (uint32_t i : IterateBitSet(GetInputsSetMask())) {
const auto& bindingInfo = GetInput(i);
auto& bindingDesc = mBindings[bindingCount];
bindingDesc.binding = i;
bindingDesc.stride = bindingInfo.stride;
bindingDesc.inputRate = VulkanInputRate(bindingInfo.stepMode);
bindingCount++;
}
// Fill in the "attribute info" that will be chained in the create info
uint32_t attributeCount = 0;
for (uint32_t i : IterateBitSet(GetAttributesSetMask())) {
const auto& attributeInfo = GetAttribute(i);
auto& attributeDesc = mAttributes[attributeCount];
attributeDesc.location = i;
attributeDesc.binding = attributeInfo.bindingSlot;
attributeDesc.format = VulkanVertexFormat(attributeInfo.format);
attributeDesc.offset = attributeInfo.offset;
attributeCount++;
}
// Build the create info
mCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
mCreateInfo.pNext = nullptr;
mCreateInfo.flags = 0;
mCreateInfo.vertexBindingDescriptionCount = bindingCount;
mCreateInfo.pVertexBindingDescriptions = mBindings.data();
mCreateInfo.vertexAttributeDescriptionCount = attributeCount;
mCreateInfo.pVertexAttributeDescriptions = mAttributes.data();
}
const VkPipelineVertexInputStateCreateInfo* InputState::GetCreateInfo() const {
return &mCreateInfo;
}
}} // namespace backend::vulkan

View File

@ -0,0 +1,41 @@
// Copyright 2018 The NXT 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 BACKEND_VULKAN_INPUTSTATE_H_
#define BACKEND_VULKAN_INPUTSTATE_H_
#include "backend/InputState.h"
#include "backend/vulkan/vulkan_platform.h"
namespace backend { namespace vulkan {
class Device;
// Pre-computes the input state configuration to give to a graphics pipeline create info.
class InputState : public InputStateBase {
public:
InputState(InputStateBuilder* builder);
const VkPipelineVertexInputStateCreateInfo* GetCreateInfo() const;
private:
VkPipelineVertexInputStateCreateInfo mCreateInfo;
std::array<VkVertexInputBindingDescription, kMaxVertexInputs> mBindings;
std::array<VkVertexInputAttributeDescription, kMaxVertexAttributes> mAttributes;
};
}} // namespace backend::vulkan
#endif // BACKEND_VULKAN_INPUTSTATE_H_

View File

@ -19,6 +19,7 @@
#include "backend/vulkan/BufferVk.h" #include "backend/vulkan/BufferVk.h"
#include "backend/vulkan/CommandBufferVk.h" #include "backend/vulkan/CommandBufferVk.h"
#include "backend/vulkan/FencedDeleter.h" #include "backend/vulkan/FencedDeleter.h"
#include "backend/vulkan/InputStateVk.h"
#include "backend/vulkan/PipelineLayoutVk.h" #include "backend/vulkan/PipelineLayoutVk.h"
#include "backend/vulkan/RenderPassVk.h" #include "backend/vulkan/RenderPassVk.h"
#include "backend/vulkan/TextureVk.h" #include "backend/vulkan/TextureVk.h"

View File

@ -24,7 +24,6 @@
#include "backend/DepthStencilState.h" #include "backend/DepthStencilState.h"
#include "backend/Device.h" #include "backend/Device.h"
#include "backend/Framebuffer.h" #include "backend/Framebuffer.h"
#include "backend/InputState.h"
#include "backend/Queue.h" #include "backend/Queue.h"
#include "backend/RenderPipeline.h" #include "backend/RenderPipeline.h"
#include "backend/Sampler.h" #include "backend/Sampler.h"
@ -51,7 +50,7 @@ namespace backend { namespace vulkan {
using DepthStencilState = DepthStencilStateBase; using DepthStencilState = DepthStencilStateBase;
class Device; class Device;
using Framebuffer = FramebufferBase; using Framebuffer = FramebufferBase;
using InputState = InputStateBase; class InputState;
class PipelineLayout; class PipelineLayout;
class Queue; class Queue;
class RenderPass; class RenderPass;