Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
GrVkMSAALoadManager Class Reference

#include <GrVkMSAALoadManager.h>

Public Member Functions

 GrVkMSAALoadManager ()
 
 ~GrVkMSAALoadManager ()
 
bool loadMSAAFromResolve (GrVkGpu *gpu, GrVkCommandBuffer *commandBuffer, const GrVkRenderPass &renderPass, GrAttachment *dst, GrVkImage *src, const SkIRect &srcRect)
 
void destroyResources (GrVkGpu *gpu)
 

Detailed Description

Definition at line 24 of file GrVkMSAALoadManager.h.

Constructor & Destructor Documentation

◆ GrVkMSAALoadManager()

GrVkMSAALoadManager::GrVkMSAALoadManager ( )

Definition at line 25 of file GrVkMSAALoadManager.cpp.

26 : fVertShaderModule(VK_NULL_HANDLE)
27 , fFragShaderModule(VK_NULL_HANDLE)
28 , fPipelineLayout(VK_NULL_HANDLE) {}
#define VK_NULL_HANDLE
Definition: vulkan_core.h:46

◆ ~GrVkMSAALoadManager()

GrVkMSAALoadManager::~GrVkMSAALoadManager ( )

Definition at line 30 of file GrVkMSAALoadManager.cpp.

30{}

Member Function Documentation

◆ destroyResources()

void GrVkMSAALoadManager::destroyResources ( GrVkGpu gpu)

Definition at line 220 of file GrVkMSAALoadManager.cpp.

220 {
221 if (fVertShaderModule != VK_NULL_HANDLE) {
222 GR_VK_CALL(gpu->vkInterface(),
223 DestroyShaderModule(gpu->device(), fVertShaderModule, nullptr));
224 fVertShaderModule = VK_NULL_HANDLE;
225 }
226
227 if (fFragShaderModule != VK_NULL_HANDLE) {
228 GR_VK_CALL(gpu->vkInterface(),
229 DestroyShaderModule(gpu->device(), fFragShaderModule, nullptr));
230 fFragShaderModule = VK_NULL_HANDLE;
231 }
232
233 if (fPipelineLayout != VK_NULL_HANDLE) {
234 GR_VK_CALL(gpu->vkInterface(),
235 DestroyPipelineLayout(gpu->device(), fPipelineLayout, nullptr));
236 fPipelineLayout = VK_NULL_HANDLE;
237 }
238}
#define GR_VK_CALL(IFACE, X)
Definition: GrVkUtil.h:24
const skgpu::VulkanInterface * vkInterface() const
Definition: GrVkGpu.h:60
VkDevice device() const
Definition: GrVkGpu.h:71

◆ loadMSAAFromResolve()

bool GrVkMSAALoadManager::loadMSAAFromResolve ( GrVkGpu gpu,
GrVkCommandBuffer commandBuffer,
const GrVkRenderPass renderPass,
GrAttachment dst,
GrVkImage src,
const SkIRect srcRect 
)

Definition at line 117 of file GrVkMSAALoadManager.cpp.

122 {
123 if (!dst) {
124 return false;
125 }
126 if (!src || !src->supportsInputAttachmentUsage()) {
127 return false;
128 }
129
130 if (VK_NULL_HANDLE == fVertShaderModule) {
131 SkASSERT(fFragShaderModule == VK_NULL_HANDLE && fPipelineLayout == VK_NULL_HANDLE);
132 if (!this->createMSAALoadProgram(gpu)) {
133 SkDebugf("Failed to create copy program.\n");
134 return false;
135 }
136 }
137 SkASSERT(fPipelineLayout != VK_NULL_HANDLE);
138
139 GrVkResourceProvider& resourceProv = gpu->resourceProvider();
140
142 resourceProv.findOrCreateMSAALoadPipeline(renderPass, dst->numSamples(),
143 fShaderStageInfo, fPipelineLayout);
144 if (!pipeline) {
145 return false;
146 }
147 commandBuffer->bindPipeline(gpu, std::move(pipeline));
148
149 // Set Dynamic viewport and stencil
150 // We always use one viewport the size of the RT
151 VkViewport viewport;
152 viewport.x = 0.0f;
153 viewport.y = 0.0f;
154 viewport.width = SkIntToScalar(dst->width());
155 viewport.height = SkIntToScalar(dst->height());
156 viewport.minDepth = 0.0f;
157 viewport.maxDepth = 1.0f;
158 commandBuffer->setViewport(gpu, 0, 1, &viewport);
159
160 // We assume the scissor is not enabled so just set it to the whole RT
161 VkRect2D scissor;
162 scissor.extent.width = dst->width();
163 scissor.extent.height = dst->height();
164 scissor.offset.x = 0;
165 scissor.offset.y = 0;
166 commandBuffer->setScissor(gpu, 0, 1, &scissor);
167
168 // Update and bind uniform descriptor set
169 int w = rect.width();
170 int h = rect.height();
171
172 // dst rect edges in NDC (-1 to 1)
173 int dw = dst->width();
174 int dh = dst->height();
175 float dx0 = 2.f * rect.fLeft / dw - 1.f;
176 float dx1 = 2.f * (rect.fLeft + w) / dw - 1.f;
177 float dy0 = 2.f * rect.fTop / dh - 1.f;
178 float dy1 = 2.f * (rect.fTop + h) / dh - 1.f;
179
180 float uniData[] = {dx1 - dx0, dy1 - dy0, dx0, dy0}; // posXform
181
182 GrResourceProvider* resourceProvider = gpu->getContext()->priv().resourceProvider();
183 // TODO: Is it worth holding onto the last used uniform buffer and tracking the width, height,
184 // dst width, and dst height so that we can use the buffer again without having to update the
185 // data?
186 sk_sp<GrGpuBuffer> uniformBuffer = resourceProvider->createBuffer(uniData,
187 sizeof(uniData),
190 if (!uniformBuffer) {
191 return false;
192 }
193 GrVkBuffer* vkUniformBuffer = static_cast<GrVkBuffer*>(uniformBuffer.get());
195 commandBuffer->bindDescriptorSets(gpu, fPipelineLayout,
197 /*setCount=*/1, vkUniformBuffer->uniformDescriptorSet(),
198 /*dynamicOffsetCount=*/0, /*dynamicOffsets=*/nullptr);
199 commandBuffer->addGrBuffer(std::move(uniformBuffer));
200
201 // Update the input descriptor set
202 gr_rp<const GrVkDescriptorSet> inputDS = src->inputDescSetForMSAALoad(gpu);
203 if (!inputDS) {
204 return false;
205 }
206 commandBuffer->bindDescriptorSets(gpu, fPipelineLayout,
207 GrVkUniformHandler::kInputDescSet, /*setCount=*/1,
208 inputDS->descriptorSet(),
209 /*dynamicOffsetCount=*/0, /*dynamicOffsets=*/nullptr);
210
211 // We don't need to add the src and dst resources here since those are all tracked by the main
212 // render pass code out in GrVkOpsRenderPass and GrVkRenderTarget::adResources.
213 commandBuffer->addRecycledResource(std::move(inputDS));
214
215 commandBuffer->draw(gpu, 4, 1, 0, 0);
216
217 return true;
218}
@ kDynamic_GrAccessPattern
Definition: GrTypesPriv.h:426
#define SkASSERT(cond)
Definition: SkAssert.h:116
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define SkIntToScalar(x)
Definition: SkScalar.h:57
GrResourceProvider * resourceProvider()
GrDirectContextPriv priv()
GrDirectContext * getContext()
Definition: GrGpu.h:67
sk_sp< GrGpuBuffer > createBuffer(size_t size, GrGpuBufferType, GrAccessPattern, ZeroInit)
const VkDescriptorSet * uniformDescriptorSet() const
Definition: GrVkBuffer.cpp:359
void setViewport(const GrVkGpu *gpu, uint32_t firstViewport, uint32_t viewportCount, const VkViewport *viewports)
void bindPipeline(const GrVkGpu *gpu, sk_sp< const GrVkPipeline > pipeline)
void addRecycledResource(gr_rp< const GrRecycledResource > resource)
void setScissor(const GrVkGpu *gpu, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *scissors)
void addGrBuffer(sk_sp< const GrBuffer > buffer)
void bindDescriptorSets(const GrVkGpu *gpu, VkPipelineLayout layout, uint32_t firstSet, uint32_t setCount, const VkDescriptorSet *descriptorSets, uint32_t dynamicOffsetCount, const uint32_t *dynamicOffsets)
void draw(const GrVkGpu *gpu, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
GrVkResourceProvider & resourceProvider()
Definition: GrVkGpu.h:83
sk_sp< const GrVkPipeline > findOrCreateMSAALoadPipeline(const GrVkRenderPass &renderPass, int numSamples, VkPipelineShaderStageCreateInfo *, VkPipelineLayout)
T * get() const
Definition: SkRefCnt.h:303
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
dst
Definition: cp.py:12
SkScalar w
SkScalar h
uint32_t width
Definition: vulkan_core.h:2858
uint32_t height
Definition: vulkan_core.h:2859
int32_t x
Definition: vulkan_core.h:2869
int32_t y
Definition: vulkan_core.h:2870
VkExtent2D extent
Definition: vulkan_core.h:2881
VkOffset2D offset
Definition: vulkan_core.h:2880
float maxDepth
Definition: vulkan_core.h:3570
float height
Definition: vulkan_core.h:3568
float minDepth
Definition: vulkan_core.h:3569

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