Skip to content

Commit 12070ab

Browse files
[d3d8] Partially implement ValidateVertexShader/ValidatePixelShader
1 parent 86aeb5d commit 12070ab

File tree

1 file changed

+61
-15
lines changed

1 file changed

+61
-15
lines changed

src/d3d8/d3d8_main.cpp

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,38 @@ extern "C" {
1919
const D3DCAPS8* pCaps,
2020
BOOL errorReturn,
2121
char** pErrorString) {
22-
dxvk::Logger::warn("D3D8: ValidatePixelShader: Stub");
22+
const char* errorMessage = "";
23+
24+
if (unlikely(pPixelShader == nullptr)) {
25+
errorMessage = "D3D8: ValidatePixelShader: Null pPixelShader";
26+
} else {
27+
uint32_t majorVersion = (pPixelShader[0] >> 8) & 0xff;
28+
uint32_t minorVersion = pPixelShader[0] & 0xff;
29+
30+
if (unlikely(majorVersion != 1 || minorVersion > 4)) {
31+
errorMessage = dxvk::str::format("D3D8: ValidatePixelShader: Unsupported PS version ",
32+
majorVersion, ".", minorVersion).c_str();
33+
} else if (unlikely(pCaps && pPixelShader[0] > pCaps->PixelShaderVersion)) {
34+
errorMessage = dxvk::str::format("D3D8: ValidatePixelShader: Caps: Unsupported PS version ",
35+
majorVersion, ".", minorVersion).c_str();
36+
}
37+
}
2338

24-
if (unlikely(pPixelShader == nullptr))
25-
return E_FAIL;
39+
const size_t errorMessageSize = strlen(errorMessage) + 1;
40+
41+
#ifdef _WIN32
42+
if (pErrorString != nullptr && errorReturn) {
43+
// Wine tests call HeapFree() on the returned error string,
44+
// so the expectation is for it to be allocated on the heap.
45+
*pErrorString = (char*) HeapAlloc(GetProcessHeap(), 0, errorMessageSize);
46+
if (*pErrorString)
47+
memcpy(*pErrorString, errorMessage, errorMessageSize);
48+
}
49+
#endif
2650

27-
if (errorReturn && pErrorString != nullptr) {
28-
const char* errorMessage = "";
29-
*pErrorString = (char *) errorMessage;
51+
if (errorMessageSize > 1) {
52+
dxvk::Logger::warn(errorMessage);
53+
return E_FAIL;
3054
}
3155

3256
return S_OK;
@@ -38,22 +62,44 @@ extern "C" {
3862
const D3DCAPS8* pCaps,
3963
BOOL errorReturn,
4064
char** pErrorString) {
41-
dxvk::Logger::warn("D3D8: ValidateVertexShader: Stub");
65+
const char* errorMessage = "";
66+
67+
if (unlikely(pVertexShader == nullptr)) {
68+
errorMessage = "D3D8: ValidateVertexShader: Null pVertexShader";
69+
} else {
70+
uint32_t majorVersion = (pVertexShader[0] >> 8) & 0xff;
71+
uint32_t minorVersion = pVertexShader[0] & 0xff;
72+
73+
if (unlikely(majorVersion != 1 || minorVersion > 1)) {
74+
errorMessage = dxvk::str::format("D3D8: ValidateVertexShader: Unsupported VS version ",
75+
majorVersion, ".", minorVersion).c_str();
76+
} else if (unlikely(pCaps && pVertexShader[0] > pCaps->VertexShaderVersion)) {
77+
errorMessage = dxvk::str::format("D3D8: ValidateVertexShader: Caps: Unsupported VS version ",
78+
majorVersion, ".", minorVersion).c_str();
79+
}
80+
}
4281

43-
if (unlikely(pVertexShader == nullptr))
44-
return E_FAIL;
82+
const size_t errorMessageSize = strlen(errorMessage) + 1;
4583

46-
if (errorReturn && pErrorString != nullptr) {
47-
const char* errorMessage = "";
48-
*pErrorString = (char *) errorMessage;
84+
#ifdef _WIN32
85+
if (pErrorString != nullptr && errorReturn) {
86+
// Wine tests call HeapFree() on the returned error string,
87+
// so the expectation is for it to be allocated on the heap.
88+
*pErrorString = (char*) HeapAlloc(GetProcessHeap(), 0, errorMessageSize);
89+
if (*pErrorString)
90+
memcpy(*pErrorString, errorMessage, errorMessageSize);
91+
}
92+
#endif
93+
94+
if (errorMessageSize > 1) {
95+
dxvk::Logger::warn(errorMessage);
96+
return E_FAIL;
4997
}
5098

5199
return S_OK;
52100
}
53101

54-
DLLEXPORT void __stdcall DebugSetMute() {
55-
dxvk::Logger::debug("D3D8: DebugSetMute: Stub");
56-
}
102+
DLLEXPORT void __stdcall DebugSetMute() {}
57103

58104
DLLEXPORT IDirect3D8* __stdcall Direct3DCreate8(UINT nSDKVersion) {
59105
IDirect3D8* pDirect3D = nullptr;

0 commit comments

Comments
 (0)