Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprite Drawing Benchmark #4

Open
Nathan-MV opened this issue Feb 1, 2024 · 5 comments
Open

Sprite Drawing Benchmark #4

Nathan-MV opened this issue Feb 1, 2024 · 5 comments

Comments

@Nathan-MV
Copy link
Contributor

As it is still in development, it may help you, LiteRGSS2 seems to be the fastest of the bunch for now

Engine Sprites Frames per Second
MKXP-Z 20,000 34
RGM 50,000 33
LiteRGSS2 50,000 47
class SpriteGenerator
  DEFAULT_SPRITE_COUNT = 20_000
  SCREEN_WIDTH = 640
  SCREEN_HEIGHT = 480
  SPRITE_SIZE = 32

  def initialize
    @sprite_count = DEFAULT_SPRITE_COUNT
    @viewport = Viewport.new(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)
    @bitmap = nil
  end

  def run
    initialize_sprites
    loop do
      Graphics.update
    end
  rescue StandardError
    puts "\nEND\n"
  end

  private

  def initialize_sprites
    puts "Sprite Count: #{@sprite_count}"

    @sprites = @sprite_count.times.map do |i|
      initialize_bitmap if (i % 100).zero?
      initialize_sprite
    end
  end

  def initialize_bitmap
    @bitmap = Bitmap.new(320, 320)
    @bitmap.fill_rect(0, 0, 320, 320, random_color)
  end

  def initialize_sprite
    sprite = Sprite.new(@viewport)
    sprite.bitmap = @bitmap
    sprite.x = rand(SCREEN_WIDTH) - SPRITE_SIZE
    sprite.y = rand(SCREEN_HEIGHT) - SPRITE_SIZE
    set_sprite_src_rect(sprite)
    sprite
  end

  def set_sprite_src_rect(sprite)
    j = @sprite_count % 100
    sprite.src_rect.set(32 * (j / 10), 32 * (j % 10), SPRITE_SIZE, SPRITE_SIZE)
  end

  def random_color
    Color.new(rand(256), rand(256), rand(256), 32)
  end
end

SpriteGenerator.new.run
@Admenri
Copy link
Owner

Admenri commented Feb 7, 2024

Thank you for the test code. I tested it with my 3050 graphics card, and it can run 20,000 sprites at a full 60 FPS, but drops to about 30 FPS with 50,000 sprites. However, I don't plan to pursue extremely high performance since my time is limited, so I might lean more towards compatibility and extensibility.

@Nathan-MV
Copy link
Contributor Author

Nathan-MV commented Feb 22, 2024

Updated my benchmarks

mkxp-z can draw 10k at 26 fps, with YJIT it can draw 20k at 34 fps (YJIT was tested with Linux)
mkxp-z with Angle (Direct3D) can draw 10k at 39 fps and Angle (Vulkan) at 44 fps, with YJIT
 and Angle (Direct3D) it can draw 20k at 19 fps and Angle (Vulkan) at 24 fps (YJIT was tested with Linux)

RGD can draw 10k at 39 fps, with batch drawing it can draw 10k at 49 fps (RGD 1.5.4 is faster than the experimental 1.6.1)
RGU with any Angle options can draw 10k at 19 fps (The new build released a day ago)
RGM can draw 50k with 33 fps

LiteRGSS2 can draw 60k at 42 fps

I assume that RGM performance at it is because of Centurion? (I mean everything is just using SDL2 minus LiteRGSS2)
https://github.com/albin-johansson/centurion
YJIT is just a matter of building Ruby with Rust installed and using --yjit to start Ruby, but only works on MacOS and Linux

@Admenri
Copy link
Owner

Admenri commented Feb 23, 2024

The engine has just reached a stable phase. In the early stages of development, I skipped many optimization steps to save development time. Perhaps it's time to start optimizing soon.

@Nathan-MV
Copy link
Contributor Author

On the latest release, this benchmark is only capable of drawing 2k sprites at 60 FPS, the same as RGSS3 Game.exe

@Admenri
Copy link
Owner

Admenri commented Sep 28, 2024

On the latest release, this benchmark is only capable of drawing 2k sprites at 60 FPS, the same as RGSS3 Game.exe

Oh, the renderer does not batch sprites. Although the benchmark scores might be lower, the actual performance in the game is good (an action game on steam is using the engine).
I have marked the 1.0 version branch using OpenGL as legacy. The current 2.0 version branch uses the native graphics APIs of bgfx's D3D12/Vulkan, which should significantly improve performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants