First render

This commit is contained in:
Dynamitos
2020-10-23 01:47:56 +02:00
parent 8d4c43361b
commit b4fc5df74e
21 changed files with 128 additions and 43 deletions
+17
View File
@@ -1868,6 +1868,23 @@ typedef enum SeStencilFaceFlagBits
SE_STENCIL_FACE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
} SeStencilFaceFlagBits;
typedef SeFlags SeStencilFaceFlags;
typedef union SeClearColorValue {
float float32[4];
int32_t int32[4];
uint32_t uint32[4];
} SeClearColorValue;
typedef struct SeClearDepthStencilValue {
float depth;
uint32_t stencil;
} SeClearDepthStencilValue;
typedef union SeClearValue {
SeClearColorValue color;
SeClearDepthStencilValue depthStencil;
} SeClearValue;
enum class QueueType
{
GRAPHICS = 1,
+2 -2
View File
@@ -210,10 +210,10 @@ IndexBuffer::IndexBuffer(QueueFamilyMapping mapping, uint32 size, Gfx::SeIndexTy
switch (indexType)
{
case SE_INDEX_TYPE_UINT16:
numIndices = size / 16;
numIndices = size / sizeof(uint16);
break;
case SE_INDEX_TYPE_UINT32:
numIndices = size / 32;
numIndices = size / sizeof(uint32);
default:
break;
}
+7 -1
View File
@@ -569,7 +569,8 @@ public:
inline SeAttachmentStoreOp getStoreOp() const { return storeOp; }
inline SeAttachmentLoadOp getStencilLoadOp() const { return stencilLoadOp; }
inline SeAttachmentStoreOp getStencilStoreOp() const { return stencilStoreOp; }
SeClearValue clear;
SeColorComponentFlags componentFlags;
protected:
PTexture2D texture;
SeAttachmentLoadOp loadOp;
@@ -589,6 +590,11 @@ public:
SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE)
: RenderTargetAttachment(nullptr, loadOp, storeOp, stencilLoadOp, stencilStoreOp), owner(owner)
{
clear.color.float32[0] = 0.0f;
clear.color.float32[1] = 0.0f;
clear.color.float32[2] = 0.0f;
clear.color.float32[3] = 0.0f;
componentFlags = SE_COLOR_COMPONENT_R_BIT | SE_COLOR_COMPONENT_G_BIT | SE_COLOR_COMPONENT_B_BIT | SE_COLOR_COMPONENT_A_BIT;
}
virtual PTexture2D getTexture() override
{
+2 -1
View File
@@ -93,7 +93,8 @@ BasePass::BasePass(const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport v
depthBufferInfo.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
depthBuffer = graphics->createTexture2D(depthBufferInfo);
Gfx::PRenderTargetAttachment depthAttachment =
new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
depthAttachment->clear.depthStencil.depth = 1.0f;
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment);
renderPass = graphics->createRenderPass(layout);
+4 -1
View File
@@ -36,6 +36,10 @@ ShaderBuffer::ShaderBuffer(PGraphics graphics, uint32 size, VkBufferUsageFlags u
init::BufferCreateInfo(
usage,
size);
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
uint32 queueFamilyIndex = graphics->getFamilyMapping().getQueueTypeFamilyIndex(queueType);
info.pQueueFamilyIndices = &queueFamilyIndex;
info.queueFamilyIndexCount = 0;
VkBufferMemoryRequirementsInfo2 bufferReqInfo;
bufferReqInfo.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2;
bufferReqInfo.pNext = nullptr;
@@ -53,7 +57,6 @@ ShaderBuffer::ShaderBuffer(PGraphics graphics, uint32 size, VkBufferUsageFlags u
buffers[i].allocation = graphics->getAllocator()->allocate(memRequirements, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, buffers[i].buffer);
vkBindBufferMemory(graphics->getDevice(), buffers[i].buffer, buffers[i].allocation->getHandle(), buffers[i].allocation->getOffset());
}
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
}
ShaderBuffer::~ShaderBuffer()
@@ -203,7 +203,7 @@ void SecondaryCmdBuffer::bindVertexBuffer(const Array<VertexInputStream>& stream
void SecondaryCmdBuffer::bindIndexBuffer(Gfx::PIndexBuffer indexBuffer)
{
PIndexBuffer buf = indexBuffer.cast<IndexBuffer>();
vkCmdBindIndexBuffer(handle, buf->getHandle(), 0, VK_INDEX_TYPE_UINT16);
vkCmdBindIndexBuffer(handle, buf->getHandle(), 0, cast(buf->getIndexType()));
}
void SecondaryCmdBuffer::draw(const MeshBatchElement& data)
{
@@ -282,7 +282,6 @@ Array<const char *> Graphics::getRequiredExtensions()
{
extensions.add(glfwExtensions[i]);
}
std::cout << ENABLE_VALIDATION << std::endl;
#if ENABLE_VALIDATION
extensions.add(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
#endif // ENABLE_VALIDATION
@@ -1307,4 +1307,40 @@ Gfx::SeCompareOp Seele::Vulkan::cast(const VkCompareOp &op)
default:
return SE_COMPARE_OP_MAX_ENUM;
}
}
}
VkClearValue Seele::Vulkan::cast(const Gfx::SeClearValue& clear)
{
VkClearValue result;
if(sizeof(clear) == sizeof(Gfx::SeClearColorValue))
{
result.color.float32[0] = clear.color.float32[0];
result.color.float32[1] = clear.color.float32[1];
result.color.float32[2] = clear.color.float32[2];
result.color.float32[3] = clear.color.float32[3];
}
else
{
result.depthStencil.depth = clear.depthStencil.depth;
result.depthStencil.stencil = clear.depthStencil.stencil;
}
return result;
}
Gfx::SeClearValue Seele::Vulkan::cast(const VkClearValue& clear)
{
Gfx::SeClearValue result;
if(sizeof(clear) == sizeof(VkClearColorValue))
{
result.color.float32[0] = clear.color.float32[0];
result.color.float32[1] = clear.color.float32[1];
result.color.float32[2] = clear.color.float32[2];
result.color.float32[3] = clear.color.float32[3];
}
else
{
result.depthStencil.depth = clear.depthStencil.depth;
result.depthStencil.stencil = clear.depthStencil.stencil;
}
return result;
}
@@ -46,5 +46,7 @@ VkPolygonMode cast(const Gfx::SePolygonMode &mode);
Gfx::SePolygonMode cast(const VkPolygonMode &mode);
VkCompareOp cast(const Gfx::SeCompareOp &op);
Gfx::SeCompareOp cast(const VkCompareOp &op);
VkClearValue cast(const Gfx::SeClearValue &clear);
Gfx::SeClearValue cast(const VkClearValue &clear);
} // namespace Vulkan
} // namespace Seele
@@ -131,7 +131,7 @@ PGraphicsPipeline PipelineCache::createPipeline(const GraphicsPipelineCreateInfo
{
bindings.resize(element.streamIndex + 1); // This should not cause any actual allocations
}
VkVertexInputBindingDescription currBinding = bindings[element.streamIndex];
VkVertexInputBindingDescription& currBinding = bindings[element.streamIndex];
if((bindingsMask & (1 << element.streamIndex)) != 0)
{
assert(currBinding.binding == element.streamIndex);
@@ -228,7 +228,7 @@ PGraphicsPipeline PipelineCache::createPipeline(const GraphicsPipelineCreateInfo
cast(gfxInfo.depthStencilState.depthCompareOp)
);
const auto colorAttachments = gfxInfo.renderPass->getLayout()->colorAttachments;
const auto& colorAttachments = gfxInfo.renderPass->getLayout()->colorAttachments;
Array<VkPipelineColorBlendAttachmentState> blendAttachments(colorAttachments.size());
for(uint32 i = 0; i < colorAttachments.size(); ++i)
{
@@ -237,7 +237,7 @@ PGraphicsPipeline PipelineCache::createPipeline(const GraphicsPipelineCreateInfo
blendAttachment.alphaBlendOp = (VkBlendOp)attachment.alphaBlendOp;
blendAttachment.blendEnable = attachment.blendEnable;
blendAttachment.colorBlendOp = (VkBlendOp)attachment.colorBlendOp;
blendAttachment.colorWriteMask = attachment.colorWriteMask;
blendAttachment.colorWriteMask = colorAttachments[i]->componentFlags;
blendAttachment.dstAlphaBlendFactor = (VkBlendFactor)attachment.dstAlphaBlendFactor;
blendAttachment.srcAlphaBlendFactor = (VkBlendFactor)attachment.srcAlphaBlendFactor;
blendAttachment.dstColorBlendFactor = (VkBlendFactor)attachment.dstColorBlendFactor;
@@ -52,6 +52,12 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::PRenderTargetLayout layout)
desc.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VkClearValue& clearValue = clearValues.add();
if(desc.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
{
clearValue = cast(colorAttachment->clear);
}
VkAttachmentReference &ref = colorRefs.add();
ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
ref.attachment = attachmentCounter;
@@ -71,6 +77,12 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::PRenderTargetLayout layout)
desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
VkClearValue& clearValue = clearValues.add();
if(desc.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
{
clearValue = cast(layout->depthAttachment->clear);
}
VkAttachmentReference &ref = depthRef;
ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
ref.attachment = attachmentCounter;