%undefine _annotated_build

%global dxil_spirv_rev 41dae24cdba6771ceede9d45dae1c8580c147ce4

Name:		vkd3d-proton
Version:	2.13
Release:	1%{?dist}
Summary:	D3D12 to Vulkan translation library

License:	LGPLv2+
URL:		https://github.com/HansKristian-Work/vkd3d-proton
Source0:	https://github.com/HansKristian-Work/vkd3d-proton/archive/refs/tags/v%{version}.tar.gz#/%{name}-%{version}.tar.gz

# git clone https://github.com/HansKristian-Work/dxil-spirv.git
# cd dxil-spirv/
# git  reset --hard %{dxil_spirv_rev}
# git submodule init
# git submodule update
# cd ..
# tar -cJf dxil-spirv.tar.xz dxil-spirv/
Source2:    dxil-spirv.tar.xz

Patch0:     vkd3d-proton-includes.patch
Patch1:     fix-exponent-in-build.h.patch

BuildRequires:  clang
BuildRequires:  meson
BuildRequires:	ninja-build
BuildRequires:	glslang
BuildRequires:  vulkan-headers >= 1.3.289
BuildRequires:  wine-devel

%ifnarch %ix86
BuildRequires:	mingw32-filesystem >= 95
BuildRequires:	mingw32-gcc >= 8.1
BuildRequires:	mingw32-gcc-plugin-devel
BuildRequires:  mingw32-vulkan-headers >= 1.3.289
BuildRequires:	mingw-w64-tools
BuildRequires:	mingw64-filesystem >= 95
BuildRequires:	mingw64-gcc >= 8.1
BuildRequires:	mingw64-gcc-plugin-devel
BuildRequires:  mingw64-vulkan-headers >= 1.3.289
%endif

%description
vkd3d-proton is a fork of VKD3D, which aims to implement the
full Direct3D 12 API on top of Vulkan. The project serves
as the development effort for Direct3D 12 support in Proton..


%ifnarch %ix86
%package -n mingw32-%{name}
Summary:	%{summary}
BuildArch:	noarch


%description -n mingw32-%{name}
%{summary}.


%package -n mingw64-%{name}
Summary:	%{summary}
BuildArch:	noarch


%description -n mingw64-%{name}
%{summary}.
%endif

%package devel
Summary:  Header files for %{name}
Requires: %{name} = %{version}-%{release}

%description devel
%{summary}.

%prep
%autosetup -p1

pushd subprojects
tar -xf %{SOURCE2}
popd

%build
export CC=clang
export CXX=clang++

CFLAGS="-I$(pwd)/subprojects/dxil-spirv/third_party/spirv-headers/include %{optflags}"
CXXFLAGS="-I$(pwd)/subprojects/dxil-spirv/third_party/spirv-headers/include %{optflags}"

# These flags are taken from Proton
CFLAGS+=" -mfpmath=sse -fwrapv -fno-strict-aliasing"
CXXFLAGS+=" -mfpmath=sse -fwrapv -fno-strict-aliasing"

export CFLAGS CXXFLAGS
export LDFLAGS="-Wl,-O1,--sort-common,--as-needed"

# Native libs
%meson --buildtype release
%ninja_build -C %{_target_platform}

%ifnarch %ix86
# Mingw x64
%mingw_meson \
    -Denable_tests=false

%mingw_ninja
%endif

%install
%ninja_install -C %{_target_platform}

%ifnarch %ix86
mkdir -p %{buildroot}%{mingw64_libdir}
mkdir -p %{buildroot}%{mingw32_libdir}

install -o root -m 0755 build_win64/libs/{d3d12/d3d12.dll,d3d12core/d3d12core.dll} %{buildroot}%{mingw64_libdir}/
install -o root -m 0755 build_win32/libs/{d3d12/d3d12.dll,d3d12core/d3d12core.dll} %{buildroot}%{mingw32_libdir}/
%endif

%files
%license LICENSE
%{_libdir}/libvkd3d-proton-d3d12*.so

%files devel
%{_includedir}/vkd3d-proton/*.h
%{_libdir}/pkgconfig/libvkd3d-proton.pc

%ifnarch %ix86
%files -n mingw64-%{name}
%license LICENSE
%{mingw64_libdir}/d3d12*.dll

%files -n mingw32-%{name}
%license LICENSE
%{mingw32_libdir}/d3d12*.dll
%endif
