Skip to content

Commit

Permalink
vulkan: Fix renderer for matrix changes (swaywm#2770)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyorain committed Mar 20, 2021
1 parent 7291418 commit ed64b53
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions include/render/vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ struct wlr_vk_renderer {

uint32_t render_width;
uint32_t render_height;
float projection[9];

size_t last_pool_size;
struct wl_list descriptor_pools; // type wlr_vk_descriptor_pool
Expand Down
25 changes: 20 additions & 5 deletions render/vulkan/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <render/vulkan.h>
#include <wlr/render/interface.h>
#include <wlr/types/wlr_drm.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/util/log.h>
#include <wlr/render/vulkan.h>
#include <wlr/backend/interface.h>
Expand Down Expand Up @@ -563,6 +564,10 @@ static void vulkan_begin(struct wlr_renderer *wlr_renderer,
vkCmdSetViewport(cb, 0, 1, &vp);
vkCmdSetScissor(cb, 0, 1, &rect);

// refresh projection matrix
wlr_matrix_projection(renderer->projection, width, height,
WL_OUTPUT_TRANSFORM_NORMAL);

renderer->render_width = width;
renderer->render_height = height;
renderer->recording_cb = true;
Expand Down Expand Up @@ -769,8 +774,12 @@ static bool vulkan_render_subtexture_with_matrix(struct wlr_renderer *wlr_render
vkCmdBindDescriptorSets(cb, VK_PIPELINE_BIND_POINT_GRAPHICS,
renderer->pipe_layout, 0, 1, &texture->ds, 0, NULL);

float final_matrix[9];
wlr_matrix_multiply(final_matrix, renderer->projection, matrix);

struct vert_pcr_data vert_pcr_data;
mat3_to_mat4(matrix, vert_pcr_data.mat4);
mat3_to_mat4(final_matrix, vert_pcr_data.mat4);

vert_pcr_data.uv_off[0] = box->x / wlr_texture->width;
vert_pcr_data.uv_off[1] = box->y / wlr_texture->height;
vert_pcr_data.uv_size[0] = box->width / wlr_texture->width;
Expand Down Expand Up @@ -854,8 +863,11 @@ static void vulkan_render_quad_with_matrix(struct wlr_renderer *wlr_renderer,
vkCmdBindPipeline(cb, VK_PIPELINE_BIND_POINT_GRAPHICS,
renderer->current_render_buffer->render_setup->quad_pipe);

struct vert_pcr_data vert_pcr_data;
mat3_to_mat4(matrix, vert_pcr_data.mat4);
float final_matrix[9];
wlr_matrix_multiply(final_matrix, renderer->projection, matrix);

struct vert_pcr_data vert_pcr_data;
mat3_to_mat4(final_matrix, vert_pcr_data.mat4);
vert_pcr_data.uv_off[0] = 0.f;
vert_pcr_data.uv_off[1] = 0.f;
vert_pcr_data.uv_size[0] = 1.f;
Expand All @@ -878,8 +890,11 @@ static void vulkan_render_ellipse_with_matrix(struct wlr_renderer *wlr_renderer,
vkCmdBindPipeline(cb, VK_PIPELINE_BIND_POINT_GRAPHICS,
renderer->current_render_buffer->render_setup->ellipse_pipe);

struct vert_pcr_data vert_pcr_data;
mat3_to_mat4(matrix, vert_pcr_data.mat4);
float final_matrix[9];
wlr_matrix_multiply(final_matrix, renderer->projection, matrix);

struct vert_pcr_data vert_pcr_data;
mat3_to_mat4(final_matrix, vert_pcr_data.mat4);
vert_pcr_data.uv_off[0] = 0.f;
vert_pcr_data.uv_off[1] = 0.f;
vert_pcr_data.uv_size[0] = 1.f;
Expand Down
4 changes: 0 additions & 4 deletions render/vulkan/vulkan.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ struct wlr_vk_instance *wlr_vk_instance_create(
application_info.engineVersion = WLR_VERSION_NUM;
application_info.apiVersion = VK_API_VERSION_1_1;

// standard_validation: reports error in api usage to debug callback
// renderdoc: allows to capture (and debug) frames with renderdoc
// renderdoc has problems with some extensions we use atm so
// does not work
const char *layers[] = {
"VK_LAYER_KHRONOS_validation",
// "VK_LAYER_RENDERDOC_Capture",
Expand Down

0 comments on commit ed64b53

Please sign in to comment.