Files
Seele/src/Engine/Graphics/GraphicsResources.cpp
T

300 lines
7.5 KiB
C++
Raw Normal View History

#include "GraphicsResources.h"
2020-05-05 01:51:13 +02:00
#include "Material/MaterialInstance.h"
#include "Material/Material.h"
2020-06-02 11:46:18 +02:00
#include "Graphics.h"
2020-04-12 15:47:19 +02:00
using namespace Seele;
using namespace Seele::Gfx;
std::string getShaderNameFromRenderPassType(Gfx::RenderPassType type)
{
switch (type)
{
case Gfx::RenderPassType::DepthPrepass:
return "DepthPrepass.slang";
case Gfx::RenderPassType::BasePass:
return "ForwardPlus.slang";
default:
return "";
}
}
ShaderMap::ShaderMap()
{
}
ShaderMap::~ShaderMap()
{
}
const ShaderCollection* ShaderMap::findShaders(PermutationId&& id) const
{
for(uint32 i = 0; i < shaders.size(); ++i)
{
if(shaders[i].id == id)
{
return &(shaders[i]);
}
}
return nullptr;
}
ShaderCollection& ShaderMap::createShaders(
PGraphics graphics,
RenderPassType renderPass,
PMaterial material,
2020-09-19 14:36:50 +02:00
VertexInputType* vertexInput,
bool bPositionOnly)
{
ShaderCollection& collection = shaders.add();
2020-09-19 14:36:50 +02:00
//collection.vertexDeclaration = bPositionOnly ? vertexInput->getPositionDeclaration() : vertexInput->getDeclaration();
ShaderCreateInfo createInfo;
createInfo.entryPoint = "vertexMain";
2020-09-19 14:36:50 +02:00
createInfo.typeParameter = {material->getName().c_str()};
createInfo.defines["VERTEX_INPUT_IMPORT"] = vertexInput->getShaderFilename();
createInfo.defines["MATERIAL_IMPORT"] = material->getName().c_str();
createInfo.defines["NUM_MATERIAL_TEXCOORDS"] = "1";
createInfo.defines["USE_INSTANCING"] = "0";
2020-09-19 14:36:50 +02:00
std::ifstream codeStream("./shaders/" + getShaderNameFromRenderPassType(renderPass), std::ios::ate);
auto fileSize = codeStream.tellg();
codeStream.seekg(0);
Array<char> buffer(static_cast<uint32>(fileSize));
codeStream.read(buffer.data(), fileSize);
createInfo.shaderCode.add(std::string(buffer.data()));
collection.vertexShader = graphics->createVertexShader(createInfo);
2020-09-19 14:36:50 +02:00
if(renderPass != RenderPassType::DepthPrepass)
{
createInfo.entryPoint = "fragmentMain";
collection.fragmentShader = graphics->createFragmentShader(createInfo);
}
return collection;
}
void DescriptorLayout::addDescriptorBinding(uint32 bindingIndex, SeDescriptorType type, uint32 arrayCount)
{
if (descriptorBindings.size() <= bindingIndex)
{
descriptorBindings.resize(bindingIndex + 1);
}
DescriptorBinding binding;
binding.binding = bindingIndex;
binding.descriptorType = type;
binding.descriptorCount = arrayCount;
descriptorBindings[bindingIndex] = binding;
}
PDescriptorSet DescriptorLayout::allocatedDescriptorSet()
{
PDescriptorSet result;
allocator->allocateDescriptorSet(result);
return result;
}
void PipelineLayout::addDescriptorLayout(uint32 setIndex, PDescriptorLayout layout)
{
if (descriptorSetLayouts.size() <= setIndex)
{
descriptorSetLayouts.resize(setIndex + 1);
}
if (descriptorSetLayouts[setIndex] != nullptr)
{
2020-04-12 15:47:19 +02:00
auto &thisBindings = descriptorSetLayouts[setIndex]->descriptorBindings;
auto &otherBindings = layout->descriptorBindings;
thisBindings.resize(otherBindings.size());
for (size_t i = 0; i < otherBindings.size(); ++i)
{
if (otherBindings[i].descriptorType != SE_DESCRIPTOR_TYPE_MAX_ENUM)
{
assert(thisBindings[i].descriptorType != SE_DESCRIPTOR_TYPE_MAX_ENUM ? thisBindings[i].descriptorType == otherBindings[i].descriptorType : true);
thisBindings[i] = otherBindings[i];
}
}
}
else
{
descriptorSetLayouts[setIndex] = layout;
2020-05-05 01:51:13 +02:00
layout->setIndex = setIndex;
}
}
2020-04-12 15:47:19 +02:00
void PipelineLayout::addPushConstants(const SePushConstantRange &pushConstant)
{
pushConstants.add(pushConstant);
}
2020-04-01 02:17:49 +02:00
2020-09-19 14:36:50 +02:00
QueueOwnedResource::QueueOwnedResource(QueueFamilyMapping mapping, QueueType startQueueType)
: mapping(mapping)
2020-06-02 11:46:18 +02:00
, currentOwner(startQueueType)
{
}
QueueOwnedResource::~QueueOwnedResource()
{
}
void QueueOwnedResource::transferOwnership(QueueType newOwner)
{
2020-09-19 14:36:50 +02:00
if(mapping.needsTransfer(currentOwner, newOwner))
2020-06-02 11:46:18 +02:00
{
executeOwnershipBarrier(newOwner);
currentOwner = newOwner;
}
}
2020-09-19 14:36:50 +02:00
Buffer::Buffer(QueueFamilyMapping mapping, QueueType startQueue)
: QueueOwnedResource(mapping, startQueue)
2020-06-02 11:46:18 +02:00
{
}
Buffer::~Buffer()
{
}
2020-09-19 14:36:50 +02:00
UniformBuffer::UniformBuffer(QueueFamilyMapping mapping, QueueType startQueueType)
: Buffer(mapping, startQueueType)
2020-04-12 15:47:19 +02:00
{
}
UniformBuffer::~UniformBuffer()
{
}
2020-09-19 14:36:50 +02:00
StructuredBuffer::StructuredBuffer(QueueFamilyMapping mapping, QueueType startQueueType)
: Buffer(mapping, startQueueType)
2020-06-02 11:46:18 +02:00
{
}
StructuredBuffer::~StructuredBuffer()
{
}
2020-09-19 14:36:50 +02:00
VertexBuffer::VertexBuffer(QueueFamilyMapping mapping, uint32 numVertices, uint32 vertexSize, QueueType startQueueType)
: Buffer(mapping, startQueueType)
, numVertices(numVertices)
, vertexSize(vertexSize)
2020-05-05 01:51:13 +02:00
{
}
VertexBuffer::~VertexBuffer()
{
}
2020-09-19 14:36:50 +02:00
IndexBuffer::IndexBuffer(QueueFamilyMapping mapping, uint32 size, Gfx::SeIndexType indexType, QueueType startQueueType)
: Buffer(mapping, startQueueType)
2020-06-02 11:46:18 +02:00
, indexType(indexType)
2020-05-05 01:51:13 +02:00
{
switch (indexType)
{
case SE_INDEX_TYPE_UINT16:
numIndices = size / 16;
break;
case SE_INDEX_TYPE_UINT32:
numIndices = size / 32;
default:
break;
}
}
IndexBuffer::~IndexBuffer()
{
}
2020-06-08 01:44:47 +02:00
VertexStream::VertexStream()
{}
2020-09-19 14:36:50 +02:00
VertexStream::VertexStream(uint32 stride, uint32 offset, uint8 instanced)
: stride(stride), instanced(instanced), offset(offset)
2020-05-05 01:51:13 +02:00
{
}
VertexStream::~VertexStream()
{
}
void VertexStream::addVertexElement(VertexElement element)
{
vertexDescription.add(element);
}
const Array<VertexElement> VertexStream::getVertexDescriptions() const
{
return vertexDescription;
}
VertexDeclaration::VertexDeclaration()
{
}
VertexDeclaration::~VertexDeclaration()
{
}
2020-09-19 14:36:50 +02:00
uint32 VertexDeclaration::addVertexStream(const VertexStreamComponent &element)
2020-05-05 01:51:13 +02:00
{
2020-09-19 14:36:50 +02:00
VertexStream& stream = vertexStreams.add();
stream.addVertexElement(VertexElement(element.streamOffset, element.type, element.offset));
return stream.vertexDescription.size() - 1;
2020-05-05 01:51:13 +02:00
}
const Array<VertexStream> &VertexDeclaration::getVertexStreams() const
{
return vertexStreams;
}
2020-04-12 15:47:19 +02:00
2020-09-19 14:36:50 +02:00
Texture::Texture(QueueFamilyMapping mapping, Gfx::QueueType startQueueType)
: QueueOwnedResource(mapping, startQueueType)
2020-06-02 11:46:18 +02:00
{
}
Texture::~Texture()
{
}
2020-09-19 14:36:50 +02:00
Texture2D::Texture2D(QueueFamilyMapping mapping, Gfx::QueueType startQueueType)
: Texture(mapping, startQueueType)
2020-06-02 11:46:18 +02:00
{
}
Texture2D::~Texture2D()
{
}
RenderCommand::RenderCommand()
{
}
RenderCommand::~RenderCommand()
{
}
2020-04-01 02:17:49 +02:00
RenderTargetLayout::RenderTargetLayout()
2020-04-12 15:47:19 +02:00
: inputAttachments(), colorAttachments(), depthAttachment()
2020-04-01 02:17:49 +02:00
{
}
2020-04-12 15:47:19 +02:00
RenderTargetLayout::RenderTargetLayout(PRenderTargetAttachment depthAttachment)
: inputAttachments(), colorAttachments(), depthAttachment(depthAttachment)
2020-04-01 02:17:49 +02:00
{
}
2020-04-12 15:47:19 +02:00
RenderTargetLayout::RenderTargetLayout(PRenderTargetAttachment colorAttachment, PRenderTargetAttachment depthAttachment)
: inputAttachments(), depthAttachment(depthAttachment)
2020-04-01 02:17:49 +02:00
{
colorAttachments.add(colorAttachment);
}
2020-04-12 15:47:19 +02:00
RenderTargetLayout::RenderTargetLayout(Array<PRenderTargetAttachment> colorAttachments, PRenderTargetAttachment depthAttachmet)
: inputAttachments(), colorAttachments(colorAttachments), depthAttachment(depthAttachment)
2020-04-01 02:17:49 +02:00
{
}
2020-04-12 15:47:19 +02:00
RenderTargetLayout::RenderTargetLayout(Array<PRenderTargetAttachment> inputAttachments, Array<PRenderTargetAttachment> colorAttachments, PRenderTargetAttachment depthAttachment)
: inputAttachments(inputAttachments), colorAttachments(colorAttachments), depthAttachment(depthAttachment)
2020-04-01 02:17:49 +02:00
{
}
2020-04-12 15:47:19 +02:00
Window::Window(const WindowCreateInfo &createInfo)
2020-08-11 21:23:20 +02:00
: sizeX(createInfo.width), sizeY(createInfo.height), bFullscreen(createInfo.bFullscreen), title(createInfo.title), pixelFormat(createInfo.pixelFormat), samples(createInfo.numSamples)
2020-04-12 15:47:19 +02:00
{
}
Window::~Window()
{
}
Viewport::Viewport(PWindow owner, const ViewportCreateInfo &viewportInfo)
: sizeX(viewportInfo.sizeX), sizeY(viewportInfo.sizeY), offsetX(viewportInfo.offsetX), offsetY(viewportInfo.offsetY), owner(owner)
{
}
Viewport::~Viewport()
{
}