dzn: merge util sources

There, no more C and C++ sources of the same base-name. We can do both
in one source.

This is our last C++ source file, so let's also clean away the C++20
mess in meson.build.

Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15816>
This commit is contained in:
Erik Faye-Lund 2022-04-07 18:16:19 +02:00 committed by Marge Bot
parent 0551f8ed62
commit 2ca4e21df7
5 changed files with 149 additions and 209 deletions

View File

@ -32,10 +32,6 @@
#include "nir.h"
#ifdef __cplusplus
extern "C" {
#endif
struct dzn_indirect_draw_params {
uint32_t vertex_count;
uint32_t instance_count;
@ -134,8 +130,4 @@ dzn_nir_blit_vs(void);
nir_shader *
dzn_nir_blit_fs(const struct dzn_nir_blit_info *info);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -206,10 +206,6 @@ dzn_physical_device_get_mem_type_mask_for_resource(const struct dzn_physical_dev
#define dzn_debug_ignored_stype(sType) \
mesa_logd("%s: ignored VkStructureType %u\n", __func__, (sType))
#ifdef __cplusplus
extern "C" {
#endif
IDXGIFactory4 *
dxgi_get_factory(bool debug);
@ -225,10 +221,6 @@ d3d12_enable_gpu_validation();
ID3D12Device1 *
d3d12_create_device(IDXGIAdapter1 *adapter, bool experimental_features);
#ifdef __cplusplus
}
#endif
struct dzn_queue {
struct vk_queue vk;
@ -905,17 +897,11 @@ struct dzn_sampler {
((_range)->levelCount == VK_REMAINING_MIP_LEVELS ? \
(_image)->vk.mip_levels - (_range)->baseMipLevel : (_range)->levelCount)
#ifdef __cplusplus
extern "C" {
#endif
DXGI_FORMAT dzn_pipe_to_dxgi_format(enum pipe_format in);
D3D12_FILTER dzn_translate_sampler_filter(const VkSamplerCreateInfo *create_info);
D3D12_COMPARISON_FUNC dzn_translate_compare_op(VkCompareOp in);
void dzn_translate_viewport(D3D12_VIEWPORT *out, const VkViewport *in);
void dzn_translate_rect(D3D12_RECT *out, const VkRect2D *in);
#ifdef __cplusplus
}
#endif
#define dzn_foreach_aspect(aspect, mask) \
for (VkImageAspectFlagBits aspect = VK_IMAGE_ASPECT_COLOR_BIT; \

View File

@ -22,11 +22,16 @@
*/
#define D3D12_IGNORE_SDK_LAYERS
#define COBJMACROS
#include <directx/d3d12.h>
#include <vulkan/vulkan.h>
#include "util/format/u_format.h"
#include "util/log.h"
#include <directx/d3d12sdklayers.h>
#include <dxgi1_4.h>
static const DXGI_FORMAT formats[PIPE_FORMAT_COUNT] = {
#define MAP_FORMAT_NORM(FMT) \
@ -235,3 +240,147 @@ dzn_translate_rect(D3D12_RECT *out,
out->right = in->offset.x + in->extent.width;
out->bottom = in->offset.y + in->extent.height;
}
IDXGIFactory4 *
dxgi_get_factory(bool debug)
{
static const GUID IID_IDXGIFactory4 = {
0x1bc6ea02, 0xef36, 0x464f,
{ 0xbf, 0x0c, 0x21, 0xca, 0x39, 0xe5, 0x16, 0x8a }
};
HMODULE dxgi_mod = LoadLibraryA("DXGI.DLL");
if (!dxgi_mod) {
mesa_loge("failed to load DXGI.DLL\n");
return NULL;
}
typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY2)(UINT flags, REFIID riid, void **ppFactory);
PFN_CREATE_DXGI_FACTORY2 CreateDXGIFactory2;
CreateDXGIFactory2 = (PFN_CREATE_DXGI_FACTORY2)GetProcAddress(dxgi_mod, "CreateDXGIFactory2");
if (!CreateDXGIFactory2) {
mesa_loge("failed to load CreateDXGIFactory2 from DXGI.DLL\n");
return NULL;
}
UINT flags = 0;
if (debug)
flags |= DXGI_CREATE_FACTORY_DEBUG;
IDXGIFactory4 *factory;
HRESULT hr = CreateDXGIFactory2(flags, &IID_IDXGIFactory4, &factory);
if (FAILED(hr)) {
mesa_loge("CreateDXGIFactory2 failed: %08x\n", hr);
return NULL;
}
return factory;
}
static ID3D12Debug *
get_debug_interface()
{
typedef HRESULT(WINAPI *PFN_D3D12_GET_DEBUG_INTERFACE)(REFIID riid, void **ppFactory);
PFN_D3D12_GET_DEBUG_INTERFACE D3D12GetDebugInterface;
HMODULE d3d12_mod = LoadLibraryA("D3D12.DLL");
if (!d3d12_mod) {
mesa_loge("failed to load D3D12.DLL\n");
return NULL;
}
D3D12GetDebugInterface = (PFN_D3D12_GET_DEBUG_INTERFACE)GetProcAddress(d3d12_mod, "D3D12GetDebugInterface");
if (!D3D12GetDebugInterface) {
mesa_loge("failed to load D3D12GetDebugInterface from D3D12.DLL\n");
return NULL;
}
ID3D12Debug *debug;
if (FAILED(D3D12GetDebugInterface(&IID_ID3D12Debug, &debug))) {
mesa_loge("D3D12GetDebugInterface failed\n");
return NULL;
}
return debug;
}
void
d3d12_enable_debug_layer()
{
ID3D12Debug *debug = get_debug_interface();
if (debug) {
ID3D12Debug_EnableDebugLayer(debug);
ID3D12Debug_Release(debug);
}
}
void
d3d12_enable_gpu_validation()
{
ID3D12Debug *debug = get_debug_interface();
if (debug) {
ID3D12Debug3 *debug3;
if (SUCCEEDED(ID3D12Debug_QueryInterface(debug,
&IID_ID3D12Debug3,
&debug3))) {
ID3D12Debug3_SetEnableGPUBasedValidation(debug3, true);
ID3D12Debug3_Release(debug3);
}
ID3D12Debug_Release(debug);
}
}
ID3D12Device1 *
d3d12_create_device(IDXGIAdapter1 *adapter, bool experimental_features)
{
typedef HRESULT(WINAPI *PFN_D3D12CREATEDEVICE)(IDXGIAdapter1*, D3D_FEATURE_LEVEL, REFIID, void**);
PFN_D3D12CREATEDEVICE D3D12CreateDevice;
HMODULE d3d12_mod = LoadLibraryA("D3D12.DLL");
if (!d3d12_mod) {
mesa_loge("failed to load D3D12.DLL\n");
return NULL;
}
#ifdef _WIN32
if (experimental_features)
#endif
{
typedef HRESULT(WINAPI *PFN_D3D12ENABLEEXPERIMENTALFEATURES)(UINT, const IID*, void*, UINT*);
PFN_D3D12ENABLEEXPERIMENTALFEATURES D3D12EnableExperimentalFeatures =
(PFN_D3D12ENABLEEXPERIMENTALFEATURES)GetProcAddress(d3d12_mod, "D3D12EnableExperimentalFeatures");
if (FAILED(D3D12EnableExperimentalFeatures(1, &D3D12ExperimentalShaderModels, NULL, NULL))) {
mesa_loge("failed to enable experimental shader models\n");
return NULL;
}
}
D3D12CreateDevice = (PFN_D3D12CREATEDEVICE)GetProcAddress(d3d12_mod, "D3D12CreateDevice");
if (!D3D12CreateDevice) {
mesa_loge("failed to load D3D12CreateDevice from D3D12.DLL\n");
return NULL;
}
ID3D12Device1 *dev;
if (SUCCEEDED(D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_11_0,
&IID_ID3D12Device1,
&dev)))
return dev;
mesa_loge("D3D12CreateDevice failed\n");
return NULL;
}
PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE
d3d12_get_serialize_root_sig(void)
{
HMODULE d3d12_mod = LoadLibraryA("d3d12.dll");
if (!d3d12_mod) {
mesa_loge("failed to load d3d12.dll\n");
return NULL;
}
return (PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE)
GetProcAddress(d3d12_mod, "D3D12SerializeVersionedRootSignature");
}

View File

@ -1,177 +0,0 @@
/*
* Copyright © Microsoft Corporation
*
* 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 (including the next
* paragraph) 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 "dzn_private.h"
#include "vk_enum_to_str.h"
#include <stdarg.h>
#include <stdio.h>
#define CINTERFACE
#include <directx/d3d12sdklayers.h>
#undef CINTERFACE
IDXGIFactory4 *
dxgi_get_factory(bool debug)
{
static const GUID IID_IDXGIFactory4 = {
0x1bc6ea02, 0xef36, 0x464f,
{ 0xbf, 0x0c, 0x21, 0xca, 0x39, 0xe5, 0x16, 0x8a }
};
HMODULE dxgi_mod = LoadLibraryA("DXGI.DLL");
if (!dxgi_mod) {
mesa_loge("failed to load DXGI.DLL\n");
return NULL;
}
typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY2)(UINT flags, REFIID riid, void **ppFactory);
PFN_CREATE_DXGI_FACTORY2 CreateDXGIFactory2;
CreateDXGIFactory2 = (PFN_CREATE_DXGI_FACTORY2)GetProcAddress(dxgi_mod, "CreateDXGIFactory2");
if (!CreateDXGIFactory2) {
mesa_loge("failed to load CreateDXGIFactory2 from DXGI.DLL\n");
return NULL;
}
UINT flags = 0;
if (debug)
flags |= DXGI_CREATE_FACTORY_DEBUG;
IDXGIFactory4 *factory;
HRESULT hr = CreateDXGIFactory2(flags, IID_IDXGIFactory4, (void **)&factory);
if (FAILED(hr)) {
mesa_loge("CreateDXGIFactory2 failed: %08x\n", hr);
return NULL;
}
return factory;
}
static ID3D12Debug *
get_debug_interface()
{
typedef HRESULT(WINAPI *PFN_D3D12_GET_DEBUG_INTERFACE)(REFIID riid, void **ppFactory);
PFN_D3D12_GET_DEBUG_INTERFACE D3D12GetDebugInterface;
HMODULE d3d12_mod = LoadLibraryA("D3D12.DLL");
if (!d3d12_mod) {
mesa_loge("failed to load D3D12.DLL\n");
return NULL;
}
D3D12GetDebugInterface = (PFN_D3D12_GET_DEBUG_INTERFACE)GetProcAddress(d3d12_mod, "D3D12GetDebugInterface");
if (!D3D12GetDebugInterface) {
mesa_loge("failed to load D3D12GetDebugInterface from D3D12.DLL\n");
return NULL;
}
ID3D12Debug *debug;
if (FAILED(D3D12GetDebugInterface(IID_ID3D12Debug, (void **)&debug))) {
mesa_loge("D3D12GetDebugInterface failed\n");
return NULL;
}
return debug;
}
void
d3d12_enable_debug_layer()
{
ID3D12Debug *debug = get_debug_interface();
if (debug) {
ID3D12Debug_EnableDebugLayer(debug);
ID3D12Debug_Release(debug);
}
}
void
d3d12_enable_gpu_validation()
{
ID3D12Debug *debug = get_debug_interface();
if (debug) {
ID3D12Debug3 *debug3;
if (SUCCEEDED(ID3D12Debug_QueryInterface(debug,
IID_ID3D12Debug3,
(void **)&debug3))) {
ID3D12Debug3_SetEnableGPUBasedValidation(debug3, true);
ID3D12Debug3_Release(debug3);
}
ID3D12Debug_Release(debug);
}
}
ID3D12Device1 *
d3d12_create_device(IDXGIAdapter1 *adapter, bool experimental_features)
{
typedef HRESULT(WINAPI *PFN_D3D12CREATEDEVICE)(IDXGIAdapter1*, D3D_FEATURE_LEVEL, REFIID, void**);
PFN_D3D12CREATEDEVICE D3D12CreateDevice;
HMODULE d3d12_mod = LoadLibraryA("D3D12.DLL");
if (!d3d12_mod) {
mesa_loge("failed to load D3D12.DLL\n");
return NULL;
}
#ifdef _WIN32
if (experimental_features)
#endif
{
typedef HRESULT(WINAPI *PFN_D3D12ENABLEEXPERIMENTALFEATURES)(UINT, const IID*, void*, UINT*);
PFN_D3D12ENABLEEXPERIMENTALFEATURES D3D12EnableExperimentalFeatures =
(PFN_D3D12ENABLEEXPERIMENTALFEATURES)GetProcAddress(d3d12_mod, "D3D12EnableExperimentalFeatures");
if (FAILED(D3D12EnableExperimentalFeatures(1, &D3D12ExperimentalShaderModels, NULL, NULL))) {
mesa_loge("failed to enable experimental shader models\n");
return nullptr;
}
}
D3D12CreateDevice = (PFN_D3D12CREATEDEVICE)GetProcAddress(d3d12_mod, "D3D12CreateDevice");
if (!D3D12CreateDevice) {
mesa_loge("failed to load D3D12CreateDevice from D3D12.DLL\n");
return NULL;
}
ID3D12Device1 *dev;
if (SUCCEEDED(D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_11_0,
IID_ID3D12Device1,
(void **)&dev)))
return dev;
mesa_loge("D3D12CreateDevice failed\n");
return NULL;
}
PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE
d3d12_get_serialize_root_sig(void)
{
HMODULE d3d12_mod = LoadLibraryA("d3d12.dll");
if (!d3d12_mod) {
mesa_loge("failed to load d3d12.dll\n");
return NULL;
}
return (PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE)
GetProcAddress(d3d12_mod, "D3D12SerializeVersionedRootSignature");
}

View File

@ -42,7 +42,6 @@ libdzn_files = files(
'dzn_pipeline.c',
'dzn_query.c',
'dzn_sync.c',
'dzn_util.cpp',
'dzn_util.c',
'dzn_wsi.c',
)
@ -64,14 +63,6 @@ if with_platform_windows
dzn_flags += '-DVK_USE_PLATFORM_WIN32_KHR'
endif
if meson.version().version_compare('>= 0.60')
cpp_std = 'cpp_std=c++20'
elif cpp.get_id() == 'msvc'
cpp_std = 'cpp_std=c++latest'
else
cpp_std = 'cpp_std=c++2a'
endif
libvulkan_dzn = shared_library(
'vulkan_dzn',
[libdzn_files, dzn_entrypoints, sha1_h],
@ -87,7 +78,6 @@ libvulkan_dzn = shared_library(
link_args : [ld_args_bsymbolic, ld_args_gc_sections],
name_prefix : host_machine.system() == 'windows' ? '' : 'lib',
install : true,
override_options: [cpp_std]
)
icd_file_name = 'libvulkan_dzn.so'