From 24bc2c67bcd4c42e5d9763671c964340ebf86f08 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Tue, 3 Jun 2025 09:16:51 +0200 Subject: [PATCH] changed the pipeline to use 16 bit int as coords thank you renderdoc for making me feel less stupid --- .gitignore | 1 + resources/shaders/compiled/rect.frag.spv | Bin 836 -> 0 bytes resources/shaders/compiled/rect.vert.spv | Bin 2764 -> 0 bytes resources/shaders/source/rect.vert.glsl | 13 +++++++----- src/renderer.c3 | 26 +++++++---------------- 5 files changed, 17 insertions(+), 23 deletions(-) delete mode 100644 resources/shaders/compiled/rect.frag.spv delete mode 100644 resources/shaders/compiled/rect.vert.spv diff --git a/.gitignore b/.gitignore index 042d5c7..eb64e0d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ build/* perf.data* *.rdc test_renderer +resources/shaders/compiled/** diff --git a/resources/shaders/compiled/rect.frag.spv b/resources/shaders/compiled/rect.frag.spv deleted file mode 100644 index 3cc8f056785b496a3fffddf27bc63dc76cb9c2bd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 836 zcmZ`%QHv8X5FW4ByI#(oilA>2>C4^2ZF_KvP|g>TzEmps1D0hs)?iG^Zg!!Ff6ia! zi{SUA?oqG?CX;XG%giJ*gQLl*$OAc-v0TV*J&_|=1hx~LL>9|W%dCl2cKd2Z#)S;1 z66cYe$}!GE$hX3J+7;v>@X`9 z_1eU1ZZ@FE+$#$PGrifw4)r3+;dX}r_3D{Z~*OnIxz;O2)J zxU-}1H{Jyo>bX)~uvL2D<(2xb&hA|Znj-x`9~63(FIKC?@_k-zHhB}b&g3jDuPp!9 zc1FM(?eVNHU0dxFhG6XXa|pzq-lxQQi0-h*NG*$$S>y#U7cqT3eu^$~VqRkBtnmB{ zJLf_}p2IqVCZ=CwKZ7QZ_W57T8fc^c9GWxH`-z!zXFE>%1eo^MsoLF)0;U|lP!s(l dpgs5 diff --git a/resources/shaders/compiled/rect.vert.spv b/resources/shaders/compiled/rect.vert.spv deleted file mode 100644 index 439d76d10af3d355ad240dc1fee43841633781e9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2764 zcmZ{lTW=dh6vvn5($u9brL^Tz!ldD1lVoj&q!dirrfCTeL5WnUua>bl>5A>HiWemQzwsW&f^?$eIhX&r&dg@+!s^8!cq6zRTnWAnChK}|L7G6iMR7r} zfAH)e%!^*QwcP-5HJD@bm}^1B^9%ZY*@;tx&qbS}Z$uA8Pem6MpO|5N5aro$(2eqX z{-V>12HL$WL$?S=(Vz%Vk~|T1F8I^u|4WYe*6Z%D|9#dQCehI#Q-nO~xhO3LBx}bYmooTx|+mkNKlL zCFzW_VNuPa!tJ=`y89tcdvSUqp;2?gG(OG-FWvJv`l+7{3inIpQap;fn{Fgc%Y^Ls zxK;VJH4Tj)!^8c9r|oXP-_DD1616${4> z>+v;fU(nwb?RFu=>IF`8@LY?DZr89! zNQ?i9e({IDrC)ul11GvIEj=RR?<8L;W%M^CliP`i2mVd%=)f;aW`^h>{I6=qhQ3wG z%n#j~WPINe5s&!SwL1|DJM!CJn#8*y9$);-|Mraij(F;a%-{N_o|^RJq95u(=Dg6+ zPpBPV=5t5C^-?Cra(SN(gAF2XQ#PAn7XPvMAb7QBeR3DDFA2}i*%0%de=)q9$s)(!n)0G{ ze7OUBQ|Q6uYAIVRJEL8BaYpZmIA_il+m7Op>!t`>CYgA*N}c(=D;Yn|bk^@Z$=J;A zeevl2P}RiwKtwF`yV7wFJ`_SS5&kHlNeoVV5N#ACDEE8@|a-(B%m z^Q_;h^w`YrWAW&$=1;^E3;nBd9-oRwZ#{e_o*sxx56EDw2jmAHJ5&9#Y4tM%15q{`-2i$%9 zx#um>rik3sgbdzl;@nyE#C?Ax;;u7SV(*F`i7eNi_{aYtW)Aj=2s{{a@y5_uF76cT KAH9(KqJIJIdSEF4 diff --git a/resources/shaders/source/rect.vert.glsl b/resources/shaders/source/rect.vert.glsl index abe367a..0fab590 100644 --- a/resources/shaders/source/rect.vert.glsl +++ b/resources/shaders/source/rect.vert.glsl @@ -5,21 +5,24 @@ layout(set = 1, binding = 0) uniform Viewport { ivec2 off; }; -layout(location = 0) in vec2 position; -layout(location = 1) in vec2 uv; +layout(location = 0) in ivec2 position; +layout(location = 1) in ivec2 uv; layout(location = 2) in ivec4 color; layout(location = 0) out vec4 col; void main() { - //vec2 shift = vec2(0); + // per vertex shift vec2 shift; shift.x = float(off.x) / view.x; shift.y = -(float(off.y) / view.y); - vec2 pos = position + shift; + // vertex position + vec2 pos; + pos.x = float(position.x)*2.0 / view.x - 1.0; + pos.y = -(float(position.y)*2.0 / view.y - 1.0); - gl_Position = vec4(pos.x, pos.y, 0.0, 1.0); + gl_Position = vec4(pos+shift, 0.0, 1.0); col = vec4(color) / 255.0; } diff --git a/src/renderer.c3 b/src/renderer.c3 index 99f10a5..a62c9c6 100644 --- a/src/renderer.c3 +++ b/src/renderer.c3 @@ -51,10 +51,10 @@ struct Renderer { // how each vertex is represented in the gpu struct Vertex @packed { struct pos { - float x, y; + short x, y; } struct uv { - float u, v; + short u, v; } struct col { // FIXME: this is shit union { @@ -321,13 +321,13 @@ fn void Renderer.create_pipeline(&self, String shader_name, PipelineType type) { // at location zero there is the position of the vertex .location = 0, .buffer_slot = 0, // only one buffer so always slot zero - .format = GPU_VERTEXELEMENTFORMAT_FLOAT2, + .format = GPU_VERTEXELEMENTFORMAT_SHORT2, .offset = Vertex.pos.offsetof, }, { // at location one there are the uv coordinates .location = 1, .buffer_slot = 0, - .format = GPU_VERTEXELEMENTFORMAT_FLOAT2, + .format = GPU_VERTEXELEMENTFORMAT_SHORT2, .offset = Vertex.uv.offsetof, }, { // at location two there is the color @@ -500,12 +500,6 @@ fn void Renderer.update_texture(&self, String name, char[] pixels, ushort width, } -macro void Vertex.norm(&p, float w, float h) -{ - p.pos.x = p.pos.x * 2.0 / w - 1.0; - p.pos.y = -(p.pos.y * 2.0 / h - 1.0); -} - // an highly inefficient way to draw a single quad, no batching, per-quad upload fn void Renderer.draw_rect(&self, short x, short y, short w, short h, uint color, String shader_name) { @@ -541,15 +535,11 @@ fn void Renderer.draw_rect(&self, short x, short y, short w, short h, uint color * +-------------+ * v2 v3 */ - quad.vertices.v1 = {.pos = {.x = x, .y = y}, .col.u = color}; - quad.vertices.v2 = {.pos = {.x = x, .y = (float)y+h}, .col.u = color}; - quad.vertices.v3 = {.pos = {.x = (float)x+w, .y = (float)y+h}, .col.u = color}; - quad.vertices.v4 = {.pos = {.x = (float)x+w, .y = y}, .col.u = color}; + quad.vertices.v1 = {.pos = {.x = x, .y = y}, .col.u = color}; + quad.vertices.v2 = {.pos = {.x = x, .y = y+h}, .col.u = color}; + quad.vertices.v3 = {.pos = {.x = x+w, .y = y+h}, .col.u = color}; + quad.vertices.v4 = {.pos = {.x = x+w, .y = y}, .col.u = color}; - quad.vertices.v1.norm(640.0, 480.0); - quad.vertices.v2.norm(640.0, 480.0); - quad.vertices.v3.norm(640.0, 480.0); - quad.vertices.v4.norm(640.0, 480.0); // triangle 1 quad.indices.i1 = 0; // v1