mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
213 lines
6.2 KiB
C
213 lines
6.2 KiB
C
/*
|
|
* Copyright 2016 Józef Kucia for CodeWeavers
|
|
*
|
|
* 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 "vkd3d_private.h"
|
|
|
|
BOOL is_valid_feature_level(D3D_FEATURE_LEVEL feature_level)
|
|
{
|
|
static const D3D_FEATURE_LEVEL valid_feature_levels[] =
|
|
{
|
|
D3D_FEATURE_LEVEL_12_1,
|
|
D3D_FEATURE_LEVEL_12_0,
|
|
D3D_FEATURE_LEVEL_11_1,
|
|
D3D_FEATURE_LEVEL_11_0,
|
|
D3D_FEATURE_LEVEL_10_1,
|
|
D3D_FEATURE_LEVEL_10_0,
|
|
D3D_FEATURE_LEVEL_9_3,
|
|
D3D_FEATURE_LEVEL_9_2,
|
|
D3D_FEATURE_LEVEL_9_1,
|
|
};
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(valid_feature_levels); ++i)
|
|
{
|
|
if (valid_feature_levels[i] == feature_level)
|
|
return TRUE;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
BOOL check_feature_level_support(D3D_FEATURE_LEVEL feature_level)
|
|
{
|
|
return feature_level <= D3D_FEATURE_LEVEL_11_0;
|
|
}
|
|
|
|
HRESULT return_interface(IUnknown *iface, REFIID iface_riid,
|
|
REFIID requested_riid, void **object)
|
|
{
|
|
HRESULT hr;
|
|
|
|
if (IsEqualGUID(iface_riid, requested_riid))
|
|
{
|
|
*object = iface;
|
|
return S_OK;
|
|
}
|
|
|
|
hr = IUnknown_QueryInterface(iface, requested_riid, object);
|
|
IUnknown_Release(iface);
|
|
return hr;
|
|
}
|
|
|
|
const char *debug_vk_extent_3d(VkExtent3D extent)
|
|
{
|
|
return vkd3d_dbg_sprintf("(%u, %u, %u)",
|
|
(unsigned int)extent.width,
|
|
(unsigned int)extent.height,
|
|
(unsigned int)extent.depth);
|
|
}
|
|
|
|
const char *debug_vk_queue_flags(VkQueueFlags flags)
|
|
{
|
|
char buffer[120];
|
|
|
|
buffer[0] = '\0';
|
|
#define FLAG_TO_STR(f) if (flags & f) { strcat(buffer, " | "#f); flags &= ~f; }
|
|
FLAG_TO_STR(VK_QUEUE_GRAPHICS_BIT)
|
|
FLAG_TO_STR(VK_QUEUE_COMPUTE_BIT)
|
|
FLAG_TO_STR(VK_QUEUE_TRANSFER_BIT)
|
|
FLAG_TO_STR(VK_QUEUE_SPARSE_BINDING_BIT)
|
|
#undef FLAG_TO_STR
|
|
if (flags)
|
|
FIXME("Unrecognized flag(s) %#x.\n", flags);
|
|
|
|
if (!buffer[0])
|
|
return "0";
|
|
return vkd3d_dbg_sprintf("%s", &buffer[3]);
|
|
}
|
|
|
|
const char *debug_vk_memory_heap_flags(VkMemoryHeapFlags flags)
|
|
{
|
|
char buffer[50];
|
|
|
|
buffer[0] = '\0';
|
|
#define FLAG_TO_STR(f) if (flags & f) { strcat(buffer, " | "#f); flags &= ~f; }
|
|
FLAG_TO_STR(VK_MEMORY_HEAP_DEVICE_LOCAL_BIT)
|
|
#undef FLAG_TO_STR
|
|
if (flags)
|
|
FIXME("Unrecognized flag(s) %#x.\n", flags);
|
|
|
|
if (!buffer[0])
|
|
return "0";
|
|
return vkd3d_dbg_sprintf("%s", &buffer[3]);
|
|
}
|
|
|
|
const char *debug_vk_memory_property_flags(VkMemoryPropertyFlags flags)
|
|
{
|
|
char buffer[200];
|
|
|
|
buffer[0] = '\0';
|
|
#define FLAG_TO_STR(f) if (flags & f) { strcat(buffer, " | "#f); flags &= ~f; }
|
|
FLAG_TO_STR(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
|
|
FLAG_TO_STR(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
|
|
FLAG_TO_STR(VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
|
|
FLAG_TO_STR(VK_MEMORY_PROPERTY_HOST_CACHED_BIT)
|
|
FLAG_TO_STR(VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT)
|
|
#undef FLAG_TO_STR
|
|
if (flags)
|
|
FIXME("Unrecognized flag(s) %#x.\n", flags);
|
|
|
|
if (!buffer[0])
|
|
return "0";
|
|
return vkd3d_dbg_sprintf("%s", &buffer[3]);
|
|
}
|
|
|
|
VkFormat vk_format_from_dxgi_format(DXGI_FORMAT format)
|
|
{
|
|
switch (format)
|
|
{
|
|
case DXGI_FORMAT_R32G32B32A32_FLOAT:
|
|
return VK_FORMAT_R32G32B32A32_SFLOAT;
|
|
case DXGI_FORMAT_R32G32B32A32_UINT:
|
|
return VK_FORMAT_R32G32B32A32_UINT;
|
|
case DXGI_FORMAT_R32G32B32A32_SINT:
|
|
return VK_FORMAT_R32G32B32A32_SINT;
|
|
case DXGI_FORMAT_R32G32B32_FLOAT:
|
|
return VK_FORMAT_R32G32B32_SFLOAT;
|
|
case DXGI_FORMAT_R8G8B8A8_UNORM:
|
|
return VK_FORMAT_R8G8B8A8_UNORM;
|
|
case DXGI_FORMAT_R32_FLOAT:
|
|
return VK_FORMAT_R32_SFLOAT;
|
|
case DXGI_FORMAT_B8G8R8A8_UNORM:
|
|
return VK_FORMAT_B8G8R8A8_UNORM;
|
|
default:
|
|
FIXME("Unhandled format %#x.\n", format);
|
|
return VK_FORMAT_UNDEFINED;
|
|
}
|
|
}
|
|
|
|
HRESULT hresult_from_vk_result(VkResult vr)
|
|
{
|
|
switch (vr)
|
|
{
|
|
case VK_SUCCESS:
|
|
return S_OK;
|
|
case VK_ERROR_OUT_OF_HOST_MEMORY:
|
|
case VK_ERROR_OUT_OF_DEVICE_MEMORY:
|
|
return E_OUTOFMEMORY;
|
|
|
|
default:
|
|
FIXME("Unhandled VkResult %d.\n", vr);
|
|
return E_FAIL;
|
|
}
|
|
}
|
|
|
|
#define LOAD_INSTANCE_PFN(name) \
|
|
if (!(procs->name = (void *)vkGetInstanceProcAddr(instance, #name))) \
|
|
{ \
|
|
ERR("Could not get instance proc addr for '" #name "'.\n"); \
|
|
return E_FAIL; \
|
|
}
|
|
|
|
HRESULT vkd3d_load_vk_instance_procs(struct vkd3d_vk_instance_procs *procs,
|
|
VkInstance instance)
|
|
{
|
|
memset(procs, 0, sizeof(*procs));
|
|
|
|
#define VK_INSTANCE_PFN LOAD_INSTANCE_PFN
|
|
#include "vulkan_procs.h"
|
|
|
|
TRACE("Loaded procs for VkInstance %p.\n", instance);
|
|
return S_OK;
|
|
}
|
|
|
|
#define COPY_PARENT_PFN(name) procs->name = parent_procs->name;
|
|
#define LOAD_DEVICE_PFN(name) \
|
|
if (!(procs->name = (void *)procs->vkGetDeviceProcAddr(device, #name))) \
|
|
{ \
|
|
ERR("Could not get device proc addr for '" #name "'.\n"); \
|
|
return E_FAIL; \
|
|
}
|
|
|
|
HRESULT vkd3d_load_vk_device_procs(struct vkd3d_vk_device_procs *procs,
|
|
const struct vkd3d_vk_instance_procs *parent_procs, VkDevice device)
|
|
{
|
|
memset(procs, 0, sizeof(*procs));
|
|
|
|
#define VK_INSTANCE_PFN COPY_PARENT_PFN
|
|
#define VK_DEVICE_PFN LOAD_DEVICE_PFN
|
|
#include "vulkan_procs.h"
|
|
|
|
TRACE("Loaded procs for VkDevice %p.\n", device);
|
|
return S_OK;
|
|
}
|