From 3c35899a2f6d66144543cfd3ba02fc5b618e835d Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Fri, 17 Apr 2020 16:01:37 -0700 Subject: [PATCH] Render circles WIP --- piet-gpu-types/src/scene.rs | 9 +++++++-- piet-gpu/shader/build.ninja | 2 +- piet-gpu/shader/image.comp | 18 ++++++++++++++++++ piet-gpu/shader/image.spv | Bin 2624 -> 4372 bytes piet-gpu/shader/scene.h | 31 +++++++++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 3 deletions(-) diff --git a/piet-gpu-types/src/scene.rs b/piet-gpu-types/src/scene.rs index d2cc466..8e4ec3c 100644 --- a/piet-gpu-types/src/scene.rs +++ b/piet-gpu-types/src/scene.rs @@ -1,7 +1,7 @@ use piet_gpu_derive::piet_gpu; pub use self::scene::{ - Bbox, PietFill, PietItem, PietStrokeLine, PietStrokePolyLine, Point, SimpleGroup, + Bbox, PietCircle, PietFill, PietItem, PietStrokeLine, PietStrokePolyLine, Point, SimpleGroup, }; piet_gpu! { @@ -20,6 +20,11 @@ piet_gpu! { items: Ref, bboxes: Ref, } + struct PietCircle { + rgba_color: u32, + center: Point, + radius: f32, + } struct PietStrokeLine { flags: u32, rgba_color: u32, @@ -40,7 +45,7 @@ piet_gpu! { points: Ref, } enum PietItem { - Circle(), + Circle(PietCircle), Line(PietStrokeLine), Fill(PietFill), Poly(PietStrokePolyLine), diff --git a/piet-gpu/shader/build.ninja b/piet-gpu/shader/build.ninja index d0086bc..037540b 100644 --- a/piet-gpu/shader/build.ninja +++ b/piet-gpu/shader/build.ninja @@ -7,4 +7,4 @@ glslang_validator = glslangValidator rule glsl command = $glslang_validator -V -o $out $in -build image.spv: glsl image.comp +build image.spv: glsl image.comp | scene.h diff --git a/piet-gpu/shader/image.comp b/piet-gpu/shader/image.comp index 5487366..6174724 100644 --- a/piet-gpu/shader/image.comp +++ b/piet-gpu/shader/image.comp @@ -26,6 +26,24 @@ void main() { uvec2 xy = gl_GlobalInvocationID.xy; vec2 uv = vec2(xy) * vec2(1.0 / IMAGE_WIDTH, 1.0 / IMAGE_HEIGHT); vec4 rgba = vec4(uv.xyy, 1.0); + + // Render the scene. Right now, every pixel traverses the scene graph, + // which is horribly wasteful, but the goal is to get *some* output and + // then optimize. + + SimpleGroup group = SimpleGroup_read(SimpleGroupRef(0)); + for (uint i = 0; i < group.n_items; i++) { + // Writing this out by hand is illuminating the need for array access + // in piet-gpu-derive. There is some support in the `_index` functions, + // but those are only generated for structs, not for `Ref` or other + // types. + PietItemRef item_ref = PietItemRef(scene[(group.items.offset >> 2) + i]); + uint tag = PietItem_tag(item_ref); + if (tag == PietItem_Circle) { + PietCircle = PietItem_Circle_read(item_ref); + } + } + uvec4 s = uvec4(round(rgba * 255.0)); uint rgba_packed = s.x | (s.y << 8) | (s.z << 16) | (s.w << 24); image[xy.y * IMAGE_WIDTH + xy.x] = rgba_packed; diff --git a/piet-gpu/shader/image.spv b/piet-gpu/shader/image.spv index e05c8c0b2c93bb8614f9adb4c529eac717fb9354..5be9f6d742f443cbcfdc2ce1d76f9908fca72f9d 100644 GIT binary patch literal 4372 zcmZvdhj&y}5Qi^@6;v#UVna+oY!s!cU<1n%jRuIlZ8pggSJF&22sUExy?5-r{|6pD z{zcYv^!R=6y@3~xH)k@x`OVz9bLY)_+jhX>St-p(v-$fWf8-&5=fJpgG>?Z#8!|jGJAGYmW2}O%9X;DnyjeuW&Y(N`fnMG$yR=PkTH3V z#b9!*lrrb(xxFg4+mgvCJ=?bty=%94b~Y1(L$&JAXkUG(b7bdef4$Wl9qDvdJmYfo z24|sgAua3&jxEVd@Q!MOT(PQ=T`fz5qrCxM1!TAzIQmw;!K?4@91 zj6V}?-QFeYS`9W{|2njO@2n{)%&&3Xh%xf!+=_OeGjBcH(B_oa ze>Gaa^+wL?z$r~#xD3Csw;&6Vqo}Njb|0^OcF)LrC$_Qjk>@UON_#HWc0L|NoS(2C z13O3B_UuU{>M;Hp#COwqiFe6)c>zw_`@D#@Uvl}eQ{56PNHw|~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+4wljxHZPL6TlVzn{c1s^F58N z6~1x(Gr)6={Bv;6B;r%>I1~F{05QMy)4)4&5cLYyoI`N$p1yN_fVHQZ??pc=wAg0` z-xYIQ(_t{{=b+ZxdoOGr8+kY2&hP#U*x0`f*SEfdwO-Br^}U~J(dQQ2=NzYl_s9FH zCOpHlymRv_z~vb{LaAcy=?wno_&)T#PyVlj?_Kb}CH$lCVHmxI^VB=TGr;@X zKvmyaXzH#ZaDhqO*O+zY?Ez{l_&(F#Li@G2x4thm@2~aFsb;*99L+gaJ6#Y;X?BquQRFN#Tcjo^NssGIFn~(%$dx46{!8jp8Bs9+Hvd- z-kI77;C{mR617LLCxJ2hdgl7m^zqE!0BU|W?&bYC1=J(wEx0+}gUERsuKs{N)|>@u zeoucC+Be1^xxY`tmUgzQVGZwur!tLcZ8NJ?zt4FU(aJ6X= zy)MJ;XUsG4-l;|3S-AJ7{JbCHtN&6wTOF=;4Mg2XaO=uv`7yrw-J-4mw^lu7z7BVW zX-;wu`w7Uv3^3mr)y#{%K80_d@iR2_d+gYDx4?b;k1*dooTG_#Ifpsl0X654#~k0oH_y>R xQ;(dR|C6(brXJ_{1Kj^R&(m0(dk=0b@_vNJxx0_&u4bOk7&B`B`~uJZr@ diff --git a/piet-gpu/shader/scene.h b/piet-gpu/shader/scene.h index eb99bd4..440f491 100644 --- a/piet-gpu/shader/scene.h +++ b/piet-gpu/shader/scene.h @@ -12,6 +12,10 @@ struct SimpleGroupRef { uint offset; }; +struct PietCircleRef { + uint offset; +}; + struct PietStrokeLineRef { uint offset; }; @@ -60,6 +64,18 @@ SimpleGroupRef SimpleGroup_index(SimpleGroupRef ref, uint index) { return SimpleGroupRef(ref.offset + index * SimpleGroup_size); } +struct PietCircle { + uint rgba_color; + Point center; + float radius; +}; + +#define PietCircle_size 16 + +PietCircleRef PietCircle_index(PietCircleRef ref, uint index) { + return PietCircleRef(ref.offset + index * PietCircle_size); +} + struct PietStrokeLine { uint flags; uint rgba_color; @@ -140,6 +156,17 @@ SimpleGroup SimpleGroup_read(SimpleGroupRef ref) { return s; } +PietCircle PietCircle_read(PietCircleRef ref) { + uint ix = ref.offset >> 2; + uint raw0 = scene[ix + 0]; + uint raw3 = scene[ix + 3]; + PietCircle s; + s.rgba_color = raw0; + s.center = Point_read(PointRef(ref.offset + 4)); + s.radius = uintBitsToFloat(raw3); + return s; +} + PietStrokeLine PietStrokeLine_read(PietStrokeLineRef ref) { uint ix = ref.offset >> 2; uint raw0 = scene[ix + 0]; @@ -186,6 +213,10 @@ uint PietItem_tag(PietItemRef ref) { return scene[ref.offset >> 2]; } +PietCircle PietItem_Circle_read(PietItemRef ref) { + return PietCircle_read(PietCircleRef(ref.offset + 4)); +} + PietStrokeLine PietItem_Line_read(PietItemRef ref) { return PietStrokeLine_read(PietStrokeLineRef(ref.offset + 4)); }