forked from Gcenx/DXVK-macOS
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathd3d8_main.cpp
More file actions
131 lines (106 loc) · 4.07 KB
/
d3d8_main.cpp
File metadata and controls
131 lines (106 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "d3d8_interface.h"
namespace dxvk {
Logger Logger::s_instance("d3d8.log");
HRESULT CreateD3D8(IDirect3D8** ppDirect3D8) {
if (!ppDirect3D8)
return D3DERR_INVALIDCALL;
try {
*ppDirect3D8 = ref(new D3D8Interface());
} catch (const DxvkError& e) {
Logger::err(e.message());
*ppDirect3D8 = nullptr;
return D3DERR_NOTAVAILABLE;
}
return D3D_OK;
}
}
extern "C" {
DLLEXPORT HRESULT __stdcall ValidatePixelShader(
const DWORD* pPixelShader,
const D3DCAPS8* pCaps,
BOOL ErrorReturn,
char** pErrorString) {
HRESULT res = S_OK;
std::string errorMessage = "";
// ValidatePixelShader returns immediately in case of a NULL pPixelShader
if (unlikely(pPixelShader == nullptr)) {
dxvk::Logger::warn("D3D8: ValidatePixelShader: Null pPixelShader");
return E_FAIL;
} else {
const uint32_t majorVersion = D3DSHADER_VERSION_MAJOR(pPixelShader[0]);
const uint32_t minorVersion = D3DSHADER_VERSION_MINOR(pPixelShader[0]);
if (unlikely(majorVersion != 1 || minorVersion > 4)) {
errorMessage = dxvk::str::format("D3D8: ValidatePixelShader: Unsupported PS version ",
majorVersion, ".", minorVersion);
res = E_FAIL;
} else if (unlikely(pCaps && pPixelShader[0] > pCaps->PixelShaderVersion)) {
errorMessage = dxvk::str::format("D3D8: ValidatePixelShader: Caps: Unsupported PS version ",
majorVersion, ".", minorVersion);
res = E_FAIL;
}
}
if (unlikely(res != S_OK)) {
dxvk::Logger::warn(errorMessage);
if (!ErrorReturn)
errorMessage = "";
}
#ifdef _WIN32
if (pErrorString != nullptr) {
const size_t errorMessageSize = errorMessage.size() + 1;
// Wine tests call HeapFree() on the returned error string,
// so the expectation is for it to be allocated on the heap.
*pErrorString = (char*) HeapAlloc(GetProcessHeap(), 0, errorMessageSize);
if (*pErrorString)
memcpy(*pErrorString, errorMessage.c_str(), errorMessageSize);
}
#endif
return res;
}
DLLEXPORT HRESULT __stdcall ValidateVertexShader(
const DWORD* pVertexShader,
const DWORD* pVertexDecl,
const D3DCAPS8* pCaps,
BOOL ErrorReturn,
char** pErrorString) {
HRESULT res = S_OK;
std::string errorMessage = "";
if (unlikely(pVertexShader == nullptr)) {
errorMessage = "D3D8: ValidateVertexShader: Null pVertexShader";
res = E_FAIL;
} else {
const uint32_t majorVersion = D3DSHADER_VERSION_MAJOR(pVertexShader[0]);
const uint32_t minorVersion = D3DSHADER_VERSION_MINOR(pVertexShader[0]);
if (unlikely(majorVersion != 1 || minorVersion > 1)) {
errorMessage = dxvk::str::format("D3D8: ValidateVertexShader: Unsupported VS version ",
majorVersion, ".", minorVersion);
res = E_FAIL;
} else if (unlikely(pCaps && pVertexShader[0] > pCaps->VertexShaderVersion)) {
errorMessage = dxvk::str::format("D3D8: ValidateVertexShader: Caps: Unsupported VS version ",
majorVersion, ".", minorVersion);
res = E_FAIL;
}
}
if (unlikely(res != S_OK)) {
dxvk::Logger::warn(errorMessage);
if (!ErrorReturn)
errorMessage = "";
}
#ifdef _WIN32
if (pErrorString != nullptr) {
const size_t errorMessageSize = errorMessage.size() + 1;
// Wine tests call HeapFree() on the returned error string,
// so the expectation is for it to be allocated on the heap.
*pErrorString = (char*) HeapAlloc(GetProcessHeap(), 0, errorMessageSize);
if (*pErrorString)
memcpy(*pErrorString, errorMessage.c_str(), errorMessageSize);
}
#endif
return res;
}
DLLEXPORT void __stdcall DebugSetMute() {}
DLLEXPORT IDirect3D8* __stdcall Direct3DCreate8(UINT nSDKVersion) {
IDirect3D8* pDirect3D = nullptr;
dxvk::CreateD3D8(&pDirect3D);
return pDirect3D;
}
}