Code Monkey home page Code Monkey logo

dxil-spirv's Introduction

dxil-spirv

This project aims to provide translation of DXIL (SM 6.x) shaders to SPIR-V which can be used in the vkd3d project, which implements D3D12 on top of Vulkan.

Building

Dependencies

Check out submodules first with git submodule update --init. No external dependencies apart from the submodules are required to build.

This project implements a "small" LLVM C++ API subset which acts as a drop-in replacement for the full LLVM. It is possible to build against the true LLVM C++ API if llvm is checked out in external/llvm and -DDXIL_SPIRV_NATIVE_LLVM=ON CMake option is used. See checkout_llvm.sh script.

Build

Standard CMake build.

mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
make install

Linking against dxil-spirv

Only the C API is installed and is expected to be kept ABI/API stable when it releases.

pkg-config

pkg-config dxil-spirv-c-shared --cflags --libs

CMake module

Something like:

find_package(dxil_spirv_c_shared)
if (dxil_spirv_c_shared_FOUND)
	message("Found dxil-spirv! Enabling DXIL support.")
	target_link_libraries(vkd3d-shader PRIVATE dxil-spirv-c-shared)
	target_compile_definitions(vkd3d-shader PRIVATE HAVE_DXIL_SPV)
	target_sources(vkd3d-shader PRIVATE vkd3d/libs/vkd3d-shader/dxil.c)
else()
	message("Did not find dxil-spirv :( Disabling DXIL support.")
endif()

Testing

The primary method of testing dxil-spirv and avoiding regressions is through a reference shader suite.

Build DXC

First, build DXC. To keep output consistent, we must use a fixed version of DXC. Currently, this only works on Linux, the Windows build of DXC does not seem to support CMake properly.

./checkout_dxc.sh
./build_dxc.sh

The test suite accepts an arbitrary path to DXC, so if you have a standalone binary somewhere, that can work as well.

Run test suite

When adding new tests, place the HLSL test in shaders/ somewhere and run:

./test_shaders.py shaders --dxc external/dxc-build/bin/dxc --dxil-spirv cmake-build-debug/dxil-spirv

If there is any mismatch, the test script will complain. If there are legitimate changes to be made, add --update to the command. The updated files should now be committed alongside the dxil-spirv change.

License

dxil-spirv is currently licensed as MIT. See LICENSE.MIT for more details.

/* Copyright (c) 2019-2022 Hans-Kristian Arntzen for Valve Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

dxil-spirv's People

Contributors

aeikum avatar damcclos avatar doitsujin avatar hanskristian-work avatar joshua-ashton avatar konstantinseurer avatar null77 avatar pixelcluster avatar saancreed avatar wine-pardon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dxil-spirv's Issues

Assertion failed: frontier

Trying to get Greed of Man beta to work with proton, but it crashes when joining a lobby with the following error:

25155.030:019c:01ac:trace:seh:raise (22)
Assertion failed: frontier, file ../src-vkd3d-proton/subprojects/dxil-spirv/cfg_structurizer.cpp, line 1290

Compilation for Wine fails

  • Wine version: 8.6
  • VKD3D-Proton version: git master
  • GCC 13.1
  • mingw-w64-gcc 12.2

Failure when compiling https://github.com/HansKristian-Work/vkd3d-proton as PE's for Wine:

FAILED: subprojects/dxil-spirv/libdxil-spirv.a.p/bc_module.cpp.obj 
x86_64-w64-mingw32-g++ -Isubprojects/dxil-spirv/libdxil-spirv.a.p -Isubprojects/dxil-spirv -I../../vkd3d-proton/subprojects/dxil-spirv -I../../vkd3d-proton/subprojects/dxil-spirv/bc -I../../vkd3d-proton/subprojects/dxil-spirv/debug -I../../vkd3d-proton/subprojects/dxil-spirv/util -I../../vkd3d-proton/subprojects/dxil-spirv/third_party/bc-decoder -I../../vkd3d-proton/subprojects/dxil-spirv/third_party/glslang-spirv -I../../vkd3d-proton/subprojects/dxil-spirv/third_party/spirv-headers/include/spirv/unified1 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=c++14 -DAMD_EXTENSIONS -DHAVE_LLVMBC -DNOMINMAX -Wno-missing-field-initializers -Wno-empty-body -ffast-math -Wno-unused-parameter -fno-exceptions -fvisibility=hidden -march=native -mtune=native -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2 -Wformat -w -Wno-deprecated-declarations -fstack-clash-protection -fcf-protection -Wp,-D_GLIBCXX_ASSERTIONS -fpermissive -MD -MQ subprojects/dxil-spirv/libdxil-spirv.a.p/bc_module.cpp.obj -MF subprojects/dxil-spirv/libdxil-spirv.a.p/bc_module.cpp.obj.d -o subprojects/dxil-spirv/libdxil-spirv.a.p/bc_module.cpp.obj -c ../../vkd3d-proton/subprojects/dxil-spirv/bc/module.cpp
during RTL pass: final
In file included from /usr/x86_64-w64-mingw32/include/c++/12.2.0/vector:64,
                 from ../../vkd3d-proton/subprojects/dxil-spirv/util/thread_local_allocator.hpp:27,
                 from ../../vkd3d-proton/subprojects/dxil-spirv/bc/data_structures.hpp:27,
                 from ../../vkd3d-proton/subprojects/dxil-spirv/bc/module.hpp:27,
                 from ../../vkd3d-proton/subprojects/dxil-spirv/bc/module.cpp:25:
/usr/x86_64-w64-mingw32/include/c++/12.2.0/bits/stl_vector.h: In function 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](size_type) const [with _Tp = long long unsigned int; _Alloc = dxil_spv::ThreadLocalAllocator<long long unsigned int>]':
/usr/x86_64-w64-mingw32/include/c++/12.2.0/bits/stl_vector.h:1144:7: internal compiler error: in seh_emit_stackalloc, at config/i386/winnt.cc:1055
 1144 |       }
      |       ^
0x1b5de97 internal_error(char const*, ...)
	???:0
0x6a0bea fancy_abort(char const*, int, char const*)
	???:0
0x1162278 i386_pe_seh_unwind_emit(_IO_FILE*, rtx_insn*)
	???:0
0xa78c3b final_scan_insn(rtx_insn*, _IO_FILE*, int, int, int*)
	???:0

Sorry for reporting: Fixed by โ†’ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90458

3DMark Sampler feedback feature test fails to run with "Unimplemented DXIL opcode 177"..

Hi,
will try to capture dxil shaders later but for now fails..
log with:
07:49:37.279 INFO workload: 990c:err:vkd3d_dxil_log_callback: dxil-spirv: Unimplemented DXIL opcode 177
07:49:37.279 INFO workload: 990c:err:vkd3d_dxil_log_callback: dxil-spirv: Failed to emit instruction.
07:49:37.279 INFO workload: 990c:err:vkd3d_dxil_log_callback: dxil-spirv: Failed to convert function.
07:49:37.279 INFO workload: 990c:err:vkd3d_dxil_log_callback: dxil-spirv: Unimplemented DXIL opcode 177
07:49:37.279 INFO workload: 990c:err:vkd3d_dxil_log_callback: dxil-spirv: Failed to emit instruction.
07:49:37.279 INFO workload: 990c:err:vkd3d_dxil_log_callback: dxil-spirv: Failed to convert function.

EDIT: using latest master & VKD3D_FEATURE_LEVEL=12_2 on a RTX 4070

Raw 16-bit load-store was used

I'm encountering the following error while attempting to run Cyberpunk 2077 with Proton 5.13-4:

Dec 12 01:19:00 steam steam.desktop[17194]: 216:err:vkd3d_dxil_log_callback: dxil-spirv: Raw 16-bit load-store was used, which must be implemented with SSBO or BDA.
Dec 12 01:19:00 steam steam.desktop[17194]: 216:err:vkd3d_dxil_log_callback: dxil-spirv: Failed to convert function.

More details here: ValveSoftware/Proton#4450 (comment)

Since adding the above comment on the ValveSoftware/Proton issue tracker I have updated to the latest Mesa git:

steam@steam:~$ glxinfo | grep OpenGL
OpenGL vendor string: AMD
OpenGL renderer string: AMD Radeon R9 200 Series (HAWAII, DRM 3.39.0, 5.9.0-4-amd64, LLVM 11.0.0)
OpenGL core profile version string: 4.6 (Core Profile) Mesa 21.0.0-devel (git-d7911f9c6b)
OpenGL core profile shading language version string: 4.60
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.6 (Compatibility Profile) Mesa 21.0.0-devel (git-d7911f9c6b)
OpenGL shading language version string: 4.60
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 21.0.0-devel (git-d7911f9c6b)
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:

Guardians of the Galaxy RT shaders cause segfault during conversion

Faulting DXIL:
gotg_rt_crash_dxil.zip

Backtrace:

#0  0x00007ffff7e8adf6 in dxil_spv::CFGNode::dominates (this=0x555555dafff0, other=0x0) at node.cpp:95
#1  0x00007ffff7e631fc in dxil_spv::CFGStructurizer::find_switch_blocks (this=0x7fffffffb5d0, pass=0) at cfg_structurizer.cpp:2056
#2  0x00007ffff7e67318 in dxil_spv::CFGStructurizer::structurize (this=0x7fffffffb5d0, pass=0) at cfg_structurizer.cpp:3067
#3  0x00007ffff7e5c2d8 in dxil_spv::CFGStructurizer::run (this=0x7fffffffb5d0) at cfg_structurizer.cpp:382
#4  0x00007ffff7dfd2cd in dxil_spv_converter_run (converter=0x555555b85ea0) at dxil_spirv_c.cpp:531
#5  0x0000555555582628 in main (argc=2, argv=0x7fffffffdca8) at dxil_spirv.cpp:900

Rare infinite loop in recompute_immediate_post_dominator

It seems in certain rare instances the recompute_immediate_post_dominator can end up in a recursive infinite loop.

To reproduce, clone https://github.com/Juice-Labs/vkd3d-proton/tree/dxil-converter (branch dxil-converter).

Apply the attached patch to node.cpp in the dxil-spirv subproject and then run the vkd3d-proton-converter program with the attached bin file as the first and only argument. This will execute a serialized conversion call from the game I am debugging and reproduces the stack overflow. Some changes may need to be done if your build has a different order of elements in node 96's fake_succ. Comments are in node.cpp with the ordering from the game that causes the stack overflow.

meson command-line used on Windows with Visual Studio 2019
meson setup --backend=vs2019 --buildtype=debugoptimized build\debugoptimized_vs2019 -Denable_extras=true

Also attached is a mini dump of the stack overflow.
recursive-error.zip

Please let me know if you have any issues.

Renaming spirv-headers

Maybe renaming "spirv-headers" into "SPIRV-Headers" for consistency.

It helps a bit when packaging, as you can activate all modules in a loop:

for Module in "${Modules[@]}"; do
    so git submodule init "${Dir}/${Module}"
    so git submodule set-url "${Dir}/${Module}" "${srcdir}/${Module#*/}"
    so git -c protocol.file.allow=always submodule update "${Dir}/${Module}"
done

Justice RTX demo attached shader fails to compile..

Hi,
finally looking into issues on 3 DXR NV demos:
HansKristian-Work/vkd3d-proton#596
there attached a patch to be able to run Reflections demo (and also Atomic Heart) under VKD3D..
Reflections demo renders OK, Atomic Heart still no seems some issue still present..
anyway last one is Justice RTX demo and did a VKD3D debug build to dump shaders as log was showing failing cause:

170:info:vkd3d_shader_dump_blob: Dumping blob to ./vkd3dshaders/f990137678a6ba18.lib.dxil.
0170:err:msvcrt:msvcrt_get_flags incorrect mode flag: x
0170:err:vkd3d_dxil_log_callback: dxil-spirv: Cannot reliably convert LLVM pointer type, we cannot differentiate between Function and Private.

I attach this shader:
f990137678a6ba18.lib.zip

I can confirm manually by running:
./dxil-spirv f990137678a6ba18.lib.dxil
[ERROR]: Cannot reliably convert LLVM pointer type, we cannot differentiate between Function and Private.
that this is the failing shader..

hope you can give a look..
sadly from source code I see:

// Have to deal with this from the outside. Should only be relevant for getelementptr and instructions like that.
		LOGE("Cannot reliably convert LLVM pointer type, we cannot differentiate between Function and Private.\n");

hope fix is not difficult to implement..

thanks..

Assertion failed - Battlefield 2042

Hey! Trying to launch BF 2042 using latest bleeding-edge Proton Experimental (should contain latest dxil-spirv) leads to Assertion Failed! error.
Screenshot_20230623_190839
Here are also packed to zip shaders what are generated when trying to launch 2042: 2042.zip

Random switch + continue shenanigans

For later, this shader fails CFG validation.

float main(int4 i : I) : SV_Target
{
	[loop]
	for (;;)
	{
		switch (i.x)
		{
			case 5:
				i.x++;
				i = i.yzwx;
				continue;

			case 7:
				i.x += 10;
				i = i.yzwx;
				continue;

			default:
				break;
		}

		i = i.yzwx;
		break;
	}

	return float(i.x + i.y);
}

Not compiling on GCC 6.3

In reference to earlier today's ticket at: HansKristian-Work/vkd3d-proton#212

I've tried to build dxil-spirv by itself without vkd3d but the compile still fails.

Steps I took:

  1. extracted dxil-spirv itself.
  2. extracted 'spirv-headers', 'spirv-cross' and 'spirv-tools' in their respective 'third_party' folder.
  3. ran: 'meson . ./build' (folder I used for compilation)
  4. 'cd build' and then 'ninja'

1

2

Let me know if there's anything else I could try.

"There is no candidate for ladder merging." x2

I used to be able to boot into Horizon: Zero Dawn just fine, despite barely playable performance - now I'm back to crashing at launch.

steam-1151640.log

Looking through the logs, I see two dxil-spirv errors which declare:

316:err:vkd3d_dxil_log_callback: dxil-spirv: There is no candidate for ladder merging.

Error: Failed to parse blob

Hello HansKristian,

I am getting the following error when I keep my dxil files in a folder shaders/dk:
[ERROR]: Failed to parse blob.
Error: Command '['build/dxil-spirv', '--output', '/tmp/tmpw8s9hededilan_gt1.qcc!eva_player_exe-Context-fb417d660ba93b43-Compile-170.PS.dc0d44c1.dxil', 'shaders/dk/dilan_gt1.qcc!eva_player_exe-Context-fb417d660ba93b43-Compile-170.PS.dc0d44c1.dxil', '--vertex-input', 'ATTR', '0', '--asm', '--glsl', '--validate', '--ssbo-uav', '--ssbo-srv']' returned non-zero exit status 1

I am using Ubuntu 16.04, g++ version 7.5.0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.