GrVkFramebuffer.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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/GrVkFramebuffer.h"
  8. #include "src/gpu/vk/GrVkGpu.h"
  9. #include "src/gpu/vk/GrVkImageView.h"
  10. #include "src/gpu/vk/GrVkRenderPass.h"
  11. GrVkFramebuffer* GrVkFramebuffer::Create(GrVkGpu* gpu,
  12. int width, int height,
  13. const GrVkRenderPass* renderPass,
  14. const GrVkImageView* colorAttachment,
  15. const GrVkImageView* stencilAttachment) {
  16. // At the very least we need a renderPass and a colorAttachment
  17. SkASSERT(renderPass);
  18. SkASSERT(colorAttachment);
  19. VkImageView attachments[3];
  20. attachments[0] = colorAttachment->imageView();
  21. int numAttachments = 1;
  22. if (stencilAttachment) {
  23. attachments[numAttachments++] = stencilAttachment->imageView();
  24. }
  25. VkFramebufferCreateInfo createInfo;
  26. memset(&createInfo, 0, sizeof(VkFramebufferCreateInfo));
  27. createInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
  28. createInfo.pNext = nullptr;
  29. createInfo.flags = 0;
  30. createInfo.renderPass = renderPass->vkRenderPass();
  31. createInfo.attachmentCount = numAttachments;
  32. createInfo.pAttachments = attachments;
  33. createInfo.width = width;
  34. createInfo.height = height;
  35. createInfo.layers = 1;
  36. VkFramebuffer framebuffer;
  37. VkResult err = GR_VK_CALL(gpu->vkInterface(), CreateFramebuffer(gpu->device(),
  38. &createInfo,
  39. nullptr,
  40. &framebuffer));
  41. if (err) {
  42. return nullptr;
  43. }
  44. return new GrVkFramebuffer(framebuffer);
  45. }
  46. void GrVkFramebuffer::freeGPUData(GrVkGpu* gpu) const {
  47. SkASSERT(fFramebuffer);
  48. GR_VK_CALL(gpu->vkInterface(), DestroyFramebuffer(gpu->device(), fFramebuffer, nullptr));
  49. }