Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use ComPtr for D3D9 #19413

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions Common/GPU/D3D9/D3D9ShaderCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
#include "Common/SysError.h"
#include "Common/Log.h"
#include "Common/StringUtils.h"
#include <wrl/client.h>

using namespace Microsoft::WRL;

struct ID3DXConstantTable;

LPD3DBLOB CompileShaderToByteCodeD3D9(const char *code, const char *target, std::string *errorMessage) {
LPD3DBLOB pShaderCode = nullptr;
LPD3DBLOB pErrorMsg = nullptr;
ComPtr<ID3DBlob> pShaderCode;
ComPtr<ID3DBlob> pErrorMsg;

// Compile pixel shader.
HRESULT hr = dyn_D3DCompile(code,
Expand All @@ -34,43 +37,31 @@ LPD3DBLOB CompileShaderToByteCodeD3D9(const char *code, const char *target, std:

OutputDebugStringUTF8(LineNumberString(std::string(code)).c_str());
OutputDebugStringUTF8(errorMessage->c_str());

pErrorMsg->Release();
if (pShaderCode) {
pShaderCode->Release();
pShaderCode = nullptr;
}
} else if (FAILED(hr)) {
*errorMessage = GetStringErrorMsg(hr);
if (pShaderCode) {
pShaderCode->Release();
pShaderCode = nullptr;
}
} else {
errorMessage->clear();
}

return pShaderCode;
return pShaderCode.Detach();
}

bool CompilePixelShaderD3D9(LPDIRECT3DDEVICE9 device, const char *code, LPDIRECT3DPIXELSHADER9 *pShader, std::string *errorMessage) {
LPD3DBLOB pShaderCode = CompileShaderToByteCodeD3D9(code, "ps_3_0", errorMessage);
ComPtr<ID3DBlob> pShaderCode = CompileShaderToByteCodeD3D9(code, "ps_3_0", errorMessage);
if (pShaderCode) {
// Create pixel shader.
device->CreatePixelShader((DWORD*)pShaderCode->GetBufferPointer(), pShader);
pShaderCode->Release();
return true;
} else {
return false;
}
}

bool CompileVertexShaderD3D9(LPDIRECT3DDEVICE9 device, const char *code, LPDIRECT3DVERTEXSHADER9 *pShader, std::string *errorMessage) {
LPD3DBLOB pShaderCode = CompileShaderToByteCodeD3D9(code, "vs_3_0", errorMessage);
ComPtr<ID3DBlob> pShaderCode = CompileShaderToByteCodeD3D9(code, "vs_3_0", errorMessage);
if (pShaderCode) {
// Create vertex shader.
device->CreateVertexShader((DWORD*)pShaderCode->GetBufferPointer(), pShader);
pShaderCode->Release();
return true;
} else {
return false;
Expand Down
5 changes: 3 additions & 2 deletions Common/GPU/D3D9/D3D9StateCache.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#ifdef _WIN32

#include "Common/GPU/D3D9/D3D9StateCache.h"
#include <wrl/client.h>

DirectXState dxstate;

LPDIRECT3DDEVICE9 pD3Ddevice9 = nullptr;
LPDIRECT3DDEVICE9EX pD3DdeviceEx9 = nullptr;
Microsoft::WRL::ComPtr<IDirect3DDevice9> pD3Ddevice9;
Microsoft::WRL::ComPtr<IDirect3DDevice9Ex> pD3DdeviceEx9;

int DirectXState::state_count = 0;

Expand Down
5 changes: 3 additions & 2 deletions Common/GPU/D3D9/D3D9StateCache.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#pragma once

#include <cstring>
#include <wrl/client.h>

#include "Common/GPU/D3D9/D3D9ShaderCompiler.h"

// TODO: Get rid of these somehow.
extern LPDIRECT3DDEVICE9 pD3Ddevice9;
extern LPDIRECT3DDEVICE9EX pD3DdeviceEx9;
extern Microsoft::WRL::ComPtr<IDirect3DDevice9> pD3Ddevice9;
extern Microsoft::WRL::ComPtr<IDirect3DDevice9Ex> pD3DdeviceEx9;

class DirectXState {
private:
Expand Down
Loading
Loading