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

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

Issue 2105433002: Add support for draws in vulkan read and write pixels (Closed) Base URL: https://skia.googlesource.com/skia.git@unitTests
Patch Set: nit Created 4 years, 5 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 | tests/WritePixelsTest.cpp » ('j') | 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 } 245 }
246 246
247 //////////////////////////////////////////////////////////////////////////////// 247 ////////////////////////////////////////////////////////////////////////////////
248 bool GrVkGpu::onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, 248 bool GrVkGpu::onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
249 GrPixelConfig srcConfig, DrawPreference* draw Preference, 249 GrPixelConfig srcConfig, DrawPreference* draw Preference,
250 WritePixelTempDrawInfo* tempDrawInfo) { 250 WritePixelTempDrawInfo* tempDrawInfo) {
251 if (kIndex_8_GrPixelConfig == srcConfig || GrPixelConfigIsCompressed(dstSurf ace->config())) { 251 if (kIndex_8_GrPixelConfig == srcConfig || GrPixelConfigIsCompressed(dstSurf ace->config())) {
252 return false; 252 return false;
253 } 253 }
254 254
255 // Currently we don't handle draws, so if the caller wants/needs to do a dra w we need to fail 255 if (dstSurface->config() == srcConfig) {
256 if (kNoDraw_DrawPreference != *drawPreference) { 256 return true;
257 return false;
258 } 257 }
259 258
260 if (dstSurface->config() != srcConfig) { 259 GrRenderTarget* renderTarget = dstSurface->asRenderTarget();
261 // TODO: This should fall back to drawing or copying to change config of dstSurface to 260
262 // match that of srcConfig. 261 // Start off assuming no swizzling
263 return false; 262 tempDrawInfo->fSwizzle = GrSwizzle::RGBA();
263 tempDrawInfo->fWriteConfig = srcConfig;
264
265 // These settings we will always want if a temp draw is performed. Initially set the config
266 // to srcConfig, though that may be modified if we decide to do a R/B swap
267 tempDrawInfo->fTempSurfaceDesc.fFlags = kNone_GrSurfaceFlags;
268 tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig;
269 tempDrawInfo->fTempSurfaceDesc.fWidth = width;
270 tempDrawInfo->fTempSurfaceDesc.fHeight = height;
271 tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0;
272 tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
273
274 if (renderTarget && this->vkCaps().isConfigRenderable(renderTarget->config() , false)) {
275 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
276
277 bool configsAreRBSwaps = GrPixelConfigSwapRAndB(srcConfig) == dstSurface ->config();
278
279 if (!this->vkCaps().isConfigTexturable(srcConfig) && configsAreRBSwaps) {
280 if (!this->vkCaps().isConfigTexturable(dstSurface->config())) {
281 return false;
282 }
283 tempDrawInfo->fTempSurfaceDesc.fConfig = dstSurface->config();
284 tempDrawInfo->fSwizzle = GrSwizzle::BGRA();
285 tempDrawInfo->fWriteConfig = dstSurface->config();
286 }
287 return true;
264 } 288 }
265 289
266 return true; 290 return false;
267 } 291 }
268 292
269 bool GrVkGpu::onWritePixels(GrSurface* surface, 293 bool GrVkGpu::onWritePixels(GrSurface* surface,
270 int left, int top, int width, int height, 294 int left, int top, int width, int height,
271 GrPixelConfig config, 295 GrPixelConfig config,
272 const SkTArray<GrMipLevel>& texels) { 296 const SkTArray<GrMipLevel>& texels) {
273 GrVkTexture* vkTex = static_cast<GrVkTexture*>(surface->asTexture()); 297 GrVkTexture* vkTex = static_cast<GrVkTexture*>(surface->asTexture());
274 if (!vkTex) { 298 if (!vkTex) {
275 return false; 299 return false;
276 } 300 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 int newMipLevels = texels.count(); 341 int newMipLevels = texels.count();
318 int currentMipLevels = vkTex->texturePriv().maxMipMapLevel() + 1; 342 int currentMipLevels = vkTex->texturePriv().maxMipMapLevel() + 1;
319 if (newMipLevels != currentMipLevels) { 343 if (newMipLevels != currentMipLevels) {
320 if (!vkTex->reallocForMipmap(this, newMipLevels)) { 344 if (!vkTex->reallocForMipmap(this, newMipLevels)) {
321 return false; 345 return false;
322 } 346 }
323 } 347 }
324 success = this->uploadTexDataOptimal(vkTex, left, top, width, height , config, texels); 348 success = this->uploadTexDataOptimal(vkTex, left, top, width, height , config, texels);
325 } 349 }
326 } 350 }
327 351
328 return success; 352 return success;
329 } 353 }
330 354
331 bool GrVkGpu::uploadTexDataLinear(GrVkTexture* tex, 355 bool GrVkGpu::uploadTexDataLinear(GrVkTexture* tex,
332 int left, int top, int width, int height, 356 int left, int top, int width, int height,
333 GrPixelConfig dataConfig, 357 GrPixelConfig dataConfig,
334 const void* data, 358 const void* data,
335 size_t rowBytes) { 359 size_t rowBytes) {
336 SkASSERT(data); 360 SkASSERT(data);
337 SkASSERT(tex->isLinearTiled()); 361 SkASSERT(tex->isLinearTiled());
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 } 519 }
496 520
497 VkBufferImageCopy& region = regions.push_back(); 521 VkBufferImageCopy& region = regions.push_back();
498 memset(&region, 0, sizeof(VkBufferImageCopy)); 522 memset(&region, 0, sizeof(VkBufferImageCopy));
499 region.bufferOffset = individualMipOffsets[currentMipLevel]; 523 region.bufferOffset = individualMipOffsets[currentMipLevel];
500 region.bufferRowLength = currentWidth; 524 region.bufferRowLength = currentWidth;
501 region.bufferImageHeight = currentHeight; 525 region.bufferImageHeight = currentHeight;
502 region.imageSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, SkToU32(currentMi pLevel), 0, 1 }; 526 region.imageSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, SkToU32(currentMi pLevel), 0, 1 };
503 region.imageOffset = { left, flipY ? tex->height() - top - currentHeight : top, 0 }; 527 region.imageOffset = { left, flipY ? tex->height() - top - currentHeight : top, 0 };
504 region.imageExtent = { (uint32_t)currentWidth, (uint32_t)currentHeight, 1 }; 528 region.imageExtent = { (uint32_t)currentWidth, (uint32_t)currentHeight, 1 };
505 529
506 currentWidth = SkTMax(1, currentWidth/2); 530 currentWidth = SkTMax(1, currentWidth/2);
507 currentHeight = SkTMax(1, currentHeight/2); 531 currentHeight = SkTMax(1, currentHeight/2);
508 } 532 }
509 533
510 transferBuffer->unmap(); 534 transferBuffer->unmap();
511 535
512 // make sure the unmap has finished 536 // make sure the unmap has finished
513 transferBuffer->addMemoryBarrier(this, 537 transferBuffer->addMemoryBarrier(this,
514 VK_ACCESS_HOST_WRITE_BIT, 538 VK_ACCESS_HOST_WRITE_BIT,
515 VK_ACCESS_TRANSFER_READ_BIT, 539 VK_ACCESS_TRANSFER_READ_BIT,
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 void GrVkGpu::onGetMultisampleSpecs(GrRenderTarget* rt, const GrStencilSettings& , 1349 void GrVkGpu::onGetMultisampleSpecs(GrRenderTarget* rt, const GrStencilSettings& ,
1326 int* effectiveSampleCnt, SkAutoTDeleteArray< SkPoint>*) { 1350 int* effectiveSampleCnt, SkAutoTDeleteArray< SkPoint>*) {
1327 // TODO: stub. 1351 // TODO: stub.
1328 SkASSERT(!this->caps()->sampleLocationsSupport()); 1352 SkASSERT(!this->caps()->sampleLocationsSupport());
1329 *effectiveSampleCnt = rt->desc().fSampleCnt; 1353 *effectiveSampleCnt = rt->desc().fSampleCnt;
1330 } 1354 }
1331 1355
1332 bool GrVkGpu::onGetReadPixelsInfo(GrSurface* srcSurface, int width, int height, size_t rowBytes, 1356 bool GrVkGpu::onGetReadPixelsInfo(GrSurface* srcSurface, int width, int height, size_t rowBytes,
1333 GrPixelConfig readConfig, DrawPreference* draw Preference, 1357 GrPixelConfig readConfig, DrawPreference* draw Preference,
1334 ReadPixelTempDrawInfo* tempDrawInfo) { 1358 ReadPixelTempDrawInfo* tempDrawInfo) {
1335 // Currently we don't handle draws, so if the caller wants/needs to do a dra w we need to fail 1359 if (srcSurface->config() == readConfig) {
1336 if (kNoDraw_DrawPreference != *drawPreference) { 1360 return true;
1337 return false;
1338 } 1361 }
1339 1362
1340 if (srcSurface->config() != readConfig) { 1363 if (this->vkCaps().isConfigRenderable(readConfig, false)) {
1341 // TODO: This should fall back to drawing or copying to change config of srcSurface to match 1364 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
1342 // that of readConfig. 1365 tempDrawInfo->fTempSurfaceDesc.fConfig = readConfig;
1343 return false; 1366 tempDrawInfo->fReadConfig = readConfig;
1367 return true;
1344 } 1368 }
1345 1369
1346 return true; 1370 return false;
1347 } 1371 }
1348 1372
1349 bool GrVkGpu::onReadPixels(GrSurface* surface, 1373 bool GrVkGpu::onReadPixels(GrSurface* surface,
1350 int left, int top, int width, int height, 1374 int left, int top, int width, int height,
1351 GrPixelConfig config, 1375 GrPixelConfig config,
1352 void* buffer, 1376 void* buffer,
1353 size_t rowBytes) { 1377 size_t rowBytes) {
1354 VkFormat pixelFormat; 1378 VkFormat pixelFormat;
1355 if (!GrPixelConfigToVkFormat(config, &pixelFormat)) { 1379 if (!GrPixelConfigToVkFormat(config, &pixelFormat)) {
1356 return false; 1380 return false;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 GrVkRenderTarget* target, 1467 GrVkRenderTarget* target,
1444 const SkIRect& bounds) { 1468 const SkIRect& bounds) {
1445 // Currently it is fine for us to always pass in 1 for the clear count even if no attachment 1469 // Currently it is fine for us to always pass in 1 for the clear count even if no attachment
1446 // uses it. In the current state, we also only use the LOAD_OP_CLEAR for the color attachment 1470 // uses it. In the current state, we also only use the LOAD_OP_CLEAR for the color attachment
1447 // which is always at the first attachment. 1471 // which is always at the first attachment.
1448 fCurrentCmdBuffer->beginRenderPass(this, renderPass, 1, colorClear, *target, bounds, true); 1472 fCurrentCmdBuffer->beginRenderPass(this, renderPass, 1, colorClear, *target, bounds, true);
1449 fCurrentCmdBuffer->executeCommands(this, buffer); 1473 fCurrentCmdBuffer->executeCommands(this, buffer);
1450 fCurrentCmdBuffer->endRenderPass(this); 1474 fCurrentCmdBuffer->endRenderPass(this);
1451 } 1475 }
1452 1476
OLDNEW
« no previous file with comments | « no previous file | tests/WritePixelsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698