GrVkImageView.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright 2016 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "src/gpu/vk/GrVkGpu.h"
  8. #include "src/gpu/vk/GrVkImageView.h"
  9. #include "src/gpu/vk/GrVkSamplerYcbcrConversion.h"
  10. #include "src/gpu/vk/GrVkUtil.h"
  11. const GrVkImageView* GrVkImageView::Create(GrVkGpu* gpu, VkImage image, VkFormat format,
  12. Type viewType, uint32_t miplevels,
  13. const GrVkYcbcrConversionInfo& ycbcrInfo) {
  14. void* pNext = nullptr;
  15. VkSamplerYcbcrConversionInfo conversionInfo;
  16. GrVkSamplerYcbcrConversion* ycbcrConversion = nullptr;
  17. if (ycbcrInfo.isValid()) {
  18. SkASSERT(gpu->vkCaps().supportsYcbcrConversion() && format == VK_FORMAT_UNDEFINED);
  19. ycbcrConversion =
  20. gpu->resourceProvider().findOrCreateCompatibleSamplerYcbcrConversion(ycbcrInfo);
  21. if (!ycbcrConversion) {
  22. return nullptr;
  23. }
  24. conversionInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO;
  25. conversionInfo.pNext = nullptr;
  26. conversionInfo.conversion = ycbcrConversion->ycbcrConversion();
  27. pNext = &conversionInfo;
  28. }
  29. VkImageView imageView;
  30. // Create the VkImageView
  31. VkImageViewCreateInfo viewInfo = {
  32. VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // sType
  33. pNext, // pNext
  34. 0, // flags
  35. image, // image
  36. VK_IMAGE_VIEW_TYPE_2D, // viewType
  37. format, // format
  38. { VK_COMPONENT_SWIZZLE_IDENTITY,
  39. VK_COMPONENT_SWIZZLE_IDENTITY,
  40. VK_COMPONENT_SWIZZLE_IDENTITY,
  41. VK_COMPONENT_SWIZZLE_IDENTITY }, // components
  42. { VK_IMAGE_ASPECT_COLOR_BIT, 0, miplevels, 0, 1 }, // subresourceRange
  43. };
  44. if (kStencil_Type == viewType) {
  45. viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
  46. }
  47. VkResult err = GR_VK_CALL(gpu->vkInterface(), CreateImageView(gpu->device(), &viewInfo,
  48. nullptr, &imageView));
  49. if (err) {
  50. return nullptr;
  51. }
  52. return new GrVkImageView(imageView, ycbcrConversion);
  53. }
  54. void GrVkImageView::freeGPUData(GrVkGpu* gpu) const {
  55. GR_VK_CALL(gpu->vkInterface(), DestroyImageView(gpu->device(), fImageView, nullptr));
  56. if (fYcbcrConversion) {
  57. fYcbcrConversion->unref(gpu);
  58. }
  59. }
  60. void GrVkImageView::abandonGPUData() const {
  61. if (fYcbcrConversion) {
  62. fYcbcrConversion->unrefAndAbandon();
  63. }
  64. }