Commit 2995dc2a by Chris Forbes

Wire up depth and stencil attachments to pipeline

- 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/+/26011Tested-by: 's avatarChris Forbes <chrisforbes@google.com> Presubmit-Ready: Chris Forbes <chrisforbes@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent b69078e2
...@@ -193,8 +193,8 @@ namespace sw ...@@ -193,8 +193,8 @@ namespace sw
rasterizerDiscard = false; rasterizerDiscard = false;
depthCompareMode = VK_COMPARE_OP_LESS; depthCompareMode = VK_COMPARE_OP_LESS;
depthBufferEnable = true; depthBufferEnable = false;
depthWriteEnable = true; depthWriteEnable = false;
alphaBlendEnable = false; alphaBlendEnable = false;
sourceBlendFactorState = VK_BLEND_FACTOR_ONE; sourceBlendFactorState = VK_BLEND_FACTOR_ONE;
......
...@@ -419,9 +419,9 @@ namespace sw ...@@ -419,9 +419,9 @@ namespace sw
if(draw->renderTarget[index]) if(draw->renderTarget[index])
{ {
VkOffset3D offset = { 0, 0, static_cast<int32_t>(context->renderTargetLayer[index]) }; VkOffset3D offset = { 0, 0, static_cast<int32_t>(context->renderTargetLayer[index]) };
data->colorBuffer[index] = (unsigned int*)context->renderTarget[index]->getOffsetPointer(offset); data->colorBuffer[index] = (unsigned int*)context->renderTarget[index]->getOffsetPointer(offset, VK_IMAGE_ASPECT_COLOR_BIT);
data->colorPitchB[index] = context->renderTarget[index]->rowPitchBytes(); data->colorPitchB[index] = context->renderTarget[index]->rowPitchBytes(VK_IMAGE_ASPECT_COLOR_BIT);
data->colorSliceB[index] = context->renderTarget[index]->slicePitchBytes(); data->colorSliceB[index] = context->renderTarget[index]->slicePitchBytes(VK_IMAGE_ASPECT_COLOR_BIT);
} }
} }
...@@ -431,17 +431,17 @@ namespace sw ...@@ -431,17 +431,17 @@ namespace sw
if(draw->depthBuffer) if(draw->depthBuffer)
{ {
VkOffset3D offset = { 0, 0, static_cast<int32_t>(context->depthBufferLayer) }; VkOffset3D offset = { 0, 0, static_cast<int32_t>(context->depthBufferLayer) };
data->depthBuffer = (float*)context->depthBuffer->getOffsetPointer(offset); data->depthBuffer = (float*)context->depthBuffer->getOffsetPointer(offset, VK_IMAGE_ASPECT_DEPTH_BIT);
data->depthPitchB = context->depthBuffer->rowPitchBytes(); data->depthPitchB = context->depthBuffer->rowPitchBytes(VK_IMAGE_ASPECT_DEPTH_BIT);
data->depthSliceB = context->depthBuffer->slicePitchBytes(); data->depthSliceB = context->depthBuffer->slicePitchBytes(VK_IMAGE_ASPECT_DEPTH_BIT);
} }
if(draw->stencilBuffer) if(draw->stencilBuffer)
{ {
VkOffset3D offset = { 0, 0, static_cast<int32_t>(context->stencilBufferLayer) }; VkOffset3D offset = { 0, 0, static_cast<int32_t>(context->stencilBufferLayer) };
data->stencilBuffer = (unsigned char*)context->stencilBuffer->getOffsetPointer(offset); data->stencilBuffer = (unsigned char*)context->stencilBuffer->getOffsetPointer(offset, VK_IMAGE_ASPECT_STENCIL_BIT);
data->stencilPitchB = context->stencilBuffer->rowPitchBytes(); data->stencilPitchB = context->stencilBuffer->rowPitchBytes(VK_IMAGE_ASPECT_STENCIL_BIT);
data->stencilSliceB = context->stencilBuffer->slicePitchBytes(); data->stencilSliceB = context->stencilBuffer->slicePitchBytes(VK_IMAGE_ASPECT_STENCIL_BIT);
} }
} }
......
...@@ -159,6 +159,38 @@ struct IndexBufferBind : public CommandBuffer::Command ...@@ -159,6 +159,38 @@ struct IndexBufferBind : public CommandBuffer::Command
const VkIndexType indexType; 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 struct Draw : public CommandBuffer::Command
{ {
Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
...@@ -189,15 +221,7 @@ struct Draw : public CommandBuffer::Command ...@@ -189,15 +221,7 @@ struct Draw : public CommandBuffer::Command
executionState.renderer->setViewport(pipeline->getViewport()); executionState.renderer->setViewport(pipeline->getViewport());
executionState.renderer->setBlendConstant(pipeline->getBlendConstants()); executionState.renderer->setBlendConstant(pipeline->getBlendConstants());
for (auto i = 0u; i < executionState.renderPass->getCurrentSubpass().colorAttachmentCount; i++) executionState.bindAttachments();
{
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);
}
}
const uint32_t primitiveCount = pipeline->computePrimitiveCount(vertexCount); const uint32_t primitiveCount = pipeline->computePrimitiveCount(vertexCount);
const uint32_t lastInstance = firstInstance + instanceCount - 1; const uint32_t lastInstance = firstInstance + instanceCount - 1;
...@@ -247,15 +271,7 @@ struct DrawIndexed : public CommandBuffer::Command ...@@ -247,15 +271,7 @@ struct DrawIndexed : public CommandBuffer::Command
executionState.renderer->setViewport(pipeline->getViewport()); executionState.renderer->setViewport(pipeline->getViewport());
executionState.renderer->setBlendConstant(pipeline->getBlendConstants()); executionState.renderer->setBlendConstant(pipeline->getBlendConstants());
for (auto i = 0u; i < executionState.renderPass->getCurrentSubpass().colorAttachmentCount; i++) executionState.bindAttachments();
{
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);
}
}
auto drawType = executionState.indexType == VK_INDEX_TYPE_UINT16 auto drawType = executionState.indexType == VK_INDEX_TYPE_UINT16
? (context.drawType | sw::DRAW_INDEXED16) : (context.drawType | sw::DRAW_INDEXED32); ? (context.drawType | sw::DRAW_INDEXED16) : (context.drawType | sw::DRAW_INDEXED32);
......
...@@ -135,6 +135,8 @@ public: ...@@ -135,6 +135,8 @@ public:
VertexInputBinding vertexInputBindings[MAX_VERTEX_INPUT_BINDINGS] = {}; VertexInputBinding vertexInputBindings[MAX_VERTEX_INPUT_BINDINGS] = {};
VertexInputBinding indexBufferBinding; VertexInputBinding indexBufferBinding;
VkIndexType indexType; VkIndexType indexType;
void bindAttachments();
}; };
void submit(CommandBuffer::ExecutionState& executionState); void submit(CommandBuffer::ExecutionState& executionState);
......
...@@ -53,29 +53,29 @@ public: ...@@ -53,29 +53,29 @@ public:
VkFormat getFormat() const { return format; } VkFormat getFormat() const { return format; }
uint32_t getArrayLayers() const { return arrayLayers; } uint32_t getArrayLayers() const { return arrayLayers; }
VkSampleCountFlagBits getSampleCountFlagBits() const { return samples; } VkSampleCountFlagBits getSampleCountFlagBits() const { return samples; }
int rowPitchBytes(const VkImageAspectFlags& flags, uint32_t mipLevel) const; int rowPitchBytes(VkImageAspectFlagBits aspect, uint32_t mipLevel) const;
int slicePitchBytes(const VkImageAspectFlags& flags, uint32_t mipLevel) const; int slicePitchBytes(VkImageAspectFlagBits aspect, uint32_t mipLevel) const;
void* getTexelPointer(const VkOffset3D& offset, const VkImageSubresourceLayers& subresource) const; void* getTexelPointer(const VkOffset3D& offset, const VkImageSubresourceLayers& subresource) const;
bool isCube() const; bool isCube() const;
private: private:
sw::Surface* asSurface(const VkImageAspectFlags& flags, uint32_t mipLevel, uint32_t layer) const; sw::Surface* asSurface(VkImageAspectFlagBits aspect, uint32_t mipLevel, uint32_t layer) const;
void copy(VkBuffer buffer, const VkBufferImageCopy& region, bool bufferIsSource); void copy(VkBuffer buffer, const VkBufferImageCopy& region, bool bufferIsSource);
VkDeviceSize getStorageSize(const VkImageAspectFlags& flags) const; VkDeviceSize getStorageSize(VkImageAspectFlags flags) const;
VkDeviceSize getMipLevelSize(const VkImageAspectFlags& flags, uint32_t mipLevel) const; VkDeviceSize getMipLevelSize(VkImageAspectFlagBits aspect, uint32_t mipLevel) const;
VkDeviceSize getLayerSize(const VkImageAspectFlags& flags) const; VkDeviceSize getLayerSize(VkImageAspectFlagBits aspect) const;
VkDeviceSize getMemoryOffset(const VkImageAspectFlags& flags, uint32_t mipLevel) const; VkDeviceSize getMemoryOffset(VkImageAspectFlagBits aspect, uint32_t mipLevel) const;
VkDeviceSize getMemoryOffset(const VkImageAspectFlags& flags, uint32_t mipLevel, uint32_t layer) const; VkDeviceSize getMemoryOffset(VkImageAspectFlagBits aspect, uint32_t mipLevel, uint32_t layer) const;
VkDeviceSize texelOffsetBytesInStorage(const VkOffset3D& offset, const VkImageSubresourceLayers& subresource) const; VkDeviceSize texelOffsetBytesInStorage(const VkOffset3D& offset, const VkImageSubresourceLayers& subresource) const;
VkDeviceSize getMemoryOffset(const VkImageAspectFlags& flags) const; VkDeviceSize getMemoryOffset(VkImageAspectFlagBits aspect) const;
int bytesPerTexel(const VkImageAspectFlags& flags) const; int bytesPerTexel(VkImageAspectFlagBits flags) const;
VkExtent3D getMipLevelExtent(uint32_t mipLevel) const; VkExtent3D getMipLevelExtent(uint32_t mipLevel) const;
VkFormat getFormat(const VkImageAspectFlags& flags) const; VkFormat getFormat(VkImageAspectFlagBits flags) const;
uint32_t getLastLayerIndex(const VkImageSubresourceRange& subresourceRange) const; uint32_t getLastLayerIndex(const VkImageSubresourceRange& subresourceRange) const;
uint32_t getLastMipLevel(const VkImageSubresourceRange& subresourceRange) const; uint32_t getLastMipLevel(const VkImageSubresourceRange& subresourceRange) const;
VkFormat getClearFormat() const; VkFormat getClearFormat() const;
void clear(void* pixelData, VkFormat format, const VkImageSubresourceRange& subresourceRange, VkImageAspectFlags aspectMask); void clear(void* pixelData, VkFormat format, const VkImageSubresourceRange& subresourceRange, VkImageAspectFlagBits aspect);
void clear(void* pixelData, VkFormat format, const VkRect2D& renderArea, const VkImageSubresourceRange& subresourceRange, VkImageAspectFlags aspectMask); void clear(void* pixelData, VkFormat format, const VkRect2D& renderArea, const VkImageSubresourceRange& subresourceRange, VkImageAspectFlagBits aspect);
DeviceMemory* deviceMemory = nullptr; DeviceMemory* deviceMemory = nullptr;
VkDeviceSize memoryOffset = 0; VkDeviceSize memoryOffset = 0;
......
...@@ -119,17 +119,11 @@ void ImageView::clear(const VkClearValue& clearValue, const VkImageAspectFlags a ...@@ -119,17 +119,11 @@ void ImageView::clear(const VkClearValue& clearValue, const VkImageAspectFlags a
image->clear(clearValue, renderArea.rect, sr); image->clear(clearValue, renderArea.rect, sr);
} }
void *ImageView::getPointer() const void *ImageView::getOffsetPointer(const VkOffset3D& offset, VkImageAspectFlagBits aspect) const
{
VkOffset3D noOffset = { 0, 0, 0 };
return getOffsetPointer(noOffset);
}
void *ImageView::getOffsetPointer(const VkOffset3D& offset) const
{ {
VkImageSubresourceLayers imageSubresourceLayers = VkImageSubresourceLayers imageSubresourceLayers =
{ {
subresourceRange.aspectMask, aspect,
subresourceRange.baseMipLevel, subresourceRange.baseMipLevel,
subresourceRange.baseArrayLayer, subresourceRange.baseArrayLayer,
subresourceRange.layerCount subresourceRange.layerCount
......
...@@ -31,16 +31,17 @@ public: ...@@ -31,16 +31,17 @@ public:
static size_t ComputeRequiredAllocationSize(const VkImageViewCreateInfo* pCreateInfo); static size_t ComputeRequiredAllocationSize(const VkImageViewCreateInfo* pCreateInfo);
void clear(const VkClearValue& clearValues, const VkImageAspectFlags aspectMask, const VkRect2D& renderArea); void clear(const VkClearValue& clearValues, VkImageAspectFlags aspectMask, const VkRect2D& renderArea);
void clear(const VkClearValue& clearValue, const VkImageAspectFlags aspectMask, const VkClearRect& renderArea); void clear(const VkClearValue& clearValue, VkImageAspectFlags aspectMask, const VkClearRect& renderArea);
VkFormat getFormat() const { return format; } VkFormat getFormat() const { return format; }
int rowPitchBytes() const { return image->rowPitchBytes(subresourceRange.aspectMask, subresourceRange.baseMipLevel); }
int slicePitchBytes() const { return image->slicePitchBytes(subresourceRange.aspectMask, subresourceRange.baseMipLevel); }
int getSampleCount() const { return image->getSampleCountFlagBits(); } int getSampleCount() const { return image->getSampleCountFlagBits(); }
int rowPitchBytes(VkImageAspectFlagBits aspect) const { return image->rowPitchBytes(aspect, subresourceRange.baseMipLevel); }
int slicePitchBytes(VkImageAspectFlagBits aspect) const { return image->slicePitchBytes(aspect, subresourceRange.baseMipLevel); }
void *getPointer() const; void *getOffsetPointer(const VkOffset3D& offset, VkImageAspectFlagBits aspect) const;
void *getOffsetPointer(const VkOffset3D& offset) const; bool hasDepthAspect() const { return (subresourceRange.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != 0; }
bool hasStencilAspect() const { return (subresourceRange.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != 0; }
private: private:
bool imageTypesMatch(VkImageType imageType) const; bool imageTypesMatch(VkImageType imageType) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment