Skip to content

Commit

Permalink
Initial testing of DXVK NvAPI_D3D11_SetDepthBoundsTest
Browse files Browse the repository at this point in the history
  • Loading branch information
SveSop committed Jul 1, 2019
1 parent 3b44537 commit 3e6bcc5
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 12 deletions.
74 changes: 74 additions & 0 deletions dlls/nvapi/dxvk.idl
@@ -0,0 +1,74 @@
import "unknwn.idl";
import "d3d11.idl";


typedef enum D3D11_VK_EXTENSION {
D3D11_VK_EXT_MULTI_DRAW_INDIRECT = 0,
D3D11_VK_EXT_MULTI_DRAW_INDIRECT_COUNT = 1,
D3D11_VK_EXT_DEPTH_BOUNDS = 2,
D3D11_VK_EXT_BARRIER_CONTROL = 3,
} D3D11_VK_EXTENSION;


typedef enum D3D11_VK_BARRIER_CONTROL {
D3D11_VK_BARRIER_CONTROL_IGNORE_WRITE_AFTER_WRITE = 1 << 0,
} D3D11_VK_BARRIER_CONTROL;


[
object,
local,
uuid(8a6e3c42-f74c-45b7-8265-a231b677ca17),
pointer_default(unique)
]
interface ID3D11VkExtDevice : IUnknown
{
BOOL GetExtensionSupport(
[in] D3D11_VK_EXTENSION Extension);
}


[
object,
local,
uuid(fd0bca13-5cb6-4c3a-987e-4750de2ca791),
pointer_default(unique)
]
interface ID3D11VkExtContext : IUnknown
{
void MultiDrawIndirect(
[in] UINT DrawCount,
[in] ID3D11Buffer* pBufferForArgs,
[in] UINT ByteOffsetForArgs,
[in] UINT ByteStrideForArgs);

void MultiDrawIndexedIndirect(
[in] UINT DrawCount,
[in] ID3D11Buffer* pBufferForArgs,
[in] UINT ByteOffsetForArgs,
[in] UINT ByteStrideForArgs);

void MultiDrawIndirectCount(
[in] UINT MaxDrawCount,
[in] ID3D11Buffer* pBufferForCount,
[in] UINT ByteOffsetForCount,
[in] ID3D11Buffer* pBufferForArgs,
[in] UINT ByteOffsetForArgs,
[in] UINT ByteStrideForArgs);

void MultiDrawIndexedIndirectCount(
[in] UINT MaxDrawCount,
[in] ID3D11Buffer* pBufferForCount,
[in] UINT ByteOffsetForCount,
[in] ID3D11Buffer* pBufferForArgs,
[in] UINT ByteOffsetForArgs,
[in] UINT ByteStrideForArgs);

void SetDepthBoundsTest(
[in] BOOL Enable,
[in] FLOAT MinDepthBounds,
[in] FLOAT MaxDepthBounds);

void SetBarrierControl(
[in] UINT ControlFlags);
}
1 change: 1 addition & 0 deletions dlls/nvapi/meson.build
@@ -1,5 +1,6 @@
nvapi_src = [
'nvapi.c',
idl_generator.process('dxvk.idl'),
]


Expand Down
47 changes: 35 additions & 12 deletions dlls/nvapi/nvapi.c
Expand Up @@ -39,6 +39,7 @@
#include "d3d9.h"
#include "d3d11.h"
#include "wine/wined3d.h"
#include "dxvk.h"

WINE_DEFAULT_DEBUG_CHANNEL(nvapi);

Expand Down Expand Up @@ -1661,27 +1662,49 @@ static NvAPI_Status CDECL NvAPI_GPU_GetGpuCoreCount(NvPhysicalGpuHandle hPhysica

static NvAPI_Status CDECL NvAPI_D3D11_SetDepthBoundsTest(IUnknown *pDeviceOrContext, NvU32 bEnable, float fMinDepth, float fMaxDepth)
{
struct wined3d_device *device;
union { DWORD d; float f; } z;
ID3D11Device *d3d11_device;
ID3D11DeviceContext *ctx;
ID3D11VkExtDevice *dxvk_ext_device;
ID3D11VkExtContext *dxvk_ext_context;

TRACE("(%p, %u, %f, %f)\n", pDeviceOrContext, bEnable, fMinDepth, fMaxDepth);
TRACE("(%p, %u, %f, %f): dxvk\n", pDeviceOrContext, bEnable, fMinDepth, fMaxDepth);

if (!pDeviceOrContext)
return NVAPI_INVALID_ARGUMENT;

if (FAILED(IUnknown_QueryInterface(pDeviceOrContext, &IID_IWineD3DDevice, (void **)&device)))
if (0 > fMinDepth || fMinDepth > fMaxDepth || fMaxDepth > 1)
{
ERR("Failed to get wined3d device handle!\n");
ERR("(%p, %u, %f, %f): Invalid argument!\n", pDeviceOrContext, bEnable, fMinDepth, fMaxDepth);
return NVAPI_OK; /* Hack: Don't crash games */
/*return NVAPI_INVALID_ARGUMENT;*/
}

if (FAILED(IUnknown_QueryInterface(pDeviceOrContext, &IID_ID3D11VkExtDevice, (void **)&dxvk_ext_device)))
{
ERR("Failed to get DXVK extension device handle!\n");
return NVAPI_ERROR;
}

if(!ID3D11VkExtDevice_GetExtensionSupport(dxvk_ext_device, D3D11_VK_EXT_DEPTH_BOUNDS))
{
ERR("DXVK extension not supported!\n");
return NVAPI_ERROR;
}

if (FAILED(IUnknown_QueryInterface(pDeviceOrContext, &IID_ID3D11Device, (void **)&d3d11_device)))
{
ERR("Failed to get DXVK device handle!\n");
return NVAPI_ERROR;
}

ID3D11Device_GetImmediateContext(d3d11_device, &ctx);
if (FAILED(IUnknown_QueryInterface(ctx, &IID_ID3D11VkExtContext, (void **)&dxvk_ext_context)))
{
ERR("Failed to get DXVK context handle!\n");
return NVAPI_ERROR;
}

wined3d_mutex_lock();
wined3d_device_set_render_state(device, WINED3D_RS_ADAPTIVETESS_X, bEnable ? WINED3DFMT_NVDB : 0);
z.f = fMinDepth;
wined3d_device_set_render_state(device, WINED3D_RS_ADAPTIVETESS_Z, z.d);
z.f = fMaxDepth;
wined3d_device_set_render_state(device, WINED3D_RS_ADAPTIVETESS_W, z.d);
wined3d_mutex_unlock();
ID3D11VkExtContext_SetDepthBoundsTest(dxvk_ext_context, bEnable, fMinDepth, fMaxDepth);

return NVAPI_OK;
}
Expand Down
1 change: 1 addition & 0 deletions dlls/nvapi64/meson.build
@@ -1,5 +1,6 @@
nvapi64_src = [
'../nvapi/nvapi.c',
idl_generator.process('../nvapi/dxvk.idl'),
]


Expand Down
5 changes: 5 additions & 0 deletions meson.build
Expand Up @@ -16,12 +16,17 @@ lib_nvml = declare_dependency(link_args: [ '-lnvidia-ml' ])

winebuild = find_program('winebuild')
winegcc = find_program('winegcc')
widl = find_program('widl')

target_arch = cpu_family == 'x86_64' ? '-m64' : '-m32'

def_generator = generator(winebuild,
output : [ '@BASENAME@.def' ],
arguments : [ '-w', ' --def', '--export', '@INPUT@', '-o', '@OUTPUT@' ])

idl_generator = generator(widl,
output : [ '@BASENAME@.h' ],
arguments : [ target_arch, '-o', '@OUTPUT@', '-D__WINESRC__', '@EXTRA_ARGS@', '@INPUT@' ])

subdir('dlls')
subdir('utils')

0 comments on commit 3e6bcc5

Please sign in to comment.