void setup_vk_attachment_description(VkAttachmentDescription* attachment, const AttachmentDesc& desc, VkImageLayout layout) { attachment->flags = 0; attachment->format = desc.fFormat; SkAssertResult(GrSampleCountToVkSampleCount(desc.fSamples, &attachment->samples)); switch (layout) { case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: attachment->loadOp = desc.fLoadStoreOps.fLoadOp; attachment->storeOp = desc.fLoadStoreOps.fStoreOp; attachment->stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; attachment->stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; break; case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: attachment->loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; attachment->storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; attachment->stencilLoadOp = desc.fLoadStoreOps.fLoadOp; attachment->stencilStoreOp = desc.fLoadStoreOps.fStoreOp; break; default: SkFAIL("Unexpected attachment layout"); } attachment->initialLayout = layout; attachment->finalLayout = layout; }
bool GrVkImage::InitImageInfo(const GrVkGpu* gpu, const ImageDesc& imageDesc, GrVkImageInfo* info) { VkImage image = 0; GrVkAlloc alloc; bool isLinear = VK_IMAGE_TILING_LINEAR == imageDesc.fImageTiling; VkImageLayout initialLayout = isLinear ? VK_IMAGE_LAYOUT_PREINITIALIZED : VK_IMAGE_LAYOUT_UNDEFINED; // Create Image VkSampleCountFlagBits vkSamples; if (!GrSampleCountToVkSampleCount(imageDesc.fSamples, &vkSamples)) { return false; } SkASSERT(VK_IMAGE_TILING_OPTIMAL == imageDesc.fImageTiling || VK_SAMPLE_COUNT_1_BIT == vkSamples); // sRGB format images may need to be aliased to linear for various reasons (legacy mode): VkImageCreateFlags createFlags = GrVkFormatIsSRGB(imageDesc.fFormat, nullptr) ? VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT : 0; const VkImageCreateInfo imageCreateInfo = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // sType NULL, // pNext createFlags, // VkImageCreateFlags imageDesc.fImageType, // VkImageType imageDesc.fFormat, // VkFormat { imageDesc.fWidth, imageDesc.fHeight, 1 }, // VkExtent3D imageDesc.fLevels, // mipLevels 1, // arrayLayers vkSamples, // samples imageDesc.fImageTiling, // VkImageTiling imageDesc.fUsageFlags, // VkImageUsageFlags VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode 0, // queueFamilyCount 0, // pQueueFamilyIndices initialLayout // initialLayout }; GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateImage(gpu->device(), &imageCreateInfo, nullptr, &image)); if (!GrVkMemory::AllocAndBindImageMemory(gpu, image, isLinear, &alloc)) { VK_CALL(gpu, DestroyImage(gpu->device(), image, nullptr)); return false; } info->fImage = image; info->fAlloc = alloc; info->fImageTiling = imageDesc.fImageTiling; info->fImageLayout = initialLayout; info->fFormat = imageDesc.fFormat; info->fLevelCount = imageDesc.fLevels; return true; }
static void setup_multisample_state(int numSamples, VkPipelineMultisampleStateCreateInfo* multisampleInfo) { memset(multisampleInfo, 0, sizeof(VkPipelineMultisampleStateCreateInfo)); multisampleInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; multisampleInfo->pNext = nullptr; multisampleInfo->flags = 0; SkAssertResult(GrSampleCountToVkSampleCount(numSamples, &multisampleInfo->rasterizationSamples)); multisampleInfo->sampleShadingEnable = VK_FALSE; multisampleInfo->minSampleShading = 0.0f; multisampleInfo->pSampleMask = nullptr; multisampleInfo->alphaToCoverageEnable = VK_FALSE; multisampleInfo->alphaToOneEnable = VK_FALSE; }
void setup_multisample_state(const GrPipeline& pipeline, const GrPrimitiveProcessor& primProc, const GrCaps* caps, VkPipelineMultisampleStateCreateInfo* multisampleInfo) { memset(multisampleInfo, 0, sizeof(VkPipelineMultisampleStateCreateInfo)); multisampleInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; multisampleInfo->pNext = nullptr; multisampleInfo->flags = 0; int numSamples = pipeline.getRenderTarget()->numColorSamples(); SkAssertResult(GrSampleCountToVkSampleCount(numSamples, &multisampleInfo->rasterizationSamples)); float sampleShading = primProc.getSampleShading(); SkASSERT(sampleShading == 0.0f || caps->sampleShadingSupport()); multisampleInfo->sampleShadingEnable = sampleShading > 0.0f; multisampleInfo->minSampleShading = sampleShading; multisampleInfo->pSampleMask = nullptr; multisampleInfo->alphaToCoverageEnable = VK_FALSE; multisampleInfo->alphaToOneEnable = VK_FALSE; }