Commit d9ed1c27 by Alexis Hetu Committed by Alexis Hétu

Prevent rasterizing fragments outside the framebuffer

The scissor is now restricted to the framebuffer's size, in order to avoid writing out of bounds of the image. Vulkan 1.1 spec section 25.2. Scissor Test states that "Rasterization does not produce fragments outside of the framebuffer" Bug: b/141999739, angleproject:4060 Change-Id: Id0bce035b0ab9072f354b9f00be8d42577e4af54 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/38008Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarAlexis Hétu <sugoi@google.com>
parent 27a3d31d
...@@ -178,7 +178,7 @@ namespace sw ...@@ -178,7 +178,7 @@ namespace sw
} }
void Renderer::draw(const sw::Context* context, VkIndexType indexType, unsigned int count, int baseVertex, void Renderer::draw(const sw::Context* context, VkIndexType indexType, unsigned int count, int baseVertex,
TaskEvents *events, int instanceID, int viewID, void *indexBuffer, TaskEvents *events, int instanceID, int viewID, void *indexBuffer, const VkExtent3D& framebufferExtent,
PushConstantStorage const & pushConstants, bool update) PushConstantStorage const & pushConstants, bool update)
{ {
if(count == 0) { return; } if(count == 0) { return; }
...@@ -384,10 +384,10 @@ namespace sw ...@@ -384,10 +384,10 @@ namespace sw
// Scissor // Scissor
{ {
data->scissorX0 = scissor.offset.x; data->scissorX0 = clamp<int>(scissor.offset.x, 0, framebufferExtent.width);
data->scissorX1 = scissor.offset.x + scissor.extent.width; data->scissorX1 = clamp<int>(scissor.offset.x + scissor.extent.width, 0, framebufferExtent.width);
data->scissorY0 = scissor.offset.y; data->scissorY0 = clamp<int>(scissor.offset.y, 0, framebufferExtent.height);
data->scissorY1 = scissor.offset.y + scissor.extent.height; data->scissorY1 = clamp<int>(scissor.offset.y + scissor.extent.height, 0, framebufferExtent.height);
} }
// Push constants // Push constants
......
...@@ -202,7 +202,7 @@ namespace sw ...@@ -202,7 +202,7 @@ namespace sw
bool hasOcclusionQuery() const { return occlusionQuery != nullptr; } bool hasOcclusionQuery() const { return occlusionQuery != nullptr; }
void draw(const sw::Context* context, VkIndexType indexType, unsigned int count, int baseVertex, void draw(const sw::Context* context, VkIndexType indexType, unsigned int count, int baseVertex,
TaskEvents *events, int instanceID, int viewID, void *indexBuffer, TaskEvents *events, int instanceID, int viewID, void *indexBuffer, const VkExtent3D& framebufferExtent,
PushConstantStorage const & pushConstants, bool update = true); PushConstantStorage const & pushConstants, bool update = true);
// Viewport & Clipper // Viewport & Clipper
......
...@@ -617,6 +617,7 @@ struct DrawBase : public CommandBuffer::Command ...@@ -617,6 +617,7 @@ struct DrawBase : public CommandBuffer::Command
{ {
executionState.renderer->draw(&context, executionState.indexType, indexBuffer.first, vertexOffset, executionState.renderer->draw(&context, executionState.indexType, indexBuffer.first, vertexOffset,
executionState.events, instance, viewID, indexBuffer.second, executionState.events, instance, viewID, indexBuffer.second,
executionState.renderPassFramebuffer->getExtent(),
executionState.pushConstants); executionState.pushConstants);
} }
} }
......
...@@ -23,7 +23,8 @@ namespace vk ...@@ -23,7 +23,8 @@ namespace vk
Framebuffer::Framebuffer(const VkFramebufferCreateInfo* pCreateInfo, void* mem) : Framebuffer::Framebuffer(const VkFramebufferCreateInfo* pCreateInfo, void* mem) :
attachmentCount(pCreateInfo->attachmentCount), attachmentCount(pCreateInfo->attachmentCount),
attachments(reinterpret_cast<ImageView**>(mem)) attachments(reinterpret_cast<ImageView**>(mem)),
extent{pCreateInfo->width, pCreateInfo->height, pCreateInfo->layers}
{ {
for(uint32_t i = 0; i < attachmentCount; i++) for(uint32_t i = 0; i < attachmentCount; i++)
{ {
......
...@@ -36,9 +36,12 @@ public: ...@@ -36,9 +36,12 @@ public:
ImageView *getAttachment(uint32_t index) const; ImageView *getAttachment(uint32_t index) const;
void resolve(const RenderPass* renderPass, uint32_t subpassIndex); void resolve(const RenderPass* renderPass, uint32_t subpassIndex);
const VkExtent3D& getExtent() const { return extent; }
private: private:
uint32_t attachmentCount = 0; uint32_t attachmentCount = 0;
ImageView** attachments = nullptr; ImageView** attachments = nullptr;
const VkExtent3D extent = {};
}; };
static inline Framebuffer* Cast(VkFramebuffer object) static inline Framebuffer* Cast(VkFramebuffer object)
......
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