Skip to content

Commit

Permalink
Wire up depth and stencil attachments to pipeline
Browse files Browse the repository at this point in the history
- Fix broken use of VkImageCreateFlags in various places as an aspect mask
- Be consistent about layout of D+S images. Layout is now [aspect][layer][level].
- Allow fetching an offset into a particular aspect.

Fixes dEQP-VK.pipeline.depth.*

Bug: b/118619338
Change-Id: I46adc9c637882e7144945eaeacce9f087d53caf0
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/26011
Tested-by: Chris Forbes <chrisforbes@google.com>
Presubmit-Ready: Chris Forbes <chrisforbes@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
  • Loading branch information
chrisforbes committed Mar 7, 2019
1 parent b69078e commit 2995dc2
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 139 deletions.
4 changes: 2 additions & 2 deletions src/Device/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ namespace sw
rasterizerDiscard = false;

depthCompareMode = VK_COMPARE_OP_LESS;
depthBufferEnable = true;
depthWriteEnable = true;
depthBufferEnable = false;
depthWriteEnable = false;

alphaBlendEnable = false;
sourceBlendFactorState = VK_BLEND_FACTOR_ONE;
Expand Down
18 changes: 9 additions & 9 deletions src/Device/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,9 @@ namespace sw
if(draw->renderTarget[index])
{
VkOffset3D offset = { 0, 0, static_cast<int32_t>(context->renderTargetLayer[index]) };
data->colorBuffer[index] = (unsigned int*)context->renderTarget[index]->getOffsetPointer(offset);
data->colorPitchB[index] = context->renderTarget[index]->rowPitchBytes();
data->colorSliceB[index] = context->renderTarget[index]->slicePitchBytes();
data->colorBuffer[index] = (unsigned int*)context->renderTarget[index]->getOffsetPointer(offset, VK_IMAGE_ASPECT_COLOR_BIT);
data->colorPitchB[index] = context->renderTarget[index]->rowPitchBytes(VK_IMAGE_ASPECT_COLOR_BIT);
data->colorSliceB[index] = context->renderTarget[index]->slicePitchBytes(VK_IMAGE_ASPECT_COLOR_BIT);
}
}

Expand All @@ -431,17 +431,17 @@ namespace sw
if(draw->depthBuffer)
{
VkOffset3D offset = { 0, 0, static_cast<int32_t>(context->depthBufferLayer) };
data->depthBuffer = (float*)context->depthBuffer->getOffsetPointer(offset);
data->depthPitchB = context->depthBuffer->rowPitchBytes();
data->depthSliceB = context->depthBuffer->slicePitchBytes();
data->depthBuffer = (float*)context->depthBuffer->getOffsetPointer(offset, VK_IMAGE_ASPECT_DEPTH_BIT);
data->depthPitchB = context->depthBuffer->rowPitchBytes(VK_IMAGE_ASPECT_DEPTH_BIT);
data->depthSliceB = context->depthBuffer->slicePitchBytes(VK_IMAGE_ASPECT_DEPTH_BIT);
}

if(draw->stencilBuffer)
{
VkOffset3D offset = { 0, 0, static_cast<int32_t>(context->stencilBufferLayer) };
data->stencilBuffer = (unsigned char*)context->stencilBuffer->getOffsetPointer(offset);
data->stencilPitchB = context->stencilBuffer->rowPitchBytes();
data->stencilSliceB = context->stencilBuffer->slicePitchBytes();
data->stencilBuffer = (unsigned char*)context->stencilBuffer->getOffsetPointer(offset, VK_IMAGE_ASPECT_STENCIL_BIT);
data->stencilPitchB = context->stencilBuffer->rowPitchBytes(VK_IMAGE_ASPECT_STENCIL_BIT);
data->stencilSliceB = context->stencilBuffer->slicePitchBytes(VK_IMAGE_ASPECT_STENCIL_BIT);
}
}

Expand Down
52 changes: 34 additions & 18 deletions src/Vulkan/VkCommandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,38 @@ struct IndexBufferBind : public CommandBuffer::Command
const VkIndexType indexType;
};

void CommandBuffer::ExecutionState::bindAttachments()
{
// Binds all the attachments for the current subpass
// Ideally this would be performed by BeginRenderPass and NextSubpass, but
// there is too much stomping of the renderer's state by setContext() in
// draws.

for (auto i = 0u; i < renderPass->getCurrentSubpass().colorAttachmentCount; i++)
{
auto attachmentReference = renderPass->getCurrentSubpass().pColorAttachments[i];
if (attachmentReference.attachment != VK_ATTACHMENT_UNUSED)
{
auto attachment = renderPassFramebuffer->getAttachment(attachmentReference.attachment);
renderer->setRenderTarget(i, attachment, 0);
}
}

auto attachmentReference = renderPass->getCurrentSubpass().pDepthStencilAttachment;
if (attachmentReference && attachmentReference->attachment != VK_ATTACHMENT_UNUSED)
{
auto attachment = renderPassFramebuffer->getAttachment(attachmentReference->attachment);
if (attachment->hasDepthAspect())
{
renderer->setDepthBuffer(attachment, 0);
}
if (attachment->hasStencilAspect())
{
renderer->setStencilBuffer(attachment, 0);
}
}
}

struct Draw : public CommandBuffer::Command
{
Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
Expand Down Expand Up @@ -189,15 +221,7 @@ struct Draw : public CommandBuffer::Command
executionState.renderer->setViewport(pipeline->getViewport());
executionState.renderer->setBlendConstant(pipeline->getBlendConstants());

for (auto i = 0u; i < executionState.renderPass->getCurrentSubpass().colorAttachmentCount; i++)
{
auto attachmentReference = executionState.renderPass->getCurrentSubpass().pColorAttachments[i];
if (attachmentReference.attachment != VK_ATTACHMENT_UNUSED)
{
auto attachment = executionState.renderPassFramebuffer->getAttachment(attachmentReference.attachment);
executionState.renderer->setRenderTarget(i, attachment, 0);
}
}
executionState.bindAttachments();

const uint32_t primitiveCount = pipeline->computePrimitiveCount(vertexCount);
const uint32_t lastInstance = firstInstance + instanceCount - 1;
Expand Down Expand Up @@ -247,15 +271,7 @@ struct DrawIndexed : public CommandBuffer::Command
executionState.renderer->setViewport(pipeline->getViewport());
executionState.renderer->setBlendConstant(pipeline->getBlendConstants());

for (auto i = 0u; i < executionState.renderPass->getCurrentSubpass().colorAttachmentCount; i++)
{
auto attachmentReference = executionState.renderPass->getCurrentSubpass().pColorAttachments[i];
if (attachmentReference.attachment != VK_ATTACHMENT_UNUSED)
{
auto attachment = executionState.renderPassFramebuffer->getAttachment(attachmentReference.attachment);
executionState.renderer->setRenderTarget(i, attachment, 0);
}
}
executionState.bindAttachments();

auto drawType = executionState.indexType == VK_INDEX_TYPE_UINT16
? (context.drawType | sw::DRAW_INDEXED16) : (context.drawType | sw::DRAW_INDEXED32);
Expand Down
2 changes: 2 additions & 0 deletions src/Vulkan/VkCommandBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class CommandBuffer
VertexInputBinding vertexInputBindings[MAX_VERTEX_INPUT_BINDINGS] = {};
VertexInputBinding indexBufferBinding;
VkIndexType indexType;

void bindAttachments();
};

void submit(CommandBuffer::ExecutionState& executionState);
Expand Down
Loading

0 comments on commit 2995dc2

Please sign in to comment.