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

WIP: MRT Proof of concept #2953

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft

WIP: MRT Proof of concept #2953

wants to merge 34 commits into from

Conversation

Zyko0
Copy link
Contributor

@Zyko0 Zyko0 commented Apr 6, 2024

What issue is this addressing?

#2930

What this PR does | solves

This is a proof of concept of MRT (multiple render target), to investigate if the concept could be integrated to ebitengine, this is not a merge candidate for now.

go run ./examples/mrt
image

dsts = [4]*ebiten.Image{
		ebiten.NewImageWithOptions(image.Rect(0, 0, 128, 128), &ebiten.NewImageOptions{Unmanaged: true}),
		ebiten.NewImageWithOptions(image.Rect(0, 0, 128, 128), &ebiten.NewImageOptions{Unmanaged: true}),
		ebiten.NewImageWithOptions(image.Rect(0, 0, 128, 128), &ebiten.NewImageOptions{Unmanaged: true}),
		ebiten.NewImageWithOptions(image.Rect(0, 0, 128, 128), &ebiten.NewImageOptions{Unmanaged: true}),
}
shaderSrc = []byte(`
//kage:units pixels

package main

func Fragment(dst vec4, src vec2, color vec4) (vec4, vec4, vec4, vec4) {
	return vec4(1,0,0,1), vec4(0,1,0,1), vec4(0,0,1,1), vec4(1,0,1,1)
}
`

{
      ebiten.DrawTrianglesShaderMRT(dsts, vertices, indices, s, nil)
      // screen.Draw all 4 images to assess that they've been written to with the same geometry / draw call
}
  • OpenGL
  • DirectX 11
  • DirectX 12
  • WebGL => A bit more problematic due to the glsl compatibility between desktop
  • Metal

Notes:

  • It only seems to make sense with unmanaged *ebiten.Image (as in different internal textures).
    • dst images could be moved to separate atlases if they're not ebiten.unmanaged: Support Multiple render target (MRT) #2930 (comment)
    • dst images, if moved to new textures or existing (available) ones should share the same region (rectangle) as they originally do, because of scissor, viewport definition but mostly because the triangles define the logical destination position, moving to an arbitrary region would make the triangles target the wrong rectangle
    • dst images should have the same sizes probably, since the triangles, scissor and viewport should target the same region for all destination textures
  • I set the max dst images count to 8, since 8 seems to be the guaranteed minimum by all drivers

@Zyko0 Zyko0 mentioned this pull request Apr 6, 2024
11 tasks
@Zyko0 Zyko0 force-pushed the main branch 3 times, most recently from bc1eae0 to 5b54a1d Compare April 13, 2024 14:21
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

Successfully merging this pull request may close these issues.

None yet

1 participant