Commit Graph

41 Commits

Author SHA1 Message Date
Hajime Hoshi
b620b4334e buffered: Bug fix: Corner case of the race condition
Updates #1195
2020-06-17 03:31:54 +09:00
Hajime Hoshi
0beddf5519 buffered: Bug fix: Race condition at checkDealeydCommandsNil
This change also renames checkDealeydCommandsNil to
checkDealeydCommandsFlushed, which makes more sense.

Updates #1195
2020-06-17 03:19:35 +09:00
Hajime Hoshi
d9cf1095d4 buffered: Bug fix: Race conndition on delayedCommands
This CL fixes the race condtion on delayedCommands, which can be
accessed and set to nil at the same time.

This CL separates some operations for delayedCommands into slow-
paths and fast-paths, and use mutex only at slow-paths for
performance. The implementation is based on sync.Once.

Fixes #1195
2020-06-16 23:22:18 +09:00
Hajime Hoshi
620981a09a ebiten: Make ebiten.Image and buffered.Image 1:1
This change creates a new buffered.Image even for a sub-image. This
can increase a memory usage a little, but decrease the GPU memory
usage since only the necessary pixels are allocated on a texture
atlas.

Fixes #896
Updates #1194
2020-06-14 11:15:38 +09:00
Hajime Hoshi
1395ab5e84 buffered: Defer ReplacePixels when possible 2020-06-14 04:41:51 +09:00
Hajime Hoshi
cf3436da21 buffered: Skip filling operation if possible 2020-06-14 04:17:57 +09:00
Hajime Hoshi
96fa0565e4 buffered: Remove mutex and use sync/atomic for performance
This change also enables to remove the optimization at
(*buffered.Image).ReplacePixels.

  // This commit w/ the optimization
  BenchmarkImageDrawOver-8           60225             19241 ns/op

  // This commit w/o the optimization
  BenchmarkImageDrawOver-8           66567             17700 ns/op

  // The previous w/ the optimization
  BenchmarkImageDrawOver-8           62355             19580 ns/op

  // The previous w/o the optimization
  BenchmarkImageDrawOver-8           54460             22768 ns/op

Updates #1137
2020-06-14 01:16:23 +09:00
Hajime Hoshi
40906676e6 buffered: Add 'Pixels' and remove 'At'
This is a preparation to make shareable.Image and ebiten.Image 1:1
Now sub-images doesn't have its own shareable.Image.

Updates #896
Updates #1194
2020-06-13 21:01:50 +09:00
Hajime Hoshi
2f843c49a6 shader: Fix the case when the source image is nil for shaders 2020-06-04 01:35:35 +09:00
Hajime Hoshi
f92253487f buffered: Add Shader 2020-05-30 03:36:28 +09:00
Hajime Hoshi
218b6fc172 mipmap: Add Shader 2020-05-29 04:12:41 +09:00
Hajime Hoshi
bbf9b219ec buffered: Skip mutex at ReplacePixels when possible
Updates #1137
2020-04-19 00:18:19 +09:00
Hajime Hoshi
3550abef7a shareable: Replace At with Pixels
This change replaces the API At with Pixels to reduce mutex locks.

Updates #1137
2020-04-18 21:05:51 +09:00
Hajime Hoshi
bbeb0d14e6 buffered: Defer filling an image
This change defers filling an image so that successive fillings
can be merged into one for more efficient rendering.

Fixes #1134
2020-04-18 02:11:25 +09:00
Hajime Hoshi
514c3faebd buffered: Remove unnecessary line and add comments 2020-04-17 21:50:42 +09:00
Hajime Hoshi
1d701577d6 buffered: Use the pending pixels when possible at At
(*Image).At can be unnecessarily slow since this tries to get
pixels from GPU. This change reduces the chance to read GPU by
using its pending pixels when possible.

Fixes #1137
2020-04-17 21:34:49 +09:00
Hajime Hoshi
ab94cebd02 buffered: Use RunGame for tests 2020-04-01 18:32:14 +09:00
corfe83
b3c567de89
Fix another ~300 allocations per frame in my test project (#1089)
This simple change brings my simple test project from 752 allocations per frame to 474 allocations per frame. It seems a shame that go's escape analysis is not smart enough to leave this variable on the stack.

GeoM is a 24-byte struct and there is a slight perf difference that we are storing it in stack, but also copying it around with this change (instead of an 8-byte pointer). This could make things faster (due to stack / CPU cache) or slower (due to copying more memory) - when I try a stress test (drawing 100K images per frame), I can't see any actual performance difference (but I do see 100K fewer allocations, and GC is no longer running almost all the time).
2020-02-22 13:40:17 +09:00
Hajime Hoshi
875a529708 graphics: Allow ReplacePixels on a sub-image
Fixes #980
2020-02-16 22:18:07 +09:00
Hajime Hoshi
d9bd7ab07d buffered: Remove (*Image).Set
This is a preparation for ReplacePixels of a sub-image.

Updates #980
2020-02-16 21:45:28 +09:00
Hajime Hoshi
733c1b649a buffered: Bug fix: Copying pixels failed for the delayed commands
Fixes #1082
2020-02-16 20:16:04 +09:00
Hajime Hoshi
911b36ed98 buffered: Refactoring 2020-02-16 20:03:04 +09:00
Hajime Hoshi
405ae99b32 buffered: Refactoring: Flush delayed functions without the lock 2020-02-16 19:53:17 +09:00
Hajime Hoshi
ff8689cfcd buffered: Bug fix: Set and some functions before the main loop caused wrong results
invalidatePendingPixels was not called properly.

Fixes #1081
2020-02-16 19:06:48 +09:00
Hajime Hoshi
6250dd9f9b buffered: Bug fix: ebiten.Run must be called from the main thread
Updates #1027
2020-02-09 04:53:26 +09:00
Hajime Hoshi
4159c500bd buffered: Refactoring: Use defer
defer's performance will be much better as of Go 1.14.

https://tip.golang.org/doc/go1.14#runtime
2020-02-08 20:58:28 +09:00
Hajime Hoshi
46601bb516 graphics: Fill the screenshot in black when the screen is not transparent
Fixes #997
2020-02-06 03:08:16 +09:00
Hajime Hoshi
b3bdf51905
graphicscommand: Return the error immediately (#1060)
Now grpahicscommand saves the error and shows the error after a
while. This was good to simplify the API but was the cause to hide
some issues.

This change fixes all the errors to be returned immediately, and
buffer this in the ebiten package instead.

Fixes #971
2020-01-19 01:18:56 +09:00
Hajime Hoshi
68d58d7452 buffered: Refactoring 2020-01-11 03:11:56 +09:00
Hajime Hoshi
52a5ed0ad4 buffered: Add tests for #1050 2020-01-11 02:45:46 +09:00
hiroebe
27404b7ae3 buffered: Fix delayed DrawImage() (#1050) 2020-01-10 23:58:22 +09:00
Hajime Hoshi
c99fd1a742 mipmap: Create mipmap package and bufferd.Image uses it
Mipmap calculation must be executed after the main loop starts
because the graphics driver's HasHighPrecisionFloat is needed.
Then, operations on mipmap images must be called from images in
buffered package.

Updates #1044
2020-01-08 02:06:01 +09:00
Hajime Hoshi
42056c2d61 restorable: Refactoring: Remove Clear
Fill now fills the whole texture.
2019-12-02 03:03:07 +09:00
Hajime Hoshi
16b3a5c296 buffered: Bug fix: Needed to copy pixels when buffering
Updates #983
2019-11-16 16:39:02 +09:00
Hajime Hoshi
8d12446dbe buffered: Bug fix: reset the flag when invalidating the pending pixels
Updates #977
2019-11-09 05:54:27 +09:00
Hajime Hoshi
ec59e9b9ae buffered: Bug fix: Resolve pixels only when Set is called
Fixes #977
2019-11-09 05:43:36 +09:00
Hajime Hoshi
5027bc1af5 buffered: Allow Set before the game runs
Fixes #949
2019-10-12 03:13:29 +09:00
Hajime Hoshi
3cf867035d buffered: Do not delay commands if possible
Delaying commands causes memory allocations, which can be heavy
especially on browsers.

This avoids to use 'defer' for performance.
2019-09-27 03:27:47 +09:00
Hajime Hoshi
3291ec51bb buffered: Use a raw function to avoid allocating structs 2019-09-27 00:37:31 +09:00
Hajime Hoshi
fc3e8bebe4 Use 0-length slice instead of nil to keep capacities 2019-09-27 00:34:55 +09:00
Hajime Hoshi
79b32c7601 graphics: Add buffered package
Moved the command queue to the package.
2019-09-21 22:34:37 +09:00