VBoxDispD3D.cpp revision 9441dbf0fb711026d58d0c64d61a6dcfc3c6784d
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync/* $Id$ */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync/** @file
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * VBoxVideo Display D3D User mode dll
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync/*
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * Copyright (C) 2011 Oracle Corporation
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync *
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * available from http://www.virtualbox.org. This file is free software;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * you can redistribute it and/or modify it under the terms of the GNU
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * General Public License (GPL) as published by the Free Software
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#define INITGUID
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#include <iprt/initterm.h>
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#include <iprt/log.h>
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#include <iprt/mem.h>
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#include <VBox/Log.h>
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#include <VBox/VBoxGuestLib.h>
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#include "VBoxDispD3DCmn.h"
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#include "VBoxDispD3D.h"
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#include "VBoxScreen.h"
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#include <VBox/VBoxCrHgsmi.h>
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#include <Psapi.h>
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef VBOX_WDDMDISP_WITH_PROFILE
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncvolatile uint32_t g_u32VBoxDispProfileFunctionLoggerIndex = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstruct VBOXDISPPROFILE_GLOBAL {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBoxDispProfileFpsCounter ProfileDdiFps;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBoxDispProfileSet ProfileDdiFunc;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync} g_VBoxDispProfile;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync/* uncomment to enable particular logging */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync/* allows dumping fps + how much time is spent in ddi functions in comparison with the rest time */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync//# define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_ENABLE
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync/* allows dumping time spent in each function and the number of calls made for any given function */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_ENABLE
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# ifdef VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_ENABLE
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncclass VBoxDispProfileDevicePostProcess
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncpublic:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBoxDispProfileDevicePostProcess(PVBOXWDDMDISP_DEVICE pDevice) :
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync m_pDevice(pDevice)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync void postProcess()
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (m_pDevice->pDevice9If)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync m_pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9Finish((IDirect3DDevice9Ex *)m_pDevice->pDevice9If);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncprivate:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE m_pDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync};
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync//static VBoxDispProfileSet g_VBoxDispProfileDDI("D3D_DDI");
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE_DEV(_pObj) VBOXDISPPROFILE_FUNCTION_LOGGER_DEFINE((_pObj)->ProfileDdiFunc, VBoxDispProfileDevicePostProcess, VBoxDispProfileDevicePostProcess(_pObj))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE_BASE(_pObj) VBOXDISPPROFILE_FUNCTION_LOGGER_DEFINE((_pObj)->ProfileDdiFunc, VBoxDispProfileDummyPostProcess, VBoxDispProfileDummyPostProcess())
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_DUMP(_pObj) do {\
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync (_pObj)->ProfileDdiFunc.dump(_pObj); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync } while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_RESET(_pObj) do {\
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync (_pObj)->ProfileDdiFunc.resetEntries();\
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync } while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_DISABLE_CURRENT() do {\
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_FUNCTION_LOGGER_DISABLE_CURRENT();\
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync } while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_LOG_AND_DISABLE_CURRENT() VBOXDISPPROFILE_FUNCTION_LOGGER_LOG_AND_DISABLE_CURRENT()
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_REPORT_FRAME(_pObj) do { \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!((_pObj)->ProfileDdiFunc.reportIteration() % 31) /*&& !VBOXVDBG_IS_DWM()*/) {\
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_DUMP(_pObj); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_RESET(_pObj); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync } \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync } while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE_DEV(_pObj) do {} while(0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE_BASE(_pObj) do {} while(0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_DUMP(_pObj) do {} while(0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_RESET(_pObj) do {} while(0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_DISABLE_CURRENT() do {} while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_LOG_AND_DISABLE_CURRENT() do {} while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_REPORT_FRAME(_pDev) do {} while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# ifdef VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_ENABLE
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync//static VBoxDispProfileFpsCounter g_VBoxDispFpsDDI(64);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_PROLOGUE(_pObj) VBOXDISPPROFILE_STATISTIC_LOGGER_DEFINE(&(_pObj)->ProfileDdiFps, VBoxDispProfileDummyPostProcess, VBoxDispProfileDummyPostProcess())
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_DISABLE_CURRENT() do {\
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_STATISTIC_LOGGER_DISABLE_CURRENT();\
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync } while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_DUMP(_pObj) do { \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync double fps = (_pObj)->ProfileDdiFps.GetFps(); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync double cps = (_pObj)->ProfileDdiFps.GetCps(); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync double tup = (_pObj)->ProfileDdiFps.GetTimeProcPercent(); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DUMP(("[0x%p]: fps: %f, cps: %.1f, host %.1f%%", (_pObj), fps, cps, tup)); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync } while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_REPORT_FRAME(_pObj) do { \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync (_pObj)->ProfileDdiFps.ReportFrame(); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if(!((_pObj)->ProfileDdiFps.GetNumFrames() % 31)) \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync { \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_DUMP(_pObj); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync } \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync } while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_LOG_AND_DISABLE_CURRENT() VBOXDISPPROFILE_STATISTIC_LOGGER_LOG_AND_DISABLE_CURRENT()
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_PROLOGUE(_pObj) do {} while(0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_DISABLE_CURRENT() do {} while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_LOG_AND_DISABLE_CURRENT() do {} while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_REPORT_FRAME(_pDev) do {} while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_DUMP(_pObj) do {} while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_DEV(_pObj) \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE_DEV(_pObj); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_PROLOGUE(_pObj);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_BASE(_pObj) \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE_BASE(_pObj); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_PROLOGUE(_pObj);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_LOG_AND_DISABLE_CURRENT() \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_LOG_AND_DISABLE_CURRENT(); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_LOG_AND_DISABLE_CURRENT();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_REPORT_FRAME(_pDev) do {\
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_LOG_AND_DISABLE_CURRENT(); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_REPORT_FRAME(_pDev); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_REPORT_FRAME(_pDev); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync } while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#if 0
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_REPORT_FLUSH(_pDev) do {\
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_LOG_AND_DISABLE_CURRENT(); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_REPORT_FRAME(_pDev); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_REPORT_FRAME(_pDev); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync } while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_REPORT_FLUSH(_pDev) do {} while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_INIT_CMN(_pObj, _name, _cEntries) do { \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync (_pObj)->ProfileDdiFps = VBoxDispProfileFpsCounter(); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync (_pObj)->ProfileDdiFps.init(_cEntries); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync (_pObj)->ProfileDdiFunc = VBoxDispProfileSet(_name); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync } while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_TERM_CMN(_pObj) do { \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync (_pObj)->ProfileDdiFps.term(); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync } while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_TERM(_pObj) do {\
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_LOG_AND_DISABLE_CURRENT(); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_DUMP(_pObj); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_RESET(_pObj); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_DDI_TERM_CMN(_pObj); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync } while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_PRINT(_m) VBOXDISPPROFILE_DUMP(_m)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_INIT_GLBL() VBOXDISPPROFILE_DDI_INIT_CMN(&g_VBoxDispProfile, "DDI_Adp", 64)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_INIT_ADP(_pAdp) VBOXDISPPROFILE_DDI_INIT_CMN(_pAdp, "DDI_Adp", 64)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_INIT_DEV(_pDev) VBOXDISPPROFILE_DDI_INIT_CMN(_pDev, "DDI_Dev", 64)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_DEV(_pObj) do {} while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_BASE(_pObj) do {} while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_REPORT_FRAME(_pDev) do {} while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_REPORT_FLUSH(_pDev) do {} while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_INIT_GLBL() do {} while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_INIT_ADP(_pAdp) do {} while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_INIT_DEV(_pDev) do {} while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_TERM(_pObj) do {} while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXDISPPROFILE_DDI_PRINT(_m) do {} while (0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync/* debugging/profiling stuff could go here.
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * NOP in release */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#define VBOXDISP_DDI_PROLOGUE_CMN() \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_BREAK_DDI(); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_CREATE_CHECK_SWAPCHAIN();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#define VBOXDISP_DDI_PROLOGUE_DEV(_hDevice) \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_CMN(); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_DEV((PVBOXWDDMDISP_DEVICE)(_hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#define VBOXDISP_DDI_PROLOGUE_ADP(_hAdapter) \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_CMN(); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_BASE((PVBOXWDDMDISP_ADAPTER)(_hAdapter));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#define VBOXDISP_DDI_PROLOGUE_GLBL() \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_CMN(); \
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_BASE(&g_VBoxDispProfile);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef VBOXDISPMP_TEST
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncHRESULT vboxDispMpTstStart();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncHRESULT vboxDispMpTstStop();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#define VBOXDISP_WITH_WINE_BB_WORKAROUND
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic VBOXSCREENMONRUNNER g_VBoxScreenMonRunner;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync//#define VBOXWDDMOVERLAY_TEST
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic D3DDDIQUERYTYPE gVBoxQueryTypes[] = {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync D3DDDIQUERYTYPE_EVENT,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// D3DDDIQUERYTYPE_OCCLUSION
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync};
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#define VBOX_QUERYTYPE_COUNT() RT_ELEMENTS(gVBoxQueryTypes)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic CRITICAL_SECTION g_VBoxCritSect;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncvoid vboxDispLock()
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync EnterCriticalSection(&g_VBoxCritSect);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncvoid vboxDispUnlock()
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync LeaveCriticalSection(&g_VBoxCritSect);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncvoid vboxDispLockInit()
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync InitializeCriticalSection(&g_VBoxCritSect);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#define VBOXDISPCRHGSMI_SCOPE_SET_DEV(_pDev) do {} while(0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#define VBOXDISPCRHGSMI_SCOPE_SET_GLOBAL() do {} while(0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsynctypedef struct VBOXWDDMDISP_NSCADD
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VOID* pvCommandBuffer;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync UINT cbCommandBuffer;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync D3DDDI_ALLOCATIONLIST* pAllocationList;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync UINT cAllocationList;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync D3DDDI_PATCHLOCATIONLIST* pPatchLocationList;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync UINT cPatchLocationList;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync UINT cAllocations;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}VBOXWDDMDISP_NSCADD, *PVBOXWDDMDISP_NSCADD;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT vboxWddmNSCAddAlloc(PVBOXWDDMDISP_NSCADD pData, PVBOXWDDMDISP_ALLOCATION pAlloc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pData->cAllocationList && pData->cPatchLocationList && pData->cbCommandBuffer > 4)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync memset(pData->pAllocationList, 0, sizeof (D3DDDI_ALLOCATIONLIST));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->pAllocationList[0].hAllocation = pAlloc->hAllocation;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pAlloc->fDirtyWrite)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->pAllocationList[0].WriteOperation = 1;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync memset(pData->pPatchLocationList, 0, sizeof (D3DDDI_PATCHLOCATIONLIST));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->pPatchLocationList[0].PatchOffset = pData->cAllocations*4;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->pPatchLocationList[0].AllocationIndex = pData->cAllocations;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->cbCommandBuffer -= 4;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync --pData->cAllocationList;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync --pData->cPatchLocationList;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ++pData->cAllocations;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ++pData->pAllocationList;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ++pData->pPatchLocationList;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->pvCommandBuffer = (VOID*)(((uint8_t*)pData->pvCommandBuffer) + 4);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = S_FALSE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic BOOLEAN vboxWddmDalCheckRemove(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_ALLOCATION pAlloc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync BOOLEAN fRemoved = FALSE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pAlloc->DirtyAllocListEntry.pNext)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync RTListNodeRemove(&pAlloc->DirtyAllocListEntry);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pAlloc->fDirtyWrite = FALSE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync fRemoved = TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return fRemoved;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT vboxWddmDalNotifyChange(PVBOXWDDMDISP_DEVICE pDevice)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXWDDMDISP_NSCADD NscAdd;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync BOOL bReinitRenderData = TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync do
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (bReinitRenderData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync NscAdd.pvCommandBuffer = pDevice->DefaultContext.ContextInfo.pCommandBuffer;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync NscAdd.cbCommandBuffer = pDevice->DefaultContext.ContextInfo.CommandBufferSize;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync NscAdd.pAllocationList = pDevice->DefaultContext.ContextInfo.pAllocationList;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync NscAdd.cAllocationList = pDevice->DefaultContext.ContextInfo.AllocationListSize;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync NscAdd.pPatchLocationList = pDevice->DefaultContext.ContextInfo.pPatchLocationList;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync NscAdd.cPatchLocationList = pDevice->DefaultContext.ContextInfo.PatchLocationListSize;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync NscAdd.cAllocations = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(NscAdd.cbCommandBuffer >= sizeof (VBOXWDDM_DMA_PRIVATEDATA_BASEHDR));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (NscAdd.cbCommandBuffer < sizeof (VBOXWDDM_DMA_PRIVATEDATA_BASEHDR))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return E_FAIL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDM_DMA_PRIVATEDATA_BASEHDR pHdr = (PVBOXWDDM_DMA_PRIVATEDATA_BASEHDR)NscAdd.pvCommandBuffer;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pHdr->enmCmd = VBOXVDMACMD_TYPE_DMA_NOP;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync NscAdd.pvCommandBuffer = (VOID*)(((uint8_t*)NscAdd.pvCommandBuffer) + sizeof (*pHdr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync NscAdd.cbCommandBuffer -= sizeof (*pHdr);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync bReinitRenderData = FALSE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_ALLOCATION pAlloc = RTListGetFirst(&pDevice->DirtyAllocList, VBOXWDDMDISP_ALLOCATION, DirtyAllocListEntry);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pAlloc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT tmpHr = vboxWddmNSCAddAlloc(&NscAdd, pAlloc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(tmpHr == S_OK || tmpHr == S_FALSE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (tmpHr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmDalCheckRemove(pDevice, pAlloc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync continue;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!NscAdd.cAllocations)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync D3DDDICB_RENDER RenderData = {0};
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync RenderData.CommandLength = pDevice->DefaultContext.ContextInfo.CommandBufferSize - NscAdd.cbCommandBuffer;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(RenderData.CommandLength);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(RenderData.CommandLength < UINT32_MAX/2);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync RenderData.CommandOffset = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync RenderData.NumAllocations = pDevice->DefaultContext.ContextInfo.AllocationListSize - NscAdd.cAllocationList;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(RenderData.NumAllocations == NscAdd.cAllocations);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync RenderData.NumPatchLocations = pDevice->DefaultContext.ContextInfo.PatchLocationListSize - NscAdd.cPatchLocationList;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(RenderData.NumPatchLocations == NscAdd.cAllocations);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// RenderData.NewCommandBufferSize = sizeof (VBOXVDMACMD) + 4 * (100);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// RenderData.NewAllocationListSize = 100;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// RenderData.NewPatchLocationListSize = 100;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync RenderData.hContext = pDevice->DefaultContext.ContextInfo.hContext;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = pDevice->RtCallbacks.pfnRenderCb(pDevice->hDevice, &RenderData);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->DefaultContext.ContextInfo.CommandBufferSize = RenderData.NewCommandBufferSize;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->DefaultContext.ContextInfo.pCommandBuffer = RenderData.pNewCommandBuffer;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->DefaultContext.ContextInfo.AllocationListSize = RenderData.NewAllocationListSize;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->DefaultContext.ContextInfo.pAllocationList = RenderData.pNewAllocationList;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->DefaultContext.ContextInfo.PatchLocationListSize = RenderData.NewPatchLocationListSize;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->DefaultContext.ContextInfo.pPatchLocationList = RenderData.pNewPatchLocationList;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync bReinitRenderData = TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync } while (1);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync//#define VBOX_WDDM_SHRC_WO_NOTIFY
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic BOOLEAN vboxWddmDalCheckAdd(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_ALLOCATION pAlloc, BOOLEAN fWrite)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!pAlloc->hAllocation /* only shared resources matter */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef VBOX_WDDM_SHRC_WO_NOTIFY
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync || !fWrite /* only write op matter */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync )
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef VBOX_WDDM_SHRC_WO_NOTIFY
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pAlloc->DirtyAllocListEntry.pNext || (!fWrite && pAlloc->hSharedHandle && pAlloc->fDirtyWrite));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pAlloc->DirtyAllocListEntry.pNext);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pAlloc->hSharedHandle);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return FALSE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!pAlloc->DirtyAllocListEntry.pNext)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pAlloc->fDirtyWrite);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync RTListAppend(&pDevice->DirtyAllocList, &pAlloc->DirtyAllocListEntry);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pAlloc->fDirtyWrite |= fWrite;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic DECLINLINE(BOOLEAN) vboxWddmDalCheckAddRc(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_RESOURCE pRc, BOOLEAN fWrite)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync BOOLEAN fChanged = FALSE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < pRc->cAllocations; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_ALLOCATION pDAlloc = &pRc->aAllocations[i];
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync fChanged |= vboxWddmDalCheckAdd(pDevice, pDAlloc, fWrite);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return fChanged;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic VOID vboxWddmDalCheckAddRtsSamplers(PVBOXWDDMDISP_DEVICE pDevice)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < pDevice->cRTs; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pDevice->apRTs[i])
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmDalCheckAdd(pDevice, pDevice->apRTs[i], TRUE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0, iSampler = 0; iSampler < pDevice->cSamplerTextures; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(i < RT_ELEMENTS(pDevice->aSamplerTextures));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!pDevice->aSamplerTextures[i]) continue;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmDalCheckAddRc(pDevice, pDevice->aSamplerTextures[i], FALSE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ++iSampler;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef VBOX_WITH_VIDEOHWACCEL
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic bool vboxVhwaIsEnabled(PVBOXWDDMDISP_ADAPTER pAdapter)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (uint32_t i = 0; i < pAdapter->cHeads; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pAdapter->aHeads[i].Vhwa.Settings.fFlags & VBOXVHWA_F_ENABLED)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return true;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return false;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic bool vboxVhwaHasCKeying(PVBOXWDDMDISP_ADAPTER pAdapter)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (uint32_t i = 0; i < pAdapter->cHeads; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVHWA_INFO* pSettings = &pAdapter->aHeads[i].Vhwa.Settings;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if ((pSettings->fFlags & VBOXVHWA_F_ENABLED)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync && ((pSettings->fFlags & VBOXVHWA_F_CKEY_DST)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync || (pSettings->fFlags & VBOXVHWA_F_CKEY_SRC))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync )
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return true;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return false;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic void vboxResourceFree(PVBOXWDDMDISP_RESOURCE pRc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync RTMemFree(pRc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncvoid vboxWddmResourceInit(PVBOXWDDMDISP_RESOURCE pRc, UINT cAllocs)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync memset(pRc, 0, RT_OFFSETOF(VBOXWDDMDISP_RESOURCE, aAllocations[cAllocs]));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pRc->cAllocations = cAllocs;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < cAllocs; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pRc->aAllocations[i].iAlloc = i;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pRc->aAllocations[i].pRc = pRc;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic PVBOXWDDMDISP_RESOURCE vboxResourceAlloc(UINT cAllocs)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)RTMemAlloc(RT_OFFSETOF(VBOXWDDMDISP_RESOURCE, aAllocations[cAllocs]));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pRc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pRc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmResourceInit(pRc, cAllocs);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return pRc;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef VBOXWDDMDISP_DEBUG
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic void vboxWddmDbgSynchMemCheck(PVBOXWDDMDISP_ALLOCATION pAlloc, D3DLOCKED_RECT *pLockInfo)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pAlloc->SurfDesc.pitch);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pAlloc->pvMem);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync int iRc = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pAlloc->SurfDesc.pitch == pLockInfo->Pitch)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pAlloc->SurfDesc.cbSize);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync iRc = memcmp(pLockInfo->pBits, pAlloc->pvMem, pAlloc->SurfDesc.cbSize);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!iRc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync uint8_t *pvSrc, *pvDst;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync uint32_t srcPitch, dstPitch;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (1)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pvSrc = (uint8_t *)pAlloc->pvMem;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pvDst = (uint8_t *)pLockInfo->pBits;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync srcPitch = pAlloc->SurfDesc.pitch;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync dstPitch = pLockInfo->Pitch;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pvDst = (uint8_t *)pAlloc->pvMem;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pvSrc = (uint8_t *)pLockInfo->pBits;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync dstPitch = pAlloc->SurfDesc.pitch;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync srcPitch = (uint32_t)pLockInfo->Pitch;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pAlloc->SurfDesc.pitch <= (UINT)pLockInfo->Pitch);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync uint32_t pitch = RT_MIN(srcPitch, dstPitch);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pitch);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync uint32_t cRows = vboxWddmCalcNumRows(0, pAlloc->SurfDesc.height, pAlloc->SurfDesc.format);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT j = 0; j < cRows; ++j)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync iRc = memcmp(pvDst, pvSrc, pitch);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!iRc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pvSrc += srcPitch;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pvDst += dstPitch;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic VOID vboxWddmDbgRcSynchMemCheck(PVBOXWDDMDISP_RESOURCE pRc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pRc->RcDesc.enmPool != D3DDDIPOOL_SYSTEMMEM)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < pRc->cAllocations; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync D3DLOCKED_RECT Rect;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = VBoxD3DIfLockRect(pRc, i, &Rect, NULL, D3DLOCK_READONLY);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("VBoxD3DIfLockRect failed, hr(0x%x)", hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[i];
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pAlloc->pvMem);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmDbgSynchMemCheck(pAlloc, &Rect);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = VBoxD3DIfUnlockRect(pRc, i);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(SUCCEEDED(hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync/******/
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT vboxWddmRenderTargetSet(PVBOXWDDMDISP_DEVICE pDevice, UINT iRt, PVBOXWDDMDISP_ALLOCATION pAlloc, BOOL bOnSwapchainSynch);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncDECLINLINE(VOID) vboxWddmSwapchainInit(PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync RTLISTNODE ListEntry = pSwapchain->ListEntry;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync memset(pSwapchain, 0, sizeof (VBOXWDDMDISP_SWAPCHAIN));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->ListEntry = ListEntry;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->iBB = VBOXWDDMDISP_INDEX_UNDEFINED;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT vboxWddmSwapchainKmSynch(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync struct
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPIFESCAPE_SWAPCHAININFO SwapchainInfo;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync D3DKMT_HANDLE ahAllocs[VBOXWDDMDISP_MAX_SWAPCHAIN_SIZE];
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync } Buf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync memset(&Buf.SwapchainInfo, 0, sizeof (Buf.SwapchainInfo));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Buf.SwapchainInfo.EscapeHdr.escapeCode = VBOXESC_SWAPCHAININFO;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Buf.SwapchainInfo.SwapchainInfo.hSwapchainKm = pSwapchain->hSwapchainKm;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Buf.SwapchainInfo.SwapchainInfo.hSwapchainUm = (VBOXDISP_UMHANDLE)pSwapchain;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// Buf.SwapchainInfo.SwapchainInfo.Rect;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// Buf.SwapchainInfo.SwapchainInfo.u32Reserved;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Buf.SwapchainInfo.SwapchainInfo.cAllocs = pSwapchain->cRTs;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync UINT cAllocsKm = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < Buf.SwapchainInfo.SwapchainInfo.cAllocs; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// Assert(pSwapchain->aRTs[i].pAlloc->hAllocation);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Buf.SwapchainInfo.SwapchainInfo.ahAllocs[i] = pSwapchain->aRTs[i].pAlloc->hAllocation;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (Buf.SwapchainInfo.SwapchainInfo.ahAllocs[i])
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ++cAllocsKm;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(cAllocsKm == Buf.SwapchainInfo.SwapchainInfo.cAllocs || !cAllocsKm);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (cAllocsKm == Buf.SwapchainInfo.SwapchainInfo.cAllocs)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync D3DDDICB_ESCAPE DdiEscape = {0};
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync DdiEscape.hContext = pDevice->DefaultContext.ContextInfo.hContext;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync DdiEscape.hDevice = pDevice->hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync // DdiEscape.Flags.Value = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync DdiEscape.pPrivateDriverData = &Buf.SwapchainInfo;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync DdiEscape.PrivateDriverDataSize = RT_OFFSETOF(VBOXDISPIFESCAPE_SWAPCHAININFO, SwapchainInfo.ahAllocs[Buf.SwapchainInfo.SwapchainInfo.cAllocs]);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice->RtCallbacks.pfnEscapeCb(pDevice->pAdapter->hAdapter, &DdiEscape);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef DEBUG_misha
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->hSwapchainKm = Buf.SwapchainInfo.SwapchainInfo.hSwapchainKm;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT vboxWddmSwapchainKmDestroy(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->hSwapchainKm)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* submit empty swapchain to destroy the KM one */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync UINT cOldRTc = pSwapchain->cRTs;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->cRTs = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = vboxWddmSwapchainKmSynch(pDevice, pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pSwapchain->hSwapchainKm);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->cRTs = cOldRTc;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT vboxWddmSwapchainDestroyIf(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->pSwapChainIf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifndef VBOXWDDM_WITH_VISIBLE_FB
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->pRenderTargetFbCopy)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->pRenderTargetFbCopy->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->pRenderTargetFbCopy = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->bRTFbCopyUpToDate = FALSE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->pSwapChainIf->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pSwapchain->hWnd);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->pSwapChainIf = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->hWnd = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pSwapchain->hWnd);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncDECLINLINE(VOID) vboxWddmSwapchainClear(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < pSwapchain->cRTs; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->aRTs[i].pAlloc->pSwapchain = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* first do a Km destroy to ensure all km->um region submissions are completed */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmSwapchainKmDestroy(pDevice, pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxDispMpInternalCancel(&pDevice->DefaultContext, pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmSwapchainDestroyIf(pDevice, pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmSwapchainInit(pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncVOID vboxWddmSwapchainDestroy(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmSwapchainClear(pDevice, pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync RTListNodeRemove(&pSwapchain->ListEntry);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync RTMemFree(pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic VOID vboxWddmSwapchainDestroyAll(PVBOXWDDMDISP_DEVICE pDevice)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_SWAPCHAIN pCur = RTListGetFirst(&pDevice->SwapchainList, VBOXWDDMDISP_SWAPCHAIN, ListEntry);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync while (pCur)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_SWAPCHAIN pNext = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!RTListNodeIsLast(&pDevice->SwapchainList, &pCur->ListEntry))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pNext = RTListNodeGetNext(&pCur->ListEntry, VBOXWDDMDISP_SWAPCHAIN, ListEntry);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmSwapchainDestroy(pDevice, pCur);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCur = pNext;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic PVBOXWDDMDISP_SWAPCHAIN vboxWddmSwapchainAlloc(PVBOXWDDMDISP_DEVICE pDevice)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_SWAPCHAIN pSwapchain = (PVBOXWDDMDISP_SWAPCHAIN)RTMemAllocZ(sizeof (VBOXWDDMDISP_SWAPCHAIN));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync RTListAppend(&pDevice->SwapchainList, &pSwapchain->ListEntry);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmSwapchainInit(pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return pSwapchain;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncDECLINLINE(VOID) vboxWddmSwapchainRtInit(PVBOXWDDMDISP_SWAPCHAIN pSwapchain, PVBOXWDDMDISP_RENDERTGT pRt, PVBOXWDDMDISP_ALLOCATION pAlloc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->fFlags.bChanged = 1;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pRt->pAlloc = pAlloc;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pRt->cNumFlips = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pRt->fFlags.Value = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pRt->fFlags.bAdded = 1;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncDECLINLINE(VOID) vboxWddmSwapchainBbAddTail(PVBOXWDDMDISP_SWAPCHAIN pSwapchain, PVBOXWDDMDISP_ALLOCATION pAlloc, BOOL bAssignAsBb)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pAlloc->pSwapchain = pSwapchain;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXWDDMDISP_SWAPCHAIN_FLAGS fOldFlags = pSwapchain->fFlags;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_RENDERTGT pRt = &pSwapchain->aRTs[pSwapchain->cRTs];
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ++pSwapchain->cRTs;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmSwapchainRtInit(pSwapchain, pRt, pAlloc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->cRTs == 1)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pSwapchain->iBB == VBOXWDDMDISP_INDEX_UNDEFINED);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->iBB = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else if (bAssignAsBb)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->iBB = pSwapchain->cRTs - 1;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else if (pSwapchain->cRTs == 2) /* the first one is a frontbuffer */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->iBB = 1;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncDECLINLINE(VOID) vboxWddmSwapchainFlip(PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->iBB = (pSwapchain->iBB + 1) % pSwapchain->cRTs;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncDECLINLINE(UINT) vboxWddmSwapchainNumRTs(PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return pSwapchain->cRTs;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncDECLINLINE(PVBOXWDDMDISP_RENDERTGT) vboxWddmSwapchainRtForAlloc(PVBOXWDDMDISP_SWAPCHAIN pSwapchain, PVBOXWDDMDISP_ALLOCATION pAlloc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pAlloc->pSwapchain != pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < pSwapchain->cRTs; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pSwapchain->aRTs[i].pAlloc->pSwapchain = pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->aRTs[i].pAlloc == pAlloc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return &pSwapchain->aRTs[i];
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* should never happen */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncDECLINLINE(UINT) vboxWddmSwapchainRtIndex(PVBOXWDDMDISP_SWAPCHAIN pSwapchain, PVBOXWDDMDISP_RENDERTGT pRT)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync UINT offFirst = RT_OFFSETOF(VBOXWDDMDISP_SWAPCHAIN, aRTs);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync UINT offRT = UINT((uintptr_t)pRT - (uintptr_t)pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(offRT < sizeof (VBOXWDDMDISP_SWAPCHAIN));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(offRT >= offFirst);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!((offRT - offFirst) % sizeof (VBOXWDDMDISP_RENDERTGT)));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync UINT iRt = (offRT - offFirst) / sizeof (VBOXWDDMDISP_RENDERTGT);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(iRt < pSwapchain->cRTs);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return iRt;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncDECLINLINE(VOID) vboxWddmSwapchainRtRemove(PVBOXWDDMDISP_SWAPCHAIN pSwapchain, PVBOXWDDMDISP_RENDERTGT pRT)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync UINT iRt = vboxWddmSwapchainRtIndex(pSwapchain, pRT);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(iRt < pSwapchain->cRTs);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pRT->pAlloc->pSwapchain = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = iRt; i < pSwapchain->cRTs - 1; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->aRTs[i] = pSwapchain->aRTs[i + 1];
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync --pSwapchain->cRTs;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->cRTs)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->iBB > iRt)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync --pSwapchain->iBB;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else if (pSwapchain->iBB == iRt)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->iBB = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->iBB = VBOXWDDMDISP_INDEX_UNDEFINED;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->fFlags.bChanged = TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->fFlags.bSwitchReportingPresent = TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncDECLINLINE(VOID) vboxWddmSwapchainSetBb(PVBOXWDDMDISP_SWAPCHAIN pSwapchain, PVBOXWDDMDISP_RENDERTGT pRT)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync UINT iRt = vboxWddmSwapchainRtIndex(pSwapchain, pRT);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(iRt < pSwapchain->cRTs);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->iBB = iRt;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->fFlags.bChanged = TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncPVBOXWDDMDISP_SWAPCHAIN vboxWddmSwapchainFindCreate(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_ALLOCATION pBbAlloc, BOOL *pbNeedPresent)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_SWAPCHAIN pSwapchain = pBbAlloc->pSwapchain;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* check if this is what we expect */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_RENDERTGT pRt = vboxWddmSwapchainGetBb(pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pRt->pAlloc != pBbAlloc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pBbAlloc == vboxWddmSwapchainGetFb(pSwapchain)->pAlloc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* the current front-buffer present is requested, don't do anything */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync *pbNeedPresent = FALSE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return pSwapchain;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* bad, @todo: correct the swapchain by either removing the Rt and adding it to another swapchain
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * or by removing the pBbAlloc out of it */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync//@todo: Assert(0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_RENDERTGT pRt = vboxWddmSwapchainRtForAlloc(pSwapchain, pBbAlloc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pRt);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmSwapchainSetBb(pSwapchain, pRt);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->fFlags.bSwitchReportingPresent = TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync *pbNeedPresent = TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* first search for the swapchain the alloc might be added to */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_SWAPCHAIN pCur = RTListGetFirst(&pDevice->SwapchainList, VBOXWDDMDISP_SWAPCHAIN, ListEntry);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync while (pCur)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_RENDERTGT pRt = vboxWddmSwapchainGetBb(pCur);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pRt);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pRt->cNumFlips < 2
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync && vboxWddmSwapchainRtIndex(pCur, pRt) == 0) /* <- in case we add a rt to the swapchain on present this would mean
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * that the last RT in the swapchain array is now a frontbuffer and
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * thus the aRTs[0] is a backbuffer */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pBbAlloc->SurfDesc.width == pRt->pAlloc->SurfDesc.width
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync && pBbAlloc->SurfDesc.height == pRt->pAlloc->SurfDesc.height
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync && vboxWddmFmtNoAlphaFormat(pBbAlloc->SurfDesc.format) == vboxWddmFmtNoAlphaFormat(pRt->pAlloc->SurfDesc.format)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync && pBbAlloc->SurfDesc.VidPnSourceId == pRt->pAlloc->SurfDesc.VidPnSourceId
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync )
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmSwapchainBbAddTail(pCur, pBbAlloc, TRUE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain = pCur;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (RTListNodeIsLast(&pDevice->SwapchainList, &pCur->ListEntry))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCur = RTListNodeGetNext(&pCur->ListEntry, VBOXWDDMDISP_SWAPCHAIN, ListEntry);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// if (!pSwapchain) need to create a new one (see below)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain = vboxWddmSwapchainAlloc(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmSwapchainBbAddTail(pSwapchain, pBbAlloc, FALSE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return pSwapchain;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic PVBOXWDDMDISP_SWAPCHAIN vboxWddmSwapchainCreateForRc(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_RESOURCE pRc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_SWAPCHAIN pSwapchain = vboxWddmSwapchainAlloc(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < pRc->cAllocations; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmSwapchainBbAddTail(pSwapchain, &pRc->aAllocations[i], FALSE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return pSwapchain;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncDECLINLINE(UINT) vboxWddmSwapchainIdxBb2Rt(PVBOXWDDMDISP_SWAPCHAIN pSwapchain, uint32_t iBb)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return iBb != (~0) ? (iBb + pSwapchain->iBB) % pSwapchain->cRTs : vboxWddmSwapchainIdxFb(pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT vboxWddmSwapchainRtSynch(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain, uint32_t iBb)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->fFlags.bRtReportingPresent)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DSurface9 *pD3D9Surf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef VBOXDISP_WITH_WINE_BB_WORKAROUND
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->cRTs == 1)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync iBb = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync UINT iRt = vboxWddmSwapchainIdxBb2Rt(pSwapchain, iBb);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(iRt < pSwapchain->cRTs);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_RENDERTGT pRt = &pSwapchain->aRTs[iRt];
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = pSwapchain->pSwapChainIf->GetBackBuffer(iBb, D3DBACKBUFFER_TYPE_MONO, &pD3D9Surf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("GetBackBuffer failed, hr (0x%x)",hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_ALLOCATION pAlloc = pRt->pAlloc;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pD3D9Surf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pAlloc->pD3DIf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->fFlags.bChanged)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DSurface9 *pD3D9OldSurf = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pAlloc->pD3DIf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* since this can be texture, need to do the VBoxD3DIfSurfGet magic */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = VBoxD3DIfSurfGet(pAlloc->pRc, pAlloc->iAlloc, &pD3D9OldSurf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("VBoxD3DIfSurfGet failed, hr (0x%x)",hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pD3D9Surf->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pD3D9OldSurf && pD3D9OldSurf != pD3D9Surf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VOID *pvSwapchain = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* get the old surface's swapchain */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT tmpHr = pD3D9OldSurf->GetContainer(IID_IDirect3DSwapChain9, &pvSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (tmpHr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pvSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ((IDirect3DSwapChain9 *)pvSwapchain)->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pvSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pvSwapchain != pSwapchain->pSwapChainIf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* the swapchain has changed, copy data to the new surface */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef DEBUG_misha
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* @todo: we can not generally update the render target directly, implement */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(iBb != (~0));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_CHECK_SWAPCHAIN_SYNC(hr = pDevice->pDevice9If->StretchRect(pD3D9OldSurf, NULL, pD3D9Surf, NULL, D3DTEXF_NONE); Assert(hr == S_OK),
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pAlloc, pD3D9OldSurf, NULL, pAlloc, pD3D9Surf, NULL);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pD3D9OldSurf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pD3D9OldSurf->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pAlloc->pD3DIf->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pAlloc->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pAlloc->pD3DIf = pD3D9Surf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pRt->fFlags.Value = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->fFlags.bChanged)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < pDevice->cRTs; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pDevice->apRTs[i] == pAlloc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = vboxWddmRenderTargetSet(pDevice, i, pAlloc, TRUE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef VBOXDISP_WITH_WINE_BB_WORKAROUND
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->cRTs == 1)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DSurface9 *pD3D9Bb;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* only use direct bb if wine is able to handle quick blits bewteen surfaces in one swapchain,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * this is FALSE by now :( */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# ifdef VBOX_WINE_WITH_FAST_INTERSWAPCHAIN_BLT
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* here we sync the front-buffer with a backbuffer data*/
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pD3D9Bb = (IDirect3DSurface9*)vboxWddmSwapchainGetBb(pSwapchain)->pAlloc->pD3DIf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pD3D9Bb);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pD3D9Bb->AddRef();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* we use backbuffer as a rt frontbuffer copy, so release the old one and assign the current bb */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->pRenderTargetFbCopy)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->pRenderTargetFbCopy->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->pRenderTargetFbCopy = pD3D9Bb;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pD3D9Bb = pSwapchain->pRenderTargetFbCopy;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT tmpHr = pSwapchain->pSwapChainIf->GetFrontBufferData(pD3D9Bb);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (SUCCEEDED(tmpHr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_DUMP_SYNC_RT(pD3D9Bb);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->bRTFbCopyUpToDate = TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# ifndef VBOX_WINE_WITH_FAST_INTERSWAPCHAIN_BLT
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_CHECK_SWAPCHAIN_SYNC(tmpHr = pDevice->pDevice9If->StretchRect(pD3D9Bb, NULL, (IDirect3DSurface9*)vboxWddmSwapchainGetBb(pSwapchain)->pAlloc->pD3DIf, NULL, D3DTEXF_NONE); Assert(tmpHr == S_OK),
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pAlloc, pD3D9Bb, NULL, pAlloc, (IDirect3DSurface9*)vboxWddmSwapchainGetBb(pSwapchain)->pAlloc->pD3DIf, NULL);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(tmpHr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("StretchRect failed, hr (0x%x)", tmpHr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("GetFrontBufferData failed, hr (0x%x)", tmpHr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT vboxWddmSwapchainSynch(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (int iBb = -1; iBb < int(pSwapchain->cRTs - 1); ++iBb)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = vboxWddmSwapchainRtSynch(pDevice, pSwapchain, (UINT)iBb);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->fFlags.bChanged)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = vboxWddmSwapchainKmSynch(pDevice, pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->fFlags.bChanged = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic VOID vboxWddmSwapchainFillPresentParams(PVBOXWDDMDISP_SWAPCHAIN pSwapchain, D3DPRESENT_PARAMETERS *pParams)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pSwapchain->cRTs);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef DEBUG_misha
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* not supported by wine properly, need to use offscreen render targets and blit their data to swapchain RTs*/
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pSwapchain->cRTs <= 2);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_RENDERTGT pRt = vboxWddmSwapchainGetBb(pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_RESOURCE pRc = pRt->pAlloc->pRc;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBoxD3DIfFillPresentParams(pParams, pRc, pSwapchain->cRTs);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync/* copy current rt data to offscreen render targets */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT vboxWddmSwapchainSwtichOffscreenRt(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain, BOOL fForceCreate)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync D3DPRESENT_PARAMETERS Params;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmSwapchainFillPresentParams(pSwapchain, &Params);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DSurface9* pD3D9OldFb = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DSwapChain9 * pOldIf = pSwapchain->pSwapChainIf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pOldIf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pOldIf->GetBackBuffer(~0, D3DBACKBUFFER_TYPE_MONO, &pD3D9OldFb);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("GetBackBuffer ~0 failed, hr (%d)", hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* just need a pointer to match */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pD3D9OldFb->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < pSwapchain->cRTs; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_RENDERTGT pRT = &pSwapchain->aRTs[i];
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pRT->pAlloc->enmD3DIfType != VBOXDISP_D3DIFTYPE_SURFACE)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync continue;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync BOOL fHasSurf = pRT->pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE ?
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync !!pRT->pAlloc->pD3DIf
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync :
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync !!pRT->pAlloc->pRc->aAllocations[0].pD3DIf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!fForceCreate && !fHasSurf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync continue;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DSurface9* pD3D9OldSurf = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (fHasSurf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VOID *pvSwapchain = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* since this can be texture, need to do the VBoxD3DIfSurfGet magic */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = VBoxD3DIfSurfGet(pRT->pAlloc->pRc, pRT->pAlloc->iAlloc, &pD3D9OldSurf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pD3D9OldSurf->GetContainer(IID_IDirect3DSwapChain9, &pvSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pvSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ((IDirect3DSwapChain9 *)pvSwapchain)->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pvSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!pvSwapchain) /* no swapchain, it is already offscreen */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pD3D9OldSurf->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync continue;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert (pvSwapchain == pOldIf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DSurface9* pD3D9NewSurf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 *pDevice9If = pDevice->pDevice9If;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice9If->CreateRenderTarget(
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Params.BackBufferWidth, Params.BackBufferHeight,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Params.BackBufferFormat,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Params.MultiSampleType,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Params.MultiSampleQuality,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync TRUE, /*bLockable*/
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync &pD3D9NewSurf,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pRT->pAlloc->hSharedHandle ? &pRT->pAlloc->hSharedHandle : NULL
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync );
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pD3D9OldSurf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pD3D9OldSurf->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pD3D9OldSurf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pD3D9OldSurf != pD3D9OldFb)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_CHECK_SWAPCHAIN_SYNC(hr = pDevice9If->StretchRect(pD3D9OldSurf, NULL, pD3D9NewSurf, NULL, D3DTEXF_NONE); Assert(hr == S_OK),
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pRT->pAlloc, pD3D9OldSurf, NULL, pRT->pAlloc, pD3D9NewSurf, NULL);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pOldIf->GetFrontBufferData(pD3D9NewSurf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pD3D9OldSurf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pD3D9OldSurf->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pRT->pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pRT->pAlloc->pD3DIf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pRT->pAlloc->pD3DIf->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pRT->pAlloc->pD3DIf = pD3D9NewSurf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pD3D9OldSurf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pD3D9OldSurf->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync/**
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * @return old RtReportingPresent state
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT vboxWddmSwapchainSwtichRtPresent(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->fFlags.bRtReportingPresent)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->bRTFbCopyUpToDate = FALSE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->pRenderTargetFbCopy)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->pRenderTargetFbCopy->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->pRenderTargetFbCopy = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = vboxWddmSwapchainSwtichOffscreenRt(pDevice, pSwapchain,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync TRUE /* force offscreen surface creation right away. This way we ensure the swapchain data
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * is always uptodate which allows making the vboxWddmSwapchainRtSynch behave as a nop */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync );
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* ensure we update device RTs to offscreen ones we just created */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < pDevice->cRTs; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_ALLOCATION pRtAlloc = pDevice->apRTs[i];
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT j = 0; j < pSwapchain->cRTs; ++j)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_ALLOCATION pAlloc = pSwapchain->aRTs[j].pAlloc;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pRtAlloc == pAlloc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = vboxWddmRenderTargetSet(pDevice, i, pAlloc, TRUE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->fFlags.bRtReportingPresent = TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncHRESULT vboxWddmSwapchainChkCreateIf(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!pSwapchain->fFlags.bChanged && pSwapchain->pSwapChainIf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* preserve the old one */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DSwapChain9 * pOldIf = pSwapchain->pSwapChainIf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync BOOL bReuseSwapchain = FALSE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync BOOL fNeedRtPresentSwitch = FALSE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->fFlags.bSwitchReportingPresent || pSwapchain->cRTs > VBOXWDDMDISP_MAX_DIRECT_RTS)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->fFlags.bSwitchReportingPresent = FALSE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* indicae switch to Render Target Reporting Present mode is needed */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync fNeedRtPresentSwitch = TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// vboxWddmSwapchainSwtichRtPresent(pDevice, pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < pSwapchain->cRTs; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->aRTs[i].pAlloc->enmD3DIfType != VBOXDISP_D3DIFTYPE_SURFACE
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync && (pSwapchain->aRTs[i].pAlloc->enmD3DIfType != VBOXDISP_D3DIFTYPE_UNDEFINED
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync || pSwapchain->aRTs[i].pAlloc->enmType != VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync fNeedRtPresentSwitch = TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* check if we need to re-create the swapchain */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pOldIf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (fNeedRtPresentSwitch)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* the number of swapchain backbuffers does not matter */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync bReuseSwapchain = TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync D3DPRESENT_PARAMETERS OldParams;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pOldIf->GetPresentParameters(&OldParams);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (OldParams.BackBufferCount == pSwapchain->cRTs-1)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync bReuseSwapchain = TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* first create the new one */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DSwapChain9 * pNewIf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ///
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync UINT cSurfs = pSwapchain->cRTs;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 *pDevice9If = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HWND hOldWnd = pSwapchain->hWnd;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!bReuseSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXWINEEX_D3DPRESENT_PARAMETERS Params;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmSwapchainFillPresentParams(pSwapchain, &Params.Base);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Params.pHgsmi = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync DWORD fFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Params.Base.hDeviceWindow = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* @todo: it seems there should be a way to detect this correctly since
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * our vboxWddmDDevSetDisplayMode will be called in case we are using full-screen */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Params.Base.Windowed = TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync // params.EnableAutoDepthStencil = FALSE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync // params.AutoDepthStencilFormat = D3DFMT_UNKNOWN;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync // params.Flags;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync // params.FullScreen_RefreshRateInHz;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync // params.FullScreen_PresentationInterval;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!pDevice->pDevice9If)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Params.pHgsmi = &pDevice->Uhgsmi.BasePrivate.Base;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pAdapter->D3D.pD3D9If->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, fFlags, &Params.Base, &pDevice9If);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(Params.Base.hDeviceWindow);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->hWnd = Params.Base.hDeviceWindow;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->pDevice9If = pDevice9If;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice9If->GetSwapChain(0, &pNewIf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pNewIf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice9If->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice9If = pDevice->pDevice9If;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pOldIf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* need to copy data to offscreen rt to ensure the data is preserved
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * since the swapchain data may become invalid once we create a new swapchain
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * and pass the current swapchain's window to it
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * thus vboxWddmSwapchainSynch will not be able to do synchronization */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = vboxWddmSwapchainSwtichOffscreenRt(pDevice, pSwapchain, FALSE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* re-use swapchain window
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * this will invalidate the previusly used swapchain */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Params.Base.hDeviceWindow = pSwapchain->hWnd;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice->pDevice9If->CreateAdditionalSwapChain(&Params.Base, &pNewIf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(Params.Base.hDeviceWindow);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->hWnd = Params.Base.hDeviceWindow;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pNewIf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pOldIf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hOldWnd);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pNewIf = pOldIf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* to ensure the swapchain is not deleted once we release the pOldIf */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pNewIf->AddRef();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pNewIf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->pSwapChainIf = pNewIf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (fNeedRtPresentSwitch)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = vboxWddmSwapchainSwtichRtPresent(pDevice, pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifndef VBOXWDDM_WITH_VISIBLE_FB
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!pSwapchain->fFlags.bRtReportingPresent)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->bRTFbCopyUpToDate = FALSE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# if defined(VBOXDISP_WITH_WINE_BB_WORKAROUND) && defined(VBOX_WINE_WITH_FAST_INTERSWAPCHAIN_BLT)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* if wine is able to do fast fb->bb blits, we will use backbuffer directly,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * this is NOT possible currently */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->cRTs == 1)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* we will assign it to wine backbuffer on a swapchain synch */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain->pRenderTargetFbCopy)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->pRenderTargetFbCopy->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->pRenderTargetFbCopy = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!pSwapchain->pRenderTargetFbCopy)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync D3DPRESENT_PARAMETERS Params;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmSwapchainFillPresentParams(pSwapchain, &Params);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DSurface9* pD3D9Surf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice9If->CreateRenderTarget(
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Params.BackBufferWidth, Params.BackBufferHeight,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Params.BackBufferFormat,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Params.MultiSampleType,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Params.MultiSampleQuality,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync TRUE, /*bLockable*/
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync &pD3D9Surf,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync NULL /* HANDLE* pSharedHandle */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync );
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pD3D9Surf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->pRenderTargetFbCopy = pD3D9Surf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* ignore any subsequen failures */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef DEBUG
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < cSurfs; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_RENDERTGT pRt = &pSwapchain->aRTs[i];
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pRt->pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync || pRt->pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_TEXTURE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pRt->pAlloc->pRc->RcDesc.enmPool != D3DDDIPOOL_SYSTEMMEM);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = vboxWddmSwapchainSynch(pDevice, pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pSwapchain->fFlags.bChanged);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pSwapchain->fFlags.bSwitchReportingPresent);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pOldIf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hOldWnd);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pOldIf->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!hOldWnd);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT vboxWddmSwapchainCreateIfForRc(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_RESOURCE pRc, PVBOXWDDMDISP_SWAPCHAIN *ppSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_SWAPCHAIN pSwapchain = vboxWddmSwapchainCreateForRc(pDevice, pRc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync *ppSwapchain = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = vboxWddmSwapchainChkCreateIf(pDevice, pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync *ppSwapchain = pSwapchain;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return E_OUTOFMEMORY;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT vboxWddmSwapchainPresentPerform(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT vboxWddmSwapchainBbUpdate(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain, PVBOXWDDMDISP_ALLOCATION pBbAlloc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pSwapchain->fFlags.bRtReportingPresent);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < pSwapchain->cRTs; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_ALLOCATION pCurBb = vboxWddmSwapchainGetBb(pSwapchain)->pAlloc;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pCurBb == pBbAlloc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = vboxWddmSwapchainPresentPerform(pDevice, pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("vboxWddmSwapchainPresentPerform failed, hr (0x%x)", hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync AssertMsgFailed(("the given allocation not par of the swapchain\n"));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return E_FAIL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync/* get the surface for the specified allocation in the swapchain */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT vboxWddmSwapchainSurfGet(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain, PVBOXWDDMDISP_ALLOCATION pAlloc, IDirect3DSurface9 **ppSurf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pAlloc->pSwapchain == pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifndef VBOXWDDM_WITH_VISIBLE_FB
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!pSwapchain->fFlags.bRtReportingPresent
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync && vboxWddmSwapchainGetFb(pSwapchain)->pAlloc == pAlloc
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# ifdef VBOXDISP_WITH_WINE_BB_WORKAROUND
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync && vboxWddmSwapchainNumRTs(pSwapchain) != 1 /* for swapchains w/o a backbuffer the alloc will contain the back-buffer actually */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync )
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* this is a front-buffer */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(vboxWddmSwapchainNumRTs(pSwapchain) > 1);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DSurface9 *pSurf = pSwapchain->pRenderTargetFbCopy;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pSurf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSurf->AddRef();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!pSwapchain->bRTFbCopyUpToDate)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = pSwapchain->pSwapChainIf->GetFrontBufferData(pSurf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("GetFrontBufferData failed, hr (0x%x)", hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSurf->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->bRTFbCopyUpToDate = TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync *ppSurf = pSurf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* if this is not a front-buffer - just return the surface associated with the allocation */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return VBoxD3DIfSurfGet(pAlloc->pRc, pAlloc->iAlloc, ppSurf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT vboxWddmSwapchainRtSurfGet(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain, UINT iRt, PVBOXWDDMDISP_ALLOCATION pAlloc, BOOL bOnSwapchainSynch, IDirect3DSurface9 **ppSurf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pAlloc->pSwapchain == pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* do the necessary swapchain synchronization first,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * not needed on swapchain synch since it is done already and we're called here just to set RTs */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!bOnSwapchainSynch)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!pSwapchain->fFlags.bRtReportingPresent)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* iRt != 0 is untested here !! */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(iRt == 0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (iRt == 0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = vboxWddmSwapchainBbUpdate(pDevice, pSwapchain, pAlloc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("vboxWddmSwapchainBbUpdate failed, hr(0x%x)",hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync//@todo: Assert(!pSwapchain->fFlags.bChanged);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pSwapchain->pSwapChainIf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = vboxWddmSwapchainChkCreateIf(pDevice, pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("vboxWddmSwapchainChkCreateIf failed, hr(0x%x)",hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync//@todo: Assert(vboxWddmSwapchainGetBb(pSwapchain)->pAlloc == pAlloc || iRt != 0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DSurface9 *pSurf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = vboxWddmSwapchainSurfGet(pDevice, pSwapchain, pAlloc, &pSurf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("vboxWddmSwapchainSurfGet failed, hr(0x%x)", hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync *ppSurf = pSurf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT vboxWddmSwapchainPresentPerform(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_SWAPCHAIN pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_DUMP_PRESENT_ENTER(pDevice, pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!pSwapchain->fFlags.bRtReportingPresent)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pSwapchain->pSwapChainIf->Present(NULL, NULL, NULL, NULL, 0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_ALLOCATION pCurBb = vboxWddmSwapchainGetBb(pSwapchain)->pAlloc;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DSurface9 *pSurf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = vboxWddmSwapchainSurfGet(pDevice, pSwapchain, pCurBb, &pSurf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DSwapchain9Present(pSwapchain->pSwapChainIf, pSurf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSurf->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_DUMP_PRESENT_LEAVE(pDevice, pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSwapchain->bRTFbCopyUpToDate = FALSE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmSwapchainFlip(pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pSwapchain->fFlags.bChanged);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pSwapchain->fFlags.bSwitchReportingPresent);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = vboxWddmSwapchainSynch(pDevice, pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT vboxWddmSwapchainPresent(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_ALLOCATION pBbAlloc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* we currently *assume* that presenting shared resource is only possible when 3d app is rendering with composited desktop on,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * no need to do anything else since dwm will present everything for us */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pBbAlloc->hSharedHandle)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_ASSERT_IS_DWM(FALSE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9Flush((IDirect3DDevice9Ex*)pDevice->pDevice9If);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmDalNotifyChange(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_ASSERT_IS_DWM(TRUE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync BOOL bNeedPresent;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_SWAPCHAIN pSwapchain = vboxWddmSwapchainFindCreate(pDevice, pBbAlloc, &bNeedPresent);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!bNeedPresent)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = vboxWddmSwapchainChkCreateIf(pDevice, pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = vboxWddmSwapchainPresentPerform(pDevice, pSwapchain);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return E_OUTOFMEMORY;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#if 0 //def DEBUG
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic void vboxWddmDbgRenderTargetUpdateCheckSurface(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_ALLOCATION pAlloc, uint32_t iBBuf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DSurface9 *pD3D9Surf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = pDevice->aScreens[pDevice->iPrimaryScreen].pDevice9If;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = pDevice9If->GetBackBuffer(0 /*UINT iSwapChain*/,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync iBBuf, D3DBACKBUFFER_TYPE_MONO, &pD3D9Surf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pD3D9Surf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pD3D9Surf == pAlloc->pD3DIf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pD3D9Surf->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic void vboxWddmDbgRenderTargetCheck(PVBOXWDDMDISP_DEVICE pDevice, PVBOXWDDMDISP_RESOURCE pRc, uint32_t iNewRTFB)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_ALLOCATION pAlloc;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync UINT iBBuf = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(iNewRTFB < pRc->cAllocations);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 1; i < pRc->cAllocations; ++i, ++iBBuf)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync UINT iAlloc = (iNewRTFB + i) % pRc->cAllocations;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(iAlloc != iNewRTFB);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pAlloc = &pRc->aAllocations[iAlloc];
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmDbgRenderTargetUpdateCheckSurface(pDevice, pAlloc, iBBuf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pAlloc = &pRc->aAllocations[iNewRTFB];
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef VBOXWDDM_WITH_VISIBLE_FB
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmDbgRenderTargetUpdateCheckSurface(pDevice, pAlloc, ~0UL /* <- for the frontbuffer */);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert((!pAlloc->pD3DIf) == (pRc->cAllocations > 1));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < pRc->cAllocations; ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pAlloc = &pRc->aAllocations[i];
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (iNewRTFB == i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert((!pAlloc->pD3DIf) == (pRc->cAllocations > 1));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT j = i+1; j < pRc->cAllocations; ++j)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_ALLOCATION pAllocJ = &pRc->aAllocations[j];
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pAlloc->pD3DIf != pAllocJ->pD3DIf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXVDBG_RTGT_STATECHECK(_pDev) (vboxWddmDbgRenderTargetCheck((_pDev), (_pDev)->aScreens[(_pDev)->iPrimaryScreen].pRenderTargetRc, (_pDev)->aScreens[(_pDev)->iPrimaryScreen].iRenderTargetFrontBuf))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync# define VBOXVDBG_RTGT_STATECHECK(_pDev) do{}while(0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync/******/
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT vboxWddmRenderTargetSet(PVBOXWDDMDISP_DEVICE pDevice, UINT iRt, PVBOXWDDMDISP_ALLOCATION pAlloc, BOOL bOnSwapchainSynch)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_SWAPCHAIN pSwapchain = vboxWddmSwapchainForAlloc(pAlloc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DSurface9 *pD3D9Surf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSwapchain)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = vboxWddmSwapchainRtSurfGet(pDevice, pSwapchain, iRt, pAlloc, bOnSwapchainSynch, &pD3D9Surf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("vboxWddmSwapchainRtSurfGet failed, hr(0x%x)",hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = VBoxD3DIfSurfGet(pAlloc->pRc, pAlloc->iAlloc, &pD3D9Surf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("VBoxD3DIfSurfGet failed, hr(0x%x)",hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pD3D9Surf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice9If->SetRenderTarget(iRt, pD3D9Surf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(iRt < pDevice->cRTs);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->apRTs[iRt] = pAlloc;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pD3D9Surf->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync/**
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync * DLL entry point.
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncBOOL WINAPI DllMain(HINSTANCE hInstance,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync DWORD dwReason,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync LPVOID lpReserved)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync switch (dwReason)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case DLL_PROCESS_ATTACH:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxDispLockInit();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrint(("VBoxDispD3D: DLL loaded.\n"));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef VBOXWDDMDISP_DEBUG_VEHANDLER
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgVEHandlerRegister();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync int rc = RTR3InitDll(0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync AssertRC(rc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (RT_SUCCESS(rc))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// rc = VbglR3Init();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// AssertRC(rc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// if (RT_SUCCESS(rc))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = vboxDispCmInit();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = vboxDispMpInternalInit();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBoxDispD3DGlobalInit();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrint(("VBoxDispD3D: DLL loaded OK\n"));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// VbglR3Term();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef VBOXWDDMDISP_DEBUG_VEHANDLER
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgVEHandlerUnregister();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case DLL_PROCESS_DETACH:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef VBOXWDDMDISP_DEBUG_VEHANDLER
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgVEHandlerUnregister();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = vboxDispMpInternalTerm();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = vboxDispCmTerm();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// VbglR3Term();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /// @todo RTR3Term();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBoxDispD3DGlobalTerm();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync default:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return TRUE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return FALSE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDispGetCaps (HANDLE hAdapter, CONST D3DDDIARG_GETCAPS* pData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_ADP(hAdapter);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrint(("==> "__FUNCTION__", hAdapter(0x%p), caps type(%d)\n", hAdapter, pData->Type));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_GLOBAL();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)hAdapter;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync switch (pData->Type)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_DDRAW:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!VBOXDISPMODE_IS_3D(pAdapter));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pData->DataSize == sizeof (DDRAW_CAPS));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pData->DataSize >= sizeof (DDRAW_CAPS))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync memset(pData->pData, 0, sizeof (DDRAW_CAPS));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef VBOX_WITH_VIDEOHWACCEL
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!VBOXDISPMODE_IS_3D(pAdapter))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (vboxVhwaHasCKeying(pAdapter))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync DDRAW_CAPS *pCaps = (DDRAW_CAPS*)pData->pData;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->Caps |= DDRAW_CAPS_COLORKEY;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync // pCaps->Caps2 |= DDRAW_CAPS2_FLIPNOVSYNC;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("D3DDDICAPS_DDRAW query for D3D mode!"));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = E_INVALIDARG;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_DDRAW_MODE_SPECIFIC:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!VBOXDISPMODE_IS_3D(pAdapter));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pData->DataSize == sizeof (DDRAW_MODE_SPECIFIC_CAPS));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pData->DataSize >= sizeof (DDRAW_MODE_SPECIFIC_CAPS))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync DDRAW_MODE_SPECIFIC_CAPS * pCaps = (DDRAW_MODE_SPECIFIC_CAPS*)pData->pData;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync memset(&pCaps->Caps /* do not cleanup the first "Head" field,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync zero starting with the one following "Head", i.e. Caps */,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync 0, sizeof (DDRAW_MODE_SPECIFIC_CAPS) - RT_OFFSETOF(DDRAW_MODE_SPECIFIC_CAPS, Caps));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef VBOX_WITH_VIDEOHWACCEL
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!VBOXDISPMODE_IS_3D(pAdapter))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVHWA_INFO *pSettings = &pAdapter->aHeads[pCaps->Head].Vhwa.Settings;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSettings->fFlags & VBOXVHWA_F_ENABLED)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->Caps |= MODE_CAPS_OVERLAY | MODE_CAPS_OVERLAYSTRETCH;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSettings->fFlags & VBOXVHWA_F_CKEY_DST)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->CKeyCaps |= MODE_CKEYCAPS_DESTOVERLAY
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync | MODE_CKEYCAPS_DESTOVERLAYYUV /* ?? */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSettings->fFlags & VBOXVHWA_F_CKEY_SRC)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->CKeyCaps |= MODE_CKEYCAPS_SRCOVERLAY
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync | MODE_CKEYCAPS_SRCOVERLAYCLRSPACE /* ?? */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync | MODE_CKEYCAPS_SRCOVERLAYCLRSPACEYUV /* ?? */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync | MODE_CKEYCAPS_SRCOVERLAYYUV /* ?? */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->FxCaps = MODE_FXCAPS_OVERLAYSHRINKX
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync | MODE_FXCAPS_OVERLAYSHRINKY
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync | MODE_FXCAPS_OVERLAYSTRETCHX
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync | MODE_FXCAPS_OVERLAYSTRETCHY;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->MaxVisibleOverlays = pSettings->cOverlaysSupported;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->MinOverlayStretch = 1;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->MaxOverlayStretch = 32000;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("D3DDDICAPS_DDRAW_MODE_SPECIFIC query for D3D mode!"));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = E_INVALIDARG;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETFORMATCOUNT:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync *((uint32_t*)pData->pData) = pAdapter->Formats.cFormstOps;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETFORMATDATA:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pData->DataSize == pAdapter->Formats.cFormstOps * sizeof (FORMATOP));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync memcpy(pData->pData, pAdapter->Formats.paFormstOps, pAdapter->Formats.cFormstOps * sizeof (FORMATOP));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETD3DQUERYCOUNT:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#if 1
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync *((uint32_t*)pData->pData) = VBOX_QUERYTYPE_COUNT();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync *((uint32_t*)pData->pData) = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETD3DQUERYDATA:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#if 1
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pData->DataSize == VBOX_QUERYTYPE_COUNT() * sizeof (D3DDDIQUERYTYPE));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync memcpy(pData->pData, gVBoxQueryTypes, VBOX_QUERYTYPE_COUNT() * sizeof (D3DDDIQUERYTYPE));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync memset(pData->pData, 0, pData->DataSize);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETD3D3CAPS:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!VBOXDISPMODE_IS_3D(pAdapter));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pData->DataSize == sizeof (D3DHAL_GLOBALDRIVERDATA));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pData->DataSize >= sizeof (D3DHAL_GLOBALDRIVERDATA))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync D3DHAL_GLOBALDRIVERDATA *pCaps = (D3DHAL_GLOBALDRIVERDATA *)pData->pData;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync memset (pCaps, 0, sizeof (D3DHAL_GLOBALDRIVERDATA));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->dwSize = sizeof (D3DHAL_GLOBALDRIVERDATA);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dwSize = sizeof (D3DDEVICEDESC_V1);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dwFlags = D3DDD_COLORMODEL
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync | D3DDD_DEVCAPS
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync | D3DDD_DEVICERENDERBITDEPTH;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dcmColorModel = D3DCOLOR_RGB;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dwDevCaps = D3DDEVCAPS_CANRENDERAFTERFLIP
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// | D3DDEVCAPS_DRAWPRIMTLVERTEX
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync | D3DDEVCAPS_EXECUTESYSTEMMEMORY
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync | D3DDEVCAPS_EXECUTEVIDEOMEMORY
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// | D3DDEVCAPS_FLOATTLVERTEX
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync | D3DDEVCAPS_HWRASTERIZATION
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// | D3DDEVCAPS_HWTRANSFORMANDLIGHT
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// | D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// | D3DDEVCAPS_TEXTUREVIDEOMEMORY
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dtcTransformCaps.dwSize = sizeof (D3DTRANSFORMCAPS);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dtcTransformCaps.dwCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.bClipping = FALSE;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dlcLightingCaps.dwSize = sizeof (D3DLIGHTINGCAPS);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dlcLightingCaps.dwCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dlcLightingCaps.dwLightingModel = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dlcLightingCaps.dwNumLights = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcLineCaps.dwSize = sizeof (D3DPRIMCAPS);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcLineCaps.dwMiscCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcLineCaps.dwRasterCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcLineCaps.dwZCmpCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcLineCaps.dwSrcBlendCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcLineCaps.dwDestBlendCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcLineCaps.dwAlphaCmpCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcLineCaps.dwShadeCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcLineCaps.dwTextureCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcLineCaps.dwTextureFilterCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcLineCaps.dwTextureBlendCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcLineCaps.dwTextureAddressCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcLineCaps.dwStippleWidth = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcLineCaps.dwStippleHeight = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcTriCaps.dwSize = sizeof (D3DPRIMCAPS);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcTriCaps.dwMiscCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcTriCaps.dwRasterCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcTriCaps.dwZCmpCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcTriCaps.dwSrcBlendCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcTriCaps.dwDestBlendCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcTriCaps.dwAlphaCmpCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcTriCaps.dwShadeCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcTriCaps.dwTextureCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcTriCaps.dwTextureFilterCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcTriCaps.dwTextureBlendCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcTriCaps.dwTextureAddressCaps = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcTriCaps.dwStippleWidth = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dpcTriCaps.dwStippleHeight = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dwDeviceRenderBitDepth = DDBD_8 | DDBD_16 | DDBD_24 | DDBD_32;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dwDeviceZBufferBitDepth = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dwMaxBufferSize = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->hwCaps.dwMaxVertexCount = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->dwNumVertices = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->dwNumClipVertices = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->dwNumTextureFormats = 0;//pAdapter->cSurfDescs;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->lpTextureFormats = NULL;//pAdapter->paSurfDescs;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = E_INVALIDARG;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETD3D7CAPS:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!VBOXDISPMODE_IS_3D(pAdapter));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pData->DataSize == sizeof (D3DHAL_D3DEXTENDEDCAPS));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pData->DataSize >= sizeof (D3DHAL_D3DEXTENDEDCAPS))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync memset(pData->pData, 0, sizeof (D3DHAL_D3DEXTENDEDCAPS));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync D3DHAL_D3DEXTENDEDCAPS *pCaps = (D3DHAL_D3DEXTENDEDCAPS*)pData->pData;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pCaps->dwSize = sizeof (D3DHAL_D3DEXTENDEDCAPS);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = E_INVALIDARG;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETD3D9CAPS:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pData->DataSize == sizeof (D3DCAPS9));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pData->DataSize >= sizeof (D3DCAPS9))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(VBOXDISPMODE_IS_3D(pAdapter));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (VBOXDISPMODE_IS_3D(pAdapter))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync memcpy(pData->pData, &pAdapter->D3D.Caps, sizeof (D3DCAPS9));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync memset(pData->pData, 0, sizeof (D3DCAPS9));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = E_INVALIDARG;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETD3D8CAPS:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pData->DataSize == RT_OFFSETOF(D3DCAPS9, DevCaps2));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pData->DataSize == RT_OFFSETOF(D3DCAPS9, DevCaps2))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(VBOXDISPMODE_IS_3D(pAdapter));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (VBOXDISPMODE_IS_3D(pAdapter))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync memcpy(pData->pData, &pAdapter->D3D.Caps, RT_OFFSETOF(D3DCAPS9, DevCaps2));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = E_INVALIDARG;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETGAMMARAMPCAPS:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync *((uint32_t*)pData->pData) = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETVIDEOPROCESSORCAPS:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETEXTENSIONGUIDCOUNT:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETDECODEGUIDCOUNT:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETVIDEOPROCESSORDEVICEGUIDCOUNT:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETVIDEOPROCESSORRTFORMATCOUNT:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pData->pData && pData->DataSize)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync memset(pData->pData, 0, pData->DataSize);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETMULTISAMPLEQUALITYLEVELS:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETD3D5CAPS:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETD3D6CAPS:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETDECODEGUIDS:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETDECODERTFORMATCOUNT:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETDECODERTFORMATS:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETDECODECOMPRESSEDBUFFERINFOCOUNT:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETDECODECOMPRESSEDBUFFERINFO:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETDECODECONFIGURATIONCOUNT:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETDECODECONFIGURATIONS:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETVIDEOPROCESSORDEVICEGUIDS:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETVIDEOPROCESSORRTFORMATS:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETVIDEOPROCESSORRTSUBSTREAMFORMATCOUNT:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETVIDEOPROCESSORRTSUBSTREAMFORMATS:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETPROCAMPRANGE:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_FILTERPROPERTYRANGE:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETEXTENSIONGUIDS:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync case D3DDDICAPS_GETEXTENSIONCAPS:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrint((__FUNCTION__": unimplemented caps type(%d)\n", pData->Type));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pData->pData && pData->DataSize)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync memset(pData->pData, 0, pData->DataSize);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync default:
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrint((__FUNCTION__": unknown caps type(%d)\n", pData->Type));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrint(("<== "__FUNCTION__", hAdapter(0x%p), caps type(%d)\n", hAdapter, pData->Type));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevSetRenderState(HANDLE hDevice, CONST D3DDDIARG_RENDERSTATE* pData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = pDevice9If->SetRenderState(vboxDDI2D3DRenderStateType(pData->State), pData->Value);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevUpdateWInfo(HANDLE hDevice, CONST D3DDDIARG_WINFO* pData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevValidateDevice(HANDLE hDevice, D3DDDIARG_VALIDATETEXTURESTAGESTATE* pData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef DEBUG_misha
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* @todo: check if it's ok to always return success */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrint((__FUNCTION__": @todo: check if it's ok to always return success\n"));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevSetTextureStageState(HANDLE hDevice, CONST D3DDDIARG_TEXTURESTAGESTATE* pData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXWDDMDISP_TSS_LOOKUP lookup = vboxDDI2D3DTestureStageStateType(pData->State);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!lookup.bSamplerState)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice9If->SetTextureStageState(pData->Stage, D3DTEXTURESTAGESTATETYPE(lookup.dType), pData->Value);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice9If->SetSamplerState(pData->Stage, D3DSAMPLERSTATETYPE(lookup.dType), pData->Value);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevSetTexture(HANDLE hDevice, UINT Stage, HANDLE hTexture)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)hTexture;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// Assert(pRc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DBaseTexture9 *pD3DIfTex;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pRc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_CHECK_SMSYNC(pRc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_TEXTURE)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pD3DIfTex = (IDirect3DTexture9*)pRc->aAllocations[0].pD3DIf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_BREAK_SHARED(pRc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_DUMP_SETTEXTURE(pRc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_CUBE_TEXTURE)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pD3DIfTex = (IDirect3DCubeTexture9*)pRc->aAllocations[0].pD3DIf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_BREAK_SHARED(pRc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_DUMP_SETTEXTURE(pRc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pD3DIfTex = (IDirect3DVolumeTexture9*)pRc->aAllocations[0].pD3DIf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_BREAK_SHARED(pRc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_DUMP_SETTEXTURE(pRc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice->cSamplerTextures < RT_ELEMENTS(pDevice->aSamplerTextures));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync int idx = VBOXWDDMDISP_SAMPLER_IDX(Stage);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (idx >= 0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(idx < RT_ELEMENTS(pDevice->aSamplerTextures));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef DEBUG_misha
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (VBOXWDDMDISP_SAMPLER_IDX_IS_SPECIAL(Stage))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("non-zero special sampler index not tested!\n"));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!pDevice->aSamplerTextures[idx])
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ++pDevice->cSamplerTextures;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice->cSamplerTextures < RT_ELEMENTS(pDevice->aSamplerTextures));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->aSamplerTextures[idx] = pRc;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("incorrect dampler index1! (%d)\n", Stage));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pD3DIfTex = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice->cSamplerTextures < RT_ELEMENTS(pDevice->aSamplerTextures));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync int idx = VBOXWDDMDISP_SAMPLER_IDX(Stage);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (idx >= 0)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(idx < RT_ELEMENTS(pDevice->aSamplerTextures));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pDevice->aSamplerTextures[idx])
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice->cSamplerTextures);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync --pDevice->cSamplerTextures;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice->cSamplerTextures < RT_ELEMENTS(pDevice->aSamplerTextures));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->aSamplerTextures[idx] = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("incorrect dampler index2! (%d)\n", Stage));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = pDevice9If->SetTexture(Stage, pD3DIfTex);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevSetPixelShader(HANDLE hDevice, HANDLE hShaderHandle)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DPixelShader9 *pShader = (IDirect3DPixelShader9*)hShaderHandle;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = pDevice9If->SetPixelShader(pShader);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevSetPixelShaderConst(HANDLE hDevice, CONST D3DDDIARG_SETPIXELSHADERCONST* pData, CONST FLOAT* pRegisters)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = pDevice9If->SetPixelShaderConstantF(pData->Register, pRegisters, pData->Count);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevSetStreamSourceUm(HANDLE hDevice, CONST D3DDDIARG_SETSTREAMSOURCEUM* pData, CONST VOID* pUMBuffer )
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pData->Stream < RT_ELEMENTS(pDevice->aStreamSourceUm));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_STREAMSOURCEUM pStrSrcUm = &pDevice->aStreamSourceUm[pData->Stream];
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pStrSrcUm->pvBuffer && !pUMBuffer)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync --pDevice->cStreamSourcesUm;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice->cStreamSourcesUm < UINT32_MAX/2);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else if (!pStrSrcUm->pvBuffer && pUMBuffer)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ++pDevice->cStreamSourcesUm;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice->cStreamSourcesUm <= RT_ELEMENTS(pDevice->aStreamSourceUm));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pStrSrcUm->pvBuffer = pUMBuffer;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pStrSrcUm->cbStride = pData->Stride;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pDevice->aStreamSource[pData->Stream])
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice->pDevice9If->SetStreamSource(pData->Stream, NULL, 0, 0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync --pDevice->cStreamSources;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice->cStreamSources < UINT32_MAX/2);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->aStreamSource[pData->Stream] = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevSetIndices(HANDLE hDevice, CONST D3DDDIARG_SETINDICES* pData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hIndexBuffer;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_ALLOCATION pAlloc = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DIndexBuffer9 *pIndexBuffer = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pRc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_CHECK_SMSYNC(pRc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pRc->cAllocations == 1);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pAlloc = &pRc->aAllocations[0];
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pAlloc->pD3DIf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pIndexBuffer = (IDirect3DIndexBuffer9*)pAlloc->pD3DIf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = pDevice9If->SetIndices(pIndexBuffer);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->IndiciesInfo.pIndicesAlloc = pAlloc;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->IndiciesInfo.uiStride = pData->Stride;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->IndiciesInfo.pvIndicesUm = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevSetIndicesUm(HANDLE hDevice, UINT IndexSize, CONST VOID* pUMBuffer)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pDevice->IndiciesInfo.pIndicesAlloc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice9If->SetIndices(NULL);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (SUCCEEDED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->IndiciesInfo.pvIndicesUm = pUMBuffer;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->IndiciesInfo.uiStride = IndexSize;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->IndiciesInfo.pIndicesAlloc = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("SetIndices failed hr 0x%x", hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevDrawPrimitive(HANDLE hDevice, CONST D3DDDIARG_DRAWPRIMITIVE* pData, CONST UINT* pFlagBuffer)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pFlagBuffer);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_BREAK_SHARED_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_DUMP_DRAWPRIM_ENTER(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!pDevice->cStreamSources)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pDevice->aStreamSourceUm[0].pvBuffer)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef DEBUG
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 1; i < RT_ELEMENTS(pDevice->aStreamSourceUm); ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pDevice->aStreamSourceUm[i].pvBuffer);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice9If->DrawPrimitiveUP(pData->PrimitiveType,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->PrimitiveCount,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ((uint8_t*)pDevice->aStreamSourceUm[0].pvBuffer) + pData->VStart * pDevice->aStreamSourceUm[0].cbStride,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->aStreamSourceUm[0].cbStride);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// vboxVDbgMpPrintF((pDevice, __FUNCTION__": DrawPrimitiveUP\n"));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* todo: impl */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef DEBUG
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < RT_ELEMENTS(pDevice->aStreamSourceUm); ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pDevice->aStreamSourceUm[i].pvBuffer);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync uint32_t cStreams = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < RT_ELEMENTS(pDevice->aStreamSource); ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pDevice->aStreamSource[i])
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ++cStreams;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pDevice->aStreamSource[i]->LockInfo.cLocks);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(cStreams);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(cStreams == pDevice->cStreamSources);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice9If->DrawPrimitive(pData->PrimitiveType,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->VStart,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->PrimitiveCount);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// vboxVDbgMpPrintF((pDevice, __FUNCTION__": DrawPrimitive\n"));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmDalCheckAddRtsSamplers(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_DUMP_DRAWPRIM_LEAVE(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevDrawIndexedPrimitive(HANDLE hDevice, CONST D3DDDIARG_DRAWINDEXEDPRIMITIVE* pData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_BREAK_SHARED_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_DUMP_DRAWPRIM_ENTER(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef DEBUG
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync uint32_t cStreams = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < RT_ELEMENTS(pDevice->aStreamSourceUm); ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if(pDevice->aStreamSourceUm[i].pvBuffer)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ++cStreams;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(cStreams == pDevice->cStreamSourcesUm);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync cStreams = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < RT_ELEMENTS(pDevice->aStreamSource); ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pDevice->aStreamSource[i])
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ++cStreams;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pDevice->aStreamSource[i]->LockInfo.cLocks);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(cStreams == pDevice->cStreamSources);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pDevice->cStreamSources)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice->IndiciesInfo.pIndicesAlloc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pDevice->IndiciesInfo.pvIndicesUm);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pDevice->IndiciesInfo.pIndicesAlloc->LockInfo.cLocks);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pDevice->cStreamSourcesUm);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice9If->DrawIndexedPrimitive(
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->PrimitiveType,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->BaseVertexIndex,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->MinIndex,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->NumVertices,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->StartIndex,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->PrimitiveCount);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if(SUCCEEDED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("DrawIndexedPrimitive failed hr = 0x%x", hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice->cStreamSourcesUm == 1);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice->IndiciesInfo.uiStride == 2 || pDevice->IndiciesInfo.uiStride == 4);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync const uint8_t * pvIndexBuffer;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pDevice->IndiciesInfo.pIndicesAlloc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(!pDevice->IndiciesInfo.pvIndicesUm);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pDevice->IndiciesInfo.pIndicesAlloc->pvMem)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pvIndexBuffer = (const uint8_t*)pDevice->IndiciesInfo.pIndicesAlloc->pvMem;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("not expected!"));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = E_FAIL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pvIndexBuffer = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pvIndexBuffer = (const uint8_t*)pDevice->IndiciesInfo.pvIndicesUm;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (!pvIndexBuffer)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("not expected!"));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = E_FAIL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (SUCCEEDED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (UINT i = 0; i < RT_ELEMENTS(pDevice->aStreamSourceUm); ++i)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if(pDevice->aStreamSourceUm[i].pvBuffer)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice9If->DrawIndexedPrimitiveUP(pData->PrimitiveType,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->MinIndex,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->NumVertices,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->PrimitiveCount,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pvIndexBuffer + pDevice->IndiciesInfo.uiStride * pData->StartIndex,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->IndiciesInfo.uiStride == 2 ? D3DFMT_INDEX16 : D3DFMT_INDEX32,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->aStreamSourceUm[i].pvBuffer,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->aStreamSourceUm[i].cbStride);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if(SUCCEEDED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pDevice->IndiciesInfo.pIndicesAlloc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT tmpHr = pDevice9If->SetIndices((IDirect3DIndexBuffer9*)pDevice->IndiciesInfo.pIndicesAlloc->pD3DIf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if(!SUCCEEDED(tmpHr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("SetIndices failed hr = 0x%x", tmpHr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("DrawIndexedPrimitiveUP failed hr = 0x%x", hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync break;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmDalCheckAddRtsSamplers(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_DUMP_DRAWPRIM_LEAVE(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevDrawRectPatch(HANDLE hDevice, CONST D3DDDIARG_DRAWRECTPATCH* pData, CONST D3DDDIRECTPATCH_INFO* pInfo, CONST FLOAT* pPatch)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmDalCheckAddRtsSamplers(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return E_FAIL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevDrawTriPatch(HANDLE hDevice, CONST D3DDDIARG_DRAWTRIPATCH* pData, CONST D3DDDITRIPATCH_INFO* pInfo, CONST FLOAT* pPatch)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmDalCheckAddRtsSamplers(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return E_FAIL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevDrawPrimitive2(HANDLE hDevice, CONST D3DDDIARG_DRAWPRIMITIVE2* pData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#if 0
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync int stream;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (stream=0; stream<VBOXWDDMDISP_MAX_VERTEX_STREAMS; ++stream)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pDevice->aStreamSource[stream] && pDevice->aStreamSource[stream]->LockInfo.cLocks)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXWDDMDISP_LOCKINFO *pLock = &pDevice->aStreamSource[stream]->LockInfo;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pLock->fFlags.MightDrawFromLocked && (pLock->fFlags.Discard || pLock->fFlags.NoOverwrite))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DVertexBuffer9 *pD3D9VBuf = (IDirect3DVertexBuffer9*)pDevice->aStreamSource[stream]->pD3DIf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pLock->fFlags.RangeValid);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pD3D9VBuf->Lock(pLock->Range.Offset, pLock->Range.Size,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync &pLock->LockedRect.pBits,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxDDI2D3DLockFlags(pLock->fFlags));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync RECT r;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync r.top = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync r.left = pLock->Range.Offset;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync r.bottom = 1;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync r.right = pLock->Range.Offset + pLock->Range.Size;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBoxD3DIfLockUnlockMemSynch(pDevice->aStreamSource[stream], &pLock->LockedRect, &r, true /*bool bToLockInfo*/);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pD3D9VBuf->Unlock();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice9If->DrawPrimitive(pData->PrimitiveType, pData->FirstVertexOffset, pData->PrimitiveCount);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_BREAK_SHARED_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_DUMP_DRAWPRIM_ENTER(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef DEBUG
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync uint32_t cStreams = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync int stream;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync for (stream=0; stream<VBOXWDDMDISP_MAX_VERTEX_STREAMS; ++stream)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pDevice->aStreamSource[stream])
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef DEBUG
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ++cStreams;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(stream==0); /*only stream 0 should be accessed here*/
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice->StreamSourceInfo[stream].uiStride!=0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXWDDMDISP_LOCKINFO *pLock = &pDevice->aStreamSource[stream]->LockInfo;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pLock->cLocks)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// vboxVDbgMpPrintF((pDevice, __FUNCTION__": DrawPrimitiveUP\n"));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pLock->fFlags.MightDrawFromLocked && (pLock->fFlags.Discard || pLock->fFlags.NoOverwrite));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice9If->DrawPrimitiveUP(pData->PrimitiveType, pData->PrimitiveCount,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync (void*)((uintptr_t)pDevice->aStreamSource[stream]->pvMem+pDevice->StreamSourceInfo[stream].uiOffset+pData->FirstVertexOffset),
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->StreamSourceInfo[stream].uiStride);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice9If->SetStreamSource(stream, (IDirect3DVertexBuffer9*)pDevice->aStreamSource[stream]->pD3DIf, pDevice->StreamSourceInfo[stream].uiOffset, pDevice->StreamSourceInfo[stream].uiStride);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// vboxVDbgMpPrintF((pDevice, __FUNCTION__": DrawPrimitive\n"));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice9If->DrawPrimitive(pData->PrimitiveType, pData->FirstVertexOffset/pDevice->StreamSourceInfo[stream].uiStride, pData->PrimitiveCount);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef DEBUG
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(cStreams);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(cStreams == pDevice->cStreamSources);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmDalCheckAddRtsSamplers(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_DUMP_DRAWPRIM_LEAVE(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevDrawIndexedPrimitive2(HANDLE hDevice, CONST D3DDDIARG_DRAWINDEXEDPRIMITIVE2* pData, UINT dwIndicesSize, CONST VOID* pIndexBuffer, CONST UINT* pFlagBuffer)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync const uint8_t *pvVertexBuffer = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync DWORD cbVertexStride = 0;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (dwIndicesSize != 2 && dwIndicesSize != 4)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("unsupported dwIndicesSize %d", dwIndicesSize));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pDevice->aStreamSourceUm[0].pvBuffer)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice->aStreamSourceUm[0].cbStride);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pvVertexBuffer = (const uint8_t *)pDevice->aStreamSourceUm[0].pvBuffer;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync cbVertexStride = pDevice->aStreamSourceUm[0].cbStride;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else if (pDevice->aStreamSource[0])
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_ALLOCATION pAlloc = pDevice->aStreamSource[0];
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pAlloc->pvMem)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice->StreamSourceInfo[0].uiStride);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pvVertexBuffer = ((const uint8_t *)pAlloc->pvMem) + pDevice->StreamSourceInfo[0].uiOffset;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync cbVertexStride = pDevice->StreamSourceInfo[0].uiStride;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("unsupported!!"));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = E_FAIL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("not expected!"));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = E_FAIL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (SUCCEEDED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pvVertexBuffer = pvVertexBuffer + pData->BaseVertexOffset /* * cbVertexStride */;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice9If->DrawIndexedPrimitiveUP(pData->PrimitiveType,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->MinIndex,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->NumVertices,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->PrimitiveCount,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync ((uint8_t*)pIndexBuffer) + dwIndicesSize * pData->StartIndexOffset,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync dwIndicesSize == 2 ? D3DFMT_INDEX16 : D3DFMT_INDEX32,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pvVertexBuffer,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync cbVertexStride);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if(SUCCEEDED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("DrawIndexedPrimitiveUP failed hr = 0x%x", hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pDevice->aStreamSource[0])
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT tmpHr = pDevice9If->SetStreamSource(0, (IDirect3DVertexBuffer9*)pDevice->aStreamSource[0]->pD3DIf, pDevice->StreamSourceInfo[0].uiOffset, pDevice->StreamSourceInfo[0].uiStride);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if(!SUCCEEDED(tmpHr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("SetStreamSource failed hr = 0x%x", tmpHr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pDevice->IndiciesInfo.pIndicesAlloc)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT tmpHr = pDevice9If->SetIndices((IDirect3DIndexBuffer9*)pDevice->IndiciesInfo.pIndicesAlloc->pD3DIf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if(!SUCCEEDED(tmpHr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("SetIndices failed hr = 0x%x", tmpHr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmDalCheckAddRtsSamplers(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(sizeof (D3DDDIBOX) == sizeof (VBOXBOX3D));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Left) == RT_SIZEOFMEMB(VBOXBOX3D, Left));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Top) == RT_SIZEOFMEMB(VBOXBOX3D, Top));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Right) == RT_SIZEOFMEMB(VBOXBOX3D, Right));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Bottom) == RT_SIZEOFMEMB(VBOXBOX3D, Bottom));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Front) == RT_SIZEOFMEMB(VBOXBOX3D, Front));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Back) == RT_SIZEOFMEMB(VBOXBOX3D, Back));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_OFFSETOF(D3DDDIBOX, Left) == RT_OFFSETOF(VBOXBOX3D, Left));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_OFFSETOF(D3DDDIBOX, Top) == RT_OFFSETOF(VBOXBOX3D, Top));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_OFFSETOF(D3DDDIBOX, Right) == RT_OFFSETOF(VBOXBOX3D, Right));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_OFFSETOF(D3DDDIBOX, Bottom) == RT_OFFSETOF(VBOXBOX3D, Bottom));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_OFFSETOF(D3DDDIBOX, Front) == RT_OFFSETOF(VBOXBOX3D, Front));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_OFFSETOF(D3DDDIBOX, Back) == RT_OFFSETOF(VBOXBOX3D, Back));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevVolBlt(HANDLE hDevice, CONST D3DDDIARG_VOLUMEBLT* pData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_RESOURCE pDstRc = (PVBOXWDDMDISP_RESOURCE)pData->hDstResource;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_RESOURCE pSrcRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* requirements for D3DDevice9::UpdateTexture */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDstRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pSrcRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DVolumeTexture9 * pSrcTex = (IDirect3DVolumeTexture9*)pSrcRc->aAllocations[0].pD3DIf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DVolumeTexture9 * pDstTex = (IDirect3DVolumeTexture9*)pDstRc->aAllocations[0].pD3DIf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXPOINT3D Point;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Point.x = pData->DstX;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Point.y = pData->DstY;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Point.z = pData->DstZ;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9VolTexBlt((IDirect3DDevice9Ex*)pDevice9If, pSrcTex, pDstTex,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync (VBOXBOX3D*)&pData->SrcBox, &Point);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (FAILED(hr))
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync WARN(("pfnVBoxWineExD3DDev9VolTexBlt failed hr 0x%x", hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevBufBlt(HANDLE hDevice, CONST D3DDDIARG_BUFFERBLT* pData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// @todo: vboxWddmDalCheckAdd(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return E_FAIL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevTexBlt(HANDLE hDevice, CONST D3DDDIARG_TEXBLT* pData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_RESOURCE pDstRc = (PVBOXWDDMDISP_RESOURCE)pData->hDstResource;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_RESOURCE pSrcRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync /* requirements for D3DDevice9::UpdateTexture */
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDstRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_TEXTURE
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync || pDstRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_CUBE_TEXTURE
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync || pDstRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pSrcRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_TEXTURE
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync || pSrcRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_CUBE_TEXTURE
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync || pDstRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pSrcRc->aAllocations[0].enmD3DIfType == pDstRc->aAllocations[0].enmD3DIfType);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pSrcRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDstRc->RcDesc.enmPool != D3DDDIPOOL_SYSTEMMEM);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_CHECK_SMSYNC(pDstRc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_CHECK_SMSYNC(pSrcRc);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (pSrcRc->aAllocations[0].SurfDesc.d3dWidth == pDstRc->aAllocations[0].SurfDesc.d3dWidth
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync && pSrcRc->aAllocations[0].SurfDesc.height == pDstRc->aAllocations[0].SurfDesc.height
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync && pSrcRc->RcDesc.enmFormat == pDstRc->RcDesc.enmFormat
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync &&pData->DstPoint.x == 0 && pData->DstPoint.y == 0
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync && pData->SrcRect.left == 0 && pData->SrcRect.top == 0
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync && pData->SrcRect.right - pData->SrcRect.left == pSrcRc->aAllocations[0].SurfDesc.width
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync && pData->SrcRect.bottom - pData->SrcRect.top == pSrcRc->aAllocations[0].SurfDesc.height)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DBaseTexture9 *pD3DIfSrcTex = (IDirect3DBaseTexture9*)pSrcRc->aAllocations[0].pD3DIf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DBaseTexture9 *pD3DIfDstTex = (IDirect3DBaseTexture9*)pDstRc->aAllocations[0].pD3DIf;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pD3DIfSrcTex);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pD3DIfDstTex);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_CHECK_TEXBLT(
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice9If->UpdateTexture(pD3DIfSrcTex, pD3DIfDstTex); Assert(hr == S_OK),
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSrcRc,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync &pData->SrcRect,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDstRc,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync &pData->DstPoint);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync else
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDstRc->aAllocations[0].enmD3DIfType != VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pSrcRc->aAllocations[0].enmD3DIfType != VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DSurface9 *pSrcSurfIf = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DSurface9 *pDstSurfIf = NULL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = VBoxD3DIfSurfGet(pDstRc, 0, &pDstSurfIf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = VBoxD3DIfSurfGet(pSrcRc, 0, &pSrcSurfIf);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync if (hr == S_OK)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync {
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync RECT DstRect;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmRectMoved(&DstRect, &pData->SrcRect, pData->DstPoint.x, pData->DstPoint.y);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#ifdef DEBUG
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync RECT tstRect = {0,0, pDstRc->aAllocations[0].SurfDesc.width, pDstRc->aAllocations[0].SurfDesc.height};
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(vboxWddmRectIsCoveres(&tstRect, &DstRect));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync#endif
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXVDBG_CHECK_TEXBLT(
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync hr = pDevice9If->StretchRect(pSrcSurfIf, &pData->SrcRect, pDstSurfIf, &DstRect, D3DTEXF_NONE); Assert(hr == S_OK),
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSrcRc,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync &pData->SrcRect,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDstRc,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync &pData->DstPoint);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pSrcSurfIf->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDstSurfIf->Release();
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync }
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmDalCheckAddRc(pDevice, pDstRc, TRUE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxWddmDalCheckAddRc(pDevice, pSrcRc, FALSE);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevStateSet(HANDLE hDevice, D3DDDIARG_STATESET* pData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return E_FAIL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevSetPriority(HANDLE hDevice, CONST D3DDDIARG_SETPRIORITY* pData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync// VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return S_OK;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(sizeof (RECT) == sizeof (D3DRECT));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_SIZEOFMEMB(RECT, left) == RT_SIZEOFMEMB(D3DRECT, x1));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_SIZEOFMEMB(RECT, right) == RT_SIZEOFMEMB(D3DRECT, x2));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_SIZEOFMEMB(RECT, top) == RT_SIZEOFMEMB(D3DRECT, y1));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_SIZEOFMEMB(RECT, bottom) == RT_SIZEOFMEMB(D3DRECT, y2));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_OFFSETOF(RECT, left) == RT_OFFSETOF(D3DRECT, x1));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_OFFSETOF(RECT, right) == RT_OFFSETOF(D3DRECT, x2));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_OFFSETOF(RECT, top) == RT_OFFSETOF(D3DRECT, y1));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncAssertCompile(RT_OFFSETOF(RECT, bottom) == RT_OFFSETOF(D3DRECT, y2));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevClear(HANDLE hDevice, CONST D3DDDIARG_CLEAR* pData, UINT NumRect, CONST RECT* pRect)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = pDevice9If->Clear(NumRect, (D3DRECT*)pRect /* see AssertCompile above */,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->Flags,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->FillColor,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->FillDepth,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->FillStencil);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevUpdatePalette(HANDLE hDevice, CONST D3DDDIARG_UPDATEPALETTE* pData, CONST PALETTEENTRY* pPaletteData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return E_FAIL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevSetPalette(HANDLE hDevice, CONST D3DDDIARG_SETPALETTE* pData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return E_FAIL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevSetVertexShaderConst(HANDLE hDevice, CONST D3DDDIARG_SETVERTEXSHADERCONST* pData , CONST VOID* pRegisters)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = pDevice9If->SetVertexShaderConstantF(
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->Register,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync (CONST float*)pRegisters,
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pData->Count);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevMultiplyTransform(HANDLE hDevice, CONST D3DDDIARG_MULTIPLYTRANSFORM* pData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return E_FAIL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevSetTransform(HANDLE hDevice, CONST D3DDDIARG_SETTRANSFORM* pData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(0);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return E_FAIL;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevSetViewport(HANDLE hDevice, CONST D3DDDIARG_VIEWPORTINFO* pData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->ViewPort.X = pData->X;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->ViewPort.Y = pData->Y;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->ViewPort.Width = pData->Width;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->ViewPort.Height = pData->Height;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = pDevice9If->SetViewport(&pDevice->ViewPort);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync}
f9a51917495bc8ba8b60632219652a7b122c1190vboxsyncstatic HRESULT APIENTRY vboxWddmDDevSetZRange(HANDLE hDevice, CONST D3DDDIARG_ZRANGE* pData)
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync{
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->ViewPort.MinZ = pData->MinZ;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync pDevice->ViewPort.MaxZ = pData->MaxZ;
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync HRESULT hr = pDevice9If->SetViewport(&pDevice->ViewPort);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync Assert(hr == S_OK);
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
f9a51917495bc8ba8b60632219652a7b122c1190vboxsync return hr;
}
static HRESULT APIENTRY vboxWddmDDevSetMaterial(HANDLE hDevice, CONST D3DDDIARG_SETMATERIAL* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevSetLight(HANDLE hDevice, CONST D3DDDIARG_SETLIGHT* pData, CONST D3DDDI_LIGHT* pLightProperties)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevCreateLight(HANDLE hDevice, CONST D3DDDIARG_CREATELIGHT* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevDestroyLight(HANDLE hDevice, CONST D3DDDIARG_DESTROYLIGHT* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevSetClipPlane(HANDLE hDevice, CONST D3DDDIARG_SETCLIPPLANE* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
HRESULT hr = pDevice9If->SetClipPlane(pData->Index, pData->Plane);
Assert(hr == S_OK);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevGetInfo(HANDLE hDevice, UINT DevInfoID, VOID* pDevInfoStruct, UINT DevInfoSize)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
// PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
// Assert(pDevice);
// VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
HRESULT hr = S_OK;
switch (DevInfoID)
{
case D3DDDIDEVINFOID_VCACHE:
{
Assert(DevInfoSize == sizeof (D3DDDIDEVINFO_VCACHE));
if (DevInfoSize == sizeof (D3DDDIDEVINFO_VCACHE))
{
D3DDDIDEVINFO_VCACHE *pVCache = (D3DDDIDEVINFO_VCACHE*)pDevInfoStruct;
pVCache->Pattern = MAKEFOURCC('C', 'A', 'C', 'H');
pVCache->OptMethod = 0 /* D3DXMESHOPT_STRIPREORDER */;
pVCache->CacheSize = 0;
pVCache->MagicNumber = 0;
}
else
hr = E_INVALIDARG;
break;
}
default:
Assert(0);
hr = E_NOTIMPL;
}
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
AssertCompile(sizeof (D3DDDIBOX) == sizeof (D3DBOX));
AssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Left) == RT_SIZEOFMEMB(D3DBOX, Left));
AssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Top) == RT_SIZEOFMEMB(D3DBOX, Top));
AssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Right) == RT_SIZEOFMEMB(D3DBOX, Right));
AssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Bottom) == RT_SIZEOFMEMB(D3DBOX, Bottom));
AssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Front) == RT_SIZEOFMEMB(D3DBOX, Front));
AssertCompile(RT_SIZEOFMEMB(D3DDDIBOX, Back) == RT_SIZEOFMEMB(D3DBOX, Back));
AssertCompile(RT_OFFSETOF(D3DDDIBOX, Left) == RT_OFFSETOF(D3DBOX, Left));
AssertCompile(RT_OFFSETOF(D3DDDIBOX, Top) == RT_OFFSETOF(D3DBOX, Top));
AssertCompile(RT_OFFSETOF(D3DDDIBOX, Right) == RT_OFFSETOF(D3DBOX, Right));
AssertCompile(RT_OFFSETOF(D3DDDIBOX, Bottom) == RT_OFFSETOF(D3DBOX, Bottom));
AssertCompile(RT_OFFSETOF(D3DDDIBOX, Front) == RT_OFFSETOF(D3DBOX, Front));
AssertCompile(RT_OFFSETOF(D3DDDIBOX, Back) == RT_OFFSETOF(D3DBOX, Back));
static HRESULT APIENTRY vboxWddmDDevLock(HANDLE hDevice, D3DDDIARG_LOCK* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hResource;
Assert(pData->SubResourceIndex < pRc->cAllocations);
if (pData->SubResourceIndex >= pRc->cAllocations)
return E_INVALIDARG;
HRESULT hr = S_OK;
if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))
{
// Assert(pRc != pScreen->pRenderTargetRc || pScreen->iRenderTargetFrontBuf != pData->SubResourceIndex);
if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_TEXTURE
|| pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_CUBE_TEXTURE
|| pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE)
{
PVBOXWDDMDISP_ALLOCATION pTexAlloc = &pRc->aAllocations[0];
Assert(pData->SubResourceIndex < pRc->cAllocations);
PVBOXWDDMDISP_ALLOCATION pLockAlloc = &pRc->aAllocations[pData->SubResourceIndex];
IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pTexAlloc->pD3DIf;
IDirect3DCubeTexture9 *pD3DIfCubeTex = (IDirect3DCubeTexture9*)pTexAlloc->pD3DIf;
IDirect3DSurface9 *pD3DIfSurface = (IDirect3DSurface9*)pTexAlloc->pD3DIf;
Assert(pTexAlloc->pD3DIf);
RECT *pRect = NULL;
BOOL fNeedLock = TRUE;
Assert(!pData->Flags.RangeValid);
Assert(!pData->Flags.BoxValid);
if (pData->Flags.AreaValid)
{
pRect = &pData->Area;
}
/* else - we lock the entire texture, pRect == NULL */
if (pLockAlloc->LockInfo.cLocks)
{
Assert(pLockAlloc->LockInfo.fFlags.AreaValid == pData->Flags.AreaValid);
if (pLockAlloc->LockInfo.fFlags.AreaValid && pData->Flags.AreaValid)
{
Assert(pLockAlloc->LockInfo.Area.left == pData->Area.left);
Assert(pLockAlloc->LockInfo.Area.top == pData->Area.top);
Assert(pLockAlloc->LockInfo.Area.right == pData->Area.right);
Assert(pLockAlloc->LockInfo.Area.bottom == pData->Area.bottom);
}
Assert(pLockAlloc->LockInfo.LockedRect.pBits);
Assert((pLockAlloc->LockInfo.fFlags.Value & ~1) == (pData->Flags.Value & ~1)); /* <- 1 is "ReadOnly" flag */
if (pLockAlloc->LockInfo.fFlags.ReadOnly && !pData->Flags.ReadOnly)
{
switch (pTexAlloc->enmD3DIfType)
{
case VBOXDISP_D3DIFTYPE_TEXTURE:
hr = pD3DIfTex->UnlockRect(pData->SubResourceIndex);
break;
case VBOXDISP_D3DIFTYPE_CUBE_TEXTURE:
hr = pD3DIfCubeTex->UnlockRect(VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, pData->SubResourceIndex),
VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, pData->SubResourceIndex));
break;
case VBOXDISP_D3DIFTYPE_SURFACE:
hr = pD3DIfSurface->UnlockRect();
break;
default:
Assert(0);
break;
}
Assert(hr == S_OK);
}
else
{
fNeedLock = FALSE;
}
}
if (fNeedLock && SUCCEEDED(hr))
{
VBOXVDBG_CHECK_SMSYNC(pRc);
pLockAlloc->LockInfo.fFlags = pData->Flags;
if (pRect)
{
pLockAlloc->LockInfo.Area = *pRect;
Assert(pLockAlloc->LockInfo.fFlags.AreaValid == 1);
}
else
{
Assert(pLockAlloc->LockInfo.fFlags.AreaValid == 0);
}
switch (pTexAlloc->enmD3DIfType)
{
case VBOXDISP_D3DIFTYPE_TEXTURE:
hr = pD3DIfTex->LockRect(pData->SubResourceIndex,
&pLockAlloc->LockInfo.LockedRect,
pRect,
vboxDDI2D3DLockFlags(pData->Flags));
break;
case VBOXDISP_D3DIFTYPE_CUBE_TEXTURE:
hr = pD3DIfCubeTex->LockRect(VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, pData->SubResourceIndex),
VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, pData->SubResourceIndex),
&pLockAlloc->LockInfo.LockedRect,
pRect,
vboxDDI2D3DLockFlags(pData->Flags));
break;
case VBOXDISP_D3DIFTYPE_SURFACE:
hr = pD3DIfSurface->LockRect(&pLockAlloc->LockInfo.LockedRect,
pRect,
vboxDDI2D3DLockFlags(pData->Flags));
break;
default:
Assert(0);
break;
}
if (FAILED(hr))
{
WARN(("LockRect failed, hr", hr));
}
}
if (SUCCEEDED(hr))
{
++pLockAlloc->LockInfo.cLocks;
if (!pData->Flags.NotifyOnly)
{
pData->pSurfData = pLockAlloc->LockInfo.LockedRect.pBits;
pData->Pitch = pLockAlloc->LockInfo.LockedRect.Pitch;
pData->SlicePitch = 0;
Assert(pLockAlloc->SurfDesc.slicePitch == 0);
Assert(!pLockAlloc->pvMem);
}
else
{
Assert(pLockAlloc->pvMem);
Assert(pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);
}
VBOXVDBG_DUMP_LOCK_ST(pData);
hr = S_OK;
}
}
else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE)
{
PVBOXWDDMDISP_ALLOCATION pTexAlloc = &pRc->aAllocations[0];
Assert(pData->SubResourceIndex < pRc->cAllocations);
PVBOXWDDMDISP_ALLOCATION pLockAlloc = &pRc->aAllocations[pData->SubResourceIndex];
IDirect3DVolumeTexture9 *pD3DIfTex = (IDirect3DVolumeTexture9*)pTexAlloc->pD3DIf;
Assert(pTexAlloc->pD3DIf);
D3DDDIBOX *pBox = NULL;
BOOL fNeedLock = TRUE;
Assert(!pData->Flags.AreaValid);
Assert(!pData->Flags.BoxValid);
if (pData->Flags.BoxValid)
{
pBox = &pData->Box;
}
/* else - we lock the entire texture, pBox == NULL */
if (pLockAlloc->LockInfo.cLocks)
{
Assert(pLockAlloc->LockInfo.fFlags.BoxValid == pData->Flags.BoxValid);
if (pLockAlloc->LockInfo.fFlags.BoxValid && pData->Flags.BoxValid)
{
Assert(pLockAlloc->LockInfo.Box.Left == pData->Box.Left);
Assert(pLockAlloc->LockInfo.Box.Top == pData->Box.Top);
Assert(pLockAlloc->LockInfo.Box.Right == pData->Box.Right);
Assert(pLockAlloc->LockInfo.Box.Bottom == pData->Box.Bottom);
Assert(pLockAlloc->LockInfo.Box.Front == pData->Box.Front);
Assert(pLockAlloc->LockInfo.Box.Back == pData->Box.Back);
}
Assert(pLockAlloc->LockInfo.LockedBox.pBits);
Assert((pLockAlloc->LockInfo.fFlags.Value & ~1) == (pData->Flags.Value & ~1)); /* <- 1 is "ReadOnly" flag */
if (pLockAlloc->LockInfo.fFlags.ReadOnly && !pData->Flags.ReadOnly)
{
hr = pD3DIfTex->UnlockBox(pData->SubResourceIndex);
Assert(hr == S_OK);
}
else
{
fNeedLock = FALSE;
}
}
if (fNeedLock && SUCCEEDED(hr))
{
VBOXVDBG_CHECK_SMSYNC(pRc);
pLockAlloc->LockInfo.fFlags = pData->Flags;
if (pBox)
{
pLockAlloc->LockInfo.Box = *pBox;
Assert(pLockAlloc->LockInfo.fFlags.BoxValid == 1);
}
else
{
Assert(pLockAlloc->LockInfo.fFlags.BoxValid == 0);
}
hr = pD3DIfTex->LockBox(pData->SubResourceIndex,
&pLockAlloc->LockInfo.LockedBox,
(D3DBOX*)pBox,
vboxDDI2D3DLockFlags(pData->Flags));
if (FAILED(hr))
{
WARN(("LockRect failed, hr", hr));
}
}
if (SUCCEEDED(hr))
{
++pLockAlloc->LockInfo.cLocks;
if (!pData->Flags.NotifyOnly)
{
pData->pSurfData = pLockAlloc->LockInfo.LockedBox.pBits;
pData->Pitch = pLockAlloc->LockInfo.LockedBox.RowPitch;
pData->SlicePitch = pLockAlloc->LockInfo.LockedBox.SlicePitch;
Assert(!pLockAlloc->pvMem);
}
else
{
Assert(pLockAlloc->pvMem);
Assert(pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);
}
VBOXVDBG_DUMP_LOCK_ST(pData);
hr = S_OK;
}
}
else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VERTEXBUFFER)
{
Assert(pData->SubResourceIndex < pRc->cAllocations);
PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
IDirect3DVertexBuffer9 *pD3D9VBuf = (IDirect3DVertexBuffer9*)pAlloc->pD3DIf;
BOOL bLocked = false;
Assert(pD3D9VBuf);
Assert(!pData->Flags.AreaValid);
Assert(!pData->Flags.BoxValid);
D3DDDIRANGE *pRange = NULL;
if (pData->Flags.RangeValid)
{
pRange = &pData->Range;
}
/* else - we lock the entire vertex buffer, pRect == NULL */
if (!pAlloc->LockInfo.cLocks)
{
VBOXVDBG_CHECK_SMSYNC(pRc);
if (!pData->Flags.MightDrawFromLocked || (!pData->Flags.Discard && !pData->Flags.NoOverwrite))
{
hr = pD3D9VBuf->Lock(pRange ? pRange->Offset : 0,
pRange ? pRange->Size : 0,
&pAlloc->LockInfo.LockedRect.pBits,
vboxDDI2D3DLockFlags(pData->Flags));
bLocked = true;
}
Assert(hr == S_OK);
if (hr == S_OK)
{
Assert(pAlloc->SurfDesc.pitch == pAlloc->SurfDesc.width);
pAlloc->LockInfo.LockedRect.Pitch = pAlloc->SurfDesc.pitch;
// Assert(pLockAlloc->LockInfo.fFlags.Value == 0);
pAlloc->LockInfo.fFlags = pData->Flags;
if (pRange)
{
pAlloc->LockInfo.Range = *pRange;
Assert(pAlloc->LockInfo.fFlags.RangeValid == 1);
// pAlloc->LockInfo.fFlags.RangeValid = 1;
}
else
{
Assert(pAlloc->LockInfo.fFlags.RangeValid == 0);
// pAlloc->LockInfo.fFlags.RangeValid = 0;
}
}
}
else
{
Assert(pAlloc->LockInfo.fFlags.RangeValid == pData->Flags.RangeValid);
if (pAlloc->LockInfo.fFlags.RangeValid && pData->Flags.RangeValid)
{
Assert(pAlloc->LockInfo.Range.Offset == pData->Range.Offset);
Assert(pAlloc->LockInfo.Range.Size == pData->Range.Size);
}
Assert(pAlloc->LockInfo.LockedRect.pBits);
}
if (hr == S_OK)
{
++pAlloc->LockInfo.cLocks;
if (!pData->Flags.NotifyOnly)
{
pData->pSurfData = pAlloc->LockInfo.LockedRect.pBits;
pData->Pitch = pAlloc->LockInfo.LockedRect.Pitch;
pData->SlicePitch = 0;
Assert(pAlloc->SurfDesc.slicePitch == 0);
Assert(!pAlloc->pvMem);
}
else
{
Assert(pAlloc->pvMem);
Assert(pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);
if (bLocked && !pData->Flags.Discard)
{
RECT r, *pr;
if (pRange)
{
r.top = 0;
r.left = pRange->Offset;
r.bottom = 1;
r.right = pRange->Offset + pRange->Size;
pr = &r;
}
else
pr = NULL;
VBoxD3DIfLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect, pr, false /*bool bToLockInfo*/);
}
}
}
}
else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_INDEXBUFFER)
{
Assert(pData->SubResourceIndex < pRc->cAllocations);
PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
IDirect3DIndexBuffer9 *pD3D9IBuf = (IDirect3DIndexBuffer9*)pAlloc->pD3DIf;
BOOL bLocked = false;
Assert(pD3D9IBuf);
Assert(!pData->Flags.AreaValid);
Assert(!pData->Flags.BoxValid);
D3DDDIRANGE *pRange = NULL;
if (pData->Flags.RangeValid)
{
pRange = &pData->Range;
}
/* else - we lock the entire vertex buffer, pRect == NULL */
if (!pAlloc->LockInfo.cLocks)
{
VBOXVDBG_CHECK_SMSYNC(pRc);
if (!pData->Flags.MightDrawFromLocked || (!pData->Flags.Discard && !pData->Flags.NoOverwrite))
{
hr = pD3D9IBuf->Lock(pRange ? pRange->Offset : 0,
pRange ? pRange->Size : 0,
&pAlloc->LockInfo.LockedRect.pBits,
vboxDDI2D3DLockFlags(pData->Flags));
bLocked = true;
}
Assert(hr == S_OK);
if (hr == S_OK)
{
Assert(pAlloc->SurfDesc.pitch == pAlloc->SurfDesc.width);
pAlloc->LockInfo.LockedRect.Pitch = pAlloc->SurfDesc.pitch;
// Assert(pLockAlloc->LockInfo.fFlags.Value == 0);
pAlloc->LockInfo.fFlags = pData->Flags;
if (pRange)
{
pAlloc->LockInfo.Range = *pRange;
Assert(pAlloc->LockInfo.fFlags.RangeValid == 1);
// pAlloc->LockInfo.fFlags.RangeValid = 1;
}
else
{
Assert(pAlloc->LockInfo.fFlags.RangeValid == 0);
// pAlloc->LockInfo.fFlags.RangeValid = 0;
}
}
}
else
{
Assert(pAlloc->LockInfo.fFlags.RangeValid == pData->Flags.RangeValid);
if (pAlloc->LockInfo.fFlags.RangeValid && pData->Flags.RangeValid)
{
Assert(pAlloc->LockInfo.Range.Offset == pData->Range.Offset);
Assert(pAlloc->LockInfo.Range.Size == pData->Range.Size);
}
Assert(pAlloc->LockInfo.LockedRect.pBits);
}
if (hr == S_OK)
{
++pAlloc->LockInfo.cLocks;
if (!pData->Flags.NotifyOnly)
{
pData->pSurfData = pAlloc->LockInfo.LockedRect.pBits;
pData->Pitch = pAlloc->LockInfo.LockedRect.Pitch;
pData->SlicePitch = 0;
Assert(pAlloc->SurfDesc.slicePitch == 0);
Assert(!pAlloc->pvMem);
}
else
{
Assert(pAlloc->pvMem);
Assert(pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);
if (bLocked && !pData->Flags.Discard)
{
RECT r, *pr;
if (pRange)
{
r.top = 0;
r.left = pRange->Offset;
r.bottom = 1;
r.right = pRange->Offset + pRange->Size;
pr = &r;
}
else
pr = NULL;
VBoxD3DIfLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect, pr, false /*bool bToLockInfo*/);
}
}
}
}
else
{
Assert(0);
}
}
else /* if !VBOXDISPMODE_IS_3D(pDevice->pAdapter) */
{
PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
if (pAlloc->hAllocation)
{
if (pRc->RcDesc.enmPool != D3DDDIPOOL_SYSTEMMEM)
{
D3DDDICB_LOCK LockData;
LockData.hAllocation = pAlloc->hAllocation;
LockData.PrivateDriverData = 0;
LockData.NumPages = 0;
LockData.pPages = NULL;
LockData.pData = NULL; /* out */
LockData.Flags.Value = 0;
LockData.Flags.Discard = pData->Flags.Discard;
LockData.Flags.DonotWait = pData->Flags.DoNotWait;
uintptr_t offset;
if (pData->Flags.AreaValid)
{
offset = vboxWddmCalcOffXYrd(pData->Area.left, pData->Area.top, pAlloc->SurfDesc.pitch, pAlloc->SurfDesc.format);
}
else if (pData->Flags.RangeValid)
{
offset = pData->Range.Offset;
}
else if (pData->Flags.BoxValid)
{
vboxVDbgPrintF((__FUNCTION__": Implement Box area"));
Assert(0);
}
else
{
offset = 0;
}
hr = pDevice->RtCallbacks.pfnLockCb(pDevice->hDevice, &LockData);
Assert(hr == S_OK || (hr == D3DERR_WASSTILLDRAWING && pData->Flags.DoNotWait));
if (hr == S_OK)
{
pData->pSurfData = ((uint8_t*)LockData.pData) + offset;
pData->Pitch = pAlloc->SurfDesc.pitch;
pData->SlicePitch = pAlloc->SurfDesc.slicePitch;
if (pData->Flags.Discard)
{
/* check if the surface was renamed */
if (LockData.hAllocation)
pAlloc->hAllocation = LockData.hAllocation;
}
}
}
/* else - d3d may create sysmem render targets and call our Present callbacks for those
* to make it work properly we need to create a VRAM surface corresponding to sysmem one
* and copy stuff to VRAM on lock/unlock
*
* so we don't do any locking here, but still track the lock info here
* and do lock-memcopy-unlock to VRAM surface on sysmem surface unlock
* */
if (hr == S_OK)
{
Assert(!pAlloc->LockInfo.cLocks);
if (!pData->Flags.ReadOnly)
{
if (pData->Flags.AreaValid)
vboxWddmDirtyRegionAddRect(&pAlloc->DirtyRegion, &pData->Area);
else
{
Assert(!pData->Flags.RangeValid);
Assert(!pData->Flags.BoxValid);
vboxWddmDirtyRegionAddRect(&pAlloc->DirtyRegion, NULL); /* <- NULL means the entire surface */
}
}
++pAlloc->LockInfo.cLocks;
}
}
}
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(%d)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevUnlock(HANDLE hDevice, CONST D3DDDIARG_UNLOCK* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hResource;
HRESULT hr = S_OK;
Assert(pData->SubResourceIndex < pRc->cAllocations);
if (pData->SubResourceIndex >= pRc->cAllocations)
return E_INVALIDARG;
if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))
{
if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_TEXTURE
|| pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_CUBE_TEXTURE
|| pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE)
{
Assert(pData->SubResourceIndex < pRc->cAllocations);
PVBOXWDDMDISP_ALLOCATION pLockAlloc = &pRc->aAllocations[pData->SubResourceIndex];
VBOXVDBG_DUMP_UNLOCK_ST(pData);
--pLockAlloc->LockInfo.cLocks;
Assert(pLockAlloc->LockInfo.cLocks < UINT32_MAX);
if (!pLockAlloc->LockInfo.cLocks)
{
PVBOXWDDMDISP_ALLOCATION pTexAlloc = &pRc->aAllocations[0];
Assert(pTexAlloc->pD3DIf);
switch (pRc->aAllocations[0].enmD3DIfType)
{
case VBOXDISP_D3DIFTYPE_TEXTURE:
{
IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pTexAlloc->pD3DIf;
hr = pD3DIfTex->UnlockRect(pData->SubResourceIndex);
break;
}
case VBOXDISP_D3DIFTYPE_CUBE_TEXTURE:
{
IDirect3DCubeTexture9 *pD3DIfCubeTex = (IDirect3DCubeTexture9*)pTexAlloc->pD3DIf;
hr = pD3DIfCubeTex->UnlockRect(VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, pData->SubResourceIndex),
VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, pData->SubResourceIndex));
break;
}
case VBOXDISP_D3DIFTYPE_SURFACE:
{
IDirect3DSurface9 *pD3DIfSurf = (IDirect3DSurface9*)pTexAlloc->pD3DIf;
hr = pD3DIfSurf->UnlockRect();
break;
}
default:
Assert(0);
break;
}
if (FAILED(hr))
WARN(("UnlockRect failed, hr 0x%x", hr));
VBOXVDBG_CHECK_SMSYNC(pRc);
}
}
else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VOLUME_TEXTURE)
{
Assert(pData->SubResourceIndex < pRc->cAllocations);
PVBOXWDDMDISP_ALLOCATION pLockAlloc = &pRc->aAllocations[pData->SubResourceIndex];
VBOXVDBG_DUMP_UNLOCK_ST(pData);
--pLockAlloc->LockInfo.cLocks;
Assert(pLockAlloc->LockInfo.cLocks < UINT32_MAX);
if (!pLockAlloc->LockInfo.cLocks)
{
PVBOXWDDMDISP_ALLOCATION pTexAlloc = &pRc->aAllocations[0];
Assert(pTexAlloc->pD3DIf);
IDirect3DVolumeTexture9 *pD3DIfTex = (IDirect3DVolumeTexture9*)pTexAlloc->pD3DIf;
hr = pD3DIfTex->UnlockBox(pData->SubResourceIndex);
if (FAILED(hr))
WARN(("UnlockBox failed, hr 0x%x", hr));
VBOXVDBG_CHECK_SMSYNC(pRc);
}
}
else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VERTEXBUFFER)
{
Assert(pData->SubResourceIndex < pRc->cAllocations);
PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
--pAlloc->LockInfo.cLocks;
Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);
if (!pAlloc->LockInfo.cLocks
&& (!pAlloc->LockInfo.fFlags.MightDrawFromLocked
|| (!pAlloc->LockInfo.fFlags.Discard && !pAlloc->LockInfo.fFlags.NoOverwrite)))
{
// Assert(!pAlloc->LockInfo.cLocks);
IDirect3DVertexBuffer9 *pD3D9VBuf = (IDirect3DVertexBuffer9*)pAlloc->pD3DIf;
Assert(pD3D9VBuf);
/* this is a sysmem texture, update */
if (pAlloc->pvMem && !pAlloc->LockInfo.fFlags.ReadOnly)
{
RECT r, *pr;
if (pAlloc->LockInfo.fFlags.RangeValid)
{
r.top = 0;
r.left = pAlloc->LockInfo.Range.Offset;
r.bottom = 1;
r.right = pAlloc->LockInfo.Range.Offset + pAlloc->LockInfo.Range.Size;
pr = &r;
}
else
pr = NULL;
VBoxD3DIfLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect,
pr,
true /*bool bToLockInfo*/);
}
hr = pD3D9VBuf->Unlock();
Assert(hr == S_OK);
VBOXVDBG_CHECK_SMSYNC(pRc);
}
else
{
Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);
}
}
else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_INDEXBUFFER)
{
Assert(pData->SubResourceIndex < pRc->cAllocations);
PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
--pAlloc->LockInfo.cLocks;
Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);
if (!pAlloc->LockInfo.cLocks
&& (!pAlloc->LockInfo.fFlags.MightDrawFromLocked
|| (!pAlloc->LockInfo.fFlags.Discard && !pAlloc->LockInfo.fFlags.NoOverwrite)))
{
// Assert(!pAlloc->LockInfo.cLocks);
IDirect3DIndexBuffer9 *pD3D9IBuf = (IDirect3DIndexBuffer9*)pAlloc->pD3DIf;
Assert(pD3D9IBuf);
/* this is a sysmem texture, update */
if (pAlloc->pvMem && !pAlloc->LockInfo.fFlags.ReadOnly)
{
RECT r, *pr;
if (pAlloc->LockInfo.fFlags.RangeValid)
{
r.top = 0;
r.left = pAlloc->LockInfo.Range.Offset;
r.bottom = 1;
r.right = pAlloc->LockInfo.Range.Offset + pAlloc->LockInfo.Range.Size;
pr = &r;
}
else
pr = NULL;
VBoxD3DIfLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect,
pr,
true /*bool bToLockInfo*/);
}
hr = pD3D9IBuf->Unlock();
Assert(hr == S_OK);
VBOXVDBG_CHECK_SMSYNC(pRc);
}
else
{
Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);
}
}
else
{
Assert(0);
}
}
else
{
PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
if (pAlloc->hAllocation)
{
BOOL fDoUnlock = FALSE;
Assert(pAlloc->LockInfo.cLocks);
--pAlloc->LockInfo.cLocks;
Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);
if (pRc->RcDesc.enmPool != D3DDDIPOOL_SYSTEMMEM)
{
fDoUnlock = TRUE;
}
else
{
if (!pAlloc->LockInfo.cLocks)
{
D3DDDICB_LOCK LockData;
LockData.hAllocation = pAlloc->hAllocation;
LockData.PrivateDriverData = 0;
LockData.NumPages = 0;
LockData.pPages = NULL;
LockData.pData = NULL; /* out */
LockData.Flags.Value = 0;
hr = pDevice->RtCallbacks.pfnLockCb(pDevice->hDevice, &LockData);
if (hr == S_OK)
{
D3DLOCKED_RECT LRect;
LRect.pBits = LockData.pData;
LRect.Pitch = ((pAlloc->SurfDesc.bpp * pAlloc->SurfDesc.width) + 7) >> 3;
Assert(pAlloc->DirtyRegion.fFlags & VBOXWDDM_DIRTYREGION_F_VALID);
VBoxD3DIfLockUnlockMemSynch(pAlloc, &LRect, &pAlloc->DirtyRegion.Rect, TRUE /* bool bToLockInfo*/);
vboxWddmDirtyRegionClear(&pAlloc->DirtyRegion);
fDoUnlock = TRUE;
}
else
{
WARN(("pfnLockCb failed, hr 0x%x", hr));
}
}
}
if (fDoUnlock)
{
struct
{
D3DDDICB_UNLOCK Unlock;
D3DKMT_HANDLE hAllocation;
} UnlockData;
UnlockData.Unlock.NumAllocations = 1;
UnlockData.Unlock.phAllocations = &UnlockData.hAllocation;
UnlockData.hAllocation = pAlloc->hAllocation;
hr = pDevice->RtCallbacks.pfnUnlockCb(pDevice->hDevice, &UnlockData.Unlock);
if(hr != S_OK)
{
WARN(("pfnUnlockCb failed, hr 0x%x", hr));
}
}
if (!SUCCEEDED(hr))
{
WARN(("unlock failure!"));
++pAlloc->LockInfo.cLocks;
}
}
}
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevLockAsync(HANDLE hDevice, D3DDDIARG_LOCKASYNC* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevUnlockAsync(HANDLE hDevice, CONST D3DDDIARG_UNLOCKASYNC* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevRename(HANDLE hDevice, CONST D3DDDIARG_RENAME* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static void vboxWddmRequestAllocFree(D3DDDICB_ALLOCATE* pAlloc)
{
RTMemFree(pAlloc);
}
static D3DDDICB_ALLOCATE* vboxWddmRequestAllocAlloc(D3DDDIARG_CREATERESOURCE* pResource)
{
/* allocate buffer for D3DDDICB_ALLOCATE + D3DDDI_ALLOCATIONINFO * numAllocs + PVBOXWDDM_RCINFO with aAllocInfos[numAllocs] */
uint32_t cbBuf = sizeof (D3DDDICB_ALLOCATE);
uint32_t offDdiAllocInfos = (cbBuf + 7) & ~3;
uint32_t cbDdiAllocInfos = sizeof (D3DDDI_ALLOCATIONINFO) * pResource->SurfCount;
cbBuf = offDdiAllocInfos + cbDdiAllocInfos;
uint32_t offRcInfo = (cbBuf + 7) & ~3;
uint32_t cbRcInfo = sizeof (VBOXWDDM_RCINFO);
cbBuf = offRcInfo + cbRcInfo;
uint32_t offAllocInfos = (cbBuf + 7) & ~3;
uint32_t cbAllocInfos = sizeof (VBOXWDDM_ALLOCINFO) * pResource->SurfCount;
cbBuf = offAllocInfos + cbAllocInfos;
uint8_t *pvBuf = (uint8_t*)RTMemAllocZ(cbBuf);
Assert(pvBuf);
if (pvBuf)
{
D3DDDICB_ALLOCATE* pAlloc = (D3DDDICB_ALLOCATE*)pvBuf;
pAlloc->NumAllocations = pResource->SurfCount;
pAlloc->pAllocationInfo = (D3DDDI_ALLOCATIONINFO*)(pvBuf + offDdiAllocInfos);
PVBOXWDDM_RCINFO pRcInfo = (PVBOXWDDM_RCINFO)(pvBuf + offRcInfo);
pAlloc->PrivateDriverDataSize = cbRcInfo;
pAlloc->pPrivateDriverData = pRcInfo;
pAlloc->hResource = pResource->hResource;
PVBOXWDDM_ALLOCINFO pAllocInfos = (PVBOXWDDM_ALLOCINFO)(pvBuf + offAllocInfos);
for (UINT i = 0; i < pResource->SurfCount; ++i)
{
D3DDDI_ALLOCATIONINFO* pDdiAllocInfo = &pAlloc->pAllocationInfo[i];
PVBOXWDDM_ALLOCINFO pAllocInfo = &pAllocInfos[i];
pDdiAllocInfo->pPrivateDriverData = pAllocInfo;
pDdiAllocInfo->PrivateDriverDataSize = sizeof (VBOXWDDM_ALLOCINFO);
}
return pAlloc;
}
return NULL;
}
static HRESULT APIENTRY vboxWddmDDevCreateResource(HANDLE hDevice, D3DDDIARG_CREATERESOURCE* pResource)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
HRESULT hr = S_OK;
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(pResource);
PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter;
PVBOXWDDMDISP_RESOURCE pRc = vboxResourceAlloc(pResource->SurfCount);
if (!pRc)
{
WARN(("vboxResourceAlloc failed"));
return E_OUTOFMEMORY;
}
bool bIssueCreateResource = false;
bool bCreateKMResource = false;
pRc->hResource = pResource->hResource;
pRc->hKMResource = NULL;
pRc->pDevice = pDevice;
pRc->fFlags.Value = 0;
pRc->fFlags.Generic = 1;
pRc->RcDesc.fFlags = pResource->Flags;
pRc->RcDesc.enmFormat = pResource->Format;
pRc->RcDesc.enmPool = pResource->Pool;
pRc->RcDesc.enmMultisampleType = pResource->MultisampleType;
pRc->RcDesc.MultisampleQuality = pResource->MultisampleQuality;
pRc->RcDesc.MipLevels = pResource->MipLevels;
pRc->RcDesc.Fvf = pResource->Fvf;
pRc->RcDesc.VidPnSourceId = pResource->VidPnSourceId;
pRc->RcDesc.RefreshRate = pResource->RefreshRate;
pRc->RcDesc.enmRotation = pResource->Rotation;
pRc->cAllocations = pResource->SurfCount;
for (UINT i = 0; i < pResource->SurfCount; ++i)
{
PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
pAllocation->hAllocation = NULL;
pAllocation->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC;
pAllocation->iAlloc = i;
pAllocation->pRc = pRc;
pAllocation->SurfDesc.d3dWidth = pSurf->Width;
pAllocation->pvMem = (void*)pSurf->pSysMem;
pAllocation->SurfDesc.slicePitch = pSurf->SysMemSlicePitch;
pAllocation->SurfDesc.depth = pSurf->Depth;
pAllocation->SurfDesc.width = pSurf->Width;
pAllocation->SurfDesc.height = pSurf->Height;
pAllocation->SurfDesc.format = pResource->Format;
if (!vboxWddmFormatToFourcc(pResource->Format))
pAllocation->SurfDesc.bpp = vboxWddmCalcBitsPerPixel(pResource->Format);
else
pAllocation->SurfDesc.bpp = 0;
if (pSurf->SysMemPitch)
pAllocation->SurfDesc.pitch = pSurf->SysMemPitch;
else
pAllocation->SurfDesc.pitch = vboxWddmCalcPitch(pSurf->Width, pResource->Format);
pAllocation->SurfDesc.cbSize = vboxWddmCalcSize(pAllocation->SurfDesc.pitch, pAllocation->SurfDesc.height, pAllocation->SurfDesc.format);
pAllocation->SurfDesc.VidPnSourceId = pResource->VidPnSourceId;
if (pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM)
{
Assert(pAllocation->pvMem);
Assert(pAllocation->SurfDesc.pitch);
UINT minPitch = vboxWddmCalcPitch(pAllocation->SurfDesc.width, pAllocation->SurfDesc.format);
Assert(minPitch);
if (minPitch)
{
if (pAllocation->SurfDesc.pitch != minPitch)
{
Assert(pAllocation->SurfDesc.pitch > minPitch);
pAllocation->SurfDesc.d3dWidth = vboxWddmCalcWidthForPitch(pAllocation->SurfDesc.pitch, pAllocation->SurfDesc.format);
Assert(VBOXWDDMDISP_IS_TEXTURE(pRc->RcDesc.fFlags) && !pRc->RcDesc.fFlags.CubeMap); /* <- tested for textures only! */
}
Assert(pAllocation->SurfDesc.d3dWidth >= pAllocation->SurfDesc.width);
}
else
{
Assert(pAllocation->SurfDesc.d3dWidth == pAllocation->SurfDesc.width);
}
}
}
if (VBOXDISPMODE_IS_3D(pAdapter))
{
if (pRc->RcDesc.fFlags.SharedResource)
{
bIssueCreateResource = true;
bCreateKMResource = true;
}
if (pRc->RcDesc.fFlags.RenderTarget)
{
bIssueCreateResource = true;
}
hr = VBoxD3DIfCreateForRc(pRc);
if (!SUCCEEDED(hr))
{
WARN(("VBoxD3DIfCreateForRc failed, hr 0x%x", hr));
}
}
else
{
bIssueCreateResource = (pResource->Pool != D3DDDIPOOL_SYSTEMMEM) || pResource->Flags.RenderTarget;
bCreateKMResource = bIssueCreateResource;
}
if (SUCCEEDED(hr) && bIssueCreateResource)
{
pRc->fFlags.KmResource = bCreateKMResource;
D3DDDICB_ALLOCATE *pDdiAllocate = vboxWddmRequestAllocAlloc(pResource);
Assert(pDdiAllocate);
if (pDdiAllocate)
{
Assert(pDdiAllocate->pPrivateDriverData);
Assert(pDdiAllocate->PrivateDriverDataSize == sizeof (VBOXWDDM_RCINFO));
PVBOXWDDM_RCINFO pRcInfo = (PVBOXWDDM_RCINFO)pDdiAllocate->pPrivateDriverData;
pRcInfo->fFlags = pRc->fFlags;
pRcInfo->RcDesc = pRc->RcDesc;
pRcInfo->cAllocInfos = pResource->SurfCount;
for (UINT i = 0; i < pResource->SurfCount; ++i)
{
D3DDDI_ALLOCATIONINFO *pDdiAllocI = &pDdiAllocate->pAllocationInfo[i];
PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
Assert(pDdiAllocI->pPrivateDriverData);
Assert(pDdiAllocI->PrivateDriverDataSize == sizeof (VBOXWDDM_ALLOCINFO));
PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pDdiAllocI->pPrivateDriverData;
CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
pDdiAllocI->hAllocation = NULL;
pDdiAllocI->pSystemMem = pSurf->pSysMem;
Assert((!!(pSurf->pSysMem)) == (pResource->Pool == D3DDDIPOOL_SYSTEMMEM));
pDdiAllocI->VidPnSourceId = pResource->VidPnSourceId;
pDdiAllocI->Flags.Value = 0;
if (pResource->Flags.Primary)
{
Assert(pResource->Flags.RenderTarget);
pDdiAllocI->Flags.Primary = 1;
}
pAllocInfo->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC;
pAllocInfo->fFlags = pResource->Flags;
pAllocInfo->hSharedHandle = (uint64_t)pAllocation->hSharedHandle;
pAllocInfo->SurfDesc = pAllocation->SurfDesc;
}
Assert(!pRc->fFlags.Opened);
// Assert(!pRc->fFlags.KmResource);
Assert(pRc->fFlags.Generic);
if (bCreateKMResource)
{
Assert(pRc->fFlags.KmResource);
hr = pDevice->RtCallbacks.pfnAllocateCb(pDevice->hDevice, pDdiAllocate);
Assert(hr == S_OK);
Assert(pDdiAllocate->hKMResource
|| pResource->Flags.SharedResource /* for some reason shared resources
* are created with zero km resource handle on Win7+ */
);
}
else
{
Assert(!pRc->fFlags.KmResource);
pDdiAllocate->hResource = NULL;
pDdiAllocate->NumAllocations = 1;
pDdiAllocate->PrivateDriverDataSize = 0;
pDdiAllocate->pPrivateDriverData = NULL;
D3DDDI_ALLOCATIONINFO *pDdiAllocIBase = pDdiAllocate->pAllocationInfo;
for (UINT i = 0; i < pResource->SurfCount; ++i)
{
pDdiAllocate->pAllocationInfo = &pDdiAllocIBase[i];
hr = pDevice->RtCallbacks.pfnAllocateCb(pDevice->hDevice, pDdiAllocate);
Assert(hr == S_OK);
Assert(!pDdiAllocate->hKMResource);
if (SUCCEEDED(hr))
{
Assert(pDdiAllocate->pAllocationInfo->hAllocation);
}
else
{
for (UINT j = 0; i < j; ++j)
{
D3DDDI_ALLOCATIONINFO * pCur = &pDdiAllocIBase[i];
D3DDDICB_DEALLOCATE Dealloc;
Dealloc.hResource = 0;
Dealloc.NumAllocations = 1;
Dealloc.HandleList = &pCur->hAllocation;
HRESULT tmpHr = pDevice->RtCallbacks.pfnDeallocateCb(pDevice->hDevice, &Dealloc);
Assert(tmpHr == S_OK);
}
break;
}
}
pDdiAllocate->pAllocationInfo = pDdiAllocIBase;
}
if (SUCCEEDED(hr))
{
pRc->hKMResource = pDdiAllocate->hKMResource;
for (UINT i = 0; i < pResource->SurfCount; ++i)
{
PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
D3DDDI_ALLOCATIONINFO *pDdiAllocI = &pDdiAllocate->pAllocationInfo[i];
PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pDdiAllocI->pPrivateDriverData;
CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
pAllocation->hAllocation = pDdiAllocI->hAllocation;
pAllocation->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC;
pAllocation->pvMem = (void*)pSurf->pSysMem;
pAllocation->SurfDesc = pAllocInfo->SurfDesc;
if (pResource->Flags.SharedResource)
{
#ifdef VBOXWDDMDISP_DEBUG_PRINT_SHARED_CREATE
Assert(VBOXWDDMDISP_IS_TEXTURE(pResource->Flags));
vboxVDbgPrint(("\n\n********\n(0x%x:0n%d)Shared CREATED pAlloc(0x%p), hRc(0x%p), hAl(0x%p), "
"Handle(0x%x), (0n%d) \n***********\n\n",
GetCurrentProcessId(), GetCurrentProcessId(),
pAllocation, pRc->hKMResource, pAllocation->hAllocation,
pAllocation->hSharedHandle, pAllocation->hSharedHandle
));
#endif
}
}
VBOXVDBG_CREATE_CHECK_SWAPCHAIN();
}
vboxWddmRequestAllocFree(pDdiAllocate);
}
else
{
hr = E_OUTOFMEMORY;
}
}
VBOXVDBG_BREAK_SHARED(pRc);
if (SUCCEEDED(hr))
{
pResource->hResource = pRc;
hr = S_OK;
}
else
vboxResourceFree(pRc);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevDestroyResource(HANDLE hDevice, HANDLE hResource)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter;
PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)hResource;
HRESULT hr = S_OK;
Assert(pDevice);
Assert(hResource);
if (VBOXDISPMODE_IS_3D(pAdapter))
{
for (UINT i = 0; i < pRc->cAllocations; ++i)
{
PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[i];
if (pAlloc->hSharedHandle)
{
#ifdef VBOXWDDMDISP_DEBUG_PRINT_SHARED_CREATE
vboxVDbgPrint(("\n\n********\n(0x%x:0n%d)Shared DESTROYED pAlloc(0x%p), hRc(0x%p), hAl(0x%p), "
"Handle(0x%x), (0n%d) \n***********\n\n",
GetCurrentProcessId(), GetCurrentProcessId(),
pAlloc, pRc->hKMResource, pAlloc->hAllocation,
pAlloc->hSharedHandle, pAlloc->hSharedHandle
));
#endif
}
if (pAlloc->pD3DIf)
pAlloc->pD3DIf->Release();
PVBOXWDDMDISP_SWAPCHAIN pSwapchain = vboxWddmSwapchainForAlloc(pAlloc);
if (pSwapchain)
{
PVBOXWDDMDISP_RENDERTGT pRt = vboxWddmSwapchainRtForAlloc(pSwapchain, pAlloc);
vboxWddmSwapchainRtRemove(pSwapchain, pRt);
Assert(!vboxWddmSwapchainForAlloc(pAlloc));
if (!vboxWddmSwapchainNumRTs(pSwapchain))
vboxWddmSwapchainDestroy(pDevice, pSwapchain);
}
vboxWddmDalCheckRemove(pDevice, pAlloc);
}
}
if (pRc->fFlags.KmResource)
{
D3DDDICB_DEALLOCATE Dealloc;
Assert(pRc->hResource);
Dealloc.hResource = pRc->hResource;
/* according to the docs the below two are ignored in case we set the hResource */
Dealloc.NumAllocations = 0;
Dealloc.HandleList = NULL;
hr = pDevice->RtCallbacks.pfnDeallocateCb(pDevice->hDevice, &Dealloc);
Assert(hr == S_OK);
}
else
{
Assert(!(pRc->fFlags.Opened));
for (UINT j = 0; j < pRc->cAllocations; ++j)
{
if (pRc->aAllocations[j].hAllocation)
{
D3DDDICB_DEALLOCATE Dealloc;
Dealloc.hResource = NULL;
Dealloc.NumAllocations = 1;
Dealloc.HandleList = &pRc->aAllocations[j].hAllocation;
HRESULT tmpHr = pDevice->RtCallbacks.pfnDeallocateCb(pDevice->hDevice, &Dealloc);
Assert(tmpHr == S_OK);
}
}
}
vboxResourceFree(pRc);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevSetDisplayMode(HANDLE hDevice, CONST D3DDDIARG_SETDISPLAYMODE* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
HRESULT hr = S_OK;
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(VBOXDISPMODE_IS_3D(pDevice->pAdapter));
PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hResource;
Assert(pRc);
Assert(pRc->cAllocations > pData->SubResourceIndex);
PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
Assert(pRc->RcDesc.fFlags.RenderTarget);
Assert(pRc->RcDesc.fFlags.Primary);
Assert(pAlloc->hAllocation);
D3DDDICB_SETDISPLAYMODE DdiDm = {0};
DdiDm.hPrimaryAllocation = pAlloc->hAllocation;
{
hr = pDevice->RtCallbacks.pfnSetDisplayModeCb(pDevice->hDevice, &DdiDm);
Assert(hr == S_OK);
}
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return hr;
}
#ifdef VBOXWDDM_TEST_UHGSMI
int vboxUhgsmiTst(PVBOXUHGSMI pUhgsmi, uint32_t cbBuf, uint32_t cNumCals, uint64_t * pTimeMs);
#endif
static HRESULT APIENTRY vboxWddmDDevPresent(HANDLE hDevice, CONST D3DDDIARG_PRESENT* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
// VBOXDISPPROFILE_DDI_CHKDUMPRESET(pDevice);
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
HRESULT hr = S_OK;
if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))
{
#ifdef VBOXWDDM_TEST_UHGSMI
{
static uint32_t cCals = 100000;
static uint32_t cbData = 8 * 1024 * 1024;
uint64_t TimeMs;
int rc = vboxUhgsmiTst(&pDevice->Uhgsmi.Base, cbData, cCals, &TimeMs);
uint32_t cCPS = (((uint64_t)cCals) * 1000ULL)/TimeMs;
}
#endif
PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource;
Assert(pRc);
Assert(pRc->cAllocations > pData->SrcSubResourceIndex);
PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SrcSubResourceIndex];
hr = vboxWddmSwapchainPresent(pDevice, pAlloc);
Assert(hr == S_OK);
}
{
D3DDDICB_PRESENT DdiPresent = {0};
if (pData->hSrcResource)
{
PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource;
Assert(pRc->cAllocations > pData->SrcSubResourceIndex);
PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SrcSubResourceIndex];
Assert(pAlloc->hAllocation);
DdiPresent.hSrcAllocation = pAlloc->hAllocation;
}
if (pData->hDstResource)
{
PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hDstResource;
Assert(pRc->cAllocations > pData->DstSubResourceIndex);
PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->DstSubResourceIndex];
Assert(pAlloc->hAllocation);
DdiPresent.hDstAllocation = pAlloc->hAllocation;
}
DdiPresent.hContext = pDevice->DefaultContext.ContextInfo.hContext;
#if 0 //def VBOX_WDDMDISP_WITH_PROFILE
VBoxDispProfileScopeLogger<VBoxDispProfileEntry> profilePresentCbLogger(pDevice->ProfileDdiPresentCb.alloc("pfnPresentCb"));
#endif
#ifdef VBOXWDDMDISP_DEBUG_TIMER
HANDLE hTimer = NULL;
vboxVDbgTimerStart(pDevice->hTimerQueue, &hTimer, 1000);
#endif
hr = pDevice->RtCallbacks.pfnPresentCb(pDevice->hDevice, &DdiPresent);
#ifdef VBOXWDDMDISP_DEBUG_TIMER
vboxVDbgTimerStop(pDevice->hTimerQueue, hTimer);
#endif
#if 0 //def VBOX_WDDMDISP_WITH_PROFILE
profilePresentCbLogger.logAndDisable();
if (pDevice->ProfileDdiPresentCb.getNumEntries() == 64)
{
pDevice->ProfileDdiPresentCb.dump(pDevice);
pDevice->ProfileDdiPresentCb.reset();
}
#endif
Assert(hr == S_OK);
}
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
VBOXDISPPROFILE_DDI_REPORT_FRAME(pDevice);
return hr;
}
static HRESULT APIENTRY vboxWddmDDevFlush(HANDLE hDevice)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
HRESULT hr = S_OK;
if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))
{
hr = pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9Flush((IDirect3DDevice9Ex*)pDevice->pDevice9If);
Assert(hr == S_OK);
vboxWddmDalNotifyChange(pDevice);
VBOXVDBG_DUMP_FLUSH(pDevice);
}
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
VBOXDISPPROFILE_DDI_REPORT_FLUSH(pDevice);
return hr;
}
AssertCompile(sizeof (D3DDDIVERTEXELEMENT) == sizeof (D3DVERTEXELEMENT9));
AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Stream) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Stream));
AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Offset) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Offset));
AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Type) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Type));
AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Method) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Method));
AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Usage) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Usage));
AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, UsageIndex) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, UsageIndex));
AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Stream) == RT_OFFSETOF(D3DVERTEXELEMENT9, Stream));
AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Offset) == RT_OFFSETOF(D3DVERTEXELEMENT9, Offset));
AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Type) == RT_OFFSETOF(D3DVERTEXELEMENT9, Type));
AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Method) == RT_OFFSETOF(D3DVERTEXELEMENT9, Method));
AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Usage) == RT_OFFSETOF(D3DVERTEXELEMENT9, Usage));
AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, UsageIndex) == RT_OFFSETOF(D3DVERTEXELEMENT9, UsageIndex));
static HRESULT APIENTRY vboxWddmDDevCreateVertexShaderDecl(HANDLE hDevice, D3DDDIARG_CREATEVERTEXSHADERDECL* pData, CONST D3DDDIVERTEXELEMENT* pVertexElements)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
IDirect3DVertexDeclaration9 *pDecl;
static D3DVERTEXELEMENT9 DeclEnd = D3DDECL_END();
D3DVERTEXELEMENT9* pVe;
HRESULT hr = S_OK;
bool bFreeVe = false;
if(memcmp(&DeclEnd, &pVertexElements[pData->NumVertexElements], sizeof (DeclEnd)))
{
pVe = (D3DVERTEXELEMENT9*)RTMemAlloc(sizeof (D3DVERTEXELEMENT9) * (pData->NumVertexElements + 1));
if (pVe)
{
memcpy(pVe, pVertexElements, sizeof (D3DVERTEXELEMENT9) * pData->NumVertexElements);
pVe[pData->NumVertexElements] = DeclEnd;
bFreeVe = true;
}
else
hr = E_OUTOFMEMORY;
}
else
pVe = (D3DVERTEXELEMENT9*)pVertexElements;
if (hr == S_OK)
{
hr = pDevice9If->CreateVertexDeclaration(
pVe,
&pDecl
);
Assert(hr == S_OK);
if (hr == S_OK)
{
Assert(pDecl);
pData->ShaderHandle = pDecl;
}
}
if (bFreeVe)
RTMemFree((void*)pVe);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevSetVertexShaderDecl(HANDLE hDevice, HANDLE hShaderHandle)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
IDirect3DVertexDeclaration9 *pDecl = (IDirect3DVertexDeclaration9*)hShaderHandle;
Assert(pDecl);
HRESULT hr = pDevice9If->SetVertexDeclaration(pDecl);
Assert(hr == S_OK);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevDeleteVertexShaderDecl(HANDLE hDevice, HANDLE hShaderHandle)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DVertexDeclaration9 *pDecl = (IDirect3DVertexDeclaration9*)hShaderHandle;
HRESULT hr = S_OK;
pDecl->Release();
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevCreateVertexShaderFunc(HANDLE hDevice, D3DDDIARG_CREATEVERTEXSHADERFUNC* pData, CONST UINT* pCode)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
IDirect3DVertexShader9 *pShader;
Assert(*((UINT*)((uint8_t*)pCode + pData->Size-4)) == 0x0000FFFF /* end token */);
HRESULT hr = pDevice9If->CreateVertexShader((const DWORD *)pCode, &pShader);
Assert(hr == S_OK);
if (hr == S_OK)
{
Assert(pShader);
pData->ShaderHandle = pShader;
}
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevSetVertexShaderFunc(HANDLE hDevice, HANDLE hShaderHandle)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
IDirect3DVertexShader9 *pShader = (IDirect3DVertexShader9*)hShaderHandle;
HRESULT hr = pDevice9If->SetVertexShader(pShader);
Assert(hr == S_OK);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevDeleteVertexShaderFunc(HANDLE hDevice, HANDLE hShaderHandle)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DVertexShader9 *pShader = (IDirect3DVertexShader9*)hShaderHandle;
HRESULT hr = S_OK;
pShader->Release();
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevSetVertexShaderConstI(HANDLE hDevice, CONST D3DDDIARG_SETVERTEXSHADERCONSTI* pData, CONST INT* pRegisters)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
HRESULT hr = pDevice9If->SetVertexShaderConstantI(pData->Register, pRegisters, pData->Count);
Assert(hr == S_OK);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevSetVertexShaderConstB(HANDLE hDevice, CONST D3DDDIARG_SETVERTEXSHADERCONSTB* pData, CONST BOOL* pRegisters)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
HRESULT hr = pDevice9If->SetVertexShaderConstantB(pData->Register, pRegisters, pData->Count);
Assert(hr == S_OK);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevSetScissorRect(HANDLE hDevice, CONST RECT* pRect)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
HRESULT hr = pDevice9If->SetScissorRect(pRect);
Assert(hr == S_OK);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevSetStreamSource(HANDLE hDevice, CONST D3DDDIARG_SETSTREAMSOURCE* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hVertexBuffer;
PVBOXWDDMDISP_ALLOCATION pAlloc = NULL;
IDirect3DVertexBuffer9 *pStreamData = NULL;
if (pRc)
{
VBOXVDBG_CHECK_SMSYNC(pRc);
Assert(pRc->cAllocations == 1);
pAlloc = &pRc->aAllocations[0];
Assert(pAlloc->pD3DIf);
pStreamData = (IDirect3DVertexBuffer9*)pAlloc->pD3DIf;
}
HRESULT hr = pDevice9If->SetStreamSource(pData->Stream, pStreamData, pData->Offset, pData->Stride);
Assert(hr == S_OK);
Assert(pData->Stream<VBOXWDDMDISP_MAX_VERTEX_STREAMS);
if (hr == S_OK)
{
if (pDevice->aStreamSource[pData->Stream] && !pAlloc)
{
--pDevice->cStreamSources;
Assert(pDevice->cStreamSources < UINT32_MAX/2);
}
else if (!pDevice->aStreamSource[pData->Stream] && pAlloc)
{
++pDevice->cStreamSources;
Assert(pDevice->cStreamSources <= RT_ELEMENTS(pDevice->aStreamSource));
}
pDevice->aStreamSource[pData->Stream] = pAlloc;
pDevice->StreamSourceInfo[pData->Stream].uiOffset = pData->Offset;
pDevice->StreamSourceInfo[pData->Stream].uiStride = pData->Stride;
PVBOXWDDMDISP_STREAMSOURCEUM pStrSrcUm = &pDevice->aStreamSourceUm[pData->Stream];
if (pStrSrcUm->pvBuffer)
{
--pDevice->cStreamSourcesUm;
Assert(pDevice->cStreamSourcesUm < UINT32_MAX/2);
pStrSrcUm->pvBuffer = NULL;
pStrSrcUm->cbStride = 0;
}
}
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevSetStreamSourceFreq(HANDLE hDevice, CONST D3DDDIARG_SETSTREAMSOURCEFREQ* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevSetConvolutionKernelMono(HANDLE hDevice, CONST D3DDDIARG_SETCONVOLUTIONKERNELMONO* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevComposeRects(HANDLE hDevice, CONST D3DDDIARG_COMPOSERECTS* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevBlt(HANDLE hDevice, CONST D3DDDIARG_BLT* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
// PVBOXWDDMDISP_SCREEN pScreen = &pDevice->aScreens[pDevice->iPrimaryScreen];
IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
PVBOXWDDMDISP_RESOURCE pDstRc = (PVBOXWDDMDISP_RESOURCE)pData->hDstResource;
PVBOXWDDMDISP_RESOURCE pSrcRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource;
VBOXVDBG_CHECK_SMSYNC(pDstRc);
VBOXVDBG_CHECK_SMSYNC(pSrcRc);
Assert(pDstRc->cAllocations > pData->DstSubResourceIndex);
Assert(pSrcRc->cAllocations > pData->SrcSubResourceIndex);
HRESULT hr = S_OK;
PVBOXWDDMDISP_ALLOCATION pSrcAlloc = &pSrcRc->aAllocations[pData->SrcSubResourceIndex];
PVBOXWDDMDISP_ALLOCATION pDstAlloc = &pDstRc->aAllocations[pData->DstSubResourceIndex];
PVBOXWDDMDISP_SWAPCHAIN pSrcSwapchain = vboxWddmSwapchainForAlloc(pSrcAlloc);
PVBOXWDDMDISP_SWAPCHAIN pDstSwapchain = vboxWddmSwapchainForAlloc(pDstAlloc);
/* try StretchRect */
IDirect3DSurface9 *pSrcSurfIf = NULL;
IDirect3DSurface9 *pDstSurfIf = NULL;
Assert(!pDstSwapchain || vboxWddmSwapchainGetFb(pDstSwapchain)->pAlloc != pDstAlloc || vboxWddmSwapchainNumRTs(pDstSwapchain) == 1);
VBOXVDBG_BREAK_SHARED(pSrcRc);
VBOXVDBG_BREAK_SHARED(pDstRc);
hr = VBoxD3DIfSurfGet(pDstRc, pData->DstSubResourceIndex, &pDstSurfIf);
Assert(hr == S_OK);
if (hr == S_OK)
{
Assert(pDstSurfIf);
do
{
if (pSrcSwapchain)
{
hr = vboxWddmSwapchainSurfGet(pDevice, pSrcSwapchain, pSrcAlloc, &pSrcSurfIf);
Assert(hr == S_OK);
}
else
{
hr = VBoxD3DIfSurfGet(pSrcRc, pData->SrcSubResourceIndex, &pSrcSurfIf);
Assert(hr == S_OK);
}
if (hr == S_OK)
{
Assert(pSrcSurfIf);
VBOXVDBG_BREAK_SHARED(pSrcRc);
VBOXVDBG_BREAK_SHARED(pDstRc);
/* we support only Point & Linear, we ignore [Begin|Continue|End]PresentToDwm */
Assert((pData->Flags.Value & (~(0x00000100 | 0x00000200 | 0x00000400 | 0x00000001 | 0x00000002))) == 0);
VBOXVDBG_CHECK_BLT(hr = pDevice9If->StretchRect(pSrcSurfIf, &pData->SrcRect, pDstSurfIf, &pData->DstRect, vboxDDI2D3DBltFlags(pData->Flags)); Assert(hr == S_OK),
pSrcAlloc, pSrcSurfIf, &pData->SrcRect, pDstAlloc, pDstSurfIf, &pData->DstRect);
pSrcSurfIf->Release();
}
} while (0);
pDstSurfIf->Release();
}
if (hr != S_OK)
{
/* todo: fallback to memcpy or whatever ? */
Assert(0);
}
PVBOXWDDMDISP_ALLOCATION pDAlloc = &pDstRc->aAllocations[pData->DstSubResourceIndex];
vboxWddmDalCheckAdd(pDevice, pDAlloc, TRUE);
pDAlloc = &pSrcRc->aAllocations[pData->SrcSubResourceIndex];
vboxWddmDalCheckAdd(pDevice, pDAlloc, FALSE);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevColorFill(HANDLE hDevice, CONST D3DDDIARG_COLORFILL* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hResource;
Assert(pRc);
IDirect3DSurface9 *pSurfIf = NULL;
HRESULT hr = VBoxD3DIfSurfGet(pRc, pData->SubResourceIndex, &pSurfIf);
Assert(hr == S_OK);
if (hr == S_OK)
{
VBOXVDBG_CHECK_SMSYNC(pRc);
Assert(pSurfIf);
hr = pDevice9If->ColorFill(pSurfIf, &pData->DstRect, pData->Color);
Assert(hr == S_OK);
/* @todo: check what need to do when PresentToDwm flag is set */
Assert(pData->Flags.Value == 0);
pSurfIf->Release();
PVBOXWDDMDISP_ALLOCATION pDAlloc = &pRc->aAllocations[pData->SubResourceIndex];
vboxWddmDalCheckAdd(pDevice, pDAlloc, TRUE);
}
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevDepthFill(HANDLE hDevice, CONST D3DDDIARG_DEPTHFILL* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
//@todo: vboxWddmDalCheckAdd(pDevice, pDAlloc, TRUE);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevCreateQuery(HANDLE hDevice, D3DDDIARG_CREATEQUERY* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
HRESULT hr = S_OK;
PVBOXWDDMDISP_QUERY pQuery = (PVBOXWDDMDISP_QUERY)RTMemAllocZ(sizeof (VBOXWDDMDISP_QUERY));
if (!pQuery)
{
WARN(("RTMemAllocZ failed"));
return E_OUTOFMEMORY;
}
hr = pDevice9If->CreateQuery(vboxDDI2D3DQueryType(pData->QueryType), &pQuery->pQueryIf);
if (FAILED(hr))
{
WARN(("CreateQuery failed, hr 0x%x", hr));
RTMemFree(pQuery);
return hr;
}
Assert(hr == S_OK);
pQuery->enmType = pData->QueryType;
pData->hQuery = pQuery;
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevDestroyQuery(HANDLE hDevice, HANDLE hQuery)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
HRESULT hr = S_OK;
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
PVBOXWDDMDISP_QUERY pQuery = (PVBOXWDDMDISP_QUERY)hQuery;
Assert(pQuery);
pQuery->pQueryIf->Release();
RTMemFree(pQuery);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevIssueQuery(HANDLE hDevice, CONST D3DDDIARG_ISSUEQUERY* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
HRESULT hr = S_OK;
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
PVBOXWDDMDISP_QUERY pQuery = (PVBOXWDDMDISP_QUERY)pData->hQuery;
Assert(pQuery);
pQuery->fQueryState.Value |= pData->Flags.Value;
hr = pQuery->pQueryIf->Issue(vboxDDI2D3DIssueQueryFlags(pData->Flags));
if (hr != S_OK)
WARN(("Issue failed, hr = 0x%x", hr));
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevGetQueryData(HANDLE hDevice, CONST D3DDDIARG_GETQUERYDATA* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
HRESULT hr = S_OK;
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
PVBOXWDDMDISP_QUERY pQuery = (PVBOXWDDMDISP_QUERY)pData->hQuery;
Assert(pQuery);
DWORD cbData = pQuery->pQueryIf->GetDataSize();
#ifdef DEBUG
switch (pQuery->enmType)
{
case D3DDDIQUERYTYPE_EVENT:
Assert(cbData == sizeof (BOOL));
break;
default:
Assert(0);
break;
}
#endif
hr = pQuery->pQueryIf->GetData(pData->pData, cbData, 0);
if (hr != S_OK)
WARN(("GetData failed, hr = 0x%x", hr));
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevSetRenderTarget(HANDLE hDevice, CONST D3DDDIARG_SETRENDERTARGET* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hRenderTarget;
VBOXVDBG_CHECK_SMSYNC(pRc);
Assert(pRc);
Assert(pData->SubResourceIndex < pRc->cAllocations);
PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
HRESULT hr = vboxWddmRenderTargetSet(pDevice, pData->RenderTargetIndex, pAlloc, FALSE);
Assert(hr == S_OK);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevSetDepthStencil(HANDLE hDevice, CONST D3DDDIARG_SETDEPTHSTENCIL* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hZBuffer;
IDirect3DSurface9 *pD3D9Surf = NULL;
HRESULT hr = S_OK;
if (pRc)
{
VBOXVDBG_CHECK_SMSYNC(pRc);
Assert(pRc->cAllocations == 1);
hr = VBoxD3DIfSurfGet(pRc, 0, &pD3D9Surf);
if (FAILED(hr))
WARN(("VBoxD3DIfSurfGet failed, hr (0x%x)",hr));
else
Assert(pD3D9Surf);
}
if (SUCCEEDED(hr))
{
hr = pDevice9If->SetDepthStencilSurface(pD3D9Surf);
if (SUCCEEDED(hr))
hr = S_OK;
else
WARN(("VBoxD3DIfSurfGet failed, hr (0x%x)",hr));
if (pD3D9Surf)
pD3D9Surf->Release();
}
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevGenerateMipSubLevels(HANDLE hDevice, CONST D3DDDIARG_GENERATEMIPSUBLEVELS* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevSetPixelShaderConstI(HANDLE hDevice, CONST D3DDDIARG_SETPIXELSHADERCONSTI* pData, CONST INT* pRegisters)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
HRESULT hr = pDevice9If->SetPixelShaderConstantI(pData->Register, pRegisters, pData->Count);
Assert(hr == S_OK);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevSetPixelShaderConstB(HANDLE hDevice, CONST D3DDDIARG_SETPIXELSHADERCONSTB* pData, CONST BOOL* pRegisters)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
HRESULT hr = pDevice9If->SetPixelShaderConstantB(pData->Register, pRegisters, pData->Count);
Assert(hr == S_OK);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevCreatePixelShader(HANDLE hDevice, D3DDDIARG_CREATEPIXELSHADER* pData, CONST UINT* pCode)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
IDirect3DPixelShader9 *pShader;
Assert(*((UINT*)((uint8_t*)pCode + pData->CodeSize-4)) == 0x0000FFFF /* end token */);
HRESULT hr = pDevice9If->CreatePixelShader((const DWORD *)pCode, &pShader);
Assert(hr == S_OK);
if (hr == S_OK)
{
Assert(pShader);
pData->ShaderHandle = pShader;
}
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevDeletePixelShader(HANDLE hDevice, HANDLE hShaderHandle)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
IDirect3DPixelShader9 *pShader = (IDirect3DPixelShader9*)hShaderHandle;
HRESULT hr = S_OK;
pShader->Release();
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevCreateDecodeDevice(HANDLE hDevice, D3DDDIARG_CREATEDECODEDEVICE* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevDestroyDecodeDevice(HANDLE hDevice, HANDLE hDecodeDevice)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevSetDecodeRenderTarget(HANDLE hDevice, CONST D3DDDIARG_SETDECODERENDERTARGET* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevDecodeBeginFrame(HANDLE hDevice, D3DDDIARG_DECODEBEGINFRAME* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevDecodeEndFrame(HANDLE hDevice, D3DDDIARG_DECODEENDFRAME* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevDecodeExecute(HANDLE hDevice, CONST D3DDDIARG_DECODEEXECUTE* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevDecodeExtensionExecute(HANDLE hDevice, CONST D3DDDIARG_DECODEEXTENSIONEXECUTE* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevCreateVideoProcessDevice(HANDLE hDevice, D3DDDIARG_CREATEVIDEOPROCESSDEVICE* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevDestroyVideoProcessDevice(HANDLE hDevice, HANDLE hVideoProcessor)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevVideoProcessBeginFrame(HANDLE hDevice, HANDLE hVideoProcess)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevVideoProcessEndFrame(HANDLE hDevice, D3DDDIARG_VIDEOPROCESSENDFRAME* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevSetVideoProcessRenderTarget(HANDLE hDevice, CONST D3DDDIARG_SETVIDEOPROCESSRENDERTARGET* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevVideoProcessBlt(HANDLE hDevice, CONST D3DDDIARG_VIDEOPROCESSBLT* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevCreateExtensionDevice(HANDLE hDevice, D3DDDIARG_CREATEEXTENSIONDEVICE* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevDestroyExtensionDevice(HANDLE hDevice, HANDLE hExtension)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevExtensionExecute(HANDLE hDevice, CONST D3DDDIARG_EXTENSIONEXECUTE* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevDestroyDevice(IN HANDLE hDevice)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
VBOXDISPPROFILE_DDI_PRINT(("Dumping on DestroyDevice: 0x%p", pDevice));
VBOXDISPPROFILE_DDI_TERM(pDevice);
#ifdef VBOXWDDMDISP_DEBUG_TIMER
DeleteTimerQueueEx(pDevice->hTimerQueue, INVALID_HANDLE_VALUE /* see term */);
pDevice->hTimerQueue = NULL;
#endif
PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter;
if (VBOXDISPMODE_IS_3D(pAdapter))
{
vboxWddmSwapchainDestroyAll(pDevice);
/* ensure the device is destroyed in any way.
* Release may not work in case of some leaking, which will leave the crOgl context refering the destroyed VBOXUHGSMI */
if (pDevice->pDevice9If)
pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9Term((IDirect3DDevice9Ex *)pDevice->pDevice9If);
}
HRESULT hr = vboxDispCmCtxDestroy(pDevice, &pDevice->DefaultContext);
Assert(hr == S_OK);
if (hr == S_OK)
RTMemFree(pDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return hr;
}
AssertCompile(sizeof (RECT) == sizeof (D3DDDIRECT));
AssertCompile(RT_SIZEOFMEMB(RECT, left) == RT_SIZEOFMEMB(D3DDDIRECT, left));
AssertCompile(RT_SIZEOFMEMB(RECT, right) == RT_SIZEOFMEMB(D3DDDIRECT, right));
AssertCompile(RT_SIZEOFMEMB(RECT, top) == RT_SIZEOFMEMB(D3DDDIRECT, top));
AssertCompile(RT_SIZEOFMEMB(RECT, bottom) == RT_SIZEOFMEMB(D3DDDIRECT, bottom));
AssertCompile(RT_OFFSETOF(RECT, left) == RT_OFFSETOF(D3DDDIRECT, left));
AssertCompile(RT_OFFSETOF(RECT, right) == RT_OFFSETOF(D3DDDIRECT, right));
AssertCompile(RT_OFFSETOF(RECT, top) == RT_OFFSETOF(D3DDDIRECT, top));
AssertCompile(RT_OFFSETOF(RECT, bottom) == RT_OFFSETOF(D3DDDIRECT, bottom));
static HRESULT APIENTRY vboxWddmDDevCreateOverlay(HANDLE hDevice, D3DDDIARG_CREATEOVERLAY* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->OverlayInfo.hResource;
Assert(pRc);
Assert(pRc->cAllocations > pData->OverlayInfo.SubResourceIndex);
PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->OverlayInfo.SubResourceIndex];
HRESULT hr = S_OK;
PVBOXWDDMDISP_OVERLAY pOverlay = (PVBOXWDDMDISP_OVERLAY)RTMemAllocZ(sizeof (VBOXWDDMDISP_OVERLAY));
Assert(pOverlay);
if (pOverlay)
{
VBOXWDDM_OVERLAY_INFO OurInfo;
OurInfo.OverlayDesc.DstColorKeyLow = pData->OverlayInfo.DstColorKeyLow;
OurInfo.OverlayDesc.DstColorKeyHigh = pData->OverlayInfo.DstColorKeyHigh;
OurInfo.OverlayDesc.SrcColorKeyLow = pData->OverlayInfo.SrcColorKeyLow;
OurInfo.OverlayDesc.SrcColorKeyHigh = pData->OverlayInfo.SrcColorKeyHigh;
OurInfo.OverlayDesc.fFlags = pData->OverlayInfo.Flags.Value;
vboxWddmDirtyRegionClear(&OurInfo.DirtyRegion);
Assert(!pAlloc->LockInfo.cLocks);
vboxWddmDirtyRegionUnite(&OurInfo.DirtyRegion, &pAlloc->DirtyRegion);
D3DDDICB_CREATEOVERLAY OverInfo;
OverInfo.VidPnSourceId = pData->VidPnSourceId;
OverInfo.OverlayInfo.hAllocation = pAlloc->hAllocation;
Assert(pAlloc->hAllocation);
OverInfo.OverlayInfo.DstRect = *(D3DDDIRECT*)((void*)&pData->OverlayInfo.DstRect);
OverInfo.OverlayInfo.SrcRect = *(D3DDDIRECT*)((void*)&pData->OverlayInfo.SrcRect);
OverInfo.OverlayInfo.pPrivateDriverData = &OurInfo;
OverInfo.OverlayInfo.PrivateDriverDataSize = sizeof (OurInfo);
OverInfo.hKernelOverlay = NULL; /* <-- out */
#ifndef VBOXWDDMOVERLAY_TEST
hr = pDevice->RtCallbacks.pfnCreateOverlayCb(pDevice->hDevice, &OverInfo);
Assert(hr == S_OK);
if (hr == S_OK)
{
Assert(OverInfo.hKernelOverlay);
pOverlay->hOverlay = OverInfo.hKernelOverlay;
pOverlay->VidPnSourceId = pData->VidPnSourceId;
Assert(!pAlloc->LockInfo.cLocks);
if (!pAlloc->LockInfo.cLocks)
{
/* we have reported the dirty rect, may clear it if no locks are pending currently */
vboxWddmDirtyRegionClear(&pAlloc->DirtyRegion);
}
pData->hOverlay = pOverlay;
}
else
{
RTMemFree(pOverlay);
}
#else
pData->hOverlay = pOverlay;
#endif
}
else
hr = E_OUTOFMEMORY;
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevUpdateOverlay(HANDLE hDevice, CONST D3DDDIARG_UPDATEOVERLAY* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->OverlayInfo.hResource;
Assert(pRc);
Assert(pRc->cAllocations > pData->OverlayInfo.SubResourceIndex);
PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->OverlayInfo.SubResourceIndex];
HRESULT hr = S_OK;
PVBOXWDDMDISP_OVERLAY pOverlay = (PVBOXWDDMDISP_OVERLAY)pData->hOverlay;
VBOXWDDM_OVERLAY_INFO OurInfo;
OurInfo.OverlayDesc.DstColorKeyLow = pData->OverlayInfo.DstColorKeyLow;
OurInfo.OverlayDesc.DstColorKeyHigh = pData->OverlayInfo.DstColorKeyHigh;
OurInfo.OverlayDesc.SrcColorKeyLow = pData->OverlayInfo.SrcColorKeyLow;
OurInfo.OverlayDesc.SrcColorKeyHigh = pData->OverlayInfo.SrcColorKeyHigh;
OurInfo.OverlayDesc.fFlags = pData->OverlayInfo.Flags.Value;
vboxWddmDirtyRegionClear(&OurInfo.DirtyRegion);
Assert(!pAlloc->LockInfo.cLocks);
vboxWddmDirtyRegionUnite(&OurInfo.DirtyRegion, &pAlloc->DirtyRegion);
D3DDDICB_UPDATEOVERLAY OverInfo;
OverInfo.hKernelOverlay = pOverlay->hOverlay;
OverInfo.OverlayInfo.hAllocation = pAlloc->hAllocation;
OverInfo.OverlayInfo.DstRect = *(D3DDDIRECT*)((void*)&pData->OverlayInfo.DstRect);
OverInfo.OverlayInfo.SrcRect = *(D3DDDIRECT*)((void*)&pData->OverlayInfo.SrcRect);
OverInfo.OverlayInfo.pPrivateDriverData = &OurInfo;
OverInfo.OverlayInfo.PrivateDriverDataSize = sizeof (OurInfo);
#ifndef VBOXWDDMOVERLAY_TEST
hr = pDevice->RtCallbacks.pfnUpdateOverlayCb(pDevice->hDevice, &OverInfo);
Assert(hr == S_OK);
if (hr == S_OK)
#endif
{
Assert(!pAlloc->LockInfo.cLocks);
if (!pAlloc->LockInfo.cLocks)
{
/* we have reported the dirty rect, may clear it if no locks are pending currently */
vboxWddmDirtyRegionClear(&pAlloc->DirtyRegion);
}
}
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevFlipOverlay(HANDLE hDevice, CONST D3DDDIARG_FLIPOVERLAY* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hSource;
Assert(pRc);
Assert(pRc->cAllocations > pData->SourceIndex);
PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SourceIndex];
HRESULT hr = S_OK;
PVBOXWDDMDISP_OVERLAY pOverlay = (PVBOXWDDMDISP_OVERLAY)pData->hOverlay;
VBOXWDDM_OVERLAYFLIP_INFO OurInfo;
vboxWddmDirtyRegionClear(&OurInfo.DirtyRegion);
Assert(!pAlloc->LockInfo.cLocks);
vboxWddmDirtyRegionUnite(&OurInfo.DirtyRegion, &pAlloc->DirtyRegion);
D3DDDICB_FLIPOVERLAY OverInfo;
OverInfo.hKernelOverlay = pOverlay->hOverlay;
OverInfo.hSource = pAlloc->hAllocation;
OverInfo.pPrivateDriverData = &OurInfo;
OverInfo.PrivateDriverDataSize = sizeof (OurInfo);
#ifndef VBOXWDDMOVERLAY_TEST
hr = pDevice->RtCallbacks.pfnFlipOverlayCb(pDevice->hDevice, &OverInfo);
Assert(hr == S_OK);
if (hr == S_OK)
#endif
{
Assert(!pAlloc->LockInfo.cLocks);
if (!pAlloc->LockInfo.cLocks)
{
/* we have reported the dirty rect, may clear it if no locks are pending currently */
vboxWddmDirtyRegionClear(&pAlloc->DirtyRegion);
}
}
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevGetOverlayColorControls(HANDLE hDevice, D3DDDIARG_GETOVERLAYCOLORCONTROLS* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevSetOverlayColorControls(HANDLE hDevice, CONST D3DDDIARG_SETOVERLAYCOLORCONTROLS* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevDestroyOverlay(HANDLE hDevice, CONST D3DDDIARG_DESTROYOVERLAY* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
PVBOXWDDMDISP_OVERLAY pOverlay = (PVBOXWDDMDISP_OVERLAY)pData->hOverlay;
D3DDDICB_DESTROYOVERLAY OverInfo;
OverInfo.hKernelOverlay = pOverlay->hOverlay;
#ifndef VBOXWDDMOVERLAY_TEST
HRESULT hr = pDevice->RtCallbacks.pfnDestroyOverlayCb(pDevice->hDevice, &OverInfo);
Assert(hr == S_OK);
if (hr == S_OK)
#else
HRESULT hr = S_OK;
#endif
{
RTMemFree(pOverlay);
}
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevQueryResourceResidency(HANDLE hDevice, CONST D3DDDIARG_QUERYRESOURCERESIDENCY* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
HRESULT hr = S_OK;
/* @todo check residency for the "real" allocations */
#if 0
for (UINT i = 0; i < pData->NumResources; ++i)
{
PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->pHandleList[i];
Assert(pRc->pDevice == pDevice);
if (pRc->hKMResource)
{
}
}
#endif
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevOpenResource(HANDLE hDevice, D3DDDIARG_OPENRESOURCE* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
HRESULT hr = S_OK;
Assert(pData->hKMResource);
Assert(pData->NumAllocations);
PVBOXWDDMDISP_RESOURCE pRc = vboxResourceAlloc(pData->NumAllocations);
Assert(pRc);
if (pRc)
{
pRc->hResource = pData->hResource;
pRc->hKMResource = pData->hKMResource;
pRc->pDevice = pDevice;
pRc->RcDesc.enmRotation = pData->Rotation;
pRc->fFlags.Value = 0;
pRc->fFlags.Opened = 1;
pRc->fFlags.KmResource = 1;
for (UINT i = 0; i < pData->NumAllocations; ++i)
{
PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
D3DDDI_OPENALLOCATIONINFO* pOAI = pData->pOpenAllocationInfo;
Assert(pOAI->PrivateDriverDataSize == sizeof (VBOXWDDM_ALLOCINFO));
if (pOAI->PrivateDriverDataSize != sizeof (VBOXWDDM_ALLOCINFO))
{
hr = E_INVALIDARG;
break;
}
Assert(pOAI->pPrivateDriverData);
PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pOAI->pPrivateDriverData;
pAllocation->hAllocation = pOAI->hAllocation;
pAllocation->enmType = pAllocInfo->enmType;
pAllocation->hSharedHandle = (HANDLE)pAllocInfo->hSharedHandle;
pAllocation->SurfDesc = pAllocInfo->SurfDesc;
pAllocation->pvMem = NULL;
#ifndef VBOXWDDMDISP_DEBUG_NOSHARED
Assert(!pAllocation->hSharedHandle == (pAllocation->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE));
#endif
#ifdef VBOXWDDMDISP_DEBUG_PRINT_SHARED_CREATE
vboxVDbgPrint(("\n\n********\n(0x%x:0n%d)Shared OPENNED pAlloc(0x%p), hRc(0x%p), hAl(0x%p), "
"Handle(0x%x), (0n%d) \n***********\n\n",
GetCurrentProcessId(), GetCurrentProcessId(),
pAllocation, pRc->hKMResource, pAllocation->hAllocation,
pAllocation->hSharedHandle, pAllocation->hSharedHandle
));
#endif
}
if (!pData->pPrivateDriverData || !pData->PrivateDriverDataSize)
{
/* this is a "standard" allocation resource */
/* both should be actually zero */
Assert(!pData->pPrivateDriverData && !pData->PrivateDriverDataSize);
pRc->RcDesc.enmPool = D3DDDIPOOL_LOCALVIDMEM;
pRc->RcDesc.enmMultisampleType = D3DDDIMULTISAMPLE_NONE;
pRc->RcDesc.MultisampleQuality = 0;
pRc->RcDesc.MipLevels = 0;
pRc->RcDesc.Fvf;
if (pData->NumAllocations != 1)
{
WARN(("NumAllocations is expected to be 1, but was %d", pData->NumAllocations));
}
for (UINT i = 0; i < pData->NumAllocations; ++i)
{
PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[i];
pAlloc->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE;
pAlloc->pD3DIf = NULL;
}
D3DDDI_OPENALLOCATIONINFO* pDdiAllocInfo = &pData->pOpenAllocationInfo[0];
Assert(pDdiAllocInfo->pPrivateDriverData);
Assert(pDdiAllocInfo->PrivateDriverDataSize >= sizeof (VBOXWDDM_ALLOCINFO));
if (pDdiAllocInfo->pPrivateDriverData && pDdiAllocInfo->PrivateDriverDataSize >= sizeof (VBOXWDDM_ALLOCINFO))
{
PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pDdiAllocInfo->pPrivateDriverData;
switch(pAllocInfo->enmType)
{
case VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE:
pRc->RcDesc.fFlags.Primary = 1;
case VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE:
case VBOXWDDM_ALLOC_TYPE_STD_STAGINGSURFACE:
pRc->RcDesc.enmFormat = pAllocInfo->SurfDesc.format;
pRc->RcDesc.VidPnSourceId = pAllocInfo->SurfDesc.VidPnSourceId;
pRc->RcDesc.RefreshRate = pAllocInfo->SurfDesc.RefreshRate;
break;
default:
Assert(0);
hr = E_INVALIDARG;
}
}
else
hr = E_INVALIDARG;
}
else
{
/* this is a "generic" resource whose creation is initiated by the UMD */
Assert(pData->PrivateDriverDataSize == sizeof (VBOXWDDM_RCINFO));
if (pData->PrivateDriverDataSize == sizeof (VBOXWDDM_RCINFO))
{
VBOXWDDM_RCINFO *pRcInfo = (VBOXWDDM_RCINFO*)pData->pPrivateDriverData;
Assert(pRcInfo->fFlags.Generic);
Assert(!pRcInfo->fFlags.Opened);
Assert(pRcInfo->cAllocInfos == pData->NumAllocations);
pRc->fFlags.Value |= pRcInfo->fFlags.Value;
pRc->fFlags.Generic = 1;
pRc->RcDesc = pRcInfo->RcDesc;
pRc->cAllocations = pData->NumAllocations;
Assert(pRc->RcDesc.fFlags.SharedResource);
hr = VBoxD3DIfCreateForRc(pRc);
if (!SUCCEEDED(hr))
{
WARN(("VBoxD3DIfCreateForRc failed, hr %d", hr));
}
}
else
hr = E_INVALIDARG;
}
if (hr == S_OK)
pData->hResource = pRc;
else
vboxResourceFree(pRc);
}
else
{
vboxVDbgPrintR((__FUNCTION__": vboxResourceAlloc failed for hDevice(0x%p), NumAllocations(%d)\n", hDevice, pData->NumAllocations));
hr = E_OUTOFMEMORY;
}
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return hr;
}
static HRESULT APIENTRY vboxWddmDDevGetCaptureAllocationHandle(HANDLE hDevice, D3DDDIARG_GETCAPTUREALLOCATIONHANDLE* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDDevCaptureToSysMem(HANDLE hDevice, CONST D3DDDIARG_CAPTURETOSYSMEM* pData)
{
VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
Assert(pDevice);
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
Assert(0);
vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
return E_FAIL;
}
static HRESULT APIENTRY vboxWddmDispCreateDevice (IN HANDLE hAdapter, IN D3DDDIARG_CREATEDEVICE* pCreateData)
{
VBOXDISP_DDI_PROLOGUE_ADP(hAdapter);
HRESULT hr = S_OK;
vboxVDbgPrint(("==> "__FUNCTION__", hAdapter(0x%p), Interface(%d), Version(%d)\n", hAdapter, pCreateData->Interface, pCreateData->Version));
// Assert(0);
PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)hAdapter;
PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)RTMemAllocZ(RT_OFFSETOF(VBOXWDDMDISP_DEVICE, apRTs[pAdapter->D3D.cMaxSimRTs]));
if (pDevice)
{
pDevice->cRTs = pAdapter->D3D.cMaxSimRTs;
pDevice->hDevice = pCreateData->hDevice;
pDevice->pAdapter = pAdapter;
pDevice->u32IfVersion = pCreateData->Interface;
pDevice->uRtVersion = pCreateData->Version;
pDevice->RtCallbacks = *pCreateData->pCallbacks;
pDevice->pvCmdBuffer = pCreateData->pCommandBuffer;
pDevice->cbCmdBuffer = pCreateData->CommandBufferSize;
pDevice->fFlags = pCreateData->Flags;
/* Set Viewport to some default values */
pDevice->ViewPort.X = 0;
pDevice->ViewPort.Y = 0;
pDevice->ViewPort.Width = 1;
pDevice->ViewPort.Height = 1;
pDevice->ViewPort.MinZ = 0.;
pDevice->ViewPort.MaxZ = 1.;
RTListInit(&pDevice->DirtyAllocList);
Assert(!pCreateData->AllocationListSize);
Assert(!pCreateData->PatchLocationListSize);
pCreateData->hDevice = pDevice;
pCreateData->pDeviceFuncs->pfnSetRenderState = vboxWddmDDevSetRenderState;
pCreateData->pDeviceFuncs->pfnUpdateWInfo = vboxWddmDDevUpdateWInfo;
pCreateData->pDeviceFuncs->pfnValidateDevice = vboxWddmDDevValidateDevice;
pCreateData->pDeviceFuncs->pfnSetTextureStageState = vboxWddmDDevSetTextureStageState;
pCreateData->pDeviceFuncs->pfnSetTexture = vboxWddmDDevSetTexture;
pCreateData->pDeviceFuncs->pfnSetPixelShader = vboxWddmDDevSetPixelShader;
pCreateData->pDeviceFuncs->pfnSetPixelShaderConst = vboxWddmDDevSetPixelShaderConst;
pCreateData->pDeviceFuncs->pfnSetStreamSourceUm = vboxWddmDDevSetStreamSourceUm;
pCreateData->pDeviceFuncs->pfnSetIndices = vboxWddmDDevSetIndices;
pCreateData->pDeviceFuncs->pfnSetIndicesUm = vboxWddmDDevSetIndicesUm;
pCreateData->pDeviceFuncs->pfnDrawPrimitive = vboxWddmDDevDrawPrimitive;
pCreateData->pDeviceFuncs->pfnDrawIndexedPrimitive = vboxWddmDDevDrawIndexedPrimitive;
pCreateData->pDeviceFuncs->pfnDrawRectPatch = vboxWddmDDevDrawRectPatch;
pCreateData->pDeviceFuncs->pfnDrawTriPatch = vboxWddmDDevDrawTriPatch;
pCreateData->pDeviceFuncs->pfnDrawPrimitive2 = vboxWddmDDevDrawPrimitive2;
pCreateData->pDeviceFuncs->pfnDrawIndexedPrimitive2 = vboxWddmDDevDrawIndexedPrimitive2;
pCreateData->pDeviceFuncs->pfnVolBlt = vboxWddmDDevVolBlt;
pCreateData->pDeviceFuncs->pfnBufBlt = vboxWddmDDevBufBlt;
pCreateData->pDeviceFuncs->pfnTexBlt = vboxWddmDDevTexBlt;
pCreateData->pDeviceFuncs->pfnStateSet = vboxWddmDDevStateSet;
pCreateData->pDeviceFuncs->pfnSetPriority = vboxWddmDDevSetPriority;
pCreateData->pDeviceFuncs->pfnClear = vboxWddmDDevClear;
pCreateData->pDeviceFuncs->pfnUpdatePalette = vboxWddmDDevUpdatePalette;
pCreateData->pDeviceFuncs->pfnSetPalette = vboxWddmDDevSetPalette;
pCreateData->pDeviceFuncs->pfnSetVertexShaderConst = vboxWddmDDevSetVertexShaderConst;
pCreateData->pDeviceFuncs->pfnMultiplyTransform = vboxWddmDDevMultiplyTransform;
pCreateData->pDeviceFuncs->pfnSetTransform = vboxWddmDDevSetTransform;
pCreateData->pDeviceFuncs->pfnSetViewport = vboxWddmDDevSetViewport;
pCreateData->pDeviceFuncs->pfnSetZRange = vboxWddmDDevSetZRange;
pCreateData->pDeviceFuncs->pfnSetMaterial = vboxWddmDDevSetMaterial;
pCreateData->pDeviceFuncs->pfnSetLight = vboxWddmDDevSetLight;
pCreateData->pDeviceFuncs->pfnCreateLight = vboxWddmDDevCreateLight;
pCreateData->pDeviceFuncs->pfnDestroyLight = vboxWddmDDevDestroyLight;
pCreateData->pDeviceFuncs->pfnSetClipPlane = vboxWddmDDevSetClipPlane;
pCreateData->pDeviceFuncs->pfnGetInfo = vboxWddmDDevGetInfo;
pCreateData->pDeviceFuncs->pfnLock = vboxWddmDDevLock;
pCreateData->pDeviceFuncs->pfnUnlock = vboxWddmDDevUnlock;
pCreateData->pDeviceFuncs->pfnCreateResource = vboxWddmDDevCreateResource;
pCreateData->pDeviceFuncs->pfnDestroyResource = vboxWddmDDevDestroyResource;
pCreateData->pDeviceFuncs->pfnSetDisplayMode = vboxWddmDDevSetDisplayMode;
pCreateData->pDeviceFuncs->pfnPresent = vboxWddmDDevPresent;
pCreateData->pDeviceFuncs->pfnFlush = vboxWddmDDevFlush;
pCreateData->pDeviceFuncs->pfnCreateVertexShaderFunc = vboxWddmDDevCreateVertexShaderFunc;
pCreateData->pDeviceFuncs->pfnDeleteVertexShaderFunc = vboxWddmDDevDeleteVertexShaderFunc;
pCreateData->pDeviceFuncs->pfnSetVertexShaderFunc = vboxWddmDDevSetVertexShaderFunc;
pCreateData->pDeviceFuncs->pfnCreateVertexShaderDecl = vboxWddmDDevCreateVertexShaderDecl;
pCreateData->pDeviceFuncs->pfnDeleteVertexShaderDecl = vboxWddmDDevDeleteVertexShaderDecl;
pCreateData->pDeviceFuncs->pfnSetVertexShaderDecl = vboxWddmDDevSetVertexShaderDecl;
pCreateData->pDeviceFuncs->pfnSetVertexShaderConstI = vboxWddmDDevSetVertexShaderConstI;
pCreateData->pDeviceFuncs->pfnSetVertexShaderConstB = vboxWddmDDevSetVertexShaderConstB;
pCreateData->pDeviceFuncs->pfnSetScissorRect = vboxWddmDDevSetScissorRect;
pCreateData->pDeviceFuncs->pfnSetStreamSource = vboxWddmDDevSetStreamSource;
pCreateData->pDeviceFuncs->pfnSetStreamSourceFreq = vboxWddmDDevSetStreamSourceFreq;
pCreateData->pDeviceFuncs->pfnSetConvolutionKernelMono = vboxWddmDDevSetConvolutionKernelMono;
pCreateData->pDeviceFuncs->pfnComposeRects = vboxWddmDDevComposeRects;
pCreateData->pDeviceFuncs->pfnBlt = vboxWddmDDevBlt;
pCreateData->pDeviceFuncs->pfnColorFill = vboxWddmDDevColorFill;
pCreateData->pDeviceFuncs->pfnDepthFill = vboxWddmDDevDepthFill;
pCreateData->pDeviceFuncs->pfnCreateQuery = vboxWddmDDevCreateQuery;
pCreateData->pDeviceFuncs->pfnDestroyQuery = vboxWddmDDevDestroyQuery;
pCreateData->pDeviceFuncs->pfnIssueQuery = vboxWddmDDevIssueQuery;
pCreateData->pDeviceFuncs->pfnGetQueryData = vboxWddmDDevGetQueryData;
pCreateData->pDeviceFuncs->pfnSetRenderTarget = vboxWddmDDevSetRenderTarget;
pCreateData->pDeviceFuncs->pfnSetDepthStencil = vboxWddmDDevSetDepthStencil;
pCreateData->pDeviceFuncs->pfnGenerateMipSubLevels = vboxWddmDDevGenerateMipSubLevels;
pCreateData->pDeviceFuncs->pfnSetPixelShaderConstI = vboxWddmDDevSetPixelShaderConstI;
pCreateData->pDeviceFuncs->pfnSetPixelShaderConstB = vboxWddmDDevSetPixelShaderConstB;
pCreateData->pDeviceFuncs->pfnCreatePixelShader = vboxWddmDDevCreatePixelShader;
pCreateData->pDeviceFuncs->pfnDeletePixelShader = vboxWddmDDevDeletePixelShader;
pCreateData->pDeviceFuncs->pfnCreateDecodeDevice = vboxWddmDDevCreateDecodeDevice;
pCreateData->pDeviceFuncs->pfnDestroyDecodeDevice = vboxWddmDDevDestroyDecodeDevice;
pCreateData->pDeviceFuncs->pfnSetDecodeRenderTarget = vboxWddmDDevSetDecodeRenderTarget;
pCreateData->pDeviceFuncs->pfnDecodeBeginFrame = vboxWddmDDevDecodeBeginFrame;
pCreateData->pDeviceFuncs->pfnDecodeEndFrame = vboxWddmDDevDecodeEndFrame;
pCreateData->pDeviceFuncs->pfnDecodeExecute = vboxWddmDDevDecodeExecute;
pCreateData->pDeviceFuncs->pfnDecodeExtensionExecute = vboxWddmDDevDecodeExtensionExecute;
pCreateData->pDeviceFuncs->pfnCreateVideoProcessDevice = vboxWddmDDevCreateVideoProcessDevice;
pCreateData->pDeviceFuncs->pfnDestroyVideoProcessDevice = vboxWddmDDevDestroyVideoProcessDevice;
pCreateData->pDeviceFuncs->pfnVideoProcessBeginFrame = vboxWddmDDevVideoProcessBeginFrame;
pCreateData->pDeviceFuncs->pfnVideoProcessEndFrame = vboxWddmDDevVideoProcessEndFrame;
pCreateData->pDeviceFuncs->pfnSetVideoProcessRenderTarget = vboxWddmDDevSetVideoProcessRenderTarget;
pCreateData->pDeviceFuncs->pfnVideoProcessBlt = vboxWddmDDevVideoProcessBlt;
pCreateData->pDeviceFuncs->pfnCreateExtensionDevice = vboxWddmDDevCreateExtensionDevice;
pCreateData->pDeviceFuncs->pfnDestroyExtensionDevice = vboxWddmDDevDestroyExtensionDevice;
pCreateData->pDeviceFuncs->pfnExtensionExecute = vboxWddmDDevExtensionExecute;
pCreateData->pDeviceFuncs->pfnCreateOverlay = vboxWddmDDevCreateOverlay;
pCreateData->pDeviceFuncs->pfnUpdateOverlay = vboxWddmDDevUpdateOverlay;
pCreateData->pDeviceFuncs->pfnFlipOverlay = vboxWddmDDevFlipOverlay;
pCreateData->pDeviceFuncs->pfnGetOverlayColorControls = vboxWddmDDevGetOverlayColorControls;
pCreateData->pDeviceFuncs->pfnSetOverlayColorControls = vboxWddmDDevSetOverlayColorControls;
pCreateData->pDeviceFuncs->pfnDestroyOverlay = vboxWddmDDevDestroyOverlay;
pCreateData->pDeviceFuncs->pfnDestroyDevice = vboxWddmDDevDestroyDevice;
pCreateData->pDeviceFuncs->pfnQueryResourceResidency = vboxWddmDDevQueryResourceResidency;
pCreateData->pDeviceFuncs->pfnOpenResource = vboxWddmDDevOpenResource;
pCreateData->pDeviceFuncs->pfnGetCaptureAllocationHandle = vboxWddmDDevGetCaptureAllocationHandle;
pCreateData->pDeviceFuncs->pfnCaptureToSysMem = vboxWddmDDevCaptureToSysMem;
pCreateData->pDeviceFuncs->pfnLockAsync = NULL; //vboxWddmDDevLockAsync;
pCreateData->pDeviceFuncs->pfnUnlockAsync = NULL; //vboxWddmDDevUnlockAsync;
pCreateData->pDeviceFuncs->pfnRename = NULL; //vboxWddmDDevRename;
VBOXDISPPROFILE_DDI_INIT_DEV(pDevice);
#ifdef VBOX_WDDMDISP_WITH_PROFILE
pDevice->ProfileDdiPresentCb = VBoxDispProfileSet("pfnPresentCb");
#endif
#ifdef VBOXWDDMDISP_DEBUG_TIMER
pDevice->hTimerQueue = CreateTimerQueue();
Assert(pDevice->hTimerQueue);
#endif
do
{
RTListInit(&pDevice->SwapchainList);
Assert(!pCreateData->AllocationListSize
&& !pCreateData->PatchLocationListSize);
if (!pCreateData->AllocationListSize
&& !pCreateData->PatchLocationListSize)
{
{
VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
hr = vboxDispCmCtxCreate(pDevice, &pDevice->DefaultContext);
Assert(hr == S_OK);
if (hr == S_OK)
{
#ifdef VBOXDISP_EARLYCREATEDEVICE
PVBOXWDDMDISP_RESOURCE pRc = vboxResourceAlloc(2);
Assert(pRc);
if (pRc)
{
D3DPRESENT_PARAMETERS params;
memset(&params, 0, sizeof (params));
// params.BackBufferWidth = 640;
// params.BackBufferHeight = 480;
params.BackBufferWidth = 0x400;
params.BackBufferHeight = 0x300;
params.BackBufferFormat = D3DFMT_A8R8G8B8;
// params.BackBufferCount = 0;
params.BackBufferCount = 1;
params.MultiSampleType = D3DMULTISAMPLE_NONE;
params.SwapEffect = D3DSWAPEFFECT_DISCARD;
// params.hDeviceWindow = hWnd;
/* @todo: it seems there should be a way to detect this correctly since
* our vboxWddmDDevSetDisplayMode will be called in case we are using full-screen */
params.Windowed = TRUE;
// params.EnableAutoDepthStencil = FALSE;
// params.AutoDepthStencilFormat = D3DFMT_UNKNOWN;
// params.Flags;
// params.FullScreen_RefreshRateInHz;
// params.FullScreen_PresentationInterval;
hr = vboxWddmD3DDeviceCreate(pDevice, 0, pRc, &params, TRUE /*BOOL bLockable*/);
Assert(hr == S_OK);
if (hr == S_OK)
break;
vboxResourceFree(pRc);
}
else
{
hr = E_OUTOFMEMORY;
}
#else
//# define VBOXDISP_TEST_SWAPCHAIN
# ifdef VBOXDISP_TEST_SWAPCHAIN
VBOXDISP_D3DEV(pDevice);
# endif
break;
#endif
HRESULT tmpHr = vboxDispCmCtxDestroy(pDevice, &pDevice->DefaultContext);
Assert(tmpHr == S_OK);
}
}
}
else
{
vboxVDbgPrintR((__FUNCTION__": Not implemented: PatchLocationListSize(%d), AllocationListSize(%d)\n",
pCreateData->PatchLocationListSize, pCreateData->AllocationListSize));
//pCreateData->pAllocationList = ??
hr = E_FAIL;
}
RTMemFree(pDevice);
} while (0);
}
else
{
vboxVDbgPrintR((__FUNCTION__": RTMemAllocZ returned NULL\n"));
hr = E_OUTOFMEMORY;
}
vboxVDbgPrint(("<== "__FUNCTION__", hAdapter(0x%p)\n", hAdapter));
return hr;
}
static HRESULT APIENTRY vboxWddmDispCloseAdapter (IN HANDLE hAdapter)
{
VBOXDISP_DDI_PROLOGUE_ADP(hAdapter);
vboxVDbgPrint(("==> "__FUNCTION__", hAdapter(0x%p)\n", hAdapter));
PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)hAdapter;
if (VBOXDISPMODE_IS_3D(pAdapter))
{
VBOXDISPCRHGSMI_SCOPE_SET_GLOBAL();
VBoxDispD3DGlobalClose(&pAdapter->D3D, &pAdapter->Formats);
}
#ifdef VBOX_WITH_VIDEOHWACCEL
else
{
VBoxDispD3DGlobal2DFormatsTerm(pAdapter);
}
#endif
VBOXDISPPROFILE_DDI_TERM(pAdapter);
RTMemFree(pAdapter);
vboxVDbgPrint(("<== "__FUNCTION__", hAdapter(0x%p)\n", hAdapter));
return S_OK;
}
#define VBOXDISP_IS_MODULE_FUNC(_pvModule, _cbModule, _pfn) ( \
(((uintptr_t)(_pfn)) >= ((uintptr_t)(_pvModule))) \
&& (((uintptr_t)(_pfn)) < (((uintptr_t)(_pvModule)) + ((DWORD)(_cbModule)))) \
)
static BOOL vboxDispIsDDraw(__inout D3DDDIARG_OPENADAPTER* pOpenData)
{
/*if we are loaded by ddraw module, the Interface version should be 7
* and pAdapterCallbacks should be ddraw-supplied, i.e. reside in ddraw module */
if (pOpenData->Interface != 7)
return FALSE;
HMODULE hDDraw = GetModuleHandleA("ddraw.dll");
if (!hDDraw)
return FALSE;
HANDLE hProcess = GetCurrentProcess();
MODULEINFO ModuleInfo = {0};
if (!GetModuleInformation(hProcess, hDDraw, &ModuleInfo, sizeof (ModuleInfo)))
{
DWORD winEr = GetLastError();
WARN(("GetModuleInformation failed, %d", winEr));
return FALSE;
}
if (VBOXDISP_IS_MODULE_FUNC(ModuleInfo.lpBaseOfDll, ModuleInfo.SizeOfImage, pOpenData->pAdapterCallbacks->pfnQueryAdapterInfoCb))
return TRUE;
if (VBOXDISP_IS_MODULE_FUNC(ModuleInfo.lpBaseOfDll, ModuleInfo.SizeOfImage, pOpenData->pAdapterCallbacks->pfnGetMultisampleMethodListCb))
return TRUE;
return FALSE;
}
HRESULT APIENTRY OpenAdapter(__inout D3DDDIARG_OPENADAPTER* pOpenData)
{
VBOXDISP_DDI_PROLOGUE_GLBL();
vboxVDbgPrint(("==> "__FUNCTION__"\n"));
#if 0 //def DEBUG_misha
DWORD dwVersion = 0;
DWORD dwMajorVersion = 0;
DWORD dwMinorVersion = 0;
dwVersion = GetVersion();
dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));
if (dwMajorVersion == 6 && dwMinorVersion <= 1 && VBOXVDBG_IS_DWM())
{
exit(0);
return E_FAIL;
}
#endif
// vboxDispLock();
HRESULT hr = E_FAIL;
do
{
LOGREL(("Built %s %s", __DATE__, __TIME__));
VBOXWDDM_QI Query;
D3DDDICB_QUERYADAPTERINFO DdiQuery;
DdiQuery.PrivateDriverDataSize = sizeof(Query);
DdiQuery.pPrivateDriverData = &Query;
hr = pOpenData->pAdapterCallbacks->pfnQueryAdapterInfoCb(pOpenData->hAdapter, &DdiQuery);
Assert(hr == S_OK);
if (hr != S_OK)
{
vboxVDbgPrintR((__FUNCTION__": pfnQueryAdapterInfoCb failed, hr (%d)\n", hr));
hr = E_FAIL;
break;
}
/* check the miniport version match display version */
if (Query.u32Version != VBOXVIDEOIF_VERSION)
{
vboxVDbgPrintR((__FUNCTION__": miniport version mismatch, expected (%d), but was (%d)\n",
VBOXVIDEOIF_VERSION,
Query.u32Version));
hr = E_FAIL;
break;
}
#ifdef VBOX_WITH_VIDEOHWACCEL
Assert(Query.cInfos >= 1);
PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)RTMemAllocZ(RT_OFFSETOF(VBOXWDDMDISP_ADAPTER, aHeads[Query.cInfos]));
#else
PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)RTMemAllocZ(sizeof (VBOXWDDMDISP_ADAPTER));
#endif
Assert(pAdapter);
if (pAdapter)
{
pAdapter->hAdapter = pOpenData->hAdapter;
pAdapter->uIfVersion = pOpenData->Interface;
pAdapter->uRtVersion= pOpenData->Version;
pAdapter->RtCallbacks = *pOpenData->pAdapterCallbacks;
pAdapter->cHeads = Query.cInfos;
pOpenData->hAdapter = pAdapter;
pOpenData->pAdapterFuncs->pfnGetCaps = vboxWddmDispGetCaps;
pOpenData->pAdapterFuncs->pfnCreateDevice = vboxWddmDispCreateDevice;
pOpenData->pAdapterFuncs->pfnCloseAdapter = vboxWddmDispCloseAdapter;
pOpenData->DriverVersion = D3D_UMD_INTERFACE_VERSION;
if (!vboxDispIsDDraw(pOpenData))
{
do
{
{
VBOXDISPCRHGSMI_SCOPE_SET_GLOBAL();
/* try enable the 3D */
hr = VBoxDispD3DGlobalOpen(&pAdapter->D3D, &pAdapter->Formats);
if (hr == S_OK)
{
LOG(("SUCCESS 3D Enabled, pAdapter (0x%p)", pAdapter));
break;
}
else
WARN(("VBoxDispD3DOpen failed, hr (%d)", hr));
}
} while (0);
}
#ifdef VBOX_WITH_VIDEOHWACCEL
if (!VBOXDISPMODE_IS_3D(pAdapter))
{
for (uint32_t i = 0; i < pAdapter->cHeads; ++i)
{
pAdapter->aHeads[i].Vhwa.Settings = Query.aInfos[i];
}
hr = VBoxDispD3DGlobal2DFormatsInit(pAdapter);
if (!SUCCEEDED(hr))
{
WARN(("VBoxDispD3DGlobal2DFormatsInit failed hr 0x%x", hr));
}
}
#endif
if (SUCCEEDED(hr))
{
VBOXDISPPROFILE_DDI_INIT_ADP(pAdapter);
hr = S_OK;
break;
}
else
{
WARN(("OpenAdapter failed hr 0x%x", hr));
}
RTMemFree(pAdapter);
}
else
{
vboxVDbgPrintR((__FUNCTION__": RTMemAllocZ returned NULL\n"));
hr = E_OUTOFMEMORY;
}
} while (0);
// vboxDispUnlock();
vboxVDbgPrint(("<== "__FUNCTION__", hr (%d)\n", hr));
return hr;
}