Skip to content

Commit 5c91c7d

Browse files
committed
Fix blit flipping in OpenGL
1 parent 009d320 commit 5c91c7d

7 files changed

Lines changed: 34 additions & 6 deletions

File tree

pathfinder/gpu/gl/shader_module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ ShaderModuleGl::ShaderModuleGl(const std::vector<char> &source_code,
6666
replaceFirst(code_string, "#version 310 es", "#version 300 es");
6767
}
6868

69-
// Deprecated, should handled by SPIRV now.
69+
// Deprecated, should be handled by SPIRV now.
7070
// if (shader_stage == ShaderStage::Vertex) {
7171
// // 1. Find where "#version" is
7272
// size_t ver_pos = code_string.find("#version");

pathfinder/shaders/blit.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ layout(location = 0) out vec4 oFragColor;
77

88
layout(location = 0) in vec2 vUV;
99

10-
layout(binding = 0) uniform sampler2D uTexture;
10+
layout(binding = 1) uniform sampler2D uTexture;
1111

1212
void main() {
1313
oFragColor = texture(uTexture, vUV);

pathfinder/shaders/blit.vert

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#version 450
22

3+
layout(binding = 0) uniform bUniform {
4+
float flip_y;
5+
float padding0;
6+
float padding1;
7+
float padding2;
8+
};
9+
310
layout(location = 0) out vec2 vUV;
411

512
void main() {
@@ -10,4 +17,6 @@ void main() {
1017

1118
// Maps clip space coordinates [-1, 1] to UV space [0, 1]
1219
vUV = gl_Position.xy * 0.5 + 0.5;
20+
21+
gl_Position.y *= flip_y;
1322
}

pathfinder/shaders/generated/blit_frag_shdbin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define PATHFINDER_RESOURCE_BLIT_FRAG_SHDBIN_H
33

44
namespace Pathfinder {
5-
static uint8_t blit_frag_shdbin[] = {83,72,68,66,1,0,0,0,0,1,0,0,0,1,0,0,0,1,4,0,0,0,44,2,0,0,109,97,105,110,3,2,35,7,0,0,1,0,11,0,8,0,20,0,0,0,0,0,0,0,17,0,2,0,1,0,0,0,11,0,6,0,1,0,0,0,71,76,83,76,46,115,116,100,46,52,53,48,0,0,0,0,14,0,3,0,0,0,0,0,1,0,0,0,15,0,7,0,4,0,0,0,4,0,0,0,109,97,105,110,0,0,0,0,9,0,0,0,17,0,0,0,16,0,3,0,4,0,0,0,7,0,0,0,3,0,3,0,2,0,0,0,194,1,0,0,5,0,4,0,4,0,0,0,109,97,105,110,0,0,0,0,5,0,5,0,9,0,0,0,111,70,114,97,103,67,111,108,111,114,0,0,5,0,5,0,13,0,0,0,117,84,101,120,116,117,114,101,0,0,0,0,5,0,3,0,17,0,0,0,118,85,86,0,71,0,4,0,9,0,0,0,30,0,0,0,0,0,0,0,71,0,4,0,13,0,0,0,33,0,0,0,0,0,0,0,71,0,4,0,13,0,0,0,34,0,0,0,0,0,0,0,71,0,4,0,17,0,0,0,30,0,0,0,0,0,0,0,19,0,2,0,2,0,0,0,33,0,3,0,3,0,0,0,2,0,0,0,22,0,3,0,6,0,0,0,32,0,0,0,23,0,4,0,7,0,0,0,6,0,0,0,4,0,0,0,32,0,4,0,8,0,0,0,3,0,0,0,7,0,0,0,59,0,4,0,8,0,0,0,9,0,0,0,3,0,0,0,25,0,9,0,10,0,0,0,6,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,27,0,3,0,11,0,0,0,10,0,0,0,32,0,4,0,12,0,0,0,0,0,0,0,11,0,0,0,59,0,4,0,12,0,0,0,13,0,0,0,0,0,0,0,23,0,4,0,15,0,0,0,6,0,0,0,2,0,0,0,32,0,4,0,16,0,0,0,1,0,0,0,15,0,0,0,59,0,4,0,16,0,0,0,17,0,0,0,1,0,0,0,54,0,5,0,2,0,0,0,4,0,0,0,0,0,0,0,3,0,0,0,248,0,2,0,5,0,0,0,61,0,4,0,11,0,0,0,14,0,0,0,13,0,0,0,61,0,4,0,15,0,0,0,18,0,0,0,17,0,0,0,87,0,5,0,7,0,0,0,19,0,0,0,14,0,0,0,18,0,0,0,62,0,3,0,9,0,0,0,19,0,0,0,253,0,1,0,56,0,1,0,83,72,68,66,1,0,0,0,1,4,0,0,0,5,0,0,0,1,4,0,0,0,245,0,0,0,109,97,105,110,47,47,66,73,78,68,73,78,71,95,83,84,65,82,84,10,47,47,84,69,88,58,117,84,101,120,116,117,114,101,58,48,10,47,47,66,73,78,68,73,78,71,95,69,78,68,10,35,118,101,114,115,105,111,110,32,52,53,48,10,10,108,97,121,111,117,116,40,98,105,110,100,105,110,103,32,61,32,48,41,32,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,117,84,101,120,116,117,114,101,59,10,10,108,97,121,111,117,116,40,108,111,99,97,116,105,111,110,32,61,32,48,41,32,111,117,116,32,118,101,99,52,32,111,70,114,97,103,67,111,108,111,114,59,10,108,97,121,111,117,116,40,108,111,99,97,116,105,111,110,32,61,32,48,41,32,105,110,32,118,101,99,50,32,118,85,86,59,10,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,32,32,32,32,111,70,114,97,103,67,111,108,111,114,32,61,32,116,101,120,116,117,114,101,40,117,84,101,120,116,117,114,101,44,32,118,85,86,41,59,10,125,10,10,83,72,68,66,1,0,0,0,4,3,0,0,0,0,0,0,0,1,4,0,0,0,154,1,0,0,109,97,105,110,47,47,66,73,78,68,73,78,71,95,83,84,65,82,84,10,47,47,84,69,88,58,117,84,101,120,116,117,114,101,58,48,10,47,47,66,73,78,68,73,78,71,95,69,78,68,10,35,118,101,114,115,105,111,110,32,51,48,48,32,101,115,10,10,112,114,101,99,105,115,105,111,110,32,104,105,103,104,112,32,102,108,111,97,116,59,10,112,114,101,99,105,115,105,111,110,32,104,105,103,104,112,32,115,97,109,112,108,101,114,50,68,59,10,112,114,101,99,105,115,105,111,110,32,104,105,103,104,112,32,115,97,109,112,108,101,114,51,68,59,10,112,114,101,99,105,115,105,111,110,32,104,105,103,104,112,32,115,97,109,112,108,101,114,67,117,98,101,59,10,112,114,101,99,105,115,105,111,110,32,104,105,103,104,112,32,115,97,109,112,108,101,114,50,68,65,114,114,97,121,59,10,112,114,101,99,105,115,105,111,110,32,109,101,100,105,117,109,112,32,102,108,111,97,116,59,10,112,114,101,99,105,115,105,111,110,32,104,105,103,104,112,32,105,110,116,59,10,10,117,110,105,102,111,114,109,32,104,105,103,104,112,32,115,97,109,112,108,101,114,50,68,32,117,84,101,120,116,117,114,101,59,10,10,108,97,121,111,117,116,40,108,111,99,97,116,105,111,110,32,61,32,48,41,32,111,117,116,32,104,105,103,104,112,32,118,101,99,52,32,111,70,114,97,103,67,111,108,111,114,59,10,105,110,32,104,105,103,104,112,32,118,101,99,50,32,118,85,86,59,10,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,32,32,32,32,111,70,114,97,103,67,111,108,111,114,32,61,32,116,101,120,116,117,114,101,40,117,84,101,120,116,117,114,101,44,32,118,85,86,41,59,10,125,10,10,83,72,68,66,1,0,0,0,3,1,0,0,0,2,0,0,0,1,4,0,0,0,166,1,0,0,109,97,105,110,35,105,110,99,108,117,100,101,32,60,109,101,116,97,108,95,115,116,100,108,105,98,62,10,35,105,110,99,108,117,100,101,32,60,115,105,109,100,47,115,105,109,100,46,104,62,10,10,117,115,105,110,103,32,110,97,109,101,115,112,97,99,101,32,109,101,116,97,108,59,10,10,115,116,114,117,99,116,32,109,97,105,110,48,95,111,117,116,10,123,10,32,32,32,32,102,108,111,97,116,52,32,111,70,114,97,103,67,111,108,111,114,32,91,91,99,111,108,111,114,40,48,41,93,93,59,10,125,59,10,10,115,116,114,117,99,116,32,109,97,105,110,48,95,105,110,10,123,10,32,32,32,32,102,108,111,97,116,50,32,118,85,86,32,91,91,117,115,101,114,40,108,111,99,110,48,41,93,93,59,10,125,59,10,10,102,114,97,103,109,101,110,116,32,109,97,105,110,48,95,111,117,116,32,109,97,105,110,48,40,109,97,105,110,48,95,105,110,32,105,110,32,91,91,115,116,97,103,101,95,105,110,93,93,44,32,116,101,120,116,117,114,101,50,100,60,102,108,111,97,116,62,32,117,84,101,120,116,117,114,101,32,91,91,116,101,120,116,117,114,101,40,48,41,93,93,44,32,115,97,109,112,108,101,114,32,117,84,101,120,116,117,114,101,83,109,112,108,114,32,91,91,115,97,109,112,108,101,114,40,48,41,93,93,41,10,123,10,32,32,32,32,109,97,105,110,48,95,111,117,116,32,111,117,116,32,61,32,123,125,59,10,32,32,32,32,111,117,116,46,111,70,114,97,103,67,111,108,111,114,32,61,32,117,84,101,120,116,117,114,101,46,115,97,109,112,108,101,40,117,84,101,120,116,117,114,101,83,109,112,108,114,44,32,105,110,46,118,85,86,41,59,10,32,32,32,32,114,101,116,117,114,110,32,111,117,116,59,10,125,10,10};
5+
static uint8_t blit_frag_shdbin[] = {83,72,68,66,1,0,0,0,0,1,0,0,0,1,0,0,0,1,4,0,0,0,44,2,0,0,109,97,105,110,3,2,35,7,0,0,1,0,11,0,8,0,20,0,0,0,0,0,0,0,17,0,2,0,1,0,0,0,11,0,6,0,1,0,0,0,71,76,83,76,46,115,116,100,46,52,53,48,0,0,0,0,14,0,3,0,0,0,0,0,1,0,0,0,15,0,7,0,4,0,0,0,4,0,0,0,109,97,105,110,0,0,0,0,9,0,0,0,17,0,0,0,16,0,3,0,4,0,0,0,7,0,0,0,3,0,3,0,2,0,0,0,194,1,0,0,5,0,4,0,4,0,0,0,109,97,105,110,0,0,0,0,5,0,5,0,9,0,0,0,111,70,114,97,103,67,111,108,111,114,0,0,5,0,5,0,13,0,0,0,117,84,101,120,116,117,114,101,0,0,0,0,5,0,3,0,17,0,0,0,118,85,86,0,71,0,4,0,9,0,0,0,30,0,0,0,0,0,0,0,71,0,4,0,13,0,0,0,33,0,0,0,1,0,0,0,71,0,4,0,13,0,0,0,34,0,0,0,0,0,0,0,71,0,4,0,17,0,0,0,30,0,0,0,0,0,0,0,19,0,2,0,2,0,0,0,33,0,3,0,3,0,0,0,2,0,0,0,22,0,3,0,6,0,0,0,32,0,0,0,23,0,4,0,7,0,0,0,6,0,0,0,4,0,0,0,32,0,4,0,8,0,0,0,3,0,0,0,7,0,0,0,59,0,4,0,8,0,0,0,9,0,0,0,3,0,0,0,25,0,9,0,10,0,0,0,6,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,27,0,3,0,11,0,0,0,10,0,0,0,32,0,4,0,12,0,0,0,0,0,0,0,11,0,0,0,59,0,4,0,12,0,0,0,13,0,0,0,0,0,0,0,23,0,4,0,15,0,0,0,6,0,0,0,2,0,0,0,32,0,4,0,16,0,0,0,1,0,0,0,15,0,0,0,59,0,4,0,16,0,0,0,17,0,0,0,1,0,0,0,54,0,5,0,2,0,0,0,4,0,0,0,0,0,0,0,3,0,0,0,248,0,2,0,5,0,0,0,61,0,4,0,11,0,0,0,14,0,0,0,13,0,0,0,61,0,4,0,15,0,0,0,18,0,0,0,17,0,0,0,87,0,5,0,7,0,0,0,19,0,0,0,14,0,0,0,18,0,0,0,62,0,3,0,9,0,0,0,19,0,0,0,253,0,1,0,56,0,1,0,83,72,68,66,1,0,0,0,1,4,0,0,0,5,0,0,0,1,4,0,0,0,245,0,0,0,109,97,105,110,47,47,66,73,78,68,73,78,71,95,83,84,65,82,84,10,47,47,84,69,88,58,117,84,101,120,116,117,114,101,58,49,10,47,47,66,73,78,68,73,78,71,95,69,78,68,10,35,118,101,114,115,105,111,110,32,52,53,48,10,10,108,97,121,111,117,116,40,98,105,110,100,105,110,103,32,61,32,49,41,32,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,117,84,101,120,116,117,114,101,59,10,10,108,97,121,111,117,116,40,108,111,99,97,116,105,111,110,32,61,32,48,41,32,111,117,116,32,118,101,99,52,32,111,70,114,97,103,67,111,108,111,114,59,10,108,97,121,111,117,116,40,108,111,99,97,116,105,111,110,32,61,32,48,41,32,105,110,32,118,101,99,50,32,118,85,86,59,10,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,32,32,32,32,111,70,114,97,103,67,111,108,111,114,32,61,32,116,101,120,116,117,114,101,40,117,84,101,120,116,117,114,101,44,32,118,85,86,41,59,10,125,10,10,83,72,68,66,1,0,0,0,4,3,0,0,0,0,0,0,0,1,4,0,0,0,154,1,0,0,109,97,105,110,47,47,66,73,78,68,73,78,71,95,83,84,65,82,84,10,47,47,84,69,88,58,117,84,101,120,116,117,114,101,58,49,10,47,47,66,73,78,68,73,78,71,95,69,78,68,10,35,118,101,114,115,105,111,110,32,51,48,48,32,101,115,10,10,112,114,101,99,105,115,105,111,110,32,104,105,103,104,112,32,102,108,111,97,116,59,10,112,114,101,99,105,115,105,111,110,32,104,105,103,104,112,32,115,97,109,112,108,101,114,50,68,59,10,112,114,101,99,105,115,105,111,110,32,104,105,103,104,112,32,115,97,109,112,108,101,114,51,68,59,10,112,114,101,99,105,115,105,111,110,32,104,105,103,104,112,32,115,97,109,112,108,101,114,67,117,98,101,59,10,112,114,101,99,105,115,105,111,110,32,104,105,103,104,112,32,115,97,109,112,108,101,114,50,68,65,114,114,97,121,59,10,112,114,101,99,105,115,105,111,110,32,109,101,100,105,117,109,112,32,102,108,111,97,116,59,10,112,114,101,99,105,115,105,111,110,32,104,105,103,104,112,32,105,110,116,59,10,10,117,110,105,102,111,114,109,32,104,105,103,104,112,32,115,97,109,112,108,101,114,50,68,32,117,84,101,120,116,117,114,101,59,10,10,108,97,121,111,117,116,40,108,111,99,97,116,105,111,110,32,61,32,48,41,32,111,117,116,32,104,105,103,104,112,32,118,101,99,52,32,111,70,114,97,103,67,111,108,111,114,59,10,105,110,32,104,105,103,104,112,32,118,101,99,50,32,118,85,86,59,10,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,32,32,32,32,111,70,114,97,103,67,111,108,111,114,32,61,32,116,101,120,116,117,114,101,40,117,84,101,120,116,117,114,101,44,32,118,85,86,41,59,10,125,10,10,83,72,68,66,1,0,0,0,3,1,0,0,0,2,0,0,0,1,4,0,0,0,166,1,0,0,109,97,105,110,35,105,110,99,108,117,100,101,32,60,109,101,116,97,108,95,115,116,100,108,105,98,62,10,35,105,110,99,108,117,100,101,32,60,115,105,109,100,47,115,105,109,100,46,104,62,10,10,117,115,105,110,103,32,110,97,109,101,115,112,97,99,101,32,109,101,116,97,108,59,10,10,115,116,114,117,99,116,32,109,97,105,110,48,95,111,117,116,10,123,10,32,32,32,32,102,108,111,97,116,52,32,111,70,114,97,103,67,111,108,111,114,32,91,91,99,111,108,111,114,40,48,41,93,93,59,10,125,59,10,10,115,116,114,117,99,116,32,109,97,105,110,48,95,105,110,10,123,10,32,32,32,32,102,108,111,97,116,50,32,118,85,86,32,91,91,117,115,101,114,40,108,111,99,110,48,41,93,93,59,10,125,59,10,10,102,114,97,103,109,101,110,116,32,109,97,105,110,48,95,111,117,116,32,109,97,105,110,48,40,109,97,105,110,48,95,105,110,32,105,110,32,91,91,115,116,97,103,101,95,105,110,93,93,44,32,116,101,120,116,117,114,101,50,100,60,102,108,111,97,116,62,32,117,84,101,120,116,117,114,101,32,91,91,116,101,120,116,117,114,101,40,49,41,93,93,44,32,115,97,109,112,108,101,114,32,117,84,101,120,116,117,114,101,83,109,112,108,114,32,91,91,115,97,109,112,108,101,114,40,49,41,93,93,41,10,123,10,32,32,32,32,109,97,105,110,48,95,111,117,116,32,111,117,116,32,61,32,123,125,59,10,32,32,32,32,111,117,116,46,111,70,114,97,103,67,111,108,111,114,32,61,32,117,84,101,120,116,117,114,101,46,115,97,109,112,108,101,40,117,84,101,120,116,117,114,101,83,109,112,108,114,44,32,105,110,46,118,85,86,41,59,10,32,32,32,32,114,101,116,117,114,110,32,111,117,116,59,10,125,10,10};
66
}
77

88
#endif //PATHFINDER_RESOURCE_BLIT_FRAG_SHDBIN_H

pathfinder/shaders/generated/blit_vert_shdbin.h

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pathfinder/utils/blit.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ Blit::Blit(const std::shared_ptr<Device> &device, const std::shared_ptr<Queue> &
2323

2424
{
2525
std::vector<DescriptorLayout> layouts = {
26-
DescriptorLayout{0, ShaderStage::Fragment, DescriptorType::Sampler},
26+
DescriptorLayout{0, ShaderStage::Vertex, DescriptorType::UniformBuffer},
27+
DescriptorLayout{1, ShaderStage::Fragment, DescriptorType::Sampler},
2728
};
2829

2930
descriptor_set_layout_ = device->create_descriptor_set_layout(layouts);
@@ -45,11 +46,27 @@ void Blit::set_texture(const std::shared_ptr<Texture> &new_texture) {
4546
texture_ = new_texture;
4647

4748
descriptor_set_->add_or_update({
48-
Descriptor::sampled(0, texture_, sampler_),
49+
Descriptor::sampled(1, texture_, sampler_),
4950
});
5051
}
5152

5253
void Blit::draw(const std::shared_ptr<CommandEncoder> &encoder) {
54+
if (!uniform_buffer_) {
55+
auto descriptor =
56+
BufferDescriptor{BufferType::Uniform, 4 * sizeof(float), MemoryProperty::HostVisibleAndCoherent};
57+
58+
uniform_buffer_ = device_->create_buffer(descriptor, "blit uniform");
59+
60+
float flip_y = 1.0f;
61+
if (device_->get_backend_type() == BackendType::Opengl) {
62+
flip_y = -1.0f;
63+
}
64+
65+
encoder->write_buffer(uniform_buffer_, 0, sizeof(float), &flip_y);
66+
67+
descriptor_set_->add_or_update({Descriptor::uniform(0, uniform_buffer_)});
68+
}
69+
5370
encoder->bind_render_pipeline(pipeline_);
5471

5572
encoder->bind_descriptor_set(descriptor_set_);

pathfinder/utils/blit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class Blit {
2323

2424
std::shared_ptr<Texture> texture_;
2525

26+
std::shared_ptr<Buffer> uniform_buffer_;
27+
2628
std::shared_ptr<RenderPipeline> pipeline_;
2729

2830
std::shared_ptr<DescriptorSetLayout> descriptor_set_layout_;

0 commit comments

Comments
 (0)