RetroArch/gfx/common/d3dcompiler_common.c

175 lines
5.3 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
* Copyright (C) 2014-2018 - Ali Bouhlel
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
2018-02-04 20:03:27 +01:00
#define CINTERFACE
2018-02-11 00:00:20 +01:00
#include <string.h>
2018-01-29 17:19:36 +01:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "d3dcompiler_common.h"
#include "../../verbosity.h"
#if defined(HAVE_DYNAMIC) && !defined(__WINRT__)
#include <dynamic/dylib.h>
2020-07-07 02:51:39 +02:00
/* TODO/FIXME - static globals */
2018-01-24 20:51:19 +01:00
static dylib_t d3dcompiler_dll;
static const char* d3dcompiler_dll_list[] = {
"D3DCompiler_47.dll", "D3DCompiler_46.dll", "D3DCompiler_45.dll", "D3DCompiler_44.dll",
"D3DCompiler_43.dll", "D3DCompiler_42.dll", "D3DCompiler_41.dll", "D3DCompiler_40.dll",
"D3DCompiler_39.dll", "D3DCompiler_38.dll", "D3DCompiler_37.dll", "D3DCompiler_36.dll",
"D3DCompiler_35.dll", "D3DCompiler_34.dll", "D3DCompiler_33.dll", NULL,
};
2018-01-24 07:45:45 +01:00
HRESULT WINAPI D3DCompile(
LPCVOID pSrcData,
SIZE_T SrcDataSize,
LPCSTR pSourceName,
CONST D3D_SHADER_MACRO* pDefines,
ID3DInclude* pInclude,
LPCSTR pEntrypoint,
LPCSTR pTarget,
UINT Flags1,
UINT Flags2,
ID3DBlob** ppCode,
ID3DBlob** ppErrorMsgs)
{
static pD3DCompile fp;
2018-01-24 20:51:19 +01:00
const char** dll_name = d3dcompiler_dll_list;
while (!d3dcompiler_dll && *dll_name)
d3dcompiler_dll = dylib_load(*dll_name++);
if (!d3dcompiler_dll)
return TYPE_E_CANTLOADLIBRARY;
if (!fp)
fp = (pD3DCompile)dylib_proc(d3dcompiler_dll, "D3DCompile");
2018-02-06 18:00:11 +01:00
if (!fp)
return TYPE_E_DLLFUNCTIONNOTFOUND;
2018-02-06 18:00:11 +01:00
return fp(
pSrcData, SrcDataSize, pSourceName, pDefines, pInclude, pEntrypoint, pTarget, Flags1,
Flags2, ppCode, ppErrorMsgs);
}
2018-01-24 20:51:19 +01:00
HRESULT WINAPI D3DCompileFromFile(
LPCWSTR pFileName,
const D3D_SHADER_MACRO* pDefines,
ID3DInclude* pInclude,
LPCSTR pEntrypoint,
LPCSTR pTarget,
UINT Flags1,
UINT Flags2,
ID3DBlob** ppCode,
ID3DBlob** ppErrorMsgs)
{
typedef HRESULT(WINAPI * pD3DCompileFromFile)(
2018-02-06 18:00:11 +01:00
LPCWSTR, const D3D_SHADER_MACRO*, ID3DInclude*, LPCSTR, LPCSTR, UINT, UINT, ID3DBlob**,
ID3DBlob**);
static pD3DCompileFromFile fp;
2018-01-24 20:51:19 +01:00
const char** dll_name = d3dcompiler_dll_list;
while (!d3dcompiler_dll && *dll_name)
d3dcompiler_dll = dylib_load(*dll_name++);
if (!d3dcompiler_dll)
return TYPE_E_CANTLOADLIBRARY;
2018-01-24 20:51:19 +01:00
if (!fp)
fp = (pD3DCompileFromFile)dylib_proc(d3dcompiler_dll, "D3DCompileFromFile");
2018-02-06 18:00:11 +01:00
if (!fp)
return TYPE_E_DLLFUNCTIONNOTFOUND;
2018-01-24 20:51:19 +01:00
2018-02-06 18:00:11 +01:00
return fp(
pFileName, pDefines, pInclude, pEntrypoint, pTarget, Flags1, Flags2, ppCode, ppErrorMsgs);
}
HRESULT WINAPI
D3DReflect(LPCVOID pSrcData, SIZE_T SrcDataSize, REFIID pInterface, void** ppReflector)
{
2018-02-06 18:00:11 +01:00
typedef HRESULT(WINAPI * pD3DCompileFromFile)(LPCVOID, SIZE_T, REFIID, void**);
static pD3DCompileFromFile fp;
const char** dll_name = d3dcompiler_dll_list;
while (!d3dcompiler_dll && *dll_name)
d3dcompiler_dll = dylib_load(*dll_name++);
if (!d3dcompiler_dll)
return TYPE_E_CANTLOADLIBRARY;
if (!fp)
fp = (pD3DCompileFromFile)dylib_proc(d3dcompiler_dll, "D3DReflect");
2018-02-06 18:00:11 +01:00
if (!fp)
return TYPE_E_DLLFUNCTIONNOTFOUND;
2018-02-06 18:00:11 +01:00
return fp(pSrcData, SrcDataSize, pInterface, ppReflector);
2018-01-24 20:51:19 +01:00
}
#endif
2018-01-24 20:51:19 +01:00
bool d3d_compile(const char* src, size_t size, LPCSTR src_name, LPCSTR entrypoint, LPCSTR target, D3DBlob* out)
{
D3DBlob error_msg;
UINT compileflags = 0;
2018-01-30 17:20:34 +01:00
#ifdef DEBUG
compileflags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;
#endif
2018-02-11 00:00:20 +01:00
if (!size)
size = strlen(src);
2019-02-03 15:49:35 -08:00
2018-01-24 07:45:45 +01:00
if (FAILED(D3DCompile(
src, size, src_name, NULL, NULL, entrypoint, target, compileflags, 0, out, &error_msg)))
2018-01-24 20:51:19 +01:00
{
if (error_msg)
{
Add HDR support for D3D12 (rebased PR from MajorPainTheCactus) (#12917) * Add HDR support * Attempt to fix Mingw build and Metal builds * (D3D12) Fix relative header includes * Add missing hdr_sm5.hlsl.h * (d3d12_common.c) Some C89 build fixes * Fix MSVC build * - Attempt to fix build on mingw/msys unix with dirty hack - Fix shader compilation of hdr_sm5.hlsl.h on MSVC/Visual Studio - the define was seen as an error and was causing the first pipeline to error out - Make sure we manually set handle of backBuffer to NULL * Moving the release of the texture above the freeing of desc.srv_heap and desc.rtv_heap solves the hard crashes on teardown/setup in RA - it was crashing hard in d3d12_release_texture before * Add HAVE_D3D12_HDR ifdef - needs to be disabled for WinRT for now because of several things that are Windows desktop-specific right now (GetWindowRect) * Add dirty GUID hack - should work for both mingw/msys on Windows/Linux as well as MSVC/Visual Studio (hopefully) * Change HAVE_D3D12_HDR to HAVE_DXGI_HDR * Move away from camelcase named variables * Fix RARCH_ERR logs - they need a newline at the end * d3d12_check_display_hdr_support - make it return a bool on return and set d3d12->hdr.support and d3d12->hdr.enable outside of the function * (DXGI) Remove D3D12 dependencies from dxgi_check_display_hdr_support and move it to dxgi_common.c instead * (DXGI) move d3d12_swapchain_color_space over to dxgi_common.c and rename it dxgi_swapchain_color_space * (DXGI) move d3d12_set_hdr_metadata to dxgi_common.c and rename it dxgi_set_hdr_metadata * (DXGI) dxgi_check_display_hdr_support - better error handling? * Fix typo * Remove video_force_resolution * (D3D12) Address TODO/FIXME * (D3D12) Backport https://github.com/libretro/RetroArch/pull/12916/commits/c1b6c0bff2aa33cde035b43cb31ac7e78ff2a07a - Fixed resource transition for present when HDR is off Fixed cel shader displaying all black as blending was enabled when the hdr shader was being applied - turned off blending during this shader * Move d3d12_hdr_uniform_t to dxgi_common.h and rename it dxgi_hdr_uniform_t * (D3D11) Add HDR support * Add TODO/FIXME notes * Cache hdr_enable in video_frame_info_t * Update comment
2021-09-03 06:15:25 +02:00
const char* msg = (const char*)D3DGetBufferPointer(error_msg);
RARCH_ERR("D3DCompile failed :\n%s\n", msg); /* Place a breakpoint here, if you want, to see shader compilation issues */
2018-01-24 20:51:19 +01:00
Release(error_msg);
}
return false;
2018-01-24 20:51:19 +01:00
}
return true;
}
bool d3d_compile_from_file(LPCWSTR filename, LPCSTR entrypoint, LPCSTR target, D3DBlob* out)
{
D3DBlob error_msg;
UINT compileflags = 0;
2018-01-30 17:20:34 +01:00
#ifdef DEBUG
compileflags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;
2018-01-24 20:51:19 +01:00
#endif
2018-01-24 20:51:19 +01:00
if (FAILED(D3DCompileFromFile(
filename, NULL, NULL, entrypoint, target, compileflags, 0, out, &error_msg)))
{
2018-01-24 20:51:19 +01:00
if (error_msg)
{
RARCH_ERR("D3DCompile failed :\n%s\n", (const char*)D3DGetBufferPointer(error_msg));
Release(error_msg);
}
return false;
}
return true;
}