Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: src/gpu/vk/GrVkGpu.cpp

Issue 2358613002: Fix possible divide by zero in vulkan granularity adjustments (Closed)
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrVkGpu.h" 8 #include "GrVkGpu.h"
9 9
10 #include "GrContextOptions.h" 10 #include "GrContextOptions.h"
(...skipping 1767 matching lines...) Expand 10 before | Expand all | Expand 10 after
1778 transferBuffer->unref(); 1778 transferBuffer->unref();
1779 return true; 1779 return true;
1780 } 1780 }
1781 1781
1782 // The RenderArea bounds we pass into BeginRenderPass must have a start x value that is a multiple 1782 // The RenderArea bounds we pass into BeginRenderPass must have a start x value that is a multiple
1783 // of the granularity. The width must also be a multiple of the granularity or e aqual to the width 1783 // of the granularity. The width must also be a multiple of the granularity or e aqual to the width
1784 // the the entire attachment. Similar requirements for the y and height componen ts. 1784 // the the entire attachment. Similar requirements for the y and height componen ts.
1785 void adjust_bounds_to_granularity(SkIRect* dstBounds, const SkIRect& srcBounds, 1785 void adjust_bounds_to_granularity(SkIRect* dstBounds, const SkIRect& srcBounds,
1786 const VkExtent2D& granularity, int maxWidth, i nt maxHeight) { 1786 const VkExtent2D& granularity, int maxWidth, i nt maxHeight) {
1787 // Adjust Width 1787 // Adjust Width
1788 // Start with the right side of rect so we know if we end up going pass the maxWidth. 1788 if ((0 != granularity.width && 1 != granularity.width)) {
1789 int rightAdj = srcBounds.fRight % granularity.width; 1789 // Start with the right side of rect so we know if we end up going pass the maxWidth.
1790 if (rightAdj != 0) { 1790 int rightAdj = srcBounds.fRight % granularity.width;
1791 rightAdj = granularity.width - rightAdj; 1791 if (rightAdj != 0) {
1792 } 1792 rightAdj = granularity.width - rightAdj;
1793 dstBounds->fRight = srcBounds.fRight + rightAdj; 1793 }
1794 if (dstBounds->fRight > maxWidth) { 1794 dstBounds->fRight = srcBounds.fRight + rightAdj;
1795 dstBounds->fRight = maxWidth; 1795 if (dstBounds->fRight > maxWidth) {
1796 dstBounds->fLeft = 0; 1796 dstBounds->fRight = maxWidth;
1797 dstBounds->fLeft = 0;
1798 } else {
1799 dstBounds->fLeft = srcBounds.fLeft - srcBounds.fLeft % granularity.w idth;
1800 }
1797 } else { 1801 } else {
1798 dstBounds->fLeft = srcBounds.fLeft - srcBounds.fLeft % granularity.width; 1802 dstBounds->fLeft = srcBounds.fLeft;
1803 dstBounds->fRight = srcBounds.fRight;
1799 } 1804 }
1800 1805
1801 // Adjust height 1806 // Adjust height
1802 // Start with the bottom side of rect so we know if we end up going pass the maxHeight. 1807 if ((0 != granularity.height && 1 != granularity.height)) {
1803 int bottomAdj = srcBounds.fBottom % granularity.height; 1808 // Start with the bottom side of rect so we know if we end up going pass the maxHeight.
1804 if (bottomAdj != 0) { 1809 int bottomAdj = srcBounds.fBottom % granularity.height;
1805 bottomAdj = granularity.height - bottomAdj; 1810 if (bottomAdj != 0) {
1806 } 1811 bottomAdj = granularity.height - bottomAdj;
1807 dstBounds->fBottom = srcBounds.fBottom + bottomAdj; 1812 }
1808 if (dstBounds->fBottom > maxHeight) { 1813 dstBounds->fBottom = srcBounds.fBottom + bottomAdj;
1809 dstBounds->fBottom = maxHeight; 1814 if (dstBounds->fBottom > maxHeight) {
1810 dstBounds->fTop = 0; 1815 dstBounds->fBottom = maxHeight;
1816 dstBounds->fTop = 0;
1817 } else {
1818 dstBounds->fTop = srcBounds.fTop - srcBounds.fTop % granularity.heig ht;
1819 }
1811 } else { 1820 } else {
1812 dstBounds->fTop = srcBounds.fTop - srcBounds.fTop % granularity.height; 1821 dstBounds->fTop = srcBounds.fTop;
1822 dstBounds->fBottom = srcBounds.fBottom;
1813 } 1823 }
1814 } 1824 }
1815 1825
1816 void GrVkGpu::submitSecondaryCommandBuffer(GrVkSecondaryCommandBuffer* buffer, 1826 void GrVkGpu::submitSecondaryCommandBuffer(GrVkSecondaryCommandBuffer* buffer,
1817 const GrVkRenderPass* renderPass, 1827 const GrVkRenderPass* renderPass,
1818 const VkClearValue* colorClear, 1828 const VkClearValue* colorClear,
1819 GrVkRenderTarget* target, 1829 GrVkRenderTarget* target,
1820 const SkIRect& bounds) { 1830 const SkIRect& bounds) {
1821 const SkIRect* pBounds = &bounds; 1831 const SkIRect* pBounds = &bounds;
1822 SkIRect flippedBounds; 1832 SkIRect flippedBounds;
(...skipping 18 matching lines...) Expand all
1841 // Currently it is fine for us to always pass in 1 for the clear count even if no attachment 1851 // Currently it is fine for us to always pass in 1 for the clear count even if no attachment
1842 // uses it. In the current state, we also only use the LOAD_OP_CLEAR for the color attachment 1852 // uses it. In the current state, we also only use the LOAD_OP_CLEAR for the color attachment
1843 // which is always at the first attachment. 1853 // which is always at the first attachment.
1844 fCurrentCmdBuffer->beginRenderPass(this, renderPass, 1, colorClear, *target, *pBounds, true); 1854 fCurrentCmdBuffer->beginRenderPass(this, renderPass, 1, colorClear, *target, *pBounds, true);
1845 fCurrentCmdBuffer->executeCommands(this, buffer); 1855 fCurrentCmdBuffer->executeCommands(this, buffer);
1846 fCurrentCmdBuffer->endRenderPass(this); 1856 fCurrentCmdBuffer->endRenderPass(this);
1847 1857
1848 this->didWriteToSurface(target, &bounds); 1858 this->didWriteToSurface(target, &bounds);
1849 } 1859 }
1850 1860
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698