<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenCL on Erik “kusma” Faye-Lund</title>
    <link>https://kusma.xyz/blog/tags/opencl/</link>
    <description>Recent content in OpenCL on Erik “kusma” Faye-Lund</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <managingEditor>kusmabite@gmail.com (Erik Faye-Lund)</managingEditor>
    <webMaster>kusmabite@gmail.com (Erik Faye-Lund)</webMaster>
    <lastBuildDate>Wed, 10 Mar 2021 20:30:28 +0100</lastBuildDate>
    <atom:link href="https://kusma.xyz/blog/tags/opencl/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>OpenGL on DirectX: Conformance &amp; upstreaming of the D3D12 driver</title>
      <link>https://kusma.xyz/blog/2021/03/10/d3d12-upstreaming/</link>
      <pubDate>Wed, 10 Mar 2021 20:30:28 +0100</pubDate>
      <author>kusmabite@gmail.com (Erik Faye-Lund)</author>
      <guid>https://kusma.xyz/blog/2021/03/10/d3d12-upstreaming/</guid>
      <description>&lt;p&gt;Over the last year and then so, we at Collabora have been working with
Microsoft on their &lt;a href=&#34;https://devblogs.microsoft.com/directx/in-the-works-opencl-and-opengl-mapping-layers-to-directx&#34;&gt;D3D12 mapping layer&lt;/a&gt;, which I announced in my
&lt;a href=&#34;https://kusma.xyz/blog/2020/03/24/d3d12-mesa-driver/&#34;&gt;previous blog post&lt;/a&gt;. In July, Louis-Francis Ratté-Boulianne &lt;a href=&#34;https://www.collabora.com/news-and-blog/blog/2020/07/09/deep-dive-into-opengl-over-directx-layering/&#34;&gt;wrote an
update&lt;/a&gt; on the status on the Collabora blog, but a lot has
happened since then, so it&amp;rsquo;s time for another update.&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s two major things that has happened since then; we have passed the
OpenGL 3.3 conformance tests, and we have upstreamed the code in &lt;a href=&#34;https://www.mesa3d.org/&#34;&gt;Mesa 3D&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;photoshop-support&#34;&gt;Photoshop support
&lt;a class=&#34;header-link&#34; href=&#34;#photoshop-support&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;It might not be a big surprise, but one of the motivation for this work was
to be able to run applications like Photoshop on Windows devices without full
OpenGL support.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m happy to report that Microsoft has released their &lt;a href=&#34;https://devblogs.microsoft.com/directx/announcing-the-opencl-and-opengl-compatibility-pack-for-windows-10-on-arm/&#34;&gt;compatibility pack&lt;/a&gt;
that uses our work to provide OpenGL (and OpenCL) support, &lt;a href=&#34;https://feedback.photoshop.com/conversations/photoshop-beta/photoshop-beta-for-windows-arm-is-here/5fb3584b38150f55db64b1e4&#34;&gt;Photoshop can now
run on Windows on ARM CPUs&lt;/a&gt;! This is pretty exciting to see
high-profile applications like that benefit from our work!&lt;/p&gt;
&lt;h2 id=&#34;opengl-33-conformance-test-suite&#34;&gt;OpenGL 3.3 Conformance Test Suite
&lt;a class=&#34;header-link&#34; href=&#34;#opengl-33-conformance-test-suite&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;First of all, I would like to point out that having passed the OpenGL
&lt;abbr title=&#34;Conformance Test Suite&#34;&gt;CTS&lt;/abbr&gt;
 isn&amp;rsquo;t necessarily the same as
being formally conformant. There&amp;rsquo;s some details about how to formally
becoming conformant on layered implementations that are complicated, and I&amp;rsquo;ll
leave the question about formal conformance up to Microsoft and Khronos.&lt;/p&gt;
&lt;p&gt;Instead, I want to talk a bit about &lt;em&gt;passing the OpenGL CTS&lt;/em&gt;.&lt;/p&gt;
&lt;h3 id=&#34;challenges-for-layered-implementations&#34;&gt;Challenges for layered implementations
&lt;a class=&#34;header-link&#34; href=&#34;#challenges-for-layered-implementations&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;A problem we face with layered implementations is that we are subject to a
few more sources of issues, some of which are entirely out of our control.
A normal OpenGL, non-layered, implementation have two primary sources of
issues:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The OpenGL driver&lt;/li&gt;
&lt;li&gt;The hardware&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Issues with the OpenGL driver itself that leads to tests failing is always
required to be fixed before results are submitted. Issues with the hardware
&lt;em&gt;generally&lt;/em&gt; requires software workarounds, but this is not always feasible,
so Khronos have a system where a vendor can file a &lt;a href=&#34;https://github.com/KhronosGroup/VK-GL-CTS/tree/master/external/openglcts#waivers&#34;&gt;waiver&lt;/a&gt; for a hardware
issue, and if approved they can mark test-failures as waived, and the
appropriate failures will be ignored.&lt;/p&gt;
&lt;p&gt;So far so good.&lt;/p&gt;
&lt;p&gt;But for our layered implementations, our world looks a bit different. We
don&amp;rsquo;t really see the hardware, but instead we see D3D12 and the D3D12
driver. This means our sources of issues are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The OpenGL driver&lt;/li&gt;
&lt;li&gt;The D3D12 run-time&lt;/li&gt;
&lt;li&gt;The D3D12 vendor-driver&lt;/li&gt;
&lt;li&gt;The hardware&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For the OpenGL driver, the story is the same as for a non-layered
implementation, but from there on things start changing.&lt;/p&gt;
&lt;p&gt;Problems in the D3D12 run-time must also be fixed before submitting results.
We work together with Microsoft to get these issues fixed as appropriate.
Such fixes can take a while to trickle all the way into a Windows build and
to end-users, but they will eventually show up.&lt;/p&gt;
&lt;p&gt;But for the D3D12 vendor-driver and below, things gets complicated. First of
all, it&amp;rsquo;s not always possible for us to tell vendor-driver issues and
hardware issues apart. And worse, as these are developed by third party
companies, we have little insight there. We can&amp;rsquo;t affect their priorities,
so it&amp;rsquo;s hard to know when or even if an issue gets resolved.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s also not really a good idea to work around such issues, because if they
turn out to be fixable software problems, we don&amp;rsquo;t know when they will be
fixed, so we can&amp;rsquo;t really tell when to disable the work-around. We also don&amp;rsquo;t
know exactly what combination of hardware and software these issues apply to.&lt;/p&gt;
&lt;p&gt;But there&amp;rsquo;s one case where we have full insight, and that&amp;rsquo;s when the D3D12
vendor-driver is &lt;a href=&#34;https://docs.microsoft.com/en-us/windows/win32/direct3darticles/directx-warp&#34;&gt;WARP&lt;/a&gt;, a high-performance software rasterizer. Because that
component is developed by Microsoft, and we have channels to report issues
and even make sure they get resolved!&lt;/p&gt;
&lt;h3 id=&#34;bugs-bugs-bugs&#34;&gt;Bugs, bugs, bugs
&lt;a class=&#34;header-link&#34; href=&#34;#bugs-bugs-bugs&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;When developing something new, there&amp;rsquo;s always going to be bugs. But usually
also when using something existing in a new way. We encountered a lot of bugs
on our way, and here&amp;rsquo;s a quick overview over some of them. This is in no way
exhaustive, and most of our own bugs are not that interesting. So this is
mostly about problems unique to layered implementations.&lt;/p&gt;
&lt;h4 id=&#34;64-bit-shifts&#34;&gt;64-bit shifts
&lt;a class=&#34;header-link&#34; href=&#34;#64-bit-shifts&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;It turned out early on that the DXIL validator in D3D12 had a requirement
when parsing the LLVM bitcode that required that the amounts were always
32-bit values. While this seems fine by itself, LLVM itself requires that
all operands to binops have the same bit-size. This obviously meant that
only 32-bit shifts could pass the validator.&lt;/p&gt;
&lt;p&gt;Microsoft quickly removed this requirement once we figured out what was
going on.&lt;/p&gt;
&lt;h4 id=&#34;aligned-block-compressed-textures&#34;&gt;Aligned block-compressed textures
&lt;a class=&#34;header-link&#34; href=&#34;#aligned-block-compressed-textures&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;In D3D12, one requirement for block-compressed textures is that the
base-level is aligned to ther block-size. This requirement does not apply
to mip-levels, and OpenGL has no such requirement. This isn&amp;rsquo;t technically
speaking a bug, but a documented limitation in DirectX.&lt;/p&gt;
&lt;p&gt;It turns out that this limitation was an artificial historical left-over,
and after a bunch of testing (and fixing of WARP), we got this limitation
lifted. Great :)&lt;/p&gt;
&lt;h3 id=&#34;d3d12-vendor-driver-bugs&#34;&gt;D3D12 vendor-driver bugs
&lt;a class=&#34;header-link&#34; href=&#34;#d3d12-vendor-driver-bugs&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Something that has been much more frustrating is bugs in the
vendor-drivers. The problem here is that even though we have channels to
file bugs, we don&amp;rsquo;t have any influence or even insight into their
prioritization and release schedule.&lt;/p&gt;
&lt;p&gt;I think it suffice to say that there&amp;rsquo;s been several reported bugs to all
vendors we&amp;rsquo;ve actively been running the OpenGL CTS on top of. We believe
fixes are underway for at least some of this, but we can&amp;rsquo;t make any promises
here.&lt;/p&gt;
&lt;h3 id=&#34;current-status&#34;&gt;Current status
&lt;a class=&#34;header-link&#34; href=&#34;#current-status&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Right now, the only configurations we&amp;rsquo;re cleanly passing the OpenGL 3.3
CTS on are WARP (which &lt;a href=&#34;https://www.khronos.org/conformance/adopters/conformant-products/opengl#submission_279&#34;&gt;became conformant on November 24th, 2020&lt;/a&gt;),
and NVIDIA (which &lt;a href=&#34;https://www.khronos.org/conformance/adopters/conformant-products/opengl#submission_288&#34;&gt;became conformant on February 26th, 2021&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Having these multiple independent implementations of DirectX drivers passing
in conjunction with the Mesa/D3D12 layer shows that we are able to implement
GLon12 in a vendor-neutral way, which allowed us to bring the layer to
conformance. Many thanks to Khronos for their assistance through this process.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ve also submitted results on top of an Intel GPU, but that submission
has been halted due to failures, and will as far as I know be updated as
soon as Intel publish updated drivers.&lt;/p&gt;
&lt;p&gt;The conformance tests have been run against our &lt;a href=&#34;https://gitlab.freedesktop.org/kusma/mesa/-/commits/msclc-d3d12&#34;&gt;downstream fork&lt;/a&gt;, which is
no longer actively maintained, because:&lt;/p&gt;
&lt;h2 id=&#34;upstreaming&#34;&gt;Upstreaming
&lt;a class=&#34;header-link&#34; href=&#34;#upstreaming&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The D3D12 driver was upstreamed in Mesa in &lt;a href=&#34;https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7477&#34;&gt;Merge-Request 7477&lt;/a&gt;, and the
OpenCL compiler followed in &lt;a href=&#34;https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7565&#34;&gt;Merge-Request 7565&lt;/a&gt;. There&amp;rsquo;s been &lt;a href=&#34;https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests?scope=all&amp;amp;state=all&amp;amp;label_name%5B%5D=d3d12&#34;&gt;a lot more
merge-requests&lt;/a&gt; since then, and even more is expected
in the future.&lt;/p&gt;
&lt;p&gt;The process of upstreaming the driver into Mesa3D went relatively smoothly,
but there were quite a lot of regressions that happened quickly after we
upstreamed the code, so to avoid this from becoming a big problem we&amp;rsquo;ve
added the D3D12 driver to Mesa&amp;rsquo;s set of GitLab CI tests. We now build and
test the D3D12 driver on top of WARP on CI, as well as running some basic
sanity-tests for the OpenCL compiler.&lt;/p&gt;
&lt;p&gt;All in all, this seems to work very well right now, and we&amp;rsquo;re looking
forward to the future. Next step, &lt;a href=&#34;https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7937&#34;&gt;WSL support&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m no longer working full-time on this project, instead I&amp;rsquo;m trying to
take some of the lessons learned and apply them to &lt;a href=&#34;https://kusma.xyz/blog/2018/10/31/introducing-zink/&#34;&gt;Zink&lt;/a&gt;. I&amp;rsquo;m sure there&amp;rsquo;s
even more room for code-reuse than what we currently have, but it will
probably take some time to figure out.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Introducing OpenCL™ and OpenGL® on DirectX</title>
      <link>https://kusma.xyz/blog/2020/03/24/d3d12-mesa-driver/</link>
      <pubDate>Tue, 24 Mar 2020 13:46:55 +0100</pubDate>
      <author>kusmabite@gmail.com (Erik Faye-Lund)</author>
      <guid>https://kusma.xyz/blog/2020/03/24/d3d12-mesa-driver/</guid>
      <description>&lt;p&gt;For the last few months, we have been working on two exciting new projects at
Collabora, and it&amp;rsquo;s finally time to share some information about them with the
world:&lt;/p&gt;
&lt;p&gt;We are partnering with &lt;a href=&#34;https://devblogs.microsoft.com/directx/in-the-works-opencl-and-opengl-mapping-layers-to-directx&#34;&gt;Microsoft DirectX engineers&lt;/a&gt; to build &lt;a href=&#34;https://www.khronos.org/opencl/&#34;&gt;OpenCL&lt;/a&gt; and &lt;a href=&#34;https://www.opengl.org/&#34;&gt;OpenGL&lt;/a&gt;
mapping layers, in order to bring OpenCL 1.2 and OpenGL 3.3 support to all Windows
and DirectX 12 enabled devices out there!&lt;/p&gt;
&lt;p&gt;This work builds on a lot of previous work. First and foremost, we are
building this by using &lt;a href=&#34;https://www.mesa3d.org/&#34;&gt;Mesa 3D&lt;/a&gt;, with the Gallium interface as the base
for the OpenGL layer, and NIR as the base for the OpenCL compiler. We are also
using &lt;a href=&#34;http://llvm.org/&#34;&gt;LLVM&lt;/a&gt; and the &lt;a href=&#34;https://github.com/KhronosGroup/SPIRV-LLVM-Translator&#34;&gt;SPIRV-LLVM-Translator&lt;/a&gt; from Khronos as the compiler
front-end.&lt;/p&gt;
&lt;p&gt;In addition, we are taking advantage of Microsoft&amp;rsquo;s experience in creating
their &lt;a href=&#34;https://devblogs.microsoft.com/directx/d3d12-translation-layer-and-d3d11on12-are-now-open-source/&#34;&gt;D3D12 Translation Layer&lt;/a&gt;, as well as our own experience from
developing &lt;a href=&#34;https://www.collabora.com/news-and-blog/blog/2018/10/31/introducing-zink-opengl-implementation-vulkan/&#34;&gt;Zink&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;what-is-mesa-3d&#34;&gt;What is Mesa 3D?
&lt;a class=&#34;header-link&#34; href=&#34;#what-is-mesa-3d&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Mesa 3D is an open source implementation of several graphics technologies,
including OpenCL and OpenGL. The OpenGL implementation in Mesa is robust
and is used as the base for several industry-strength OpenGL drivers from
multiple GPU vendors.&lt;/p&gt;
&lt;p&gt;Among other things, Mesa consists of several API implementations (called
state-trackers) as well as the Gallium low-level driver interface. The
Gallium interface hides a lot of the legacy OpenGL details and translates
OpenGL calls into something that looks more like modern GPU primitives.&lt;/p&gt;
&lt;h2 id=&#34;why-translate-apis&#34;&gt;Why translate APIs?
&lt;a class=&#34;header-link&#34; href=&#34;#why-translate-apis&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Not all Windows-powered devices have consistent support for hardware-accelerated
OpenCL and OpenGL. So in order to improve application compatibility, we are building
a generic solution to the problem. This means that a GPU vendor only has to
implement a D3D12 driver for their hardware in order to support all three
APIs.&lt;/p&gt;
&lt;p&gt;This mapping layer is also expected to serve as a starting point in porting
older OpenCL and OpenGL applications over to D3D12.&lt;/p&gt;
&lt;p&gt;In addition, we believe this is good for the wider open source community. A
lot of the problems we are solving here are shared with other drivers and
translation layers, and we hope that the code will be useful beyond the
use cases listed above.&lt;/p&gt;
&lt;h2 id=&#34;implementation&#34;&gt;Implementation
&lt;a class=&#34;header-link&#34; href=&#34;#implementation&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The work is largely split into three parts: an OpenCL compiler, an OpenCL
runtime, and a Gallium driver that builds and executes command-buffers on
the GPU using the D3D12 API.&lt;/p&gt;
&lt;p&gt;In addition, there is a shared NIR-to-DXIL shader compiler that both
components use. For those not familiar with NIR, it is Mesa&amp;rsquo;s
internal representation for GPU shaders. Similarly, DXIL is Microsoft&amp;rsquo;s
internal representation, which D3D12 drivers will consume and translate
into hardware-specific shaders.&lt;/p&gt;
&lt;h3 id=&#34;opencl-compiler&#34;&gt;OpenCL compiler
&lt;a class=&#34;header-link&#34; href=&#34;#opencl-compiler&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;The OpenCL compiler uses LLVM and the SPIRV-LLVM-Translator to generate
&lt;a href=&#34;https://www.khronos.org/spir/&#34;&gt;SPIR-V&lt;/a&gt; representations of OpenCL kernels. These, in turn, are passed to
Mesa&amp;rsquo;s SPIR-V to NIR translator, where some optimizations and semantical
translations are done. Then the NIR representation is finally passed to
NIR-to-DXIL, which produces a DXIL compute shader and the needed metadata so
it can be executed on the GPU by the runtime using D3D12.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s a diagram of the complete process, including NIR-to-DXIL, which
will be described below:&lt;/p&gt;
&lt;figure&gt;
  &lt;img src=&#34;https://kusma.xyz/blog/2020/03/24/d3d12-mesa-driver/images/opencl-compiler-overview.svg&#34; alt=&#34;OpenCL Compiler Overview&#34; title=&#34;OpenCL Compiler Overview&#34;&gt;
  &lt;figcaption&gt;OpenCL Compiler Overview&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h3 id=&#34;opencl-runtime&#34;&gt;OpenCL runtime
&lt;a class=&#34;header-link&#34; href=&#34;#opencl-runtime&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;While Mesa provides an OpenCL implementation called Clover, we are not
using it for this project. Instead, we have a new OpenCL runtime that does
a more direct translation to the DirectX 12 API.&lt;/p&gt;
&lt;h3 id=&#34;nir-to-dxil&#34;&gt;NIR-to-DXIL
&lt;a class=&#34;header-link&#34; href=&#34;#nir-to-dxil&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;DXIL is essentially LLVM 3.7 bitcode with some extra metadata and
validation. This was a technical choice that made sense for Microsoft
because all the major driver vendors already used LLVM in their compiler
toolchain. Using an older version of the LLVM bitcode format gives good
compatibility with drivers because the LLVM bitcode format is backwards
compatible.&lt;/p&gt;
&lt;p&gt;Because we depend on a much more recent version of LLVM for the compiler
front-end, we sadly cannot easily use the &lt;a href=&#34;https://github.com/microsoft/DirectXShaderCompiler&#34;&gt;DirectX Shader Compiler&lt;/a&gt; as a
compiler back-end. The DirectX Shader Compiler is effectively a fork of
LLVM 3.7, and we are currently using LLVM 10.0 for the compiler front-end.
Using DirectX Shader Compiler as that would require us to link two different
versions of LLVM into the same binary, which would have led to problems.&lt;/p&gt;
&lt;p&gt;We also cannot easily use LLVM itself to generate the bitcode. While the
LLVM bitcode format is backwards compatible, LLVM itself is not &lt;em&gt;forward
compatible&lt;/em&gt;. This means that newer versions of LLVM cannot produce a bitcode
format that is understood by older versions. This makes sense from LLVM&amp;rsquo;s
point of view because it was never meant as a general interchange format.&lt;/p&gt;
&lt;p&gt;So instead, we have decided to implement our own DXIL emitter. This is
quite a bit harder than it looks because LLVM bitcode goes to great lengths
to try to make the format as dense as possible. For instance, LLVM does not
store its bitcode as a sequence of bytes and words, but rather as variable-width
bitfields in a long sequence of bits.&lt;/p&gt;
&lt;p&gt;There are a lot of tricky details to get right, but in the end we have a
compiler that works.&lt;/p&gt;
&lt;h3 id=&#34;d3d12-gallium-driver&#34;&gt;D3D12 Gallium driver
&lt;a class=&#34;header-link&#34; href=&#34;#d3d12-gallium-driver&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;The D3D12 Gallium driver is the last piece of the puzzle. Essentially,
it takes OpenGL commands and, with the help of the NIR to DXIL translator,
turns them into D3D12 command-buffers, which it executes on the GPU using
the D3D12 driver.&lt;/p&gt;
&lt;p&gt;There are a lot of interesting details that makes this tricky as well, but
I will save those details for later.&lt;/p&gt;
&lt;p&gt;But to not leave you empty-handed, here&amp;rsquo;s a screenshot of the Windows
version of the famous glxgears, &lt;a href=&#34;https://gitlab.freedesktop.org/mesa/demos/-/blob/master/src/wgl/wglgears.c&#34;&gt;wglgears&lt;/a&gt;:&lt;/p&gt;
&lt;figure&gt;
  &lt;img src=&#34;https://kusma.xyz/blog/2020/03/24/d3d12-mesa-driver/images/wglgears.png&#34; alt=&#34;wglgears on DirectX12&#34; title=&#34;wglgears on DirectX12&#34;&gt;
  &lt;figcaption&gt;wglgears on DirectX12&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h2 id=&#34;source-code&#34;&gt;Source code
&lt;a class=&#34;header-link&#34; href=&#34;#source-code&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;In the short term, the source code can be &lt;a href=&#34;https://gitlab.freedesktop.org/kusma/mesa/-/tree/msclc-d3d12&#34;&gt;found here&lt;/a&gt;. We
intend on upstreaming this work into the &lt;a href=&#34;https://gitlab.freedesktop.org/mesa/mesa/&#34;&gt;main Mesa repository&lt;/a&gt; shortly, so
it is not a permanent home.&lt;/p&gt;
&lt;h2 id=&#34;next-steps&#34;&gt;Next steps
&lt;a class=&#34;header-link&#34; href=&#34;#next-steps&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;This is just the announcement, and a whole lot of work is left to be done. We
have something that works in some cases right now, but we are just starting to
scratch the surface.&lt;/p&gt;
&lt;p&gt;First of all, we need to get up to the feature-level that we target. Our
goals at the moment is to pass conformance tests for OpenCL 1.2 and OpenGL
3.3. We have a long way to go, but with some hard work and sweat, I am sure
we will get there.&lt;/p&gt;
&lt;p&gt;Secondly, we need to work on application compatibility. For now we will be
focusing on productivity applications.&lt;/p&gt;
&lt;p&gt;We also want to upstream this in Mesa. This way we can keep up with fixes
and new features in Mesa, and other drivers can benefit from what we are
doing as well.&lt;/p&gt;
&lt;h2 id=&#34;acknowledgments&#34;&gt;Acknowledgments
&lt;a class=&#34;header-link&#34; href=&#34;#acknowledgments&#34;&gt;&lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;It is also important to point out that I am not the only one working on
this. Our team consists of five additional Collabora engineers (Boris Brezillon,
Daniel Stone, Elie Tournier, Gert Wollny, Louis-Francis Ratté-Boulianne)
and two Microsoft DirectX engineers (Bill Kristiansen, Jesse Natalie).&lt;/p&gt;</description>
    </item>
    
  </channel>
</rss>
