Jekyll2021-04-28T01:34:26+00:00/feed.xmledenist - wwwDocumenting the projects I am working on or interesting problems I manage to solve.edenistBuilding mesa-git on Solus Linux2021-04-10T00:00:00+00:002021-04-10T00:00:00+00:00/building-mesa-git-solus<p>UPDATE 2021-04-23: This post initially forgot to include the 32bit build commands. It has been updated to include them.</p>
<p>One of the benefits of running AMDGPU is that the userland component [from Mesa] can be specified at runtime.</p>
<p>For example, fixes for Cyberpunk2077 were merged into Mesa but the version from the Solus repository is usually a few versions behind.
To get these new features [or perhaps you have a need for a specific version of Mesa], it must be built from source.</p>
<p>We can build mesa and install it in a non-standard location, then specify this version to run using the <code class="highlighter-rouge">LD_LIBRARY_PATH</code> variable.</p>
<p>The following dependencies are required to build mesa on Solus. They should be similar on most other major distributions. At the very least, meson will tell you if a dependency is missing, and you can find out which package provides it and install it. Note there is a large dependency list, particularly with the 32bit libraries, but building 32bit support is necessary to run 32bit applications such as Steam.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>eopkg <span class="nb">install </span>system.devel meson ninja llvm-devel llvm-32bit-devel llvm-clang-32bit-devel expat-devel expat-32bit-devel mako xrandr libxxf86vm-devel libxshmfence-devel glproto libva libzstd libnettle-devel libnettle-32bit-devel libva-devel zstd-devel zstd-32bit-devel libxrandr-devel libxrandr-32bit-devel libx11-devel libx11-32bit-devel libxxf86vm-32bit-devel libxshmfence-32bit-devel libxext-devel libxext-32bit-devel libxdamage-devel libxdamage-32bit-devel libelf-devel libelf-32bit-devel libunwind-devel libunwind-32bit-devel zlib-devel zlib-32bit-devel libglvnd-devel libglvnd-32bit-devel libvdpau-devel libvdpau-32bit-devel wayland-protocols-devel fakeroot-32bit libgcc libgcc-32bit xorgproto glibc-devel glibc-32bit-devel libxcb-devel libxcb-32bit-devel wayland-32bit-devel libxfixes-devel libxfixes-32bit-devel libdrm-devel libdrm-32bit-devel libstdc++ libstdc++-32bit libva-32bit-devel xorg-server-devel glslang-devel vulkan vulkan-tools vulkan-32bit
</code></pre></div></div>
<p>In this example, we will be installing mesa into <code class="highlighter-rouge">/opt</code></p>
<p>Obtain a copy of the source code, then configure and build. Take note of the <code class="highlighter-rouge">-Dprefix</code> option, which tells ninja where to install the drivers.
The build is run twice, once each for 32bit and 64bit builds. The following file is used as a crossfile to tell the compiler how to compile the 32bit version. Place it in the build32 directory prior to running meson.</p>
<p><a href="/assets/llvm32.native">llvm32.native</a></p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo mkdir</span> <span class="nt">-p</span> /opt/mesa/mesa-git-20210410
<span class="nb">sudo chown</span> <span class="nt">-R</span> <span class="nv">$USER</span> /opt/mesa
git clone https://gitlab.freedesktop.org/mesa/mesa.git
<span class="nb">cd </span>mesa
<span class="nb">mkdir </span>build
<span class="nb">mkdir </span>build32
<span class="c">#Build 64bit</span>
<span class="nb">cd </span>build
meson .. <span class="nt">-Dprefix</span><span class="o">=</span>/opt/mesa/mesa-git-20210410 <span class="nt">-Dplatforms</span><span class="o">=</span>x11 <span class="nt">-Dgallium-drivers</span><span class="o">=</span>radeonsi,svga,swrast,virgl <span class="nt">-Dgallium-vdpau</span><span class="o">=</span><span class="nb">true</span> <span class="nt">-Dgallium-xa</span><span class="o">=</span><span class="nb">true</span> <span class="nt">-Dgallium-nine</span><span class="o">=</span><span class="nb">true</span> <span class="nt">-Dvulkan-drivers</span><span class="o">=</span>amd <span class="nt">-Dshader-cache</span><span class="o">=</span><span class="nb">true</span> <span class="nt">-Dgbm</span><span class="o">=</span><span class="nb">true</span> <span class="nt">-Degl</span><span class="o">=</span><span class="nb">true</span> <span class="nt">-Dglvnd</span><span class="o">=</span><span class="nb">false</span> <span class="nt">-Dllvm</span><span class="o">=</span><span class="nb">true</span> <span class="nt">-Dosmesa</span><span class="o">=</span><span class="nb">true</span> <span class="nt">-Dvulkan-device-select-layer</span><span class="o">=</span><span class="nb">true</span> <span class="nt">-Dvulkan-overlay-layer</span><span class="o">=</span><span class="nb">true
</span>meson configure <span class="c">#[shows the current configuration to check the options]</span>
ninja
ninja <span class="nb">install</span>
<span class="c">#Build 32bit</span>
<span class="nb">cd</span> ../build32
<span class="c">#copy llvm32.native here</span>
meson .. <span class="nt">--cross-file</span> llvm32.native <span class="nt">--libdir</span><span class="o">=</span>/opt/mesa/mesa-git-20210410/lib32 <span class="nt">-Dprefix</span><span class="o">=</span>/opt/mesa/mesa-git-20210410 <span class="nt">-Dplatforms</span><span class="o">=</span>x11 <span class="nt">-Dgallium-drivers</span><span class="o">=</span>radeonsi,svga,swrast,virgl <span class="nt">-Dgallium-vdpau</span><span class="o">=</span><span class="nb">true</span> <span class="nt">-Dgallium-xa</span><span class="o">=</span><span class="nb">true</span> <span class="nt">-Dgallium-nine</span><span class="o">=</span><span class="nb">true</span> <span class="nt">-Dvulkan-drivers</span><span class="o">=</span>amd <span class="nt">-Dshader-cache</span><span class="o">=</span><span class="nb">true</span> <span class="nt">-Dgbm</span><span class="o">=</span><span class="nb">true</span> <span class="nt">-Degl</span><span class="o">=</span><span class="nb">true</span> <span class="nt">-Dglvnd</span><span class="o">=</span><span class="nb">false</span> <span class="nt">-Dllvm</span><span class="o">=</span><span class="nb">true</span> <span class="nt">-Dosmesa</span><span class="o">=</span><span class="nb">true</span> <span class="nt">-Dvulkan-device-select-layer</span><span class="o">=</span><span class="nb">true</span> <span class="nt">-Dvulkan-overlay-layer</span><span class="o">=</span><span class="nb">true
</span>ninja
ninja <span class="nb">install</span>
</code></pre></div></div>
<p>Mesa git is now built and installed in <code class="highlighter-rouge">/opt/mesa/mesa-git-20210410</code></p>
<p>To use them, simply set the variables <code class="highlighter-rouge">LD_LIBRARY_PATH</code> and <code class="highlighter-rouge">VK_ICD_FILENAMES</code> at runtime. The latter is required if you are using vulkan, including dxvk and vkd3d in the case of Cyberpunk.</p>
<p>To best check the correct driver is being loaded, I recommend using an overlay such as <a href="https://github.com/flightlessmango/MangoHud">mangohud</a>, which can be configured to display the driver version currently in use by an application. It is available via eopkg in Solus.</p>
<p>Test out your drivers by running vkcube…</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">LD_LIBRARY_PATH</span><span class="o">=</span>/opt/mesa/mesa-git-20210410/lib64:/opt/mesa/mesa-git-20210410/lib32:<span class="nv">$LD_LIBRARY_PATH</span> <span class="nv">VK_ICD_FILENAMES</span><span class="o">=</span>/opt/mesa/mesa-git-20210410/share/vulkan/icd.d/radeon_icd.x86_64.json:/opt/mesa/mesa-git-20210410/share/vulkan/icd.d/radeon_icd.i686.json <span class="nv">MANGOHUD</span><span class="o">=</span>1 vkcube
</code></pre></div></div>
<p><img src="/assets/mesa-git-mangohud.jpg" alt="" /></p>
<p>The driver version should be 21.0.99, indicating the driver has been built directly from git.</p>
<p>When using this driver for Steam games, it is best to set the variables when running Steam itself, as the games will then inherit the variables. The steam runtime does a lot of library overrides, so setting the variables in a game’s launch options won’t work.</p>
<p>My steam launch command looks like this:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">LD_LIBRARY_PATH</span><span class="o">=</span>/opt/mesa/mesa-git-20210410/lib64:/opt/mesa/mesa-git-20210410/lib32:<span class="nv">$LD_LIBRARY_PATH</span> <span class="nv">VK_ICD_FILENAMES</span><span class="o">=</span>/opt/mesa/mesa-git-20210410/share/vulkan/icd.d/radeon_icd.x86_64.json:/opt/mesa/mesa-git-20210410/share/vulkan/icd.d/radeon_icd.i686.json <span class="nv">MANGOHUD</span><span class="o">=</span>1 <span class="nv">ENABLE_VKBASALT</span><span class="o">=</span>1 steam
</code></pre></div></div>
<p>And that’s it.</p>
<p>If you ever want to try a newer version from git, simply perform a git pull, make a new prefix directory and run the meson and ninja commands again [and adjust the variables to the new prefix accordingly].</p>edenistUPDATE 2021-04-23: This post initially forgot to include the 32bit build commands. It has been updated to include them.Patching Sega Genesis/Mega Drive ROMS on Linux/BSD2021-02-15T00:00:00+00:002021-02-15T00:00:00+00:00/patching-roms<p>This post was inspired by the release of Sonic 3D Blast - Director’s cut, by the game’s original developer, Jon Burton.</p>
<ul>
<li><a href="https://ttjontt.wixsite.com/gamehut/sonic-3d-blast-dx">Gamehut link</a></li>
<li><a href="https://www.romhacking.net/hacks/3810/">romhacking.net link</a></li>
</ul>
<p>Almost all of the documentation about applying patches to ROM images is Windows focussed, and usually involves directions to a GUI utility someone has put together. These programs are simply wrappers around a delta patching utility.</p>
<p>On unix systems, we can simply use ‘xdelta3’, which performs VCDIFF (RFC 3284) binary diff. ROM patches are usually very simple, so the bare essential options can be used.</p>
<p>Here is the usage of xdelta3:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>xdelta3 <span class="o">[</span>options] <span class="nt">-s</span> <original_ROM_file> <patch_file> <output_ROM_file>
</code></pre></div></div>
<p>ROM patches are usually very simple, so the bare essential options can be used. Decompress [-d] is all that is necessary.</p>
<p>In the case of Sonic 3D Blast:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>xdelta3 <span class="nt">-d</span> <span class="nt">-s</span> Sonic_3d_Blast.bin SONICDX.xdelta Sonic_3d_Blast-DC.bin
</code></pre></div></div>
<p>Now fire up <strong>Sonic_3d_Blast-DC.bin</strong> in your flash-cart or emulator of choice and enjoy the patched ROM!</p>edenistThis post was inspired by the release of Sonic 3D Blast - Director’s cut, by the game’s original developer, Jon Burton. Gamehut link romhacking.net link