~sircmpwn/xrgears

a63ec76c08695cbc0735573656741035adc9fe4d — Lubosz Sarnecki 4 years ago 4d2c57c
vkc: move frame buffers to renderer.
M vitamin-k/vikSwapChain.hpp => vitamin-k/vikSwapChain.hpp +0 -21
@@ 16,7 16,6 @@ struct SwapChainBuffer {
class SwapChain {
public:
  std::vector<SwapChainBuffer> buffers;
  std::vector<VkFramebuffer> frame_buffers;

  uint32_t image_count = 0;



@@ 46,25 45,5 @@ public:

    vik_log_check(vkCreateImageView(device, &view_create_info, nullptr, view));
  }

  void create_frame_buffer(const VkDevice &device,
                           const VkRenderPass &render_pass, VkImageView *view,
                           uint32_t width, uint32_t height,
                           VkFramebuffer *frame_buffer) {
    VkFramebufferCreateInfo framebufferinfo = {};
    framebufferinfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
    framebufferinfo.renderPass = render_pass;
    framebufferinfo.attachmentCount = 1;
    framebufferinfo.pAttachments = view;
    framebufferinfo.width = width;
    framebufferinfo.height = height;
    framebufferinfo.layers = 1;

    vkCreateFramebuffer(device,
                        &framebufferinfo,
                        NULL,
                        frame_buffer);
  }

};
}

M vkc/vkcRenderer.cpp => vkc/vkcRenderer.cpp +2 -2
@@ 86,7 86,7 @@ void Renderer::create_vulkan_swapchain() {
  SwapChainVK* sc = (SwapChainVK*) swap_chain;
  sc->create(device, physical_device, surface, image_format, width, height);
  sc->update_images(device, image_format);
  sc->update_frame_buffers(device, width, height, render_pass);
  create_frame_buffers();
}

VkFormat Renderer::choose_surface_format() {


@@ 326,7 326,7 @@ void Renderer::build_command_buffer(VkFramebuffer frame_buffer) {
}

void Renderer::render(uint32_t index) {
  build_command_buffer(swap_chain->frame_buffers[index]);
  build_command_buffer(frame_buffers[index]);
  submit_queue();
  wait_and_reset_fences();
}

M vkc/vkcRenderer.hpp => vkc/vkcRenderer.hpp +24 -0
@@ 12,6 12,7 @@ namespace vkc {
class Renderer : public vik::Renderer {
public:
  vik::SwapChain *swap_chain;
  std::vector<VkFramebuffer> frame_buffers;

  VkInstance instance;
  VkPhysicalDevice physical_device;


@@ 57,5 58,28 @@ public:
  void render(uint32_t index);

  void render_swapchain_vk();

  void create_frame_buffer(VkImageView *view, VkFramebuffer *frame_buffer) {
    VkFramebufferCreateInfo framebufferinfo = {};
    framebufferinfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
    framebufferinfo.renderPass = render_pass;
    framebufferinfo.attachmentCount = 1;
    framebufferinfo.pAttachments = view;
    framebufferinfo.width = width;
    framebufferinfo.height = height;
    framebufferinfo.layers = 1;
    vkCreateFramebuffer(device,
                        &framebufferinfo,
                        NULL,
                        frame_buffer);
  }

  void create_frame_buffers() {
    frame_buffers.resize(swap_chain->image_count);
    for (uint32_t i = 0; i < swap_chain->image_count; i++) {
      create_frame_buffer(&swap_chain->buffers[i].view, &frame_buffers[i]);
    }
  }

};
}

M vkc/vkcSwapChainDRM.hpp => vkc/vkcSwapChainDRM.hpp +0 -4
@@ 41,13 41,11 @@ public:

  std::vector<kms_buffer> kms_buffers;
  int current;
  uint32_t image_count;

  SwapChainDRM() {
    image_count = 4;
    buffers.resize(image_count);
    kms_buffers.resize(image_count);
    frame_buffers.resize(image_count);
  }

  ~SwapChainDRM() {


@@ 101,8 99,6 @@ public:

      create_image_view(device, b->image,
                        image_format, &b->view);
      create_frame_buffer(device, render_pass, &b->view,
                          width, height, &frame_buffers[i]);
    }
  }


M vkc/vkcSwapChainVK.hpp => vkc/vkcSwapChainVK.hpp +0 -9
@@ 90,14 90,5 @@ public:
    }
  }

  void update_frame_buffers(VkDevice device, uint32_t width,
                            uint32_t height, VkRenderPass render_pass) {
    frame_buffers.resize(image_count);
    for (uint32_t i = 0; i < image_count; i++) {
      create_frame_buffer(device, render_pass, &buffers[i].view,
                          width, height, &frame_buffers[i]);
    }
  }

};
}

M vkc/vkcWindowKMS.hpp => vkc/vkcWindowKMS.hpp +1 -0
@@ 174,6 174,7 @@ public:
    SwapChainDRM *sc = (SwapChainDRM*) r->swap_chain;
    sc->init(r->device, r->image_format, gbm_dev, fd,
             r->width, r->height, r->render_pass);
    r->create_frame_buffers();
    sc->set_mode_and_page_flip(fd, crtc, connector);

    return 0;