From: Not Zed Date: Mon, 9 May 2022 13:10:09 +0000 (+0930) Subject: Generate set-field(all-fields) setters for selected inline structures. X-Git-Url: https://code.zedzone.au/cvs?a=commitdiff_plain;h=a3907c73ae46607614dbfdcb7c1ca32e978a425b;p=panamaz Generate set-field(all-fields) setters for selected inline structures. Generate get-field$field getters for selected inline structures. Clean up some of the script output/add some timing points. --- diff --git a/src/notzed.vulkan/gen/generate-vulkan b/src/notzed.vulkan/gen/generate-vulkan index 8a2a4c3..73f5149 100755 --- a/src/notzed.vulkan/gen/generate-vulkan +++ b/src/notzed.vulkan/gen/generate-vulkan @@ -4,6 +4,7 @@ use Data::Dumper; use File::Path qw(make_path); use File::Basename; +use Time::HiRes qw(clock_gettime CLOCK_REALTIME); use strict; @@ -53,6 +54,8 @@ my %primitiveMap = ( ); # ###################################################################### # +my $now = clock_gettime(CLOCK_REALTIME); +my $next; my $sys = {}; $sys->{output} = 'bin/gen/notzed.vulkan/classes'; @@ -61,17 +64,25 @@ $sys->{verbose} = 0; my $vk = new vulkan($sys); +printf "%9.6f load registry\n", (($next = clock_gettime(CLOCK_REALTIME)) - $now); $now = $next; + my $api = $vk->buildFeatures( [ 'VK_VERSION_1_0', 'VK_VERSION_1_1', 'VK_VERSION_1_2', 'VK_VERSION_1_3' ], [ 'xlib', #'wayland', 'xcb' ]); +printf "%9.6f build api view\n", (($next = clock_gettime(CLOCK_REALTIME)) - $now); $now = $next; + my $structTypes = loadTypes($api, 'struct-types.api'); my $commandTypes = loadTypes($api, 'command-types.api'); +printf "%9.6f load templates\n", (($next = clock_gettime(CLOCK_REALTIME)) - $now); $now = $next; + analyseTypes($vk, $api); +printf "%9.6f analyse types\n", (($next = clock_gettime(CLOCK_REALTIME)) - $now); $now = $next; + # Use some heuristics to create overrides for improving the api # - object constructor functions return values rather take pointer* values @@ -224,6 +235,8 @@ foreach my $s (values %{$api->{commands}}) { } } +printf "%9.6f guess overrides\n", (($next = clock_gettime(CLOCK_REALTIME)) - $now); $now = $next; + if (0) { analyseAccessors($api); exit 1; @@ -324,6 +337,8 @@ foreach my $k (sort keys %{$api->{funcpointers}}) { closeOutput($sys, $s->{name}, $f); } +printf "%9.6f export classes\n", (($next = clock_gettime(CLOCK_REALTIME)) - $now); $now = $next; + exit 0; # ###################################################################### # @@ -908,12 +923,14 @@ sub analyseTypes { } } - print "Unique Types:\n"; - my $base = {}; - map { $base->{$_} = 1 } values %$seen; + if ($sys->{verbose}) { + print "Unique Types:\n"; + my $base = {}; + map { $base->{$_} = 1 } values %$seen; - foreach my $k (sort keys %$base) { - print " $k\n"; + foreach my $k (sort keys %$base) { + print " $k\n"; + } } } @@ -1081,7 +1098,7 @@ sub formatStruct { $t = eval $t if $type->{accessor}->{"$field:eval"}; die "$@" if !defined($t); - push @{$info->{$field}}, code::formatTemplate($t, $v); + push @{$info->{$field}}, code::formatTemplate($t, $v) if $t; } } } diff --git a/src/notzed.vulkan/gen/struct-types.api b/src/notzed.vulkan/gen/struct-types.api index 913e8f9..b22304e 100644 --- a/src/notzed.vulkan/gen/struct-types.api +++ b/src/notzed.vulkan/gen/struct-types.api @@ -13,6 +13,8 @@ # {setall-arg} # {setall} +# ###################################################################### # + code value { get {{ /* {deref} */ @@ -82,6 +84,8 @@ code value { setallat {{ self$.set{Name}AtIndex(index$, {name}); }} } +# ###################################################################### # + code value-array { getorset {{ /* value-array {deref} */ @@ -124,6 +128,7 @@ END }} } +# ###################################################################### # # don't like having to pass scope here, not sure what else to do though code handle-array { getorset {{ @@ -144,6 +149,8 @@ code handle-array { }} } +# ###################################################################### # + code value-array2d { getorset {{ /* value-array2d {deref} */ @@ -163,6 +170,8 @@ code value-array2d { }} } +# ###################################################################### # + code inline { getorset {{ /* inline {deref} */ @@ -186,8 +195,14 @@ code inline { }} } +# ###################################################################### # # inline type that we also want to include expanded in initialiser +# We also create expanded setters and a getter for each simple embedded field. + code inline-expand { + + # These are basic object based accessors + getorset {{ /* inline {deref} */ public {type} get{Name}() { @@ -198,6 +213,7 @@ code inline-expand { } } }} + getorsetat {{ /* inline {deref} */ public {type} get{Name}AtIndex(long i$) { @@ -208,62 +224,117 @@ code inline-expand { } } }} - setall-arg eval {{ - my @list; - return 0 if $m->{len1}; + + # subroutine to the all-args info, only eval if len1 == 0 + # this will also include it's own inline struct's fields + analyse-args eval {{ + use integer; + my $list = []; + foreach my $a (@{$api->{data}->{$m->{baseType}}->{items}}) { my $name = "$m->{name}\$$a->{name}"; - if ($primitiveMap{$a->{baseType}}) { - push @list, "$primitiveMap{$a->{baseType}} $name"; + my $offset = ($m->{bitOffset} + $a->{bitOffset}) / 8; + my $atype = $primitiveMap{$a->{baseType}}; + + if ($atype) { + push @$list, { + name=> $name, + type => $atype, + offset => $offset, + }; } else { my $as = $api->{data}->{$a->{baseType}}; - foreach my $aa (@{$as->{items}}) { - push @list, "$primitiveMap{$aa->{baseType}} $name\$$aa->{name}"; + foreach my $b (@{$as->{items}}) { + my $btype = $primitiveMap{$b->{baseType}}; + if ($btype) { + push @$list, { + name => "$name\$$b->{name}", + type => $btype, + offset => $offset + $b->{bitOffset} / 8 + }; + } } } } - join ', ', @list; + $list; }} - setall eval {{ - my @list; + + # setBlah(all-simple-blah-fields) + set eval {{ return 0 if $m->{len1}; - foreach my $a (@{$api->{data}->{$m->{baseType}}->{items}}) { - my $pt = $primitiveMap{$a->{baseType}}; - if ($pt) { - push @list, 'self$.segment.set(Memory.'.uc($pt).', ' - .(($m->{bitOffset} + $a->{bitOffset})/8).", $m->{name}\$$a->{name}".');'; - } else { - my $as = $api->{data}->{$a->{baseType}}; - foreach my $aa (@{$as->{items}}) { - $pt = $primitiveMap{$aa->{baseType}}; - push @list, 'self$.segment.set(Memory.'.uc($pt).', ' - .(($m->{bitOffset} + $aa->{bitOffset} + $a->{bitOffset})/8).", $m->{name}\$$a->{name}\$$aa->{name}".');'; - } - } + my $setall_arg = eval($type->{accessor}->{'setall-arg'}); + my $setall = eval($type->{accessor}->{setall}); + <{len1}); + return 0 if $m->{len1}; - foreach my $a (@{$api->{data}->{$m->{baseType}}->{items}}) { - my $pt = $primitiveMap{$a->{baseType}}; - if ($pt) { - push @list, 'self$.segment.set(Memory.'.uc($pt).', index$ * '.($s->{bitSize} / 8).' + ' - .(($m->{bitOffset} + $a->{bitOffset})/8).", $m->{name}\$$a->{name}".');'; - } else { - my $as = $api->{data}->{$a->{baseType}}; - foreach my $aa (@{$as->{items}}) { - $pt = $primitiveMap{$aa->{baseType}}; - push @list, 'self$.segment.set(Memory.'.uc($pt).', index$ * '.($s->{bitSize} / 8).' + ' - .(($m->{bitOffset} + $aa->{bitOffset} + $a->{bitOffset})/8).", $m->{name}\$$a->{name}\$$aa->{name}".');'; - } - } + + my $list = eval($type->{accessor}->{'analyse-args'}); die "$@" if !defined $list; + + join("\n", map { + my $tname = uc($_->{type}); + my $fname = ucfirst($_->{name}); + <{type} get$fname() { + return this.segment.get(Memory.$tname, $_->{offset}); + } +END + } @$list); + }} + + # setBlahAtIndex(index, all-simple-blah-fields) + setat eval {{ + return 0 if $m->{len1}; + my $setall_arg = eval($type->{accessor}->{'setall-arg'}); + my $setallat = eval($type->{accessor}->{setallat}); + <{len1}; + + my $list = eval($type->{accessor}->{'analyse-args'}); die "$@" if !defined $list; + + join(', ', map { "$_->{type} $_->{name}" } @$list); + }} + + setall eval {{ + return 0 if $m->{len1}; + + my $list = eval($type->{accessor}->{'analyse-args'}); die "$@" if !defined $list; + + join("\n\t", map { 'self$.segment.set(Memory.'.uc($_->{type}).", $_->{offset}, $_->{name});" } @$list); + }} + + setallat eval {{ + use integer; + + return 0 if $m->{len1}; + + my $list = eval($type->{accessor}->{'analyse-args'}); die "$@" if !defined $list; + my $stride = $s->{bitSize} / 8; + + join("\n\t", map { 'self$.segment.set(Memory.'.uc($_->{type}).", index\$ * $stride + $_->{offset}, $_->{name});" } @$list); }} } +# ###################################################################### # + # value with a SegmentAllocator passed to set() code value-alloc value { set {{ diff --git a/src/notzed.vulkan/gen/vulkan.pm b/src/notzed.vulkan/gen/vulkan.pm index fe85338..69f94ef 100644 --- a/src/notzed.vulkan/gen/vulkan.pm +++ b/src/notzed.vulkan/gen/vulkan.pm @@ -7,7 +7,6 @@ use strict; use Data::Dumper; use XML::Parser; -use Time::HiRes qw(clock_gettime CLOCK_REALTIME); sub new { my $class = shift; @@ -25,13 +24,8 @@ sub new { bless $self, $class; - my $now = clock_gettime(CLOCK_REALTIME); - loadRegistry($self); - $now = clock_gettime(CLOCK_REALTIME) - $now; - print "$now load registry\n"; - # build various indices my $data = $self->{data}; my $handles = $self->{handles};