Vulkan lavapipe software rendering is working on Haiku

Just asking about Zink since my engine is OpenGL at the time being but does push OpenGL 4.6 stuff if present. Would be interesting (maybe only for me) where it goes and it does not require any fancy windowing system (native BeOS).

2 Likes

I implemented RadeonGfx driver server mode and now it is possible to run multiple processes that use 3D acceleration. Because of GFX ring reset hack, command buffer scheduling is limited and only one command buffer can be executed at moment of time.

screenshot53

29 Likes

RadeonGfx use client-server model with client-server thread pairs like in app_server. For each client thread that calls 3D acceleation API, server side thread is created. If client thread terminates, server side thread also exit. I made small library “ThreadLink” that implements client-server thread pair model and simpilfy code. Calling server from client is very simple:

port_id gServerPort = find_port("RadeonGfx");

ClientThreadLink *link = GetClientThreadLink(gServerPort);
link->Link().StartMessage(radeonMmapMsg);
link->Link().Attach<int32>((int32)offset);
int32 reply;
link->Link().FlushWithReply(reply);
link->Link().Read<int32>(&area);
link->Link().Read<uint64>(&areaOfs);

Example of client and server stack when waiting command buffer execution to complete.

Client:
screenshot54

Server:
screenshot55

25 Likes

When i originally began studying the code and hardware, i noticed that the Radeon driver already sort of had a acclerant design to it.

Cool stuff man

2 Likes

I looked at Zink code a bit and it seems possible to replace softpipe driver of existing Haiku Gallium add-on with Zink driver. It use memcpy() to draw surface:

static void
zink_flush_frontbuffer(struct pipe_screen *pscreen,
                       struct pipe_context *pcontext,
                       struct pipe_resource *pres,
                       unsigned level, unsigned layer,
                       void *winsys_drawable_handle,
                       struct pipe_box *sub_box)
{
   struct zink_screen *screen = zink_screen(pscreen);
   struct sw_winsys *winsys = screen->winsys;
   struct zink_resource *res = zink_resource(pres);

   if (!winsys)
     return;
   void *map = winsys->displaytarget_map(winsys, res->dt, 0);

   if (map) {
      VkImageSubresource isr = {};
      isr.aspectMask = res->aspect;
      isr.mipLevel = level;
      isr.arrayLayer = layer;
      VkSubresourceLayout layout;
      vkGetImageSubresourceLayout(screen->dev, res->image, &isr, &layout);

      void *ptr;
      VkResult result = vkMapMemory(screen->dev, res->mem, res->offset, res->size, 0, &ptr);
      if (result != VK_SUCCESS) {
         debug_printf("failed to map memory for display\n");
         return;
      }
      for (int i = 0; i < pres->height0; ++i) {
         uint8_t *src = (uint8_t *)ptr + i * layout.rowPitch;
         uint8_t *dst = (uint8_t *)map + i * res->dt_stride;
         memcpy(dst, src, res->dt_stride);
      }
      vkUnmapMemory(screen->dev, res->mem);
   }

   winsys->displaytarget_unmap(winsys, res->dt);

   assert(res->dt);
   if (res->dt)
      winsys->displaytarget_display(winsys, res->dt, winsys_drawable_handle, sub_box);
}

20 Likes

And this works. Blender is working with OpenGL over Zink. No modifications were made to Haiku Gallium addon except changing driver to Zink.

screenshot61

34 Likes

screenshot62

28 Likes

How is the performance in Blender?
You’re doing amazing things, thank you!

1 Like

Not so good for now. In addition to GFX ring problem it probably currently use inoptimal video buffer configuration.

1 Like

9 posts were split to a new topic: AMD Laptops for Haiku (moved from Vulkan lavapipe…)

screenshot63

16 Likes

Nice! as usual :wink:
Would be cool if it would become possible to render on the same card that displays the desktop at some point. Do you have plans for that yet, do you foresee difficulties, or am I just asking a bit too early? :innocent:

3 Likes

there is some kind of opengl fps test in blender, maybe it can help you to see performance differences…
from the search menu in blender, type “debug menu” and then enter “21”
there are other debugging option for opengl here in this video:

1 Like

After fixing buffer stride alignment problem, multiple windows in Blender, window resizing and GLTeapot are working. There are currently problem with efficiency in Zink and RadeonGfx in server mode that it clone and delete buffer on each frame that is time consuming.

screenshot66

28 Likes

Now wiil be a great oportunity to test Godot Engine demos too n,n BTW Godot Engine 4 Alfa have a vulkan engine.

2 Likes

Zink over Lavapipe also works, but with glitches (no cube in Blender) and crashes.

screenshot68

13 Likes

https://news.ycombinator.com/item?id=29390689

4 Likes

Ah those expected standard “Nice, and i would use IF…” comments.

5 Likes

Shall we update the title? It’s more than software rendering at this point.

Maybe better to split when I started to write about implementing stub libdrm for RADV.

6 Likes