Removing XESAFERELEASE.

This commit is contained in:
Ben Vanik 2014-08-16 17:33:24 -07:00
parent 5b83cf5fd1
commit 187d0ad277
22 changed files with 70 additions and 83 deletions

View File

@ -162,7 +162,7 @@ void XAudio2AudioDriver::Shutdown() {
mastering_voice_ = NULL; mastering_voice_ = NULL;
audio_->StopEngine(); audio_->StopEngine();
XESAFERELEASE(audio_); audio_->Release();
delete voice_callback_; delete voice_callback_;
CloseHandle(wait_handle_); CloseHandle(wait_handle_);

View File

@ -29,7 +29,7 @@ D3D11IndexBufferResource::D3D11IndexBufferResource(
} }
D3D11IndexBufferResource::~D3D11IndexBufferResource() { D3D11IndexBufferResource::~D3D11IndexBufferResource() {
XESAFERELEASE(handle_); SafeRelease(handle_);
} }
int D3D11IndexBufferResource::CreateHandle() { int D3D11IndexBufferResource::CreateHandle() {
@ -95,7 +95,7 @@ D3D11VertexBufferResource::D3D11VertexBufferResource(
} }
D3D11VertexBufferResource::~D3D11VertexBufferResource() { D3D11VertexBufferResource::~D3D11VertexBufferResource() {
XESAFERELEASE(handle_); SafeRelease(handle_);
} }
int D3D11VertexBufferResource::CreateHandle() { int D3D11VertexBufferResource::CreateHandle() {

View File

@ -11,11 +11,9 @@
#define XENIA_GPU_D3D11_D3D11_BUFFER_RESOURCE_H_ #define XENIA_GPU_D3D11_D3D11_BUFFER_RESOURCE_H_
#include <xenia/gpu/buffer_resource.h> #include <xenia/gpu/buffer_resource.h>
#include <xenia/gpu/d3d11/d3d11_gpu-private.h>
#include <xenia/gpu/xenos/xenos.h> #include <xenia/gpu/xenos/xenos.h>
#include <d3d11.h>
namespace xe { namespace xe {
namespace gpu { namespace gpu {
namespace d3d11 { namespace d3d11 {

View File

@ -31,8 +31,8 @@ D3D11GeometryShader::D3D11GeometryShader(ID3D11Device* device)
} }
D3D11GeometryShader::~D3D11GeometryShader() { D3D11GeometryShader::~D3D11GeometryShader() {
XESAFERELEASE(handle_); SafeRelease(handle_);
XESAFERELEASE(device_); SafeRelease(device_);
} }
int D3D11GeometryShader::Prepare(D3D11VertexShaderResource* vertex_shader) { int D3D11GeometryShader::Prepare(D3D11VertexShaderResource* vertex_shader) {
@ -61,7 +61,7 @@ int D3D11GeometryShader::Prepare(D3D11VertexShaderResource* vertex_shader) {
byte_code = xe_malloc(byte_code_length); byte_code = xe_malloc(byte_code_length);
xe_copy_struct( xe_copy_struct(
byte_code, shader_blob->GetBufferPointer(), byte_code_length); byte_code, shader_blob->GetBufferPointer(), byte_code_length);
XESAFERELEASE(shader_blob); SafeRelease(shader_blob);
// Create shader. // Create shader.
HRESULT hr = device_->CreateGeometryShader( HRESULT hr = device_->CreateGeometryShader(
@ -124,7 +124,7 @@ ID3D10Blob* D3D11GeometryShader::Compile(const char* shader_source) {
char* msg = (char*)error_blob->GetBufferPointer(); char* msg = (char*)error_blob->GetBufferPointer();
XELOGE("D3D11: shader compile failed with %s", msg); XELOGE("D3D11: shader compile failed with %s", msg);
} }
XESAFERELEASE(error_blob); SafeRelease(error_blob);
if (FAILED(hr)) { if (FAILED(hr)) {
return NULL; return NULL;
} }

View File

@ -13,8 +13,7 @@
#include <xenia/core.h> #include <xenia/core.h>
#include <alloy/string_buffer.h> #include <alloy/string_buffer.h>
#include <xenia/gpu/d3d11/d3d11_gpu-private.h>
#include <d3d11.h>
namespace xe { namespace xe {

View File

@ -12,20 +12,23 @@
#include <xenia/core.h> #include <xenia/core.h>
#include <xenia/gpu/d3d11/d3d11_gpu.h> #include <d3d11.h>
#include <xenia/gpu/d3d11/d3d11_gpu.h>
namespace xe { namespace xe {
namespace gpu { namespace gpu {
namespace d3d11 { namespace d3d11 {
template <typename T>
void SafeRelease(T* ptr) {
if (ptr) {
ptr->Release();
}
}
} // namespace d3d11 } // namespace d3d11
} // namespace gpu } // namespace gpu
} // namespace xe } // namespace xe
#endif // XENIA_GPU_D3D11_D3D11_GPU_PRIVATE_H_ #endif // XENIA_GPU_D3D11_D3D11_GPU_PRIVATE_H_

View File

@ -67,29 +67,29 @@ D3D11GraphicsDriver::D3D11GraphicsDriver(
D3D11GraphicsDriver::~D3D11GraphicsDriver() { D3D11GraphicsDriver::~D3D11GraphicsDriver() {
RebuildRenderTargets(0, 0); RebuildRenderTargets(0, 0);
XESAFERELEASE(state_.constant_buffers.float_constants); SafeRelease(state_.constant_buffers.float_constants);
XESAFERELEASE(state_.constant_buffers.bool_constants); SafeRelease(state_.constant_buffers.bool_constants);
XESAFERELEASE(state_.constant_buffers.loop_constants); SafeRelease(state_.constant_buffers.loop_constants);
XESAFERELEASE(state_.constant_buffers.vs_consts); SafeRelease(state_.constant_buffers.vs_consts);
XESAFERELEASE(state_.constant_buffers.gs_consts); SafeRelease(state_.constant_buffers.gs_consts);
for (auto it = rasterizer_state_cache_.begin(); for (auto it = rasterizer_state_cache_.begin();
it != rasterizer_state_cache_.end(); ++it) { it != rasterizer_state_cache_.end(); ++it) {
XESAFERELEASE(it->second); SafeRelease(it->second);
} }
for (auto it = blend_state_cache_.begin(); for (auto it = blend_state_cache_.begin();
it != blend_state_cache_.end(); ++it) { it != blend_state_cache_.end(); ++it) {
XESAFERELEASE(it->second); SafeRelease(it->second);
} }
for (auto it = depth_stencil_state_cache_.begin(); for (auto it = depth_stencil_state_cache_.begin();
it != depth_stencil_state_cache_.end(); ++it) { it != depth_stencil_state_cache_.end(); ++it) {
XESAFERELEASE(it->second); SafeRelease(it->second);
} }
XESAFERELEASE(invalid_texture_view_); SafeRelease(invalid_texture_view_);
XESAFERELEASE(invalid_texture_sampler_state_); SafeRelease(invalid_texture_sampler_state_);
delete resource_cache_; delete resource_cache_;
XESAFERELEASE(context_); SafeRelease(context_);
XESAFERELEASE(device_); SafeRelease(device_);
XESAFERELEASE(swap_chain_); SafeRelease(swap_chain_);
} }
int D3D11GraphicsDriver::Initialize() { int D3D11GraphicsDriver::Initialize() {
@ -138,7 +138,7 @@ void D3D11GraphicsDriver::InitializeInvalidTexture() {
texture_view_desc.Texture2D.MostDetailedMip = 0; texture_view_desc.Texture2D.MostDetailedMip = 0;
hr = device_->CreateShaderResourceView( hr = device_->CreateShaderResourceView(
texture, &texture_view_desc, &invalid_texture_view_); texture, &texture_view_desc, &invalid_texture_view_);
XESAFERELEASE(texture); SafeRelease(texture);
D3D11_SAMPLER_DESC sampler_desc; D3D11_SAMPLER_DESC sampler_desc;
xe_zero_struct(&sampler_desc, sizeof(sampler_desc)); xe_zero_struct(&sampler_desc, sizeof(sampler_desc));
@ -826,12 +826,12 @@ int D3D11GraphicsDriver::RebuildRenderTargets(uint32_t width,
// Remove old versions. // Remove old versions.
for (int n = 0; n < XECOUNT(render_targets_.color_buffers); n++) { for (int n = 0; n < XECOUNT(render_targets_.color_buffers); n++) {
auto& cb = render_targets_.color_buffers[n]; auto& cb = render_targets_.color_buffers[n];
XESAFERELEASE(cb.buffer); SafeRelease(cb.buffer);
XESAFERELEASE(cb.color_view_8888); SafeRelease(cb.color_view_8888);
} }
XESAFERELEASE(render_targets_.depth_buffer); SafeRelease(render_targets_.depth_buffer);
XESAFERELEASE(render_targets_.depth_view_d28s8); SafeRelease(render_targets_.depth_view_d28s8);
XESAFERELEASE(render_targets_.depth_view_d28fs8); SafeRelease(render_targets_.depth_view_d28fs8);
render_targets_.width = width; render_targets_.width = width;
render_targets_.height = height; render_targets_.height = height;
@ -917,7 +917,7 @@ int D3D11GraphicsDriver::Resolve() {
} else { } else {
// TODO(benvanik): scale size using a quad draw. // TODO(benvanik): scale size using a quad draw.
} }
XESAFERELEASE(back_buffer); SafeRelease(back_buffer);
// TODO(benvanik): remove! // TODO(benvanik): remove!
float color[4] = { 0.5f, 0.5f, 0.0f, 1.0f }; float color[4] = { 0.5f, 0.5f, 0.0f, 1.0f };

View File

@ -17,8 +17,6 @@
#include <xenia/gpu/d3d11/d3d11_resource_cache.h> #include <xenia/gpu/d3d11/d3d11_resource_cache.h>
#include <xenia/gpu/xenos/xenos.h> #include <xenia/gpu/xenos/xenos.h>
#include <d3d11.h>
namespace xe { namespace xe {
namespace gpu { namespace gpu {

View File

@ -188,9 +188,9 @@ void D3D11GraphicsSystem::Shutdown() {
DeleteTimerQueueEx(timer_queue_, NULL); DeleteTimerQueueEx(timer_queue_, NULL);
} }
XESAFERELEASE(device_); SafeRelease(device_);
device_ = 0; device_ = 0;
XESAFERELEASE(dxgi_factory_); SafeRelease(dxgi_factory_);
dxgi_factory_ = 0; dxgi_factory_ = 0;
delete window_; delete window_;
window_ = 0; window_ = 0;

View File

@ -15,8 +15,6 @@
#include <xenia/gpu/graphics_system.h> #include <xenia/gpu/graphics_system.h>
#include <xenia/gpu/d3d11/d3d11_gpu-private.h> #include <xenia/gpu/d3d11/d3d11_gpu-private.h>
#include <d3d11.h>
namespace xe { namespace xe {
namespace gpu { namespace gpu {

View File

@ -369,7 +369,7 @@ bool D3D11ProfilerDisplay::SetupFont() {
texture_view_desc.Texture2D.MostDetailedMip = 0; texture_view_desc.Texture2D.MostDetailedMip = 0;
hr = device->CreateShaderResourceView( hr = device->CreateShaderResourceView(
font_texture, &texture_view_desc, &font_texture_view_); font_texture, &texture_view_desc, &font_texture_view_);
XESAFERELEASE(font_texture); SafeRelease(font_texture);
if (FAILED(hr)) { if (FAILED(hr)) {
XELOGE("Unable to create profiler font texture view"); XELOGE("Unable to create profiler font texture view");
return false; return false;
@ -403,15 +403,15 @@ bool D3D11ProfilerDisplay::SetupFont() {
} }
D3D11ProfilerDisplay::~D3D11ProfilerDisplay() { D3D11ProfilerDisplay::~D3D11ProfilerDisplay() {
XESAFERELEASE(blend_state_); SafeRelease(blend_state_);
XESAFERELEASE(depth_stencil_state_); SafeRelease(depth_stencil_state_);
XESAFERELEASE(vertex_shader_); SafeRelease(vertex_shader_);
XESAFERELEASE(pixel_shader_); SafeRelease(pixel_shader_);
XESAFERELEASE(shader_constants_); SafeRelease(shader_constants_);
XESAFERELEASE(shader_layout_); SafeRelease(shader_layout_);
XESAFERELEASE(font_texture_view_); SafeRelease(font_texture_view_);
XESAFERELEASE(font_sampler_state_); SafeRelease(font_sampler_state_);
XESAFERELEASE(vertex_buffer_); SafeRelease(vertex_buffer_);
} }
uint32_t D3D11ProfilerDisplay::width() const { uint32_t D3D11ProfilerDisplay::width() const {

View File

@ -11,8 +11,7 @@
#define XENIA_GPU_D3D11_D3D11_PROFILER_DISPLAY_H_ #define XENIA_GPU_D3D11_D3D11_PROFILER_DISPLAY_H_
#include <xenia/core.h> #include <xenia/core.h>
#include <xenia/gpu/d3d11/d3d11_gpu-private.h>
#include <d3d11.h>
namespace xe { namespace xe {

View File

@ -31,8 +31,8 @@ D3D11ResourceCache::D3D11ResourceCache(Memory* memory,
} }
D3D11ResourceCache::~D3D11ResourceCache() { D3D11ResourceCache::~D3D11ResourceCache() {
XESAFERELEASE(device_); SafeRelease(device_);
XESAFERELEASE(context_); SafeRelease(context_);
} }
VertexShaderResource* D3D11ResourceCache::CreateVertexShader( VertexShaderResource* D3D11ResourceCache::CreateVertexShader(

View File

@ -12,10 +12,9 @@
#include <xenia/core.h> #include <xenia/core.h>
#include <xenia/gpu/d3d11/d3d11_gpu-private.h>
#include <xenia/gpu/resource_cache.h> #include <xenia/gpu/resource_cache.h>
#include <d3d11.h>
namespace xe { namespace xe {
namespace gpu { namespace gpu {

View File

@ -27,7 +27,7 @@ D3D11SamplerStateResource::D3D11SamplerStateResource(
} }
D3D11SamplerStateResource::~D3D11SamplerStateResource() { D3D11SamplerStateResource::~D3D11SamplerStateResource() {
XESAFERELEASE(handle_); SafeRelease(handle_);
} }
int D3D11SamplerStateResource::Prepare() { int D3D11SamplerStateResource::Prepare() {

View File

@ -10,12 +10,11 @@
#ifndef XENIA_GPU_D3D11_D3D11_SAMPLER_STATE_RESOURCE_H_ #ifndef XENIA_GPU_D3D11_D3D11_SAMPLER_STATE_RESOURCE_H_
#define XENIA_GPU_D3D11_D3D11_SAMPLER_STATE_RESOURCE_H_ #define XENIA_GPU_D3D11_D3D11_SAMPLER_STATE_RESOURCE_H_
#include <xenia/gpu/d3d11/d3d11_gpu-private.h>
#include <xenia/gpu/sampler_state_resource.h> #include <xenia/gpu/sampler_state_resource.h>
#include <xenia/gpu/xenos/ucode.h> #include <xenia/gpu/xenos/ucode.h>
#include <xenia/gpu/xenos/xenos.h> #include <xenia/gpu/xenos/xenos.h>
#include <d3d11.h>
namespace xe { namespace xe {
namespace gpu { namespace gpu {

View File

@ -80,7 +80,7 @@ ID3D10Blob* D3D11ShaderCompile(XE_GPU_SHADER_TYPE type,
char* msg = (char*)error_blob->GetBufferPointer(); char* msg = (char*)error_blob->GetBufferPointer();
XELOGE("D3D11: shader compile failed with %s", msg); XELOGE("D3D11: shader compile failed with %s", msg);
} }
XESAFERELEASE(error_blob); SafeRelease(error_blob);
if (FAILED(hr)) { if (FAILED(hr)) {
return nullptr; return nullptr;
} }
@ -103,8 +103,8 @@ D3D11VertexShaderResource::D3D11VertexShaderResource(
} }
D3D11VertexShaderResource::~D3D11VertexShaderResource() { D3D11VertexShaderResource::~D3D11VertexShaderResource() {
XESAFERELEASE(handle_); SafeRelease(handle_);
XESAFERELEASE(input_layout_); SafeRelease(input_layout_);
for (int i = 0; i < XECOUNT(geometry_shaders_); ++i) { for (int i = 0; i < XECOUNT(geometry_shaders_); ++i) {
delete geometry_shaders_[i]; delete geometry_shaders_[i];
} }
@ -140,7 +140,7 @@ int D3D11VertexShaderResource::Prepare(
byte_code = xe_malloc(byte_code_length); byte_code = xe_malloc(byte_code_length);
xe_copy_struct( xe_copy_struct(
byte_code, shader_blob->GetBufferPointer(), byte_code_length); byte_code, shader_blob->GetBufferPointer(), byte_code_length);
XESAFERELEASE(shader_blob); SafeRelease(shader_blob);
// Create shader. // Create shader.
HRESULT hr = resource_cache_->device()->CreateVertexShader( HRESULT hr = resource_cache_->device()->CreateVertexShader(
@ -328,7 +328,7 @@ D3D11PixelShaderResource::D3D11PixelShaderResource(
} }
D3D11PixelShaderResource::~D3D11PixelShaderResource() { D3D11PixelShaderResource::~D3D11PixelShaderResource() {
XESAFERELEASE(handle_); SafeRelease(handle_);
xe_free(translated_src_); xe_free(translated_src_);
} }
@ -363,7 +363,7 @@ int D3D11PixelShaderResource::Prepare(const xe_gpu_program_cntl_t& program_cntl,
byte_code = xe_malloc(byte_code_length); byte_code = xe_malloc(byte_code_length);
xe_copy_struct( xe_copy_struct(
byte_code, shader_blob->GetBufferPointer(), byte_code_length); byte_code, shader_blob->GetBufferPointer(), byte_code_length);
XESAFERELEASE(shader_blob); SafeRelease(shader_blob);
// Create shader. // Create shader.
HRESULT hr = resource_cache_->device()->CreatePixelShader( HRESULT hr = resource_cache_->device()->CreatePixelShader(

View File

@ -30,8 +30,8 @@ D3D11TextureResource::D3D11TextureResource(
} }
D3D11TextureResource::~D3D11TextureResource() { D3D11TextureResource::~D3D11TextureResource() {
XESAFERELEASE(texture_); SafeRelease(texture_);
XESAFERELEASE(handle_); SafeRelease(handle_);
} }
int D3D11TextureResource::CreateHandle() { int D3D11TextureResource::CreateHandle() {

View File

@ -10,11 +10,10 @@
#ifndef XENIA_GPU_D3D11_D3D11_TEXTURE_RESOURCE_H_ #ifndef XENIA_GPU_D3D11_D3D11_TEXTURE_RESOURCE_H_
#define XENIA_GPU_D3D11_D3D11_TEXTURE_RESOURCE_H_ #define XENIA_GPU_D3D11_D3D11_TEXTURE_RESOURCE_H_
#include <xenia/gpu/d3d11/d3d11_gpu-private.h>
#include <xenia/gpu/texture_resource.h> #include <xenia/gpu/texture_resource.h>
#include <xenia/gpu/xenos/xenos.h> #include <xenia/gpu/xenos/xenos.h>
#include <d3d11.h>
namespace xe { namespace xe {
namespace gpu { namespace gpu {

View File

@ -42,11 +42,11 @@ D3D11Window::~D3D11Window() {
if (context_) { if (context_) {
context_->ClearState(); context_->ClearState();
} }
XESAFERELEASE(render_target_view_); SafeRelease(render_target_view_);
XESAFERELEASE(context_); SafeRelease(context_);
XESAFERELEASE(swap_chain_); SafeRelease(swap_chain_);
XESAFERELEASE(device_); SafeRelease(device_);
XESAFERELEASE(dxgi_factory_); SafeRelease(dxgi_factory_);
} }
int D3D11Window::Initialize(const std::wstring& title, uint32_t width, int D3D11Window::Initialize(const std::wstring& title, uint32_t width,

View File

@ -12,10 +12,9 @@
#include <xenia/core.h> #include <xenia/core.h>
#include <xenia/gpu/d3d11/d3d11_gpu-private.h>
#include <xenia/ui/win32/win32_window.h> #include <xenia/ui/win32/win32_window.h>
#include <d3d11.h>
namespace xe { namespace xe {
namespace gpu { namespace gpu {

View File

@ -91,10 +91,6 @@ typedef XECACHEALIGN volatile void xe_aligned_void_t;
#define XECOUNT(array) (sizeof(array) / sizeof(array[0])) #define XECOUNT(array) (sizeof(array) / sizeof(array[0]))
#endif // MSVC #endif // MSVC
#if XE_PLATFORM_WIN32
#define XESAFERELEASE(p) if (p) { p->Release(); }
#endif // WIN32
#define XEFAIL() goto XECLEANUP #define XEFAIL() goto XECLEANUP
#define XEEXPECT(expr) if (!(expr) ) { goto XECLEANUP; } #define XEEXPECT(expr) if (!(expr) ) { goto XECLEANUP; }
#define XEEXPECTTRUE(expr) if (!(expr) ) { goto XECLEANUP; } #define XEEXPECTTRUE(expr) if (!(expr) ) { goto XECLEANUP; }