| OLD | NEW |
| 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" |
| 11 #include "GrGeometryProcessor.h" | 11 #include "GrGeometryProcessor.h" |
| 12 #include "GrGpuResourceCacheAccess.h" | 12 #include "GrGpuResourceCacheAccess.h" |
| 13 #include "GrMesh.h" | 13 #include "GrMesh.h" |
| 14 #include "GrPipeline.h" | 14 #include "GrPipeline.h" |
| 15 #include "GrRenderTargetPriv.h" | 15 #include "GrRenderTargetPriv.h" |
| 16 #include "GrSurfacePriv.h" | 16 #include "GrSurfacePriv.h" |
| 17 #include "GrTexturePriv.h" | 17 #include "GrTexturePriv.h" |
| 18 | 18 |
| 19 #include "GrVkCommandBuffer.h" | 19 #include "GrVkCommandBuffer.h" |
| 20 #include "GrVkImage.h" | 20 #include "GrVkImage.h" |
| 21 #include "GrVkIndexBuffer.h" | 21 #include "GrVkIndexBuffer.h" |
| 22 #include "GrVkMemory.h" | 22 #include "GrVkMemory.h" |
| 23 #include "GrVkPipeline.h" | 23 #include "GrVkPipeline.h" |
| 24 #include "GrVkProgram.h" | 24 #include "GrVkPipelineState.h" |
| 25 #include "GrVkProgramBuilder.h" | |
| 26 #include "GrVkProgramDesc.h" | |
| 27 #include "GrVkRenderPass.h" | 25 #include "GrVkRenderPass.h" |
| 28 #include "GrVkResourceProvider.h" | 26 #include "GrVkResourceProvider.h" |
| 29 #include "GrVkTexture.h" | 27 #include "GrVkTexture.h" |
| 30 #include "GrVkTextureRenderTarget.h" | 28 #include "GrVkTextureRenderTarget.h" |
| 31 #include "GrVkTransferBuffer.h" | 29 #include "GrVkTransferBuffer.h" |
| 32 #include "GrVkVertexBuffer.h" | 30 #include "GrVkVertexBuffer.h" |
| 33 | 31 |
| 34 #include "SkConfig8888.h" | 32 #include "SkConfig8888.h" |
| 35 | 33 |
| 36 #include "vk/GrVkInterface.h" | 34 #include "vk/GrVkInterface.h" |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 imageDesc.fLevels = 1; | 469 imageDesc.fLevels = 1; |
| 472 imageDesc.fSamples = 1; | 470 imageDesc.fSamples = 1; |
| 473 imageDesc.fImageTiling = linearTiling ? VK_IMAGE_TILING_LINEAR : VK_IMAGE_TI
LING_OPTIMAL; | 471 imageDesc.fImageTiling = linearTiling ? VK_IMAGE_TILING_LINEAR : VK_IMAGE_TI
LING_OPTIMAL; |
| 474 imageDesc.fUsageFlags = usageFlags; | 472 imageDesc.fUsageFlags = usageFlags; |
| 475 imageDesc.fMemProps = memProps; | 473 imageDesc.fMemProps = memProps; |
| 476 | 474 |
| 477 GrVkTexture* tex; | 475 GrVkTexture* tex; |
| 478 if (renderTarget) { | 476 if (renderTarget) { |
| 479 tex = GrVkTextureRenderTarget::CreateNewTextureRenderTarget(this, desc,
lifeCycle, | 477 tex = GrVkTextureRenderTarget::CreateNewTextureRenderTarget(this, desc,
lifeCycle, |
| 480 imageDesc); | 478 imageDesc); |
| 481 #if 0 | |
| 482 // This clear can be included to fix warning described in htttps://bugs.
skia.org/5045 | |
| 483 // Obviously we do not want to be clearling needlessly every time we cre
ate a render target. | |
| 484 SkIRect rect = SkIRect::MakeWH(tex->width(), tex->height()); | |
| 485 this->clear(rect, GrColor_TRANSPARENT_BLACK, tex->asRenderTarget()); | |
| 486 #endif | |
| 487 } else { | 479 } else { |
| 488 tex = GrVkTexture::CreateNewTexture(this, desc, lifeCycle, imageDesc); | 480 tex = GrVkTexture::CreateNewTexture(this, desc, lifeCycle, imageDesc); |
| 489 } | 481 } |
| 490 | 482 |
| 491 if (!tex) { | 483 if (!tex) { |
| 492 return nullptr; | 484 return nullptr; |
| 493 } | 485 } |
| 494 | 486 |
| 495 // TODO: We're ignoring MIP levels here. | 487 // TODO: We're ignoring MIP levels here. |
| 496 if (!texels.empty()) { | 488 if (!texels.empty()) { |
| (...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 memcpy(tmpRow, top, tightRowBytes); | 1276 memcpy(tmpRow, top, tightRowBytes); |
| 1285 memcpy(top, bottom, tightRowBytes); | 1277 memcpy(top, bottom, tightRowBytes); |
| 1286 memcpy(bottom, tmpRow, tightRowBytes); | 1278 memcpy(bottom, tmpRow, tightRowBytes); |
| 1287 top += rowBytes; | 1279 top += rowBytes; |
| 1288 bottom -= rowBytes; | 1280 bottom -= rowBytes; |
| 1289 } | 1281 } |
| 1290 } | 1282 } |
| 1291 | 1283 |
| 1292 return true; | 1284 return true; |
| 1293 } | 1285 } |
| 1294 | |
| 1295 bool GrVkGpu::prepareDrawState(const GrPipeline& pipeline, | 1286 bool GrVkGpu::prepareDrawState(const GrPipeline& pipeline, |
| 1296 const GrPrimitiveProcessor& primProc, | 1287 const GrPrimitiveProcessor& primProc, |
| 1297 GrPrimitiveType primitiveType, | 1288 GrPrimitiveType primitiveType, |
| 1298 const GrVkRenderPass& renderPass, | 1289 const GrVkRenderPass& renderPass, |
| 1299 GrVkProgram** program) { | 1290 GrVkPipelineState** pipelineState) { |
| 1300 // Get GrVkProgramDesc | 1291 *pipelineState = fResourceProvider.findOrCreateCompatiblePipelineState(pipel
ine, |
| 1301 GrVkProgramDesc desc; | 1292 primP
roc, |
| 1302 if (!GrVkProgramDescBuilder::Build(&desc, primProc, pipeline, *this->vkCaps(
).glslCaps())) { | 1293 primi
tiveType, |
| 1303 GrCapsDebugf(this->caps(), "Failed to vk program descriptor!\n"); | 1294 rende
rPass); |
| 1295 if (!pipelineState) { |
| 1304 return false; | 1296 return false; |
| 1305 } | 1297 } |
| 1306 | 1298 |
| 1307 *program = GrVkProgramBuilder::CreateProgram(this, | 1299 (*pipelineState)->setData(this, primProc, pipeline); |
| 1308 pipeline, | |
| 1309 primProc, | |
| 1310 primitiveType, | |
| 1311 desc, | |
| 1312 renderPass); | |
| 1313 if (!program) { | |
| 1314 return false; | |
| 1315 } | |
| 1316 | 1300 |
| 1317 (*program)->setData(this, primProc, pipeline); | 1301 (*pipelineState)->bind(this, fCurrentCmdBuffer); |
| 1318 | |
| 1319 (*program)->bind(this, fCurrentCmdBuffer); | |
| 1320 | 1302 |
| 1321 GrVkPipeline::SetDynamicState(this, fCurrentCmdBuffer, pipeline); | 1303 GrVkPipeline::SetDynamicState(this, fCurrentCmdBuffer, pipeline); |
| 1322 | 1304 |
| 1323 return true; | 1305 return true; |
| 1324 } | 1306 } |
| 1325 | 1307 |
| 1326 void GrVkGpu::onDraw(const GrPipeline& pipeline, | 1308 void GrVkGpu::onDraw(const GrPipeline& pipeline, |
| 1327 const GrPrimitiveProcessor& primProc, | 1309 const GrPrimitiveProcessor& primProc, |
| 1328 const GrMesh* meshes, | 1310 const GrMesh* meshes, |
| 1329 int meshCount) { | 1311 int meshCount) { |
| 1330 if (!meshCount) { | 1312 if (!meshCount) { |
| 1331 return; | 1313 return; |
| 1332 } | 1314 } |
| 1333 GrRenderTarget* rt = pipeline.getRenderTarget(); | 1315 GrRenderTarget* rt = pipeline.getRenderTarget(); |
| 1334 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(rt); | 1316 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(rt); |
| 1335 const GrVkRenderPass* renderPass = vkRT->simpleRenderPass(); | 1317 const GrVkRenderPass* renderPass = vkRT->simpleRenderPass(); |
| 1336 SkASSERT(renderPass); | 1318 SkASSERT(renderPass); |
| 1337 | 1319 |
| 1338 fCurrentCmdBuffer->beginRenderPass(this, renderPass, *vkRT); | 1320 fCurrentCmdBuffer->beginRenderPass(this, renderPass, *vkRT); |
| 1339 | 1321 |
| 1340 GrVkProgram* program = nullptr; | 1322 GrVkPipelineState* pipelineState = nullptr; |
| 1341 GrPrimitiveType primitiveType = meshes[0].primitiveType(); | 1323 GrPrimitiveType primitiveType = meshes[0].primitiveType(); |
| 1342 if (!this->prepareDrawState(pipeline, primProc, primitiveType, *renderPass,
&program)) { | 1324 if (!this->prepareDrawState(pipeline, primProc, primitiveType, *renderPass,
&pipelineState)) { |
| 1343 return; | 1325 return; |
| 1344 } | 1326 } |
| 1345 | 1327 |
| 1346 // Change layout of our render target so it can be used as the color attachm
ent | 1328 // Change layout of our render target so it can be used as the color attachm
ent |
| 1347 VkImageLayout layout = vkRT->currentLayout(); | 1329 VkImageLayout layout = vkRT->currentLayout(); |
| 1348 // Our color attachment is purely a destination and won't be read so don't n
eed to flush or | 1330 // Our color attachment is purely a destination and won't be read so don't n
eed to flush or |
| 1349 // invalidate any caches | 1331 // invalidate any caches |
| 1350 VkPipelineStageFlags srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(l
ayout); | 1332 VkPipelineStageFlags srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(l
ayout); |
| 1351 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; | 1333 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; |
| 1352 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(layout); | 1334 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(layout); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1384 if (GrXferBarrierType barrierType = pipeline.xferBarrierType(*this->caps
())) { | 1366 if (GrXferBarrierType barrierType = pipeline.xferBarrierType(*this->caps
())) { |
| 1385 this->xferBarrier(pipeline.getRenderTarget(), barrierType); | 1367 this->xferBarrier(pipeline.getRenderTarget(), barrierType); |
| 1386 } | 1368 } |
| 1387 | 1369 |
| 1388 const GrMesh& mesh = meshes[i]; | 1370 const GrMesh& mesh = meshes[i]; |
| 1389 GrMesh::Iterator iter; | 1371 GrMesh::Iterator iter; |
| 1390 const GrNonInstancedMesh* nonIdxMesh = iter.init(mesh); | 1372 const GrNonInstancedMesh* nonIdxMesh = iter.init(mesh); |
| 1391 do { | 1373 do { |
| 1392 if (nonIdxMesh->primitiveType() != primitiveType) { | 1374 if (nonIdxMesh->primitiveType() != primitiveType) { |
| 1393 // Technically we don't have to call this here (since there is a
safety check in | 1375 // Technically we don't have to call this here (since there is a
safety check in |
| 1394 // program:setData but this will allow for quicker freeing of re
sources if the | 1376 // pipelineState:setData but this will allow for quicker freeing
of resources if the |
| 1395 // program sits in a cache for a while. | 1377 // pipelineState sits in a cache for a while. |
| 1396 program->freeTempResources(this); | 1378 pipelineState->freeTempResources(this); |
| 1397 // This free will go away once we setup a program cache, and the
n the cache will be | 1379 pipelineState->unref(); |
| 1398 // responsible for call freeGpuResources. | 1380 SkDEBUGCODE(pipelineState = nullptr); |
| 1399 program->freeGPUResources(this); | |
| 1400 program->unref(); | |
| 1401 SkDEBUGCODE(program = nullptr); | |
| 1402 primitiveType = nonIdxMesh->primitiveType(); | 1381 primitiveType = nonIdxMesh->primitiveType(); |
| 1403 if (!this->prepareDrawState(pipeline, primProc, primitiveType, *
renderPass, | 1382 if (!this->prepareDrawState(pipeline, primProc, primitiveType, *
renderPass, |
| 1404 &program)) { | 1383 &pipelineState)) { |
| 1405 return; | 1384 return; |
| 1406 } | 1385 } |
| 1407 } | 1386 } |
| 1408 SkASSERT(program); | 1387 SkASSERT(pipelineState); |
| 1409 this->bindGeometry(primProc, *nonIdxMesh); | 1388 this->bindGeometry(primProc, *nonIdxMesh); |
| 1410 | 1389 |
| 1411 if (nonIdxMesh->isIndexed()) { | 1390 if (nonIdxMesh->isIndexed()) { |
| 1412 fCurrentCmdBuffer->drawIndexed(this, | 1391 fCurrentCmdBuffer->drawIndexed(this, |
| 1413 nonIdxMesh->indexCount(), | 1392 nonIdxMesh->indexCount(), |
| 1414 1, | 1393 1, |
| 1415 nonIdxMesh->startIndex(), | 1394 nonIdxMesh->startIndex(), |
| 1416 nonIdxMesh->startVertex(), | 1395 nonIdxMesh->startVertex(), |
| 1417 0); | 1396 0); |
| 1418 } else { | 1397 } else { |
| 1419 fCurrentCmdBuffer->draw(this, | 1398 fCurrentCmdBuffer->draw(this, |
| 1420 nonIdxMesh->vertexCount(), | 1399 nonIdxMesh->vertexCount(), |
| 1421 1, | 1400 1, |
| 1422 nonIdxMesh->startVertex(), | 1401 nonIdxMesh->startVertex(), |
| 1423 0); | 1402 0); |
| 1424 } | 1403 } |
| 1425 | 1404 |
| 1426 fStats.incNumDraws(); | 1405 fStats.incNumDraws(); |
| 1427 } while ((nonIdxMesh = iter.next())); | 1406 } while ((nonIdxMesh = iter.next())); |
| 1428 } | 1407 } |
| 1429 | 1408 |
| 1430 fCurrentCmdBuffer->endRenderPass(this); | 1409 fCurrentCmdBuffer->endRenderPass(this); |
| 1431 | 1410 |
| 1432 // Technically we don't have to call this here (since there is a safety chec
k in program:setData | 1411 // Technically we don't have to call this here (since there is a safety chec
k in |
| 1433 // but this will allow for quicker freeing of resources if the program sits
in a cache for a | 1412 // pipelineState:setData but this will allow for quicker freeing of resource
s if the |
| 1434 // while. | 1413 // pipelineState sits in a cache for a while. |
| 1435 program->freeTempResources(this); | 1414 pipelineState->freeTempResources(this); |
| 1436 // This free will go away once we setup a program cache, and then the cache
will be responsible | 1415 pipelineState->unref(); |
| 1437 // for call freeGpuResources. | |
| 1438 program->freeGPUResources(this); | |
| 1439 program->unref(); | |
| 1440 | 1416 |
| 1441 #if SWAP_PER_DRAW | 1417 #if SWAP_PER_DRAW |
| 1442 glFlush(); | 1418 glFlush(); |
| 1443 #if defined(SK_BUILD_FOR_MAC) | 1419 #if defined(SK_BUILD_FOR_MAC) |
| 1444 aglSwapBuffers(aglGetCurrentContext()); | 1420 aglSwapBuffers(aglGetCurrentContext()); |
| 1445 int set_a_break_pt_here = 9; | 1421 int set_a_break_pt_here = 9; |
| 1446 aglSwapBuffers(aglGetCurrentContext()); | 1422 aglSwapBuffers(aglGetCurrentContext()); |
| 1447 #elif defined(SK_BUILD_FOR_WIN32) | 1423 #elif defined(SK_BUILD_FOR_WIN32) |
| 1448 SwapBuf(); | 1424 SwapBuf(); |
| 1449 int set_a_break_pt_here = 9; | 1425 int set_a_break_pt_here = 9; |
| 1450 SwapBuf(); | 1426 SwapBuf(); |
| 1451 #endif | 1427 #endif |
| 1452 #endif | 1428 #endif |
| 1453 } | 1429 } |
| 1454 | 1430 |
| OLD | NEW |