~sircmpwn/xrgears

f45885637eabb02b7b3ded5075abe436ba3330d5 — Lubosz Sarnecki 4 years ago fb9d492
move swap chain to window.
M examples/vkcube/main.cpp => examples/vkcube/main.cpp +1 -1
@@ 448,7 448,7 @@ public:
  }

  void init() {
    renderer->init_render_pass();
    renderer->init_render_pass(window->swap_chain->image_format);

    VkDescriptorSetLayout set_layout = init_descriptor_set_layout();
    init_pipeline_layout(set_layout);

M vitamin-k/vikSwapChain.hpp => vitamin-k/vikSwapChain.hpp +1 -0
@@ 18,6 18,7 @@ public:
  std::vector<SwapChainBuffer> buffers;

  uint32_t image_count = 0;
  VkFormat image_format;

  SwapChain() {}
  ~SwapChain() {}

M vitamin-k/vikSwapChainVK.hpp => vitamin-k/vikSwapChainVK.hpp +0 -1
@@ 12,7 12,6 @@ public:
  VkSwapchainKHR swap_chain = VK_NULL_HANDLE;

  VkSurfaceKHR surface;
  VkFormat image_format;

  SwapChainVK() {}
  ~SwapChainVK() {}

M vitamin-k/vikWindow.hpp => vitamin-k/vikWindow.hpp +4 -0
@@ 3,10 3,14 @@
#include <stdio.h>
#include <string.h>

#include "vikSwapChain.hpp"

namespace vik {
class Window {
public:

  SwapChain *swap_chain;

  enum window_type {
    AUTO = 0,
    KMS,

M vkc/vkcRenderer.cpp => vkc/vkcRenderer.cpp +5 -7
@@ 82,11 82,10 @@ void Renderer::init_vk(const char *extension) {
  vkGetDeviceQueue(device, 0, 0, &queue);
}

void Renderer::init_render_pass() {
void Renderer::init_render_pass(VkFormat format) {

  std::array<VkAttachmentDescription, 1> attachments = {};
  SwapChainVK *sc = (SwapChainVK*) swap_chain;
  attachments[0].format = sc->image_format;
  attachments[0].format = format;
  attachments[0].samples = (VkSampleCountFlagBits) 1;
  attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
  attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;


@@ 291,14 290,13 @@ void Renderer::render(uint32_t index) {
  wait_and_reset_fences();
}

void Renderer::render_swapchain_vk() {
  SwapChainVK *sc = (SwapChainVK *) swap_chain;
void Renderer::render_swapchain_vk(SwapChainVK *swap_chain) {
  uint32_t present_index = 0;
  VkResult result = sc->acquire_next_image(device, semaphore, &present_index);
  VkResult result = swap_chain->acquire_next_image(device, semaphore, &present_index);
  switch (result) {
    case VK_SUCCESS:
      render(present_index);
      vik_log_check(sc->present(queue, present_index));
      vik_log_check(swap_chain->present(queue, present_index));
      break;
    case VK_TIMEOUT:
      // TODO: XCB times out

M vkc/vkcRenderer.hpp => vkc/vkcRenderer.hpp +3 -5
@@ 8,8 8,6 @@ namespace vkc {

class Renderer : public vik::Renderer {
public:
  vik::SwapChain *swap_chain;

  VkPipelineLayout pipeline_layout;
  VkPipeline pipeline;
  VkDeviceMemory mem;


@@ 29,7 27,7 @@ public:
  ~Renderer() ;

  void init_vk(const char *extension);
  void init_render_pass();
  void init_render_pass(VkFormat format);
  void init_vk_objects();
  void submit_queue();



@@ 41,7 39,7 @@ public:

  void render(uint32_t index);

  void render_swapchain_vk();
  void render_swapchain_vk(SwapChainVK *swap_chain);

  void create_frame_buffer(VkImageView *view, VkFramebuffer *frame_buffer) {
    VkFramebufferCreateInfo framebufferinfo = {};


@@ 58,7 56,7 @@ public:
                        frame_buffer);
  }

  void create_frame_buffers() {
  void create_frame_buffers(vik::SwapChain *swap_chain) {
    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/vkcWindowKMS.hpp => vkc/vkcWindowKMS.hpp +8 -5
@@ 166,14 166,17 @@ public:

    r->init_vk(NULL);

    r->swap_chain = new SwapChainDRM();
    swap_chain = new SwapChainDRM();

    init_cb();

    SwapChainDRM *sc = (SwapChainDRM*) r->swap_chain;
    sc->init(r->device, VK_FORMAT_R8G8B8A8_SRGB, gbm_dev, fd,
    SwapChainDRM *sc = (SwapChainDRM*) swap_chain;

    sc->image_format = VK_FORMAT_R8G8B8A8_SRGB;

    sc->init(r->device, sc->image_format, gbm_dev, fd,
             r->width, r->height, r->render_pass);
    r->create_frame_buffers();
    r->create_frame_buffers(swap_chain);
    sc->set_mode_and_page_flip(fd, crtc, connector);

    return 0;


@@ 197,7 200,7 @@ public:

    update_cb();

    SwapChainDRM *sc = (SwapChainDRM*) r->swap_chain;
    SwapChainDRM *sc = (SwapChainDRM*) swap_chain;

    int index = sc->current & 1;


M vkc/vkcWindowWayland.hpp => vkc/vkcWindowWayland.hpp +4 -4
@@ 283,8 283,8 @@ public:
    waylandSurfaceInfo.display = display;
    waylandSurfaceInfo.surface = surface;

    r->swap_chain = new SwapChainVK();
    SwapChainVK *sc = (SwapChainVK*) r->swap_chain;
    swap_chain = new SwapChainVK();
    SwapChainVK *sc = (SwapChainVK*) swap_chain;
    vik_log_f_if(sc == NULL, "no swapchain!");
    vkCreateWaylandSurfaceKHR(r->instance, &waylandSurfaceInfo, NULL, &sc->surface);



@@ 294,7 294,7 @@ public:

    sc->create(r->device, r->physical_device, r->width, r->height);
    sc->update_images(r->device);
    r->create_frame_buffers();
    r->create_frame_buffers(swap_chain);


    return 0;


@@ 320,7 320,7 @@ public:
  void iterate(Renderer *r) {
    flush();
    update_cb();
    r->render_swapchain_vk();
    r->render_swapchain_vk((SwapChainVK*) swap_chain);
  }
};
}

M vkc/vkcWindowXCB.hpp => vkc/vkcWindowXCB.hpp +9 -9
@@ 119,10 119,10 @@ public:
    surfaceInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
    surfaceInfo.connection = conn;
    surfaceInfo.window = window;
    if (r->swap_chain == nullptr)
      r->swap_chain = new SwapChainVK();
    if (swap_chain == nullptr)
      swap_chain = new SwapChainVK();

    SwapChainVK *sc = (SwapChainVK*) r->swap_chain;
    SwapChainVK *sc = (SwapChainVK*) swap_chain;

    vkCreateXcbSurfaceKHR(r->instance, &surfaceInfo, NULL, &sc->surface);



@@ 169,7 169,7 @@ public:

            vik_log_d("XCB_CONFIGURE_NOTIFY %dx%d", r->width, r->height);

            SwapChainVK *sc = (SwapChainVK*) r->swap_chain;
            SwapChainVK *sc = (SwapChainVK*) swap_chain;

            if (sc != nullptr)
              sc->destroy(r->device);


@@ 182,12 182,12 @@ public:
          vik_log_d("XCB_EXPOSE");
          //if (r->swap_chain == nullptr) {
        {
          if (r->swap_chain == nullptr)
            r->swap_chain = new SwapChainVK();
          SwapChainVK *sc = (SwapChainVK*) r->swap_chain;
          if (swap_chain == nullptr)
            swap_chain = new SwapChainVK();
          SwapChainVK *sc = (SwapChainVK*) swap_chain;
          sc->create(r->device, r->physical_device, r->width, r->height);
          sc->update_images(r->device);
          r->create_frame_buffers();
          r->create_frame_buffers(swap_chain);
        }
          schedule_repaint();
          break;


@@ 209,7 209,7 @@ public:
    if (repaint) {

      update_cb();
      r->render_swapchain_vk();
      r->render_swapchain_vk((SwapChainVK*) swap_chain);
      schedule_repaint();
    }
    xcb_flush(conn);