Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
skgpu::graphite::VulkanRenderPass Class Reference

#include <VulkanRenderPass.h>

Inheritance diagram for skgpu::graphite::VulkanRenderPass:
skgpu::graphite::Resource

Classes

struct  VulkanRenderPassMetaData
 

Public Member Functions

VkRenderPass renderPass () const
 
VkExtent2D granularity ()
 
const char * getResourceType () const override
 
- Public Member Functions inherited from skgpu::graphite::Resource
 Resource (const Resource &)=delete
 
 Resource (Resource &&)=delete
 
Resourceoperator= (const Resource &)=delete
 
Resourceoperator= (Resource &&)=delete
 
void ref () const
 
void unref () const
 
void refCommandBuffer () const
 
void unrefCommandBuffer () const
 
Ownership ownership () const
 
skgpu::Budgeted budgeted () const
 
size_t gpuMemorySize () const
 
UniqueID uniqueID () const
 
virtual const char * getResourceType () const =0
 
std::string getLabel () const
 
void setLabel (std::string_view label)
 
bool wasDestroyed () const
 
const GraphiteResourceKeykey () const
 
void setKey (const GraphiteResourceKey &key)
 
void dumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump) const
 
virtual void prepareForReturnToCache (const std::function< void()> &takeRef)
 

Static Public Member Functions

static GraphiteResourceKey MakeRenderPassKey (const RenderPassDesc &, bool compatibleOnly)
 
static sk_sp< VulkanRenderPassMakeRenderPass (const VulkanSharedContext *, const RenderPassDesc &, bool compatibleOnly)
 
static void AddRenderPassInfoToKey (VulkanRenderPassMetaData &rpMetaData, ResourceKey::Builder &builder, int &builderIdx, bool compatibleOnly)
 

Static Public Attributes

static constexpr int kColorAttachmentIdx = 0
 
static constexpr int kColorResolveAttachmentIdx = 1
 
static constexpr int kDepthStencilAttachmentIdx = 2
 
static constexpr int kMaxExpectedAttachmentCount = kDepthStencilAttachmentIdx + 1
 

Additional Inherited Members

- Protected Member Functions inherited from skgpu::graphite::Resource
 Resource (const SharedContext *, Ownership, skgpu::Budgeted, size_t gpuMemorySize, bool commandBufferRefsAsUsageRefs=false)
 
virtual ~Resource ()
 
const SharedContextsharedContext () const
 
virtual void onDumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump, const char *dumpName) const
 
void setDeleteASAP ()
 

Detailed Description

Wrapper around VkRenderPass.

Definition at line 36 of file VulkanRenderPass.h.

Member Function Documentation

◆ AddRenderPassInfoToKey()

void skgpu::graphite::VulkanRenderPass::AddRenderPassInfoToKey ( VulkanRenderPassMetaData rpMetaData,
ResourceKey::Builder builder,
int builderIdx,
bool  compatibleOnly 
)
static

Definition at line 213 of file VulkanRenderPass.cpp.

216 {
217 populate_key(rpMetaData, builder, builderIdx, /*compatibleOnly=*/true);
218}

◆ getResourceType()

const char * skgpu::graphite::VulkanRenderPass::getResourceType ( ) const
inlineoverridevirtual

Implements skgpu::graphite::Resource.

Definition at line 61 of file VulkanRenderPass.h.

61{ return "Vulkan RenderPass"; }

◆ granularity()

VkExtent2D skgpu::graphite::VulkanRenderPass::granularity ( )
inline

Definition at line 59 of file VulkanRenderPass.h.

59{ return fGranularity; }

◆ MakeRenderPass()

sk_sp< VulkanRenderPass > skgpu::graphite::VulkanRenderPass::MakeRenderPass ( const VulkanSharedContext context,
const RenderPassDesc renderPassDesc,
bool  compatibleOnly 
)
static

Definition at line 268 of file VulkanRenderPass.cpp.

270 {
271 VkRenderPass renderPass;
273 auto& colorAttachmentTextureInfo = renderPassDesc.fColorAttachment.fTextureInfo;
274 auto& colorResolveAttachmentTextureInfo = renderPassDesc.fColorResolveAttachment.fTextureInfo;
275 auto& depthStencilAttachmentTextureInfo = renderPassDesc.fDepthStencilAttachment.fTextureInfo;
276 bool hasColorAttachment = colorAttachmentTextureInfo.isValid();
277 bool hasColorResolveAttachment = colorResolveAttachmentTextureInfo.isValid();
278 bool hasDepthStencilAttachment = depthStencilAttachmentTextureInfo.isValid();
279
281 // Create and track attachment references for the subpass.
282 VkAttachmentReference colorRef;
283 VkAttachmentReference resolveRef;
284 VkAttachmentReference resolveLoadInputRef;
285 VkAttachmentReference depthStencilRef;
286
287 bool loadMSAAFromResolve = false;
288 if (hasColorAttachment) {
289 VulkanTextureInfo colorAttachTexInfo;
290 colorAttachmentTextureInfo.getVulkanTextureInfo(&colorAttachTexInfo);
291 auto& colorAttachDesc = renderPassDesc.fColorAttachment;
292
293 colorRef.attachment = attachmentDescs.size();
294 VkAttachmentDescription& vkColorAttachDesc = attachmentDescs.push_back();
295 memset(&vkColorAttachDesc, 0, sizeof(VkAttachmentDescription));
297 &vkColorAttachDesc,
298 colorAttachTexInfo,
299 colorAttachDesc,
300 compatibleOnly ? LoadOp::kDiscard : colorAttachDesc.fLoadOp,
301 compatibleOnly ? StoreOp::kDiscard : colorAttachDesc.fStoreOp,
305
306 if (hasColorResolveAttachment) {
307 loadMSAAFromResolve = renderPassDesc.fColorResolveAttachment.fLoadOp == LoadOp::kLoad;
308 SkASSERT(renderPassDesc.fColorResolveAttachment.fStoreOp == StoreOp::kStore);
309 VulkanTextureInfo resolveAttachTexInfo;
310 colorResolveAttachmentTextureInfo.getVulkanTextureInfo(&resolveAttachTexInfo);
311 auto& resolveAttachDesc = renderPassDesc.fColorResolveAttachment;
312
313 resolveRef.attachment = attachmentDescs.size();
314 VkAttachmentDescription& vkResolveAttachDesc = attachmentDescs.push_back();
315 memset(&vkResolveAttachDesc, 0, sizeof(VkAttachmentDescription));
317 &vkResolveAttachDesc,
318 resolveAttachTexInfo,
319 resolveAttachDesc,
320 compatibleOnly ? LoadOp::kDiscard : resolveAttachDesc.fLoadOp,
321 compatibleOnly ? StoreOp::kDiscard : resolveAttachDesc.fStoreOp,
322 loadMSAAFromResolve ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
326 } else {
327 resolveRef.attachment = VK_ATTACHMENT_UNUSED;
329 }
330 } else {
331 SkASSERT(false);
334 resolveRef.attachment = VK_ATTACHMENT_UNUSED;
336 }
337
338 if (hasDepthStencilAttachment) {
339 VulkanTextureInfo depthStencilTexInfo;
340 depthStencilAttachmentTextureInfo.getVulkanTextureInfo(&depthStencilTexInfo);
341 auto& depthStencilAttachDesc = renderPassDesc.fDepthStencilAttachment;
342
343 depthStencilRef.attachment = attachmentDescs.size();
344 VkAttachmentDescription& vkDepthStencilAttachDesc = attachmentDescs.push_back();
346 &vkDepthStencilAttachDesc,
347 depthStencilTexInfo,
348 depthStencilAttachDesc,
349 compatibleOnly ? LoadOp::kDiscard : depthStencilAttachDesc.fLoadOp,
350 compatibleOnly ? StoreOp::kDiscard : depthStencilAttachDesc.fStoreOp,
354 } else {
355 depthStencilRef.attachment = VK_ATTACHMENT_UNUSED;
356 depthStencilRef.layout = VK_IMAGE_LAYOUT_UNDEFINED;
357 }
358
359 // Create VkRenderPass
360 VkRenderPassCreateInfo renderPassInfo;
361 memset(&renderPassInfo, 0, sizeof(VkRenderPassCreateInfo));
363 renderPassInfo.pNext = nullptr;
364 renderPassInfo.flags = 0;
365 renderPassInfo.subpassCount = loadMSAAFromResolve ? 2 : 1;
366
367 skia_private::TArray<VkSubpassDescription> subpassDescs(renderPassInfo.subpassCount);
368 memset(subpassDescs.begin(), 0, renderPassInfo.subpassCount * sizeof(VkSubpassDescription));
369
370 // If we are loading MSAA from resolve, that subpass must always be first.
372 if (loadMSAAFromResolve) {
373 resolveLoadInputRef.attachment = resolveRef.attachment;
375
376 VkSubpassDescription& loadSubpassDesc = subpassDescs.push_back();
377 memset(&loadSubpassDesc, 0, sizeof(VkSubpassDescription));
378 loadSubpassDesc.flags = 0;
380 loadSubpassDesc.inputAttachmentCount = 1;
381 loadSubpassDesc.pInputAttachments = &resolveLoadInputRef;
382 loadSubpassDesc.colorAttachmentCount = 1;
383 loadSubpassDesc.pColorAttachments = &colorRef;
384 loadSubpassDesc.pResolveAttachments = nullptr;
385 loadSubpassDesc.pDepthStencilAttachment = nullptr;
386 loadSubpassDesc.preserveAttachmentCount = 0;
387 loadSubpassDesc.pPreserveAttachments = nullptr;
388
389 // Set up the subpass dependency
390 const int mainSubpassIdx = loadMSAAFromResolve ? 1 : 0;
391 dependency.srcSubpass = 0;
392 dependency.dstSubpass = mainSubpassIdx;
393 dependency.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
397 dependency.dstAccessMask =
399 }
400
401 VkSubpassDescription& mainSubpassDesc = subpassDescs.push_back();
402 memset(&mainSubpassDesc, 0, sizeof(VkSubpassDescription));
403 mainSubpassDesc.flags = 0;
405 mainSubpassDesc.inputAttachmentCount = 0; // TODO: Add input attachment support in main subpass
406 mainSubpassDesc.pInputAttachments = nullptr;
407 mainSubpassDesc.colorAttachmentCount = 1;
408 mainSubpassDesc.pColorAttachments = &colorRef;
409 mainSubpassDesc.pResolveAttachments = &resolveRef;
410 mainSubpassDesc.pDepthStencilAttachment = &depthStencilRef;
411 mainSubpassDesc.preserveAttachmentCount = 0;
412 mainSubpassDesc.pPreserveAttachments = nullptr;
413
414 renderPassInfo.pSubpasses = subpassDescs.begin();
415 renderPassInfo.dependencyCount = loadMSAAFromResolve ? 1 : 0;
416 renderPassInfo.pDependencies = loadMSAAFromResolve ? &dependency : VK_NULL_HANDLE;
417 renderPassInfo.attachmentCount = attachmentDescs.size();
418 renderPassInfo.pAttachments = attachmentDescs.begin();
419
421 VULKAN_CALL_RESULT(context,
422 result,
423 CreateRenderPass(context->device(), &renderPassInfo, nullptr, &renderPass));
424 if (result != VK_SUCCESS) {
425 return nullptr;
426 }
428 VULKAN_CALL(context->interface(), GetRenderAreaGranularity(context->device(),
430 &granularity));
431 return sk_sp<VulkanRenderPass>(new VulkanRenderPass(context, renderPass, granularity));
432}
void setup_vk_attachment_description(VkAttachmentDescription *attachment, const AttachmentDesc &desc, VkImageLayout startLayout, VkImageLayout endLayout)
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define VULKAN_CALL(IFACE, X)
#define VULKAN_CALL_RESULT(SHARED_CONTEXT, RESULT, X)
int size() const
Definition: SkTArray.h:421
GAsyncResult * result
VkImageLayout layout
Definition: vulkan_core.h:3814
VkStructureType sType
Definition: vulkan_core.h:3853
const VkSubpassDescription * pSubpasses
Definition: vulkan_core.h:3859
const VkSubpassDependency * pDependencies
Definition: vulkan_core.h:3861
const VkAttachmentDescription * pAttachments
Definition: vulkan_core.h:3857
VkRenderPassCreateFlags flags
Definition: vulkan_core.h:3855
const VkAttachmentReference * pDepthStencilAttachment
Definition: vulkan_core.h:3837
VkSubpassDescriptionFlags flags
Definition: vulkan_core.h:3830
uint32_t inputAttachmentCount
Definition: vulkan_core.h:3832
const VkAttachmentReference * pResolveAttachments
Definition: vulkan_core.h:3836
const uint32_t * pPreserveAttachments
Definition: vulkan_core.h:3839
const VkAttachmentReference * pInputAttachments
Definition: vulkan_core.h:3833
uint32_t colorAttachmentCount
Definition: vulkan_core.h:3834
const VkAttachmentReference * pColorAttachments
Definition: vulkan_core.h:3835
VkPipelineBindPoint pipelineBindPoint
Definition: vulkan_core.h:3831
uint32_t preserveAttachmentCount
Definition: vulkan_core.h:3838
@ VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
Definition: vulkan_core.h:1334
@ VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
Definition: vulkan_core.h:1336
@ VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
Definition: vulkan_core.h:1333
@ VK_IMAGE_LAYOUT_UNDEFINED
Definition: vulkan_core.h:1331
@ VK_DEPENDENCY_BY_REGION_BIT
Definition: vulkan_core.h:2776
@ VK_PIPELINE_BIND_POINT_GRAPHICS
Definition: vulkan_core.h:2166
#define VK_ATTACHMENT_UNUSED
Definition: vulkan_core.h:124
VkResult
Definition: vulkan_core.h:140
@ VK_SUCCESS
Definition: vulkan_core.h:141
@ VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
Definition: vulkan_core.h:2208
@ VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
Definition: vulkan_core.h:2207
#define VK_NULL_HANDLE
Definition: vulkan_core.h:46
@ VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
Definition: vulkan_core.h:2445
@ VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
Definition: vulkan_core.h:240

◆ MakeRenderPassKey()

GraphiteResourceKey skgpu::graphite::VulkanRenderPass::MakeRenderPassKey ( const RenderPassDesc renderPassDesc,
bool  compatibleOnly 
)
static

Definition at line 197 of file VulkanRenderPass.cpp.

198 {
199
200 VulkanRenderPassMetaData rpMetaData = VulkanRenderPassMetaData(renderPassDesc);
201
203 GraphiteResourceKey key;
204 GraphiteResourceKey::Builder builder(&key, kType, rpMetaData.fUint32DataCnt, Shareable::kYes);
205
206 int startingIdx = 0;
207 populate_key(rpMetaData, builder, startingIdx, compatibleOnly);
208
209 builder.finish();
210 return key;
211}
const GraphiteResourceKey & key() const
Definition: Resource.h:156
DlVertices::Builder Builder
uint32_t ResourceType

◆ renderPass()

VkRenderPass skgpu::graphite::VulkanRenderPass::renderPass ( ) const
inline

Definition at line 54 of file VulkanRenderPass.h.

54 {
55 SkASSERT(fRenderPass != VK_NULL_HANDLE);
56 return fRenderPass;
57 }

Member Data Documentation

◆ kColorAttachmentIdx

constexpr int skgpu::graphite::VulkanRenderPass::kColorAttachmentIdx = 0
staticconstexpr

Definition at line 40 of file VulkanRenderPass.h.

◆ kColorResolveAttachmentIdx

constexpr int skgpu::graphite::VulkanRenderPass::kColorResolveAttachmentIdx = 1
staticconstexpr

Definition at line 41 of file VulkanRenderPass.h.

◆ kDepthStencilAttachmentIdx

constexpr int skgpu::graphite::VulkanRenderPass::kDepthStencilAttachmentIdx = 2
staticconstexpr

Definition at line 42 of file VulkanRenderPass.h.

◆ kMaxExpectedAttachmentCount

constexpr int skgpu::graphite::VulkanRenderPass::kMaxExpectedAttachmentCount = kDepthStencilAttachmentIdx + 1
staticconstexpr

Definition at line 44 of file VulkanRenderPass.h.


The documentation for this class was generated from the following files: