feat: godot-engine-source-4.3-stable
This commit is contained in:
parent
c59a7dcade
commit
7125d019b5
11149 changed files with 5070401 additions and 0 deletions
161
engine/drivers/d3d12/SCsub
Normal file
161
engine/drivers/d3d12/SCsub
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
Import("env")
|
||||
|
||||
env_d3d12_rdd = env.Clone()
|
||||
|
||||
thirdparty_obj = []
|
||||
|
||||
|
||||
# DirectX Headers (must take precedence over Windows SDK's).
|
||||
|
||||
env.Prepend(CPPPATH=["#thirdparty/directx_headers/include/directx"])
|
||||
env_d3d12_rdd.Prepend(CPPPATH=["#thirdparty/directx_headers/include/directx"])
|
||||
env_d3d12_rdd.Prepend(CPPPATH=["#thirdparty/directx_headers/include/dxguids"])
|
||||
|
||||
|
||||
# Direct3D 12 Memory Allocator.
|
||||
|
||||
env.Append(CPPPATH=["#thirdparty/d3d12ma"])
|
||||
env_d3d12_rdd.Append(CPPPATH=["#thirdparty/d3d12ma"])
|
||||
|
||||
|
||||
# Agility SDK.
|
||||
|
||||
if env["agility_sdk_path"] != "" and os.path.exists(env["agility_sdk_path"]):
|
||||
env_d3d12_rdd.Append(CPPDEFINES=["AGILITY_SDK_ENABLED"])
|
||||
if env["agility_sdk_multiarch"]:
|
||||
env_d3d12_rdd.Append(CPPDEFINES=["AGILITY_SDK_MULTIARCH_ENABLED"])
|
||||
|
||||
|
||||
# PIX.
|
||||
|
||||
if env["use_pix"]:
|
||||
env_d3d12_rdd.Append(CPPDEFINES=["PIX_ENABLED"])
|
||||
env_d3d12_rdd.Append(CPPPATH=[env["pix_path"] + "/Include"])
|
||||
|
||||
|
||||
# Mesa (SPIR-V to DXIL functionality).
|
||||
|
||||
mesa_dir = (env["mesa_libs"] + "/godot-mesa").replace("\\", "/")
|
||||
mesa_gen_dir = (env["mesa_libs"] + "/godot-mesa/generated").replace("\\", "/")
|
||||
mesa_absdir = Dir(mesa_dir).abspath
|
||||
mesa_gen_absdir = Dir(mesa_dir + "/generated").abspath
|
||||
|
||||
custom_build_steps = [
|
||||
[
|
||||
"src/compiler",
|
||||
"glsl/ir_expression_operation.py enum > %s/ir_expression_operation.h",
|
||||
"ir_expression_operation.h",
|
||||
],
|
||||
["src/compiler/nir", "nir_builder_opcodes_h.py > %s/nir_builder_opcodes.h", "nir_builder_opcodes.h"],
|
||||
["src/compiler/nir", "nir_constant_expressions.py > %s/nir_constant_expressions.c", "nir_constant_expressions.c"],
|
||||
["src/compiler/nir", "nir_intrinsics_h.py --outdir %s", "nir_intrinsics.h"],
|
||||
["src/compiler/nir", "nir_intrinsics_c.py --outdir %s", "nir_intrinsics.c"],
|
||||
["src/compiler/nir", "nir_intrinsics_indices_h.py --outdir %s", "nir_intrinsics_indices.h"],
|
||||
["src/compiler/nir", "nir_opcodes_h.py > %s/nir_opcodes.h", "nir_opcodes.h"],
|
||||
["src/compiler/nir", "nir_opcodes_c.py > %s/nir_opcodes.c", "nir_opcodes.c"],
|
||||
["src/compiler/nir", "nir_opt_algebraic.py > %s/nir_opt_algebraic.c", "nir_opt_algebraic.c"],
|
||||
["src/compiler/spirv", "vtn_generator_ids_h.py spir-v.xml %s/vtn_generator_ids.h", "vtn_generator_ids.h"],
|
||||
[
|
||||
"src/microsoft/compiler",
|
||||
"dxil_nir_algebraic.py -p ../../../src/compiler/nir > %s/dxil_nir_algebraic.c",
|
||||
"dxil_nir_algebraic.c",
|
||||
],
|
||||
["src/util", "format_srgb.py > %s/format_srgb.c", "format_srgb.c"],
|
||||
["src/util/format", "u_format_table.py u_format.csv --header > %s/u_format_pack.h", "u_format_pack.h"],
|
||||
["src/util/format", "u_format_table.py u_format.csv > %s/u_format_table.c", "u_format_table.c"],
|
||||
]
|
||||
|
||||
mesa_gen_include_paths = [mesa_gen_dir + "/src"]
|
||||
|
||||
# See update_mesa.sh for explanation.
|
||||
for v in custom_build_steps:
|
||||
subdir = v[0]
|
||||
cmd = v[1]
|
||||
gen_filename = v[2]
|
||||
|
||||
in_dir = str(Path(mesa_absdir + "/" + subdir))
|
||||
out_full_path = mesa_dir + "/generated/" + subdir
|
||||
out_file_full_path = out_full_path + "/" + gen_filename
|
||||
|
||||
if gen_filename.endswith(".h"):
|
||||
mesa_gen_include_paths += [out_full_path.replace("\\", "/")]
|
||||
|
||||
mesa_private_inc_paths = [v[0] for v in os.walk(mesa_absdir)]
|
||||
mesa_private_inc_paths = [v.replace(mesa_absdir, mesa_dir) for v in mesa_private_inc_paths]
|
||||
mesa_private_inc_paths = [v.replace("\\", "/") for v in mesa_private_inc_paths]
|
||||
# Avoid build results depending on if generated files already exist.
|
||||
mesa_private_inc_paths = [v for v in mesa_private_inc_paths if not v.startswith(mesa_gen_dir)]
|
||||
mesa_private_inc_paths.sort()
|
||||
# Include the list of the generated ones now, so out-of-the-box sources can include generated headers.
|
||||
mesa_private_inc_paths += mesa_gen_include_paths
|
||||
# We have to blacklist some because we are bindly adding every Mesa directory
|
||||
# to the include path and in some cases that causes the wrong header to be included.
|
||||
mesa_blacklist_inc_paths = [
|
||||
"src/c11",
|
||||
]
|
||||
mesa_blacklist_inc_paths = [mesa_dir + "/" + v for v in mesa_blacklist_inc_paths]
|
||||
mesa_private_inc_paths = [v for v in mesa_private_inc_paths if v not in mesa_blacklist_inc_paths]
|
||||
|
||||
# Added by ourselves.
|
||||
extra_defines = [
|
||||
"WINDOWS_NO_FUTEX",
|
||||
]
|
||||
|
||||
mesa_ver = Path(mesa_absdir + "/VERSION.info")
|
||||
if not mesa_ver.is_file():
|
||||
mesa_ver = Path(mesa_absdir + "/VERSION")
|
||||
|
||||
# These defines are inspired by the Meson build scripts in the original repo.
|
||||
extra_defines += [
|
||||
"__STDC_CONSTANT_MACROS",
|
||||
"__STDC_FORMAT_MACROS",
|
||||
"__STDC_LIMIT_MACROS",
|
||||
("PACKAGE_VERSION", '\\"' + mesa_ver.read_text().strip() + '\\"'),
|
||||
("PACKAGE_BUGREPORT", '\\"https://gitlab.freedesktop.org/mesa/mesa/-/issues\\"'),
|
||||
"PIPE_SUBSYSTEM_WINDOWS_USER",
|
||||
("_Static_assert", "static_assert"),
|
||||
]
|
||||
|
||||
if env.msvc:
|
||||
extra_defines += [
|
||||
"_USE_MATH_DEFINES",
|
||||
"VC_EXTRALEAN",
|
||||
"_CRT_SECURE_NO_WARNINGS",
|
||||
"_CRT_SECURE_NO_DEPRECATE",
|
||||
"_SCL_SECURE_NO_WARNINGS",
|
||||
"_SCL_SECURE_NO_DEPRECATE",
|
||||
"_ALLOW_KEYWORD_MACROS",
|
||||
("_HAS_EXCEPTIONS", 0),
|
||||
"NOMINMAX",
|
||||
"HAVE_STRUCT_TIMESPEC",
|
||||
]
|
||||
else:
|
||||
extra_defines += [
|
||||
("__REQUIRED_RPCNDR_H_VERSION__", 475),
|
||||
"HAVE_STRUCT_TIMESPEC",
|
||||
]
|
||||
|
||||
# This is needed since rendering_device_d3d12.cpp needs to include some Mesa internals.
|
||||
env_d3d12_rdd.Prepend(CPPPATH=mesa_private_inc_paths)
|
||||
# For the same reason as above, the defines must be the same as in the 3rd-party code itself.
|
||||
env_d3d12_rdd.Append(CPPDEFINES=extra_defines)
|
||||
|
||||
|
||||
# Add all.
|
||||
|
||||
env.drivers_sources += thirdparty_obj
|
||||
|
||||
|
||||
# Godot source files.
|
||||
|
||||
driver_obj = []
|
||||
env_d3d12_rdd.add_source_files(driver_obj, "*.cpp")
|
||||
env.drivers_sources += driver_obj
|
||||
|
||||
# Needed to force rebuilding the driver files when the thirdparty code is updated.
|
||||
env.Depends(driver_obj, thirdparty_obj)
|
||||
60
engine/drivers/d3d12/d3d12_godot_nir_bridge.h
Normal file
60
engine/drivers/d3d12/d3d12_godot_nir_bridge.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/**************************************************************************/
|
||||
/* d3d12_godot_nir_bridge.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* 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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef D3D12_GODOT_NIR_BRIDGE_H
|
||||
#define D3D12_GODOT_NIR_BRIDGE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// This one leaves room for potentially extremely copious bindings in a set.
|
||||
static const uint32_t GODOT_NIR_DESCRIPTOR_SET_MULTIPLIER = 100000000;
|
||||
// This one leaves room for potentially big sized arrays.
|
||||
static const uint32_t GODOT_NIR_BINDING_MULTIPLIER = 100000;
|
||||
|
||||
static const uint64_t GODOT_NIR_SC_SENTINEL_MAGIC = 0x45678900; // This must be as big as to be VBR-ed as a 32 bits number.
|
||||
static const uint64_t GODOT_NIR_SC_SENTINEL_MAGIC_MASK = 0xffffffffffffff00;
|
||||
static const uint64_t GODOT_NIR_SC_SENTINEL_ID_MASK = 0x00000000000000ff;
|
||||
|
||||
typedef struct GodotNirCallbacks {
|
||||
void *data;
|
||||
void (*report_resource)(uint32_t p_register, uint32_t p_space, uint32_t p_dxil_type, void *p_data);
|
||||
void (*report_sc_bit_offset_fn)(uint32_t p_sc_id, uint64_t p_bit_offset, void *p_data);
|
||||
void (*report_bitcode_bit_offset_fn)(uint64_t p_bit_offset, void *p_data);
|
||||
} GodotNirCallbacks;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // D3D12_GODOT_NIR_BRIDGE_H
|
||||
64
engine/drivers/d3d12/d3d12ma.cpp
Normal file
64
engine/drivers/d3d12/d3d12ma.cpp
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/**************************************************************************/
|
||||
/* d3d12ma.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* 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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "rendering_context_driver_d3d12.h"
|
||||
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
||||
#pragma GCC diagnostic ignored "-Wshadow"
|
||||
#pragma GCC diagnostic ignored "-Wswitch"
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
#pragma GCC diagnostic ignored "-Wduplicated-branches"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wnonnull-compare"
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
|
||||
#pragma clang diagnostic ignored "-Wstring-plus-int"
|
||||
#pragma clang diagnostic ignored "-Wswitch"
|
||||
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
|
||||
#pragma clang diagnostic ignored "-Wtautological-undefined-compare"
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
#pragma clang diagnostic ignored "-Wunused-but-set-variable"
|
||||
#pragma clang diagnostic ignored "-Wunused-function"
|
||||
#pragma clang diagnostic ignored "-Wunused-private-field"
|
||||
#pragma clang diagnostic ignored "-Wimplicit-fallthrough"
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable : 4189 4324 4505)
|
||||
#endif
|
||||
|
||||
#include "thirdparty/d3d12ma/D3D12MemAlloc.cpp"
|
||||
209
engine/drivers/d3d12/dxil_hash.cpp
Normal file
209
engine/drivers/d3d12/dxil_hash.cpp
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
/**************************************************************************/
|
||||
/* dxil_hash.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* 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. */
|
||||
/**************************************************************************/
|
||||
|
||||
// Based on the patched public domain implementation released by Microsoft here:
|
||||
// https://github.com/microsoft/hlsl-specs/blob/main/proposals/infra/INF-0004-validator-hashing.md
|
||||
|
||||
#include "dxil_hash.h"
|
||||
|
||||
#include <memory.h>
|
||||
|
||||
#define S11 7
|
||||
#define S12 12
|
||||
#define S13 17
|
||||
#define S14 22
|
||||
#define S21 5
|
||||
#define S22 9
|
||||
#define S23 14
|
||||
#define S24 20
|
||||
#define S31 4
|
||||
#define S32 11
|
||||
#define S33 16
|
||||
#define S34 23
|
||||
#define S41 6
|
||||
#define S42 10
|
||||
#define S43 15
|
||||
#define S44 21
|
||||
|
||||
static const BYTE padding[64] = {
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
static void FF(UINT &a, UINT b, UINT c, UINT d, UINT x, UINT8 s, UINT ac) {
|
||||
a += ((b & c) | (~b & d)) + x + ac;
|
||||
a = ((a << s) | (a >> (32 - s))) + b;
|
||||
}
|
||||
|
||||
static void GG(UINT &a, UINT b, UINT c, UINT d, UINT x, UINT8 s, UINT ac) {
|
||||
a += ((b & d) | (c & ~d)) + x + ac;
|
||||
a = ((a << s) | (a >> (32 - s))) + b;
|
||||
}
|
||||
|
||||
static void HH(UINT &a, UINT b, UINT c, UINT d, UINT x, UINT8 s, UINT ac) {
|
||||
a += (b ^ c ^ d) + x + ac;
|
||||
a = ((a << s) | (a >> (32 - s))) + b;
|
||||
}
|
||||
|
||||
static void II(UINT &a, UINT b, UINT c, UINT d, UINT x, UINT8 s, UINT ac) {
|
||||
a += (c ^ (b | ~d)) + x + ac;
|
||||
a = ((a << s) | (a >> (32 - s))) + b;
|
||||
}
|
||||
|
||||
void compute_dxil_hash(const BYTE *pData, UINT byteCount, BYTE *pOutHash) {
|
||||
UINT leftOver = byteCount & 0x3f;
|
||||
UINT padAmount;
|
||||
bool bTwoRowsPadding = false;
|
||||
if (leftOver < 56) {
|
||||
padAmount = 56 - leftOver;
|
||||
} else {
|
||||
padAmount = 120 - leftOver;
|
||||
bTwoRowsPadding = true;
|
||||
}
|
||||
UINT padAmountPlusSize = padAmount + 8;
|
||||
UINT state[4] = { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 };
|
||||
UINT N = (byteCount + padAmountPlusSize) >> 6;
|
||||
UINT offset = 0;
|
||||
UINT NextEndState = bTwoRowsPadding ? N - 2 : N - 1;
|
||||
const BYTE *pCurrData = pData;
|
||||
for (UINT i = 0; i < N; i++, offset += 64, pCurrData += 64) {
|
||||
UINT x[16];
|
||||
const UINT *pX;
|
||||
if (i == NextEndState) {
|
||||
if (!bTwoRowsPadding && i == N - 1) {
|
||||
UINT remainder = byteCount - offset;
|
||||
x[0] = byteCount << 3;
|
||||
memcpy((BYTE *)x + 4, pCurrData, remainder);
|
||||
memcpy((BYTE *)x + 4 + remainder, padding, padAmount);
|
||||
x[15] = 1 | (byteCount << 1);
|
||||
} else if (bTwoRowsPadding) {
|
||||
if (i == N - 2) {
|
||||
UINT remainder = byteCount - offset;
|
||||
memcpy(x, pCurrData, remainder);
|
||||
memcpy((BYTE *)x + remainder, padding, padAmount - 56);
|
||||
NextEndState = N - 1;
|
||||
} else if (i == N - 1) {
|
||||
x[0] = byteCount << 3;
|
||||
memcpy((BYTE *)x + 4, padding + padAmount - 56, 56);
|
||||
x[15] = 1 | (byteCount << 1);
|
||||
}
|
||||
}
|
||||
pX = x;
|
||||
} else {
|
||||
pX = (const UINT *)pCurrData;
|
||||
}
|
||||
|
||||
UINT a = state[0];
|
||||
UINT b = state[1];
|
||||
UINT c = state[2];
|
||||
UINT d = state[3];
|
||||
|
||||
/* Round 1 */
|
||||
FF(a, b, c, d, pX[0], S11, 0xd76aa478); /* 1 */
|
||||
FF(d, a, b, c, pX[1], S12, 0xe8c7b756); /* 2 */
|
||||
FF(c, d, a, b, pX[2], S13, 0x242070db); /* 3 */
|
||||
FF(b, c, d, a, pX[3], S14, 0xc1bdceee); /* 4 */
|
||||
FF(a, b, c, d, pX[4], S11, 0xf57c0faf); /* 5 */
|
||||
FF(d, a, b, c, pX[5], S12, 0x4787c62a); /* 6 */
|
||||
FF(c, d, a, b, pX[6], S13, 0xa8304613); /* 7 */
|
||||
FF(b, c, d, a, pX[7], S14, 0xfd469501); /* 8 */
|
||||
FF(a, b, c, d, pX[8], S11, 0x698098d8); /* 9 */
|
||||
FF(d, a, b, c, pX[9], S12, 0x8b44f7af); /* 10 */
|
||||
FF(c, d, a, b, pX[10], S13, 0xffff5bb1); /* 11 */
|
||||
FF(b, c, d, a, pX[11], S14, 0x895cd7be); /* 12 */
|
||||
FF(a, b, c, d, pX[12], S11, 0x6b901122); /* 13 */
|
||||
FF(d, a, b, c, pX[13], S12, 0xfd987193); /* 14 */
|
||||
FF(c, d, a, b, pX[14], S13, 0xa679438e); /* 15 */
|
||||
FF(b, c, d, a, pX[15], S14, 0x49b40821); /* 16 */
|
||||
|
||||
/* Round 2 */
|
||||
GG(a, b, c, d, pX[1], S21, 0xf61e2562); /* 17 */
|
||||
GG(d, a, b, c, pX[6], S22, 0xc040b340); /* 18 */
|
||||
GG(c, d, a, b, pX[11], S23, 0x265e5a51); /* 19 */
|
||||
GG(b, c, d, a, pX[0], S24, 0xe9b6c7aa); /* 20 */
|
||||
GG(a, b, c, d, pX[5], S21, 0xd62f105d); /* 21 */
|
||||
GG(d, a, b, c, pX[10], S22, 0x2441453); /* 22 */
|
||||
GG(c, d, a, b, pX[15], S23, 0xd8a1e681); /* 23 */
|
||||
GG(b, c, d, a, pX[4], S24, 0xe7d3fbc8); /* 24 */
|
||||
GG(a, b, c, d, pX[9], S21, 0x21e1cde6); /* 25 */
|
||||
GG(d, a, b, c, pX[14], S22, 0xc33707d6); /* 26 */
|
||||
GG(c, d, a, b, pX[3], S23, 0xf4d50d87); /* 27 */
|
||||
GG(b, c, d, a, pX[8], S24, 0x455a14ed); /* 28 */
|
||||
GG(a, b, c, d, pX[13], S21, 0xa9e3e905); /* 29 */
|
||||
GG(d, a, b, c, pX[2], S22, 0xfcefa3f8); /* 30 */
|
||||
GG(c, d, a, b, pX[7], S23, 0x676f02d9); /* 31 */
|
||||
GG(b, c, d, a, pX[12], S24, 0x8d2a4c8a); /* 32 */
|
||||
|
||||
/* Round 3 */
|
||||
HH(a, b, c, d, pX[5], S31, 0xfffa3942); /* 33 */
|
||||
HH(d, a, b, c, pX[8], S32, 0x8771f681); /* 34 */
|
||||
HH(c, d, a, b, pX[11], S33, 0x6d9d6122); /* 35 */
|
||||
HH(b, c, d, a, pX[14], S34, 0xfde5380c); /* 36 */
|
||||
HH(a, b, c, d, pX[1], S31, 0xa4beea44); /* 37 */
|
||||
HH(d, a, b, c, pX[4], S32, 0x4bdecfa9); /* 38 */
|
||||
HH(c, d, a, b, pX[7], S33, 0xf6bb4b60); /* 39 */
|
||||
HH(b, c, d, a, pX[10], S34, 0xbebfbc70); /* 40 */
|
||||
HH(a, b, c, d, pX[13], S31, 0x289b7ec6); /* 41 */
|
||||
HH(d, a, b, c, pX[0], S32, 0xeaa127fa); /* 42 */
|
||||
HH(c, d, a, b, pX[3], S33, 0xd4ef3085); /* 43 */
|
||||
HH(b, c, d, a, pX[6], S34, 0x4881d05); /* 44 */
|
||||
HH(a, b, c, d, pX[9], S31, 0xd9d4d039); /* 45 */
|
||||
HH(d, a, b, c, pX[12], S32, 0xe6db99e5); /* 46 */
|
||||
HH(c, d, a, b, pX[15], S33, 0x1fa27cf8); /* 47 */
|
||||
HH(b, c, d, a, pX[2], S34, 0xc4ac5665); /* 48 */
|
||||
|
||||
/* Round 4 */
|
||||
II(a, b, c, d, pX[0], S41, 0xf4292244); /* 49 */
|
||||
II(d, a, b, c, pX[7], S42, 0x432aff97); /* 50 */
|
||||
II(c, d, a, b, pX[14], S43, 0xab9423a7); /* 51 */
|
||||
II(b, c, d, a, pX[5], S44, 0xfc93a039); /* 52 */
|
||||
II(a, b, c, d, pX[12], S41, 0x655b59c3); /* 53 */
|
||||
II(d, a, b, c, pX[3], S42, 0x8f0ccc92); /* 54 */
|
||||
II(c, d, a, b, pX[10], S43, 0xffeff47d); /* 55 */
|
||||
II(b, c, d, a, pX[1], S44, 0x85845dd1); /* 56 */
|
||||
II(a, b, c, d, pX[8], S41, 0x6fa87e4f); /* 57 */
|
||||
II(d, a, b, c, pX[15], S42, 0xfe2ce6e0); /* 58 */
|
||||
II(c, d, a, b, pX[6], S43, 0xa3014314); /* 59 */
|
||||
II(b, c, d, a, pX[13], S44, 0x4e0811a1); /* 60 */
|
||||
II(a, b, c, d, pX[4], S41, 0xf7537e82); /* 61 */
|
||||
II(d, a, b, c, pX[11], S42, 0xbd3af235); /* 62 */
|
||||
II(c, d, a, b, pX[2], S43, 0x2ad7d2bb); /* 63 */
|
||||
II(b, c, d, a, pX[9], S44, 0xeb86d391); /* 64 */
|
||||
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
}
|
||||
|
||||
memcpy(pOutHash, state, 16);
|
||||
}
|
||||
39
engine/drivers/d3d12/dxil_hash.h
Normal file
39
engine/drivers/d3d12/dxil_hash.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/**************************************************************************/
|
||||
/* dxil_hash.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* 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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef DXIL_HASH_H
|
||||
#define DXIL_HASH_H
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
void compute_dxil_hash(const BYTE *pData, UINT byteCount, BYTE *pOutHash);
|
||||
|
||||
#endif // DXIL_HASH_H
|
||||
341
engine/drivers/d3d12/rendering_context_driver_d3d12.cpp
Normal file
341
engine/drivers/d3d12/rendering_context_driver_d3d12.cpp
Normal file
|
|
@ -0,0 +1,341 @@
|
|||
/**************************************************************************/
|
||||
/* rendering_context_driver_d3d12.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* 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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "rendering_context_driver_d3d12.h"
|
||||
|
||||
#include "core/config/engine.h"
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/templates/local_vector.h"
|
||||
#include "core/version.h"
|
||||
#include "servers/rendering/rendering_device.h"
|
||||
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
||||
#pragma GCC diagnostic ignored "-Wshadow"
|
||||
#pragma GCC diagnostic ignored "-Wswitch"
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
|
||||
#pragma clang diagnostic ignored "-Wstring-plus-int"
|
||||
#pragma clang diagnostic ignored "-Wswitch"
|
||||
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
|
||||
#endif
|
||||
|
||||
#include "dxcapi.h"
|
||||
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
#if !defined(_MSC_VER)
|
||||
#include <guiddef.h>
|
||||
|
||||
#include <dxguids.h>
|
||||
#endif
|
||||
|
||||
// Note: symbols are not available in MinGW and old MSVC import libraries.
|
||||
// GUID values from https://github.com/microsoft/DirectX-Headers/blob/7a9f4d06911d30eecb56a4956dab29dcca2709ed/include/directx/d3d12.idl#L5877-L5881
|
||||
const GUID CLSID_D3D12DeviceFactoryGodot = { 0x114863bf, 0xc386, 0x4aee, { 0xb3, 0x9d, 0x8f, 0x0b, 0xbb, 0x06, 0x29, 0x55 } };
|
||||
const GUID CLSID_D3D12DebugGodot = { 0xf2352aeb, 0xdd84, 0x49fe, { 0xb9, 0x7b, 0xa9, 0xdc, 0xfd, 0xcc, 0x1b, 0x4f } };
|
||||
const GUID CLSID_D3D12SDKConfigurationGodot = { 0x7cda6aca, 0xa03e, 0x49c8, { 0x94, 0x58, 0x03, 0x34, 0xd2, 0x0e, 0x07, 0xce } };
|
||||
|
||||
#ifdef PIX_ENABLED
|
||||
#if defined(__GNUC__)
|
||||
#define _MSC_VER 1800
|
||||
#endif
|
||||
#define USE_PIX
|
||||
#include "WinPixEventRuntime/pix3.h"
|
||||
#if defined(__GNUC__)
|
||||
#undef _MSC_VER
|
||||
#endif
|
||||
#endif
|
||||
|
||||
RenderingContextDriverD3D12::RenderingContextDriverD3D12() {}
|
||||
|
||||
RenderingContextDriverD3D12::~RenderingContextDriverD3D12() {
|
||||
// Let's release manually everything that may still be holding
|
||||
// onto the DLLs before freeing them.
|
||||
device_factory.Reset();
|
||||
dxgi_factory.Reset();
|
||||
|
||||
if (lib_d3d12) {
|
||||
FreeLibrary(lib_d3d12);
|
||||
}
|
||||
if (lib_dxgi) {
|
||||
FreeLibrary(lib_dxgi);
|
||||
}
|
||||
}
|
||||
|
||||
Error RenderingContextDriverD3D12::_init_device_factory() {
|
||||
uint32_t agility_sdk_version = GLOBAL_GET("rendering/rendering_device/d3d12/agility_sdk_version");
|
||||
String agility_sdk_path = String(".\\") + Engine::get_singleton()->get_architecture_name();
|
||||
|
||||
lib_d3d12 = LoadLibraryW(L"D3D12.dll");
|
||||
ERR_FAIL_NULL_V(lib_d3d12, ERR_CANT_CREATE);
|
||||
|
||||
lib_dxgi = LoadLibraryW(L"DXGI.dll");
|
||||
ERR_FAIL_NULL_V(lib_dxgi, ERR_CANT_CREATE);
|
||||
|
||||
// Note: symbol is not available in MinGW import library.
|
||||
PFN_D3D12_GET_INTERFACE d3d_D3D12GetInterface = (PFN_D3D12_GET_INTERFACE)(void *)GetProcAddress(lib_d3d12, "D3D12GetInterface");
|
||||
if (!d3d_D3D12GetInterface) {
|
||||
return OK; // Fallback to the system loader.
|
||||
}
|
||||
|
||||
ID3D12SDKConfiguration *sdk_config = nullptr;
|
||||
if (SUCCEEDED(d3d_D3D12GetInterface(CLSID_D3D12SDKConfigurationGodot, IID_PPV_ARGS(&sdk_config)))) {
|
||||
ID3D12SDKConfiguration1 *sdk_config1 = nullptr;
|
||||
if (SUCCEEDED(sdk_config->QueryInterface(&sdk_config1))) {
|
||||
if (SUCCEEDED(sdk_config1->CreateDeviceFactory(agility_sdk_version, agility_sdk_path.ascii().get_data(), IID_PPV_ARGS(device_factory.GetAddressOf())))) {
|
||||
d3d_D3D12GetInterface(CLSID_D3D12DeviceFactoryGodot, IID_PPV_ARGS(device_factory.GetAddressOf()));
|
||||
} else if (SUCCEEDED(sdk_config1->CreateDeviceFactory(agility_sdk_version, ".\\", IID_PPV_ARGS(device_factory.GetAddressOf())))) {
|
||||
d3d_D3D12GetInterface(CLSID_D3D12DeviceFactoryGodot, IID_PPV_ARGS(device_factory.GetAddressOf()));
|
||||
}
|
||||
sdk_config1->Release();
|
||||
}
|
||||
sdk_config->Release();
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error RenderingContextDriverD3D12::_initialize_debug_layers() {
|
||||
ComPtr<ID3D12Debug> debug_controller;
|
||||
HRESULT res;
|
||||
|
||||
if (device_factory) {
|
||||
res = device_factory->GetConfigurationInterface(CLSID_D3D12DebugGodot, IID_PPV_ARGS(&debug_controller));
|
||||
} else {
|
||||
PFN_D3D12_GET_DEBUG_INTERFACE d3d_D3D12GetDebugInterface = (PFN_D3D12_GET_DEBUG_INTERFACE)(void *)GetProcAddress(lib_d3d12, "D3D12GetDebugInterface");
|
||||
ERR_FAIL_NULL_V(d3d_D3D12GetDebugInterface, ERR_CANT_CREATE);
|
||||
|
||||
res = d3d_D3D12GetDebugInterface(IID_PPV_ARGS(&debug_controller));
|
||||
}
|
||||
|
||||
ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_QUERY_FAILED);
|
||||
debug_controller->EnableDebugLayer();
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error RenderingContextDriverD3D12::_initialize_devices() {
|
||||
const UINT dxgi_factory_flags = use_validation_layers() ? DXGI_CREATE_FACTORY_DEBUG : 0;
|
||||
|
||||
typedef HRESULT(WINAPI * PFN_DXGI_CREATE_DXGI_FACTORY2)(UINT, REFIID, void **);
|
||||
PFN_DXGI_CREATE_DXGI_FACTORY2 dxgi_CreateDXGIFactory2 = (PFN_DXGI_CREATE_DXGI_FACTORY2)(void *)GetProcAddress(lib_dxgi, "CreateDXGIFactory2");
|
||||
ERR_FAIL_NULL_V(dxgi_CreateDXGIFactory2, ERR_CANT_CREATE);
|
||||
|
||||
HRESULT res = dxgi_CreateDXGIFactory2(dxgi_factory_flags, IID_PPV_ARGS(&dxgi_factory));
|
||||
ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_CANT_CREATE);
|
||||
|
||||
// Enumerate all possible adapters.
|
||||
LocalVector<IDXGIAdapter1 *> adapters;
|
||||
IDXGIAdapter1 *adapter = nullptr;
|
||||
do {
|
||||
adapter = create_adapter(adapters.size());
|
||||
if (adapter != nullptr) {
|
||||
adapters.push_back(adapter);
|
||||
}
|
||||
} while (adapter != nullptr);
|
||||
|
||||
ERR_FAIL_COND_V_MSG(adapters.is_empty(), ERR_CANT_CREATE, "Adapters enumeration reported zero accessible devices.");
|
||||
|
||||
// Fill the device descriptions with the adapters.
|
||||
driver_devices.resize(adapters.size());
|
||||
for (uint32_t i = 0; i < adapters.size(); ++i) {
|
||||
DXGI_ADAPTER_DESC1 desc = {};
|
||||
adapters[i]->GetDesc1(&desc);
|
||||
|
||||
Device &device = driver_devices[i];
|
||||
device.name = desc.Description;
|
||||
device.vendor = Vendor(desc.VendorId);
|
||||
device.workarounds = Workarounds();
|
||||
|
||||
if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) {
|
||||
device.type = DEVICE_TYPE_CPU;
|
||||
} else {
|
||||
const bool has_dedicated_vram = desc.DedicatedVideoMemory > 0;
|
||||
device.type = has_dedicated_vram ? DEVICE_TYPE_DISCRETE_GPU : DEVICE_TYPE_INTEGRATED_GPU;
|
||||
}
|
||||
}
|
||||
|
||||
// Release all created adapters.
|
||||
for (uint32_t i = 0; i < adapters.size(); ++i) {
|
||||
adapters[i]->Release();
|
||||
}
|
||||
|
||||
ComPtr<IDXGIFactory5> factory_5;
|
||||
dxgi_factory.As(&factory_5);
|
||||
if (factory_5 != nullptr) {
|
||||
// The type is important as in general, sizeof(bool) != sizeof(BOOL).
|
||||
BOOL feature_supported = FALSE;
|
||||
res = factory_5->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &feature_supported, sizeof(feature_supported));
|
||||
if (SUCCEEDED(res)) {
|
||||
tearing_supported = feature_supported;
|
||||
} else {
|
||||
ERR_PRINT("CheckFeatureSupport failed with error " + vformat("0x%08ux", (uint64_t)res) + ".");
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
bool RenderingContextDriverD3D12::use_validation_layers() const {
|
||||
return Engine::get_singleton()->is_validation_layers_enabled();
|
||||
}
|
||||
|
||||
Error RenderingContextDriverD3D12::initialize() {
|
||||
Error err = _init_device_factory();
|
||||
ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE);
|
||||
|
||||
if (use_validation_layers()) {
|
||||
err = _initialize_debug_layers();
|
||||
ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE);
|
||||
}
|
||||
|
||||
err = _initialize_devices();
|
||||
ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
const RenderingContextDriver::Device &RenderingContextDriverD3D12::device_get(uint32_t p_device_index) const {
|
||||
DEV_ASSERT(p_device_index < driver_devices.size());
|
||||
return driver_devices[p_device_index];
|
||||
}
|
||||
|
||||
uint32_t RenderingContextDriverD3D12::device_get_count() const {
|
||||
return driver_devices.size();
|
||||
}
|
||||
|
||||
bool RenderingContextDriverD3D12::device_supports_present(uint32_t p_device_index, SurfaceID p_surface) const {
|
||||
// All devices should support presenting to any surface.
|
||||
return true;
|
||||
}
|
||||
|
||||
RenderingDeviceDriver *RenderingContextDriverD3D12::driver_create() {
|
||||
return memnew(RenderingDeviceDriverD3D12(this));
|
||||
}
|
||||
|
||||
void RenderingContextDriverD3D12::driver_free(RenderingDeviceDriver *p_driver) {
|
||||
memdelete(p_driver);
|
||||
}
|
||||
|
||||
RenderingContextDriver::SurfaceID RenderingContextDriverD3D12::surface_create(const void *p_platform_data) {
|
||||
const WindowPlatformData *wpd = (const WindowPlatformData *)(p_platform_data);
|
||||
Surface *surface = memnew(Surface);
|
||||
surface->hwnd = wpd->window;
|
||||
return SurfaceID(surface);
|
||||
}
|
||||
|
||||
void RenderingContextDriverD3D12::surface_set_size(SurfaceID p_surface, uint32_t p_width, uint32_t p_height) {
|
||||
Surface *surface = (Surface *)(p_surface);
|
||||
surface->width = p_width;
|
||||
surface->height = p_height;
|
||||
surface->needs_resize = true;
|
||||
}
|
||||
|
||||
void RenderingContextDriverD3D12::surface_set_vsync_mode(SurfaceID p_surface, DisplayServer::VSyncMode p_vsync_mode) {
|
||||
Surface *surface = (Surface *)(p_surface);
|
||||
surface->vsync_mode = p_vsync_mode;
|
||||
surface->needs_resize = true;
|
||||
}
|
||||
|
||||
DisplayServer::VSyncMode RenderingContextDriverD3D12::surface_get_vsync_mode(SurfaceID p_surface) const {
|
||||
Surface *surface = (Surface *)(p_surface);
|
||||
return surface->vsync_mode;
|
||||
}
|
||||
|
||||
uint32_t RenderingContextDriverD3D12::surface_get_width(SurfaceID p_surface) const {
|
||||
Surface *surface = (Surface *)(p_surface);
|
||||
return surface->width;
|
||||
}
|
||||
|
||||
uint32_t RenderingContextDriverD3D12::surface_get_height(SurfaceID p_surface) const {
|
||||
Surface *surface = (Surface *)(p_surface);
|
||||
return surface->height;
|
||||
}
|
||||
|
||||
void RenderingContextDriverD3D12::surface_set_needs_resize(SurfaceID p_surface, bool p_needs_resize) {
|
||||
Surface *surface = (Surface *)(p_surface);
|
||||
surface->needs_resize = p_needs_resize;
|
||||
}
|
||||
|
||||
bool RenderingContextDriverD3D12::surface_get_needs_resize(SurfaceID p_surface) const {
|
||||
Surface *surface = (Surface *)(p_surface);
|
||||
return surface->needs_resize;
|
||||
}
|
||||
|
||||
void RenderingContextDriverD3D12::surface_destroy(SurfaceID p_surface) {
|
||||
Surface *surface = (Surface *)(p_surface);
|
||||
memdelete(surface);
|
||||
}
|
||||
|
||||
bool RenderingContextDriverD3D12::is_debug_utils_enabled() const {
|
||||
#ifdef PIX_ENABLED
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
IDXGIAdapter1 *RenderingContextDriverD3D12::create_adapter(uint32_t p_adapter_index) const {
|
||||
ComPtr<IDXGIFactory6> factory_6;
|
||||
dxgi_factory.As(&factory_6);
|
||||
|
||||
// TODO: Use IDXCoreAdapterList, which gives more comprehensive information.
|
||||
IDXGIAdapter1 *adapter = nullptr;
|
||||
if (factory_6) {
|
||||
if (factory_6->EnumAdapterByGpuPreference(p_adapter_index, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(&adapter)) == DXGI_ERROR_NOT_FOUND) {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
if (dxgi_factory->EnumAdapters1(p_adapter_index, &adapter) == DXGI_ERROR_NOT_FOUND) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return adapter;
|
||||
}
|
||||
|
||||
ID3D12DeviceFactory *RenderingContextDriverD3D12::device_factory_get() const {
|
||||
return device_factory.Get();
|
||||
}
|
||||
|
||||
IDXGIFactory2 *RenderingContextDriverD3D12::dxgi_factory_get() const {
|
||||
return dxgi_factory.Get();
|
||||
}
|
||||
|
||||
bool RenderingContextDriverD3D12::get_tearing_supported() const {
|
||||
return tearing_supported;
|
||||
}
|
||||
132
engine/drivers/d3d12/rendering_context_driver_d3d12.h
Normal file
132
engine/drivers/d3d12/rendering_context_driver_d3d12.h
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
/**************************************************************************/
|
||||
/* rendering_context_driver_d3d12.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* 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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef RENDERING_CONTEXT_DRIVER_D3D12_H
|
||||
#define RENDERING_CONTEXT_DRIVER_D3D12_H
|
||||
|
||||
#include "core/error/error_list.h"
|
||||
#include "core/os/mutex.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/templates/rid_owner.h"
|
||||
#include "rendering_device_driver_d3d12.h"
|
||||
#include "servers/display_server.h"
|
||||
#include "servers/rendering/rendering_context_driver.h"
|
||||
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
||||
#pragma GCC diagnostic ignored "-Wshadow"
|
||||
#pragma GCC diagnostic ignored "-Wswitch"
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
|
||||
#pragma clang diagnostic ignored "-Wstring-plus-int"
|
||||
#pragma clang diagnostic ignored "-Wswitch"
|
||||
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
|
||||
#pragma clang diagnostic ignored "-Wimplicit-fallthrough"
|
||||
#endif
|
||||
|
||||
#if defined(AS)
|
||||
#undef AS
|
||||
#endif
|
||||
|
||||
#include "d3dx12.h"
|
||||
#include <dxgi1_6.h>
|
||||
|
||||
#include <wrl/client.h>
|
||||
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
||||
class RenderingContextDriverD3D12 : public RenderingContextDriver {
|
||||
ComPtr<ID3D12DeviceFactory> device_factory;
|
||||
ComPtr<IDXGIFactory2> dxgi_factory;
|
||||
TightLocalVector<Device> driver_devices;
|
||||
bool tearing_supported = false;
|
||||
|
||||
Error _init_device_factory();
|
||||
Error _initialize_debug_layers();
|
||||
Error _initialize_devices();
|
||||
|
||||
public:
|
||||
virtual Error initialize() override;
|
||||
virtual const Device &device_get(uint32_t p_device_index) const override;
|
||||
virtual uint32_t device_get_count() const override;
|
||||
virtual bool device_supports_present(uint32_t p_device_index, SurfaceID p_surface) const override;
|
||||
virtual RenderingDeviceDriver *driver_create() override;
|
||||
virtual void driver_free(RenderingDeviceDriver *p_driver) override;
|
||||
virtual SurfaceID surface_create(const void *p_platform_data) override;
|
||||
virtual void surface_set_size(SurfaceID p_surface, uint32_t p_width, uint32_t p_height) override;
|
||||
virtual void surface_set_vsync_mode(SurfaceID p_surface, DisplayServer::VSyncMode p_vsync_mode) override;
|
||||
virtual DisplayServer::VSyncMode surface_get_vsync_mode(SurfaceID p_surface) const override;
|
||||
virtual uint32_t surface_get_width(SurfaceID p_surface) const override;
|
||||
virtual uint32_t surface_get_height(SurfaceID p_surface) const override;
|
||||
virtual void surface_set_needs_resize(SurfaceID p_surface, bool p_needs_resize) override;
|
||||
virtual bool surface_get_needs_resize(SurfaceID p_surface) const override;
|
||||
virtual void surface_destroy(SurfaceID p_surface) override;
|
||||
virtual bool is_debug_utils_enabled() const override;
|
||||
|
||||
// Platform-specific data for the Windows embedded in this driver.
|
||||
struct WindowPlatformData {
|
||||
HWND window;
|
||||
};
|
||||
|
||||
// D3D12-only methods.
|
||||
struct Surface {
|
||||
HWND hwnd = nullptr;
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
DisplayServer::VSyncMode vsync_mode = DisplayServer::VSYNC_ENABLED;
|
||||
bool needs_resize = false;
|
||||
};
|
||||
|
||||
HMODULE lib_d3d12 = nullptr;
|
||||
HMODULE lib_dxgi = nullptr;
|
||||
|
||||
IDXGIAdapter1 *create_adapter(uint32_t p_adapter_index) const;
|
||||
ID3D12DeviceFactory *device_factory_get() const;
|
||||
IDXGIFactory2 *dxgi_factory_get() const;
|
||||
bool get_tearing_supported() const;
|
||||
bool use_validation_layers() const;
|
||||
|
||||
RenderingContextDriverD3D12();
|
||||
virtual ~RenderingContextDriverD3D12() override;
|
||||
};
|
||||
|
||||
#endif // RENDERING_CONTEXT_DRIVER_D3D12_H
|
||||
6690
engine/drivers/d3d12/rendering_device_driver_d3d12.cpp
Normal file
6690
engine/drivers/d3d12/rendering_device_driver_d3d12.cpp
Normal file
File diff suppressed because it is too large
Load diff
1035
engine/drivers/d3d12/rendering_device_driver_d3d12.h
Normal file
1035
engine/drivers/d3d12/rendering_device_driver_d3d12.h
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue