Chromium Code Reviews| 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" |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 674 VK_ACCESS_HOST_WRITE_BIT, | 674 VK_ACCESS_HOST_WRITE_BIT, |
| 675 VK_ACCESS_INDEX_READ_BIT, | 675 VK_ACCESS_INDEX_READ_BIT, |
| 676 VK_PIPELINE_STAGE_HOST_BIT, | 676 VK_PIPELINE_STAGE_HOST_BIT, |
| 677 VK_PIPELINE_STAGE_VERTEX_INPUT_BIT, | 677 VK_PIPELINE_STAGE_VERTEX_INPUT_BIT, |
| 678 false); | 678 false); |
| 679 | 679 |
| 680 fCurrentCmdBuffer->bindIndexBuffer(this, ibuf); | 680 fCurrentCmdBuffer->bindIndexBuffer(this, ibuf); |
| 681 } | 681 } |
| 682 } | 682 } |
| 683 | 683 |
| 684 void GrVkGpu::buildProgramDesc(GrProgramDesc* desc, | |
| 685 const GrPrimitiveProcessor& primProc, | |
| 686 const GrPipeline& pipeline) const { | |
| 687 if (!GrVkProgramDescBuilder::Build(desc, primProc, pipeline, *this->vkCaps() .glslCaps())) { | |
| 688 SkDEBUGFAIL("Failed to generate GL program descriptor"); | |
| 689 } | |
| 690 } | |
| 691 | |
| 692 //////////////////////////////////////////////////////////////////////////////// | 684 //////////////////////////////////////////////////////////////////////////////// |
| 693 | 685 |
| 694 GrStencilAttachment* GrVkGpu::createStencilAttachmentForRenderTarget(const GrRen derTarget* rt, | 686 GrStencilAttachment* GrVkGpu::createStencilAttachmentForRenderTarget(const GrRen derTarget* rt, |
| 695 int width, | 687 int width, |
| 696 int height) { | 688 int height) { |
| 697 SkASSERT(rt->asTexture()); | 689 SkASSERT(rt->asTexture()); |
| 698 SkASSERT(width >= rt->width()); | 690 SkASSERT(width >= rt->width()); |
| 699 SkASSERT(height >= rt->height()); | 691 SkASSERT(height >= rt->height()); |
| 700 | 692 |
| 701 int samples = rt->numStencilSamples(); | 693 int samples = rt->numStencilSamples(); |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1316 memcpy(top, bottom, tightRowBytes); | 1308 memcpy(top, bottom, tightRowBytes); |
| 1317 memcpy(bottom, tmpRow, tightRowBytes); | 1309 memcpy(bottom, tmpRow, tightRowBytes); |
| 1318 top += rowBytes; | 1310 top += rowBytes; |
| 1319 bottom -= rowBytes; | 1311 bottom -= rowBytes; |
| 1320 } | 1312 } |
| 1321 } | 1313 } |
| 1322 | 1314 |
| 1323 return true; | 1315 return true; |
| 1324 } | 1316 } |
| 1325 | 1317 |
| 1326 void GrVkGpu::onDraw(const DrawArgs& args, const GrNonInstancedVertices& vertice s) { | 1318 void GrVkGpu::onDraw(const GrPipeline& pipeline, |
| 1327 GrRenderTarget* rt = args.fPipeline->getRenderTarget(); | 1319 const GrPrimitiveProcessor& primProc, |
| 1320 GrPrimitiveType primitiveType, | |
| 1321 const GrVertices* vertArray, | |
| 1322 int drawCount) { | |
| 1323 GrRenderTarget* rt = pipeline.getRenderTarget(); | |
| 1328 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(rt); | 1324 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(rt); |
| 1329 const GrVkRenderPass* renderPass = vkRT->simpleRenderPass(); | 1325 const GrVkRenderPass* renderPass = vkRT->simpleRenderPass(); |
| 1330 SkASSERT(renderPass); | 1326 SkASSERT(renderPass); |
| 1331 | 1327 |
| 1332 GrVkProgram* program = GrVkProgramBuilder::CreateProgram(this, args, | 1328 |
| 1333 vertices.primitiveT ype(), | 1329 // Get GrGLProgramDesc |
|
bsalomon
2016/03/16 20:07:22
?
egdaniel
2016/03/17 15:09:36
Done.
| |
| 1330 GrVkProgramDesc desc; | |
| 1331 if (!GrVkProgramDescBuilder::Build(&desc, primProc, pipeline, *this->vkCaps( ).glslCaps())) { | |
| 1332 GrCapsDebugf(this->caps(), "Failed to vk program descriptor!\n"); | |
| 1333 return; | |
| 1334 } | |
| 1335 GrVkProgram* program = GrVkProgramBuilder::CreateProgram(this, | |
| 1336 pipeline, | |
| 1337 primProc, | |
| 1338 primitiveType, | |
| 1339 desc, | |
| 1334 *renderPass); | 1340 *renderPass); |
| 1335 | 1341 |
| 1336 if (!program) { | 1342 if (!program) { |
| 1337 return; | 1343 return; |
| 1338 } | 1344 } |
| 1339 | 1345 |
| 1340 program->setData(this, *args.fPrimitiveProcessor, *args.fPipeline); | 1346 program->setData(this, primProc, pipeline); |
| 1341 | |
| 1342 fCurrentCmdBuffer->beginRenderPass(this, renderPass, *vkRT); | |
| 1343 | 1347 |
| 1344 program->bind(this, fCurrentCmdBuffer); | 1348 program->bind(this, fCurrentCmdBuffer); |
| 1345 | 1349 |
| 1346 this->bindGeometry(*args.fPrimitiveProcessor, vertices); | |
| 1347 | |
| 1348 // Change layout of our render target so it can be used as the color attachm ent | 1350 // Change layout of our render target so it can be used as the color attachm ent |
| 1349 VkImageLayout layout = vkRT->currentLayout(); | 1351 VkImageLayout layout = vkRT->currentLayout(); |
| 1350 // Our color attachment is purely a destination and won't be read so don't n eed to flush or | 1352 // Our color attachment is purely a destination and won't be read so don't n eed to flush or |
| 1351 // invalidate any caches | 1353 // invalidate any caches |
| 1352 VkPipelineStageFlags srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(l ayout); | 1354 VkPipelineStageFlags srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(l ayout); |
| 1353 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; | 1355 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; |
| 1354 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(layout); | 1356 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(layout); |
| 1355 VkAccessFlags dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; | 1357 VkAccessFlags dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; |
| 1356 vkRT->setImageLayout(this, | 1358 vkRT->setImageLayout(this, |
| 1357 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, | 1359 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 1358 srcAccessMask, | 1360 srcAccessMask, |
| 1359 dstAccessMask, | 1361 dstAccessMask, |
| 1360 srcStageMask, | 1362 srcStageMask, |
| 1361 dstStageMask, | 1363 dstStageMask, |
| 1362 false); | 1364 false); |
| 1363 | 1365 |
| 1364 // If we are using a stencil attachment we also need to update its layout | 1366 // If we are using a stencil attachment we also need to update its layout |
| 1365 if (!args.fPipeline->getStencil().isDisabled()) { | 1367 if (!pipeline.getStencil().isDisabled()) { |
| 1366 GrStencilAttachment* stencil = vkRT->renderTargetPriv().getStencilAttach ment(); | 1368 GrStencilAttachment* stencil = vkRT->renderTargetPriv().getStencilAttach ment(); |
| 1367 GrVkStencilAttachment* vkStencil = (GrVkStencilAttachment*)stencil; | 1369 GrVkStencilAttachment* vkStencil = (GrVkStencilAttachment*)stencil; |
| 1368 VkImageLayout origDstLayout = vkStencil->currentLayout(); | 1370 VkImageLayout origDstLayout = vkStencil->currentLayout(); |
| 1369 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(origDstL ayout); | 1371 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(origDstL ayout); |
| 1370 VkAccessFlags dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_B IT | | 1372 VkAccessFlags dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_B IT | |
| 1371 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BI T; | 1373 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; |
| 1372 VkPipelineStageFlags srcStageMask = | 1374 VkPipelineStageFlags srcStageMask = |
| 1373 GrVkMemory::LayoutToPipelineStageFlags(origDstLayout); | 1375 GrVkMemory::LayoutToPipelineStageFlags(origDstLayout); |
| 1374 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; | 1376 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; |
| 1375 vkStencil->setImageLayout(this, | 1377 vkStencil->setImageLayout(this, |
| 1376 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIM AL, | 1378 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIM AL, |
| 1377 srcAccessMask, | 1379 srcAccessMask, |
| 1378 dstAccessMask, | 1380 dstAccessMask, |
| 1379 srcStageMask, | 1381 srcStageMask, |
| 1380 dstStageMask, | 1382 dstStageMask, |
| 1381 false); | 1383 false); |
| 1382 } | 1384 } |
| 1383 | 1385 |
| 1384 if (vertices.isIndexed()) { | 1386 fCurrentCmdBuffer->beginRenderPass(this, renderPass, *vkRT); |
| 1385 fCurrentCmdBuffer->drawIndexed(this, | 1387 |
| 1386 vertices.indexCount(), | 1388 for (int i = 0; i < drawCount; ++i) { |
| 1387 1, | 1389 if (GrXferBarrierType barrierType = pipeline.xferBarrierType(*this->caps ())) { |
| 1388 vertices.startIndex(), | 1390 this->xferBarrier(pipeline.getRenderTarget(), barrierType); |
| 1389 vertices.startVertex(), | 1391 } |
| 1390 0); | 1392 |
| 1391 } else { | 1393 const GrVertices& vertices = vertArray[i]; |
| 1392 fCurrentCmdBuffer->draw(this, vertices.vertexCount(), 1, vertices.startV ertex(), 0); | 1394 GrVertices::Iterator iter; |
| 1395 const GrNonInstancedVertices* verts = iter.init(vertices); | |
| 1396 do { | |
| 1397 | |
| 1398 this->bindGeometry(primProc, *verts); | |
| 1399 | |
| 1400 if (vertices.isIndexed()) { | |
| 1401 fCurrentCmdBuffer->drawIndexed(this, | |
| 1402 verts->indexCount(), | |
| 1403 1, | |
| 1404 verts->startIndex(), | |
| 1405 verts->startVertex(), | |
| 1406 0); | |
| 1407 } else { | |
| 1408 fCurrentCmdBuffer->draw(this, verts->vertexCount(), 1, verts->st artVertex(), 0); | |
| 1409 } | |
| 1410 | |
| 1411 fStats.incNumDraws(); | |
| 1412 } while ((verts = iter.next())); | |
| 1393 } | 1413 } |
| 1394 | 1414 |
| 1395 fCurrentCmdBuffer->endRenderPass(this); | 1415 fCurrentCmdBuffer->endRenderPass(this); |
| 1396 | 1416 |
| 1397 // Technically we don't have to call this here (since there is a safety chec k in program:setData | 1417 // Technically we don't have to call this here (since there is a safety chec k in program:setData |
| 1398 // but this will allow for quicker freeing of resources if the program sits in a cache for a | 1418 // but this will allow for quicker freeing of resources if the program sits in a cache for a |
| 1399 // while. | 1419 // while. |
| 1400 program->freeTempResources(this); | 1420 program->freeTempResources(this); |
| 1401 // This free will go away once we setup a program cache, and then the cache will be responsible | 1421 // This free will go away once we setup a program cache, and then the cache will be responsible |
| 1402 // for call freeGpuResources. | 1422 // for call freeGpuResources. |
| 1403 program->freeGPUResources(this); | 1423 program->freeGPUResources(this); |
| 1404 program->unref(); | 1424 program->unref(); |
| 1405 | 1425 |
| 1406 #if SWAP_PER_DRAW | 1426 #if SWAP_PER_DRAW |
| 1407 glFlush(); | 1427 glFlush(); |
| 1408 #if defined(SK_BUILD_FOR_MAC) | 1428 #if defined(SK_BUILD_FOR_MAC) |
| 1409 aglSwapBuffers(aglGetCurrentContext()); | 1429 aglSwapBuffers(aglGetCurrentContext()); |
| 1410 int set_a_break_pt_here = 9; | 1430 int set_a_break_pt_here = 9; |
| 1411 aglSwapBuffers(aglGetCurrentContext()); | 1431 aglSwapBuffers(aglGetCurrentContext()); |
| 1412 #elif defined(SK_BUILD_FOR_WIN32) | 1432 #elif defined(SK_BUILD_FOR_WIN32) |
| 1413 SwapBuf(); | 1433 SwapBuf(); |
| 1414 int set_a_break_pt_here = 9; | 1434 int set_a_break_pt_here = 9; |
| 1415 SwapBuf(); | 1435 SwapBuf(); |
| 1416 #endif | 1436 #endif |
| 1417 #endif | 1437 #endif |
| 1418 } | 1438 } |
| 1419 | 1439 |
| OLD | NEW |