Commit 9187a060 authored by Jeffrey Lee's avatar Jeffrey Lee
Browse files

Implement sprite translation table caching

Detail:
  This set of changes allows the Wimp to cache the last-used translation table, and cleans up some instances where translation tables were being generated and then not used
  s/Wimp01 - Expand selecttable_args to store all 8 registers needed by ColourTrans_GenerateTable. Add 1K of space for caching the palette that the cached translation table was generated from. Remove unused spriteX, spriteY variables.
  s/Wimp04 - Split cachespritedata in two. cachespritedata now only caches the basic information, while the new cachespritepixtable rotuine will generate a translation table (shaded/inverted if required). This allows table generation to be deferred until we're just about to render the sprite, ensuring that the table isn't generated only to not be used. Also updated icon sprite rendering to check the sprite is within the graphics window before attempting to render it, allowing removal of one more case where tables can be needlessly generated.
  s/NewSWIs, s/Wimp09 - Change ADR to ADRL
  s/Tiling, s/Tiling3D - Use cachespritepixtable when needed
Admin:
  Tested on Iyonix, BB-xM, StrongARM RiscPC


Version 5.36. Tagged as 'Wimp-5_36'
parent 40176aa7
......@@ -11,13 +11,13 @@
GBLS Module_HelpVersion
GBLS Module_ComponentName
GBLS Module_ComponentPath
Module_MajorVersion SETS "5.35"
Module_Version SETA 535
Module_MajorVersion SETS "5.36"
Module_Version SETA 536
Module_MinorVersion SETS ""
Module_Date SETS "01 Jan 2014"
Module_ApplicationDate SETS "01-Jan-14"
Module_Date SETS "01 Mar 2014"
Module_ApplicationDate SETS "01-Mar-14"
Module_ComponentName SETS "Wimp"
Module_ComponentPath SETS "castle/RiscOS/Sources/Desktop/Wimp"
Module_FullVersion SETS "5.35"
Module_HelpVersion SETS "5.35 (01 Jan 2014)"
Module_FullVersion SETS "5.36"
Module_HelpVersion SETS "5.36 (01 Mar 2014)"
END
/* (5.35)
/* (5.36)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 5.35
#define Module_MajorVersion_CMHG 5.36
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 01 Jan 2014
#define Module_Date_CMHG 01 Mar 2014
#define Module_MajorVersion "5.35"
#define Module_Version 535
#define Module_MajorVersion "5.36"
#define Module_Version 536
#define Module_MinorVersion ""
#define Module_Date "01 Jan 2014"
#define Module_Date "01 Mar 2014"
#define Module_ApplicationDate "01-Jan-14"
#define Module_ApplicationDate "01-Mar-14"
#define Module_ComponentName "Wimp"
#define Module_ComponentPath "castle/RiscOS/Sources/Desktop/Wimp"
#define Module_FullVersion "5.35"
#define Module_HelpVersion "5.35 (01 Jan 2014)"
#define Module_LibraryVersionInfo "5:35"
#define Module_FullVersion "5.36"
#define Module_HelpVersion "5.36 (01 Mar 2014)"
#define Module_LibraryVersionInfo "5:36"
......@@ -596,7 +596,7 @@ extend_swicallback
extend_spritenamepointers
ADR R0,spritename
ADR R1,list_at
ADRL R1,list_at
STR R1,[sp]
B ExitWimp
......
......@@ -75,6 +75,8 @@ plotspritebackground
MOV R0,#0
STR R0,lengthflags ; spritename is a pointer
BL cachespritedata
MOV R1,#0
BLVC cachespritepixtable
LDR R0,pixtable_at
STR R0,tile_temptab
......@@ -269,6 +271,8 @@ findwimptilesprite Entry "R0-R1"
MOV R0,#0
STR R0,lengthflags
BL cachespritedata
MOV R1,#0
BL cachespritepixtable
STR R3,tile_width
STR R4,tile_height
......@@ -371,6 +375,8 @@ get_new_pixtable Entry "R0-R6"
MOV R0,#0
STR R0,lengthflags
BL cachespritedata
MOV R1,#0
BL cachespritepixtable
LDR R0,tile_pixtable
TEQ R0,R7
BNE %FT05
......
......@@ -335,6 +335,8 @@ get_tile_sprite_info
mov r0,#0
str r0,lengthflags
bl cachespritedata
movvc r1,#0
blvc cachespritepixtable
movvs r0,#-1
strvs r0,[r8,#TileInfo_SpritePtr]
Pull "r0-r4,pc",VS
......
......@@ -832,8 +832,6 @@ clipx0 # 4
clipy0 # 4
clipx1 # 4
clipy1 # 4
spriteX # 4 ; for sprite plotting in icons
spriteY # 4
spaceinicon # 4 ; for displaying scrollable icons
text_width # 4
text_y0 # 4
......@@ -922,6 +920,7 @@ sysflags # 1 ; actions on moving windows (drag?)
memoryOK # 1 ; flag for ChangeDynamicArea
modechanged # 1 ; flag set on mode change
sprite_needsfactors # 1 ; otherwise 1:1 scaling for this mode
sprite_needsfactors2 # 1 ; initial needsfactors guess
tsprite_needsfactors # 1 ; otherwise 1:1 scaling for this mode
tsprite_needsregen # 1 ; need to recalculate the tool sprite pixtrans
selecttable_crit # 1 ; ignore invalidate cache service calls if we're the cause
......@@ -1241,7 +1240,9 @@ transtable2 # 4 ; 2bpp ---------- "" ------------
transtable4 # 16 ; 4bpp ---------- "" ------------
ALIGNHASH 16
selecttable_args # 4*6 ; parameters used for the last sprite select table call
selecttable_args # 4*8 ; parameters used for the last sprite select table call
selecttable_lastmode # 4
selecttable_lastpalptr # 4
pixtable_at # 4
pixtable_size # 4 ; size and position of pixtrans table currently setup
......@@ -1592,6 +1593,8 @@ ptrpreserveflag # 4 ; 0 => position pointer over default err
errorbuttonoldhandlers # 3*3*4 ; old environment handlers to restore afterwards
]
selecttable_lastpal # 1024 ; Last sprite palette used with selecttable
maxwork * :INDEX:@
! 0, "Free pool = R12+&" :CC: :STR: :INDEX: freepool
......
......@@ -3033,7 +3033,6 @@ textheight TraceL font
; First calculate sprite origin
; (see findtextorigin for details of flag settings)
; Entry: R1,R2 = sprite flags, data ptr
; Exit: [spriteX], [spriteY] remembered
;
sprite_lookup
......@@ -3059,6 +3058,7 @@ iconsprite
Push "R0-R5,LR"
;
BL spritesize ; R3,R4 = size of sprite (OS units)
Push "R3,R4"
;
ASSERT if_sprite = 2_00010
ASSERT if_border = 2_00100
......@@ -3107,9 +3107,20 @@ iconsprite
TST R0,#B
MOVNE R4,y0 ; not centred ==> at bottom
;
STR R3,spriteX ; may be needed for inverting/shading
STR R4,spriteY
;
; Check the sprite is actually on screen. Without this we'll end up
; wasting time generating colour translation tables that won't be used.
ADR R0,scrx0
LDMIA R0,{R0,R2,R5,LR} ; scrx0, scry0, scrx1, scry1
CMP R3,R5
CMPLT R4,LR
Pull "R5,LR" ; recover sprite width, height
ADD R5,R3,R5
ADD LR,R4,LR
CMPLT R0,R5
CMPLT R2,LR
BGE exitspricon
[ TrueIcon2
LDR R5, border_type
TEQ R5, #border_action
......@@ -3248,6 +3259,8 @@ SWIWimp_ReadPixTrans
STR R1,thisCBptr ; used by cachespritedata
STR R2,spritename ; used by cachespritedata
BL cachespritedata
MOV R1,#0
BLVC cachespritepixtable
BVS ExitWimp
;
CMP R6,#0
......@@ -3313,12 +3326,9 @@ rationalisefactors
;; mode data set up if different input mode from last time
;;----------------------------------------------------------------------------
cachespritedata
cachespritedata ROUT
Entry "R1-R2,R5-R7"
MOV R2,#1
STRB R2,selecttable_crit ; entering critical period for pixtable
LDR R2,lengthflags
CMP R2,#0 ; absolute pointer?
LDR R2,spritename
......@@ -3329,28 +3339,15 @@ cachespritedata
;
; R2 -> sprite in area
;
LDR R7,[R2,#spImage]
LDR R14,[R2,#spTrans]
CMP R7,R14 ; min(image,trans)
MOVHI R7,R14
LDR R14,pixtable_at
CMP R14,#0 ; is a pixtable defined?
BEQ %FT10
LDR R14,sprite_lastmode
TEQ R6,R14 ; have we already cached this information?
LDREQB R7,sprite_needsfactors2 ; yes, restore our original needsfactors
BEQ %FT91 ; and skip recaching stuff
TEQ R7,#spPalette ; does it have a palette?
LDREQ R14,sprite_lastmode
TEQEQ R6,R14 ; no, so have we already cached this information?
BEQ %FT92
MOV R0,R6 ; R0 = mode of sprite
10 MOV R0,R6 ; R0 = mode of sprite
TEQ R7,#spPalette
MOVNE R6,#-1 ; if it has a palette then corrupt last mode
STR R6,sprite_lastmode
Push "R2,R3-R4" ; R2 -> sprite, R3,R4 = height / width
MOV R1,#VduExt_Log2BPP
SWI XOS_ReadModeVariable
STRVC R2,sprite_log2bpp ; get the depth of the sprite
......@@ -3370,7 +3367,6 @@ cachespritedata
MOVVC R1,#VduExt_NColour
SWIVC XOS_ReadModeVariable
STRVC R2,sprite_ncolour ; get the ncolour
Pull "R2,R3-R4",VS
BVS %FT92
LDR R6,log2bpp
......@@ -3396,14 +3392,44 @@ cachespritedata
LDR R1,sprite_log2py
LDR R6,log2py
TEQEQ R1,R6 ; any special scaling?
MOVEQ R14,#0
MOVNE R14,#-1
STRB R14,sprite_needsfactors ; may be modified later
MOVEQ R7,#0
MOVNE R7,#-1
STRB R7,sprite_needsfactors2 ; save initial guess so we can restore it when called again with same mode
ADR r2,sprite_factors
BL rationalisefactors
91
STRB R7,sprite_needsfactors ; may be modified later
92
EXIT
;;----------------------------------------------------------------------------
;; Cache the pixtable for the current sprite
;; Entry:
;; R1 = icon flags (is_inverted & is_shaded important)
;; [spritename] --> sprite name
;; [thisCBptr] --> sprite area
;; [lengthflags] ==> is R2 a name ptr or a sprite ptr?
;; [sprite_*] valid
;; Exit:
;; R0 = error
;; [selecttable_args] filled in
;; [pixtable_at], [pixtable_size] updated
;; [sprite_needsfactors] set if table actually needed
;;----------------------------------------------------------------------------
cachespritepixtable ROUT
Entry "R0-R11"
MOV R2,#1
STRB R2,selecttable_crit ; entering critical period for pixtable
BL cachespriteaddress
BVS %FT90
MOV R1,R2
LDR R7,[R2,#spImage]
LDR R14,[R2,#spTrans]
CMP R7,R14 ; min(image,trans)
MOVHI R7,R14
Pull "R1" ; R1 -> sprite
MOV R2,#-1
MOV R3,#-1 ; convert to the current mode
[ Medusa
......@@ -3462,8 +3488,9 @@ cachespritedata
Pull "R0-R3,R5"
10 MOV R4,#0 ; R4 =0 read table size
SWI XColourTrans_SelectTable
10
MOV R4,#0 ; R4 =0 read table size
SWI XColourTrans_GenerateTable
BVS %FT90 ; exit
LDR R14,pixtable_at
......@@ -3481,6 +3508,7 @@ cachespritedata
MOV R2,#0
STR R2,pixtable_at ; mark as the pix table has been released
STR R2,selecttable_args+4*4 ; nuke cached buffer pointer to force regeneration
MOV R0,#ModHandReason_Claim
MOV R3,R4
......@@ -3492,36 +3520,123 @@ cachespritedata
Pull "R0-R3"
BVS %FT90 ; return if it errors
20 MOV R6,R4 ; R6 = size of table generated (first time)
LDR R4,pixtable_at
20
Push "R4" ; remember this table size
Debug ic,"Sprite src mode, src pptr, dest mode, dest pptr",R0,R1,R2,R3
ASSERT ?selecttable_args = 4*6
ADR R7,selecttable_args
STMIA R7,{R0-R1,R2-R3,R4,R5} ; cache entry parameters for the translation
; Check if palette has changed since last call
LDR R9,sprite_ncolour
CMP R9,#256
MOVHS R8,#0 ; True colour, so no palette
BHS %FT21
; Decode R0,R1 to get sprite palette pointer
MOV R8,R1
MOV R4,#4
CMP R0,#256
BLO %FT21 ; R0,R1 is mode + palette
TST R0,#1
BNE %FT21 ; mode + palette
; R0,R1 is area + sprite
; R7 should still be valid as min(spImage,spMask)
CMP R7,#spPalette
MOVEQ R8,#0
ADDNE R8,R1,#spPalette
MOVNE R4,#8
21
; R8 = palette to check, or 0 if none
; R9 = ncolour
; R4 = entry stride
; Check against our softcopy
LDR R10,selecttable_lastpalptr
CMP R10,R8 ; Detect sprites gaining/losing palettes
STRNE R8,selecttable_lastpalptr
STRNE PC,selecttable_args ; Clobber a random arg to force recalc
CMP R8,#0
BEQ %FT25
ADRL R10,selecttable_lastpal
22
LDR R7,[R8],R4
LDR LR,[R10],#4
CMP R7,LR
BNE %FT23
SUBS R9,R9,#1
BGE %BT22
; Palettes match OK
B %FT25
23
; Palettes differ!
STR R7,[R10,#-4]
SUBS R9,R9,#1
STR PC,selecttable_args
BLT %FT25
24
LDR R7,[R8],R4
SUBS R9,R9,#1
STR R7,[R10],#4
BGE %BT24
Debug ic,"Sprite src mode, src pptr, dest mode, dest pptr",R0,R1,R2,R3
25
; Set up colour mapping function if necessary
LDR LR,sprite_log2bpp
MOV R6,#0 ; Set R6,R7 to zero if colour mapping not needed to simplify selecttable_args check
CMP LR,#3
MOV R7,#0
BHI %FT26
LDR R6,[R13,#8] ; Grab entry R1 from stack
ANDS R6,R6,#is_inverted + is_shaded
ORRNE R5,R5,#1:SHL:2
ADRNEL R7,inversefunc
26
; Check if other parameters have changed since last call
LDR R4,pixtable_at
ADR R11,selecttable_args
ASSERT ?selecttable_args = 4*8
LDMIA R11!,{R8-R10,LR} ; R0-R3
CMP R0,R8
CMPEQ R1,R9
CMPEQ R2,R10
CMPEQ R3,LR
LDMEQIA R11,{R8-R10,LR} ; R4-R8
SUB R11,R11,#4*4
CMPEQ R4,R8
CMPEQ R5,R9
LDR R8,sprite_lastmode
CMPEQ R6,R10
LDR R9,selecttable_lastmode
CMPEQ R7,LR
CMPEQ R8,R9
Pull "R9" ; recover table size
BEQ %FT34 ; Parameters & palette match. Skip table generation, but still check for 1:1 mapping.
STMIA R11,{R0-R7} ; cache entry parameters for the translation
STR R8,selecttable_lastmode
SWI XColourTrans_SelectTable
SWI XColourTrans_GenerateTable
BVS %FT90 ; return if not important
CMP R6,#256
34 CMP R9,#256
BHI %FT40 ; if its greater than 8bpp then we can ignore it (was GT)
35 SUBS R6,R6,#1 ; decrease the index into the table
35 SUBS R9,R9,#1 ; decrease the index into the table
BMI %FT90 ; return if end of the world reached
LDRB R14,[R4,R6]
TEQ R14,R6 ; colour number = index? (1:1 mapped)
LDRB R14,[R4,R9]
TEQ R14,R9 ; colour number = index? (1:1 mapped)
BEQ %BT35
40
MOV R14,#-1
STRB R14,sprite_needsfactors ; mark as needing translation
90
Pull "R3-R4"
92
MOV R14, #0
STRB R14, selecttable_crit ; passed the critical moment for pixtable
STRVS r0, [SP]
EXIT
;..............................................................................
......@@ -3905,6 +4020,8 @@ scaled
wimp_SpriteOp_putsprite
Push "R1,R5-R7,LR"
;
BL cachespritepixtable
BVS %FT90
LDR R7,pixtable_at ; -> translation table
;
TST R1,#is_inverted:OR:is_shaded
......@@ -3924,6 +4041,7 @@ wimp_SpriteOp_putsprite
MOV R0,#SpriteReason_PutSpriteUserCoords
unscaled
BL wimp_SpriteOp
90
Pull "R1,R5-R7,PC"
;
......@@ -3990,73 +4108,37 @@ do_spriteop
Pull "PC"
;----------------------------------------------------------
; calculate new ttr table to deal with inverting the sprite
; Entry: R1 = icon flag word
; R5 = plot flags
; R0,R6 = input/output log2bpp <-- don't count on this!
; update OS_SpriteOp args to deal with inverting the sprite
; Entry: R1 = icon flag word (must be at least one of is_inverted, is_shaded)
; R5 = OS_SpriteOp plot flags
; R7 --> pixtable
; Exit: R5, R7 updated to allow for inverting/shading
;---------------------------------------------------------
calcinverse ROUT
Entry "R0-R7"
ADR R7,inversefunc ; pointer to the transfer function
MOV R6,R1
LDR R1,sprite_log2bpp
CMP R1,#3
BGT %FT50
LDR R4,pixtable_at
TEQ R4,#0
EXIT EQ ; no pixtable!
[ true ; BJGA bugfix: was sometimes trying to work from a paged-out sprite!
; if <256-colour sprite without palette, we pass palette from Wimp workspace, so no problem
CMP R1, #3 ; if <256-colour sprite with palette, cachespritedata has already updated selecttable_args
BLGE cachespriteaddress ; R2 -> this sprite, ie *not* the first sprite in this run of matching-mode sprites!
EXIT VS ; bail out now if sprite not found!
CMP R1, #3
Push "R2", GE
ADR R0, selecttable_args
LDMIA R0, {R0-R5}
LDRGE R0, baseofsprites ; any non-system sprite area will do
Pull "R1", GE
|
ADR R0,selecttable_args
LDMIA R0,{R0-R5} ; get the parameters for the call
]
ORR R5,R5,#1:SHL:2 ; mark as a transfer function supplied
SWI XColourTrans_GenerateTable
; SWI XColourTrans_InvalidateCache
MOV R0,#-1
STR R0,sprite_lastmode
STRB R0,sprite_needsfactors ; mark as recache and needing translation table
CLRV
EXIT
Entry "R0"
LDR R0,sprite_log2bpp
CMP R0,#3
EXIT LS ; palettised sprites will have already been handled by cachespritepixtable
50
; For true colour sprites we want to ignore pixtable_at (it could be
; left pointing at an old table) and set things up to use a colour
; mapping descriptor - if SpriteExtend supports them
LDRB R7,checkedcolourmapping
CMP R7,#0
; For true colour sprites we want to ignore R7 and set things up to use
; a colour mapping descriptor - if SpriteExtend supports them
LDRB R0,checkedcolourmapping
CMP R0,#0
BLEQ checkandgenerateinversecolourmap
LDR R7,inversecolourmap
CMP R7,#0
LDR R0,inversecolourmap
CMP R0,#0
EXIT EQ
ASSERT is_inverted = 1<<21
ASSERT is_shaded = 1<<22
AND R1,R6,#is_inverted+is_shaded
SUB R1,R1,#is_inverted ; at least one should be set
ADD R7,R7,R1,LSR #21-3 ; index the correct descriptor
STR R7,[SP,#7*4] ; swap pixtable pointer for descriptor
CLRV
PullEnv
AND R7,R1,#is_inverted+is_shaded
SUB R7,R7,#is_inverted ; at least one should be set
ADD R7,R0,R7,LSR #21-3 ; index the correct descriptor
ORR R5,R5,#128 ; set colour mapping flag
STRB R5,sprite_needsfactors ; and ensure PutScaled used
MOV PC,LR
CLRV
EXIT
......
......@@ -84,7 +84,7 @@ makespritelist Entry "R0-R4,R8-R9"
;
Debug sprite,"list buffer allocated at, size:",R2,R3
;
ADR R0,list_at
ADRL R0,list_at
STMIA R0,{R2,R3} ; store bounds of the list away
10
LDR R3,list_at ; R3 -> buffers to store names pointers at
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment