From 187d0ad2772be088460ecfa3774a1f2360069f94 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sat, 16 Aug 2014 17:33:24 -0700 Subject: [PATCH] Removing XESAFERELEASE. --- src/xenia/apu/xaudio2/xaudio2_audio_driver.cc | 2 +- src/xenia/gpu/d3d11/d3d11_buffer_resource.cc | 4 +- src/xenia/gpu/d3d11/d3d11_buffer_resource.h | 4 +- src/xenia/gpu/d3d11/d3d11_geometry_shader.cc | 8 ++-- src/xenia/gpu/d3d11/d3d11_geometry_shader.h | 3 +- src/xenia/gpu/d3d11/d3d11_gpu-private.h | 13 +++--- src/xenia/gpu/d3d11/d3d11_graphics_driver.cc | 40 +++++++++---------- src/xenia/gpu/d3d11/d3d11_graphics_driver.h | 2 - src/xenia/gpu/d3d11/d3d11_graphics_system.cc | 4 +- src/xenia/gpu/d3d11/d3d11_graphics_system.h | 2 - src/xenia/gpu/d3d11/d3d11_profiler_display.cc | 20 +++++----- src/xenia/gpu/d3d11/d3d11_profiler_display.h | 3 +- src/xenia/gpu/d3d11/d3d11_resource_cache.cc | 4 +- src/xenia/gpu/d3d11/d3d11_resource_cache.h | 3 +- .../gpu/d3d11/d3d11_sampler_state_resource.cc | 2 +- .../gpu/d3d11/d3d11_sampler_state_resource.h | 3 +- src/xenia/gpu/d3d11/d3d11_shader_resource.cc | 12 +++--- src/xenia/gpu/d3d11/d3d11_texture_resource.cc | 4 +- src/xenia/gpu/d3d11/d3d11_texture_resource.h | 3 +- src/xenia/gpu/d3d11/d3d11_window.cc | 10 ++--- src/xenia/gpu/d3d11/d3d11_window.h | 3 +- src/xenia/types.h | 4 -- 22 files changed, 70 insertions(+), 83 deletions(-) diff --git a/src/xenia/apu/xaudio2/xaudio2_audio_driver.cc b/src/xenia/apu/xaudio2/xaudio2_audio_driver.cc index 4360ad5f5..e81140463 100644 --- a/src/xenia/apu/xaudio2/xaudio2_audio_driver.cc +++ b/src/xenia/apu/xaudio2/xaudio2_audio_driver.cc @@ -162,7 +162,7 @@ void XAudio2AudioDriver::Shutdown() { mastering_voice_ = NULL; audio_->StopEngine(); - XESAFERELEASE(audio_); + audio_->Release(); delete voice_callback_; CloseHandle(wait_handle_); diff --git a/src/xenia/gpu/d3d11/d3d11_buffer_resource.cc b/src/xenia/gpu/d3d11/d3d11_buffer_resource.cc index 1bb28f81f..9f05c7ec9 100644 --- a/src/xenia/gpu/d3d11/d3d11_buffer_resource.cc +++ b/src/xenia/gpu/d3d11/d3d11_buffer_resource.cc @@ -29,7 +29,7 @@ D3D11IndexBufferResource::D3D11IndexBufferResource( } D3D11IndexBufferResource::~D3D11IndexBufferResource() { - XESAFERELEASE(handle_); + SafeRelease(handle_); } int D3D11IndexBufferResource::CreateHandle() { @@ -95,7 +95,7 @@ D3D11VertexBufferResource::D3D11VertexBufferResource( } D3D11VertexBufferResource::~D3D11VertexBufferResource() { - XESAFERELEASE(handle_); + SafeRelease(handle_); } int D3D11VertexBufferResource::CreateHandle() { diff --git a/src/xenia/gpu/d3d11/d3d11_buffer_resource.h b/src/xenia/gpu/d3d11/d3d11_buffer_resource.h index 2e8071ae1..1860c2e07 100644 --- a/src/xenia/gpu/d3d11/d3d11_buffer_resource.h +++ b/src/xenia/gpu/d3d11/d3d11_buffer_resource.h @@ -11,11 +11,9 @@ #define XENIA_GPU_D3D11_D3D11_BUFFER_RESOURCE_H_ #include +#include #include -#include - - namespace xe { namespace gpu { namespace d3d11 { diff --git a/src/xenia/gpu/d3d11/d3d11_geometry_shader.cc b/src/xenia/gpu/d3d11/d3d11_geometry_shader.cc index 42660b462..e59f9823b 100644 --- a/src/xenia/gpu/d3d11/d3d11_geometry_shader.cc +++ b/src/xenia/gpu/d3d11/d3d11_geometry_shader.cc @@ -31,8 +31,8 @@ D3D11GeometryShader::D3D11GeometryShader(ID3D11Device* device) } D3D11GeometryShader::~D3D11GeometryShader() { - XESAFERELEASE(handle_); - XESAFERELEASE(device_); + SafeRelease(handle_); + SafeRelease(device_); } int D3D11GeometryShader::Prepare(D3D11VertexShaderResource* vertex_shader) { @@ -61,7 +61,7 @@ int D3D11GeometryShader::Prepare(D3D11VertexShaderResource* vertex_shader) { byte_code = xe_malloc(byte_code_length); xe_copy_struct( byte_code, shader_blob->GetBufferPointer(), byte_code_length); - XESAFERELEASE(shader_blob); + SafeRelease(shader_blob); // Create shader. HRESULT hr = device_->CreateGeometryShader( @@ -124,7 +124,7 @@ ID3D10Blob* D3D11GeometryShader::Compile(const char* shader_source) { char* msg = (char*)error_blob->GetBufferPointer(); XELOGE("D3D11: shader compile failed with %s", msg); } - XESAFERELEASE(error_blob); + SafeRelease(error_blob); if (FAILED(hr)) { return NULL; } diff --git a/src/xenia/gpu/d3d11/d3d11_geometry_shader.h b/src/xenia/gpu/d3d11/d3d11_geometry_shader.h index 89529b2a4..7e519f236 100644 --- a/src/xenia/gpu/d3d11/d3d11_geometry_shader.h +++ b/src/xenia/gpu/d3d11/d3d11_geometry_shader.h @@ -13,8 +13,7 @@ #include #include - -#include +#include namespace xe { diff --git a/src/xenia/gpu/d3d11/d3d11_gpu-private.h b/src/xenia/gpu/d3d11/d3d11_gpu-private.h index 7032de896..924e4b144 100644 --- a/src/xenia/gpu/d3d11/d3d11_gpu-private.h +++ b/src/xenia/gpu/d3d11/d3d11_gpu-private.h @@ -12,20 +12,23 @@ #include -#include +#include +#include namespace xe { namespace gpu { namespace d3d11 { - - - +template +void SafeRelease(T* ptr) { + if (ptr) { + ptr->Release(); + } +} } // namespace d3d11 } // namespace gpu } // namespace xe - #endif // XENIA_GPU_D3D11_D3D11_GPU_PRIVATE_H_ diff --git a/src/xenia/gpu/d3d11/d3d11_graphics_driver.cc b/src/xenia/gpu/d3d11/d3d11_graphics_driver.cc index 78e5d703d..31c38880a 100644 --- a/src/xenia/gpu/d3d11/d3d11_graphics_driver.cc +++ b/src/xenia/gpu/d3d11/d3d11_graphics_driver.cc @@ -67,29 +67,29 @@ D3D11GraphicsDriver::D3D11GraphicsDriver( D3D11GraphicsDriver::~D3D11GraphicsDriver() { RebuildRenderTargets(0, 0); - XESAFERELEASE(state_.constant_buffers.float_constants); - XESAFERELEASE(state_.constant_buffers.bool_constants); - XESAFERELEASE(state_.constant_buffers.loop_constants); - XESAFERELEASE(state_.constant_buffers.vs_consts); - XESAFERELEASE(state_.constant_buffers.gs_consts); + SafeRelease(state_.constant_buffers.float_constants); + SafeRelease(state_.constant_buffers.bool_constants); + SafeRelease(state_.constant_buffers.loop_constants); + SafeRelease(state_.constant_buffers.vs_consts); + SafeRelease(state_.constant_buffers.gs_consts); for (auto it = rasterizer_state_cache_.begin(); it != rasterizer_state_cache_.end(); ++it) { - XESAFERELEASE(it->second); + SafeRelease(it->second); } for (auto it = blend_state_cache_.begin(); it != blend_state_cache_.end(); ++it) { - XESAFERELEASE(it->second); + SafeRelease(it->second); } for (auto it = depth_stencil_state_cache_.begin(); it != depth_stencil_state_cache_.end(); ++it) { - XESAFERELEASE(it->second); + SafeRelease(it->second); } - XESAFERELEASE(invalid_texture_view_); - XESAFERELEASE(invalid_texture_sampler_state_); + SafeRelease(invalid_texture_view_); + SafeRelease(invalid_texture_sampler_state_); delete resource_cache_; - XESAFERELEASE(context_); - XESAFERELEASE(device_); - XESAFERELEASE(swap_chain_); + SafeRelease(context_); + SafeRelease(device_); + SafeRelease(swap_chain_); } int D3D11GraphicsDriver::Initialize() { @@ -138,7 +138,7 @@ void D3D11GraphicsDriver::InitializeInvalidTexture() { texture_view_desc.Texture2D.MostDetailedMip = 0; hr = device_->CreateShaderResourceView( texture, &texture_view_desc, &invalid_texture_view_); - XESAFERELEASE(texture); + SafeRelease(texture); D3D11_SAMPLER_DESC sampler_desc; xe_zero_struct(&sampler_desc, sizeof(sampler_desc)); @@ -826,12 +826,12 @@ int D3D11GraphicsDriver::RebuildRenderTargets(uint32_t width, // Remove old versions. for (int n = 0; n < XECOUNT(render_targets_.color_buffers); n++) { auto& cb = render_targets_.color_buffers[n]; - XESAFERELEASE(cb.buffer); - XESAFERELEASE(cb.color_view_8888); + SafeRelease(cb.buffer); + SafeRelease(cb.color_view_8888); } - XESAFERELEASE(render_targets_.depth_buffer); - XESAFERELEASE(render_targets_.depth_view_d28s8); - XESAFERELEASE(render_targets_.depth_view_d28fs8); + SafeRelease(render_targets_.depth_buffer); + SafeRelease(render_targets_.depth_view_d28s8); + SafeRelease(render_targets_.depth_view_d28fs8); render_targets_.width = width; render_targets_.height = height; @@ -917,7 +917,7 @@ int D3D11GraphicsDriver::Resolve() { } else { // TODO(benvanik): scale size using a quad draw. } - XESAFERELEASE(back_buffer); + SafeRelease(back_buffer); // TODO(benvanik): remove! float color[4] = { 0.5f, 0.5f, 0.0f, 1.0f }; diff --git a/src/xenia/gpu/d3d11/d3d11_graphics_driver.h b/src/xenia/gpu/d3d11/d3d11_graphics_driver.h index 2d23b142f..568d08478 100644 --- a/src/xenia/gpu/d3d11/d3d11_graphics_driver.h +++ b/src/xenia/gpu/d3d11/d3d11_graphics_driver.h @@ -17,8 +17,6 @@ #include #include -#include - namespace xe { namespace gpu { diff --git a/src/xenia/gpu/d3d11/d3d11_graphics_system.cc b/src/xenia/gpu/d3d11/d3d11_graphics_system.cc index e6fb9454f..9942ce0b6 100644 --- a/src/xenia/gpu/d3d11/d3d11_graphics_system.cc +++ b/src/xenia/gpu/d3d11/d3d11_graphics_system.cc @@ -188,9 +188,9 @@ void D3D11GraphicsSystem::Shutdown() { DeleteTimerQueueEx(timer_queue_, NULL); } - XESAFERELEASE(device_); + SafeRelease(device_); device_ = 0; - XESAFERELEASE(dxgi_factory_); + SafeRelease(dxgi_factory_); dxgi_factory_ = 0; delete window_; window_ = 0; diff --git a/src/xenia/gpu/d3d11/d3d11_graphics_system.h b/src/xenia/gpu/d3d11/d3d11_graphics_system.h index 7bd641667..487e21821 100644 --- a/src/xenia/gpu/d3d11/d3d11_graphics_system.h +++ b/src/xenia/gpu/d3d11/d3d11_graphics_system.h @@ -15,8 +15,6 @@ #include #include -#include - namespace xe { namespace gpu { diff --git a/src/xenia/gpu/d3d11/d3d11_profiler_display.cc b/src/xenia/gpu/d3d11/d3d11_profiler_display.cc index 3fed309e0..9d0bcde7f 100644 --- a/src/xenia/gpu/d3d11/d3d11_profiler_display.cc +++ b/src/xenia/gpu/d3d11/d3d11_profiler_display.cc @@ -369,7 +369,7 @@ bool D3D11ProfilerDisplay::SetupFont() { texture_view_desc.Texture2D.MostDetailedMip = 0; hr = device->CreateShaderResourceView( font_texture, &texture_view_desc, &font_texture_view_); - XESAFERELEASE(font_texture); + SafeRelease(font_texture); if (FAILED(hr)) { XELOGE("Unable to create profiler font texture view"); return false; @@ -403,15 +403,15 @@ bool D3D11ProfilerDisplay::SetupFont() { } D3D11ProfilerDisplay::~D3D11ProfilerDisplay() { - XESAFERELEASE(blend_state_); - XESAFERELEASE(depth_stencil_state_); - XESAFERELEASE(vertex_shader_); - XESAFERELEASE(pixel_shader_); - XESAFERELEASE(shader_constants_); - XESAFERELEASE(shader_layout_); - XESAFERELEASE(font_texture_view_); - XESAFERELEASE(font_sampler_state_); - XESAFERELEASE(vertex_buffer_); + SafeRelease(blend_state_); + SafeRelease(depth_stencil_state_); + SafeRelease(vertex_shader_); + SafeRelease(pixel_shader_); + SafeRelease(shader_constants_); + SafeRelease(shader_layout_); + SafeRelease(font_texture_view_); + SafeRelease(font_sampler_state_); + SafeRelease(vertex_buffer_); } uint32_t D3D11ProfilerDisplay::width() const { diff --git a/src/xenia/gpu/d3d11/d3d11_profiler_display.h b/src/xenia/gpu/d3d11/d3d11_profiler_display.h index fd9f970f9..24489f8b7 100644 --- a/src/xenia/gpu/d3d11/d3d11_profiler_display.h +++ b/src/xenia/gpu/d3d11/d3d11_profiler_display.h @@ -11,8 +11,7 @@ #define XENIA_GPU_D3D11_D3D11_PROFILER_DISPLAY_H_ #include - -#include +#include namespace xe { diff --git a/src/xenia/gpu/d3d11/d3d11_resource_cache.cc b/src/xenia/gpu/d3d11/d3d11_resource_cache.cc index 145e3d395..aaab4148e 100644 --- a/src/xenia/gpu/d3d11/d3d11_resource_cache.cc +++ b/src/xenia/gpu/d3d11/d3d11_resource_cache.cc @@ -31,8 +31,8 @@ D3D11ResourceCache::D3D11ResourceCache(Memory* memory, } D3D11ResourceCache::~D3D11ResourceCache() { - XESAFERELEASE(device_); - XESAFERELEASE(context_); + SafeRelease(device_); + SafeRelease(context_); } VertexShaderResource* D3D11ResourceCache::CreateVertexShader( diff --git a/src/xenia/gpu/d3d11/d3d11_resource_cache.h b/src/xenia/gpu/d3d11/d3d11_resource_cache.h index 27248eb9c..064d6ca46 100644 --- a/src/xenia/gpu/d3d11/d3d11_resource_cache.h +++ b/src/xenia/gpu/d3d11/d3d11_resource_cache.h @@ -12,10 +12,9 @@ #include +#include #include -#include - namespace xe { namespace gpu { diff --git a/src/xenia/gpu/d3d11/d3d11_sampler_state_resource.cc b/src/xenia/gpu/d3d11/d3d11_sampler_state_resource.cc index 7fb09858a..1f9971ae4 100644 --- a/src/xenia/gpu/d3d11/d3d11_sampler_state_resource.cc +++ b/src/xenia/gpu/d3d11/d3d11_sampler_state_resource.cc @@ -27,7 +27,7 @@ D3D11SamplerStateResource::D3D11SamplerStateResource( } D3D11SamplerStateResource::~D3D11SamplerStateResource() { - XESAFERELEASE(handle_); + SafeRelease(handle_); } int D3D11SamplerStateResource::Prepare() { diff --git a/src/xenia/gpu/d3d11/d3d11_sampler_state_resource.h b/src/xenia/gpu/d3d11/d3d11_sampler_state_resource.h index 6097339b4..35447dbc9 100644 --- a/src/xenia/gpu/d3d11/d3d11_sampler_state_resource.h +++ b/src/xenia/gpu/d3d11/d3d11_sampler_state_resource.h @@ -10,12 +10,11 @@ #ifndef XENIA_GPU_D3D11_D3D11_SAMPLER_STATE_RESOURCE_H_ #define XENIA_GPU_D3D11_D3D11_SAMPLER_STATE_RESOURCE_H_ +#include #include #include #include -#include - namespace xe { namespace gpu { diff --git a/src/xenia/gpu/d3d11/d3d11_shader_resource.cc b/src/xenia/gpu/d3d11/d3d11_shader_resource.cc index a2371a282..ed95ee39b 100644 --- a/src/xenia/gpu/d3d11/d3d11_shader_resource.cc +++ b/src/xenia/gpu/d3d11/d3d11_shader_resource.cc @@ -80,7 +80,7 @@ ID3D10Blob* D3D11ShaderCompile(XE_GPU_SHADER_TYPE type, char* msg = (char*)error_blob->GetBufferPointer(); XELOGE("D3D11: shader compile failed with %s", msg); } - XESAFERELEASE(error_blob); + SafeRelease(error_blob); if (FAILED(hr)) { return nullptr; } @@ -103,8 +103,8 @@ D3D11VertexShaderResource::D3D11VertexShaderResource( } D3D11VertexShaderResource::~D3D11VertexShaderResource() { - XESAFERELEASE(handle_); - XESAFERELEASE(input_layout_); + SafeRelease(handle_); + SafeRelease(input_layout_); for (int i = 0; i < XECOUNT(geometry_shaders_); ++i) { delete geometry_shaders_[i]; } @@ -140,7 +140,7 @@ int D3D11VertexShaderResource::Prepare( byte_code = xe_malloc(byte_code_length); xe_copy_struct( byte_code, shader_blob->GetBufferPointer(), byte_code_length); - XESAFERELEASE(shader_blob); + SafeRelease(shader_blob); // Create shader. HRESULT hr = resource_cache_->device()->CreateVertexShader( @@ -328,7 +328,7 @@ D3D11PixelShaderResource::D3D11PixelShaderResource( } D3D11PixelShaderResource::~D3D11PixelShaderResource() { - XESAFERELEASE(handle_); + SafeRelease(handle_); 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); xe_copy_struct( byte_code, shader_blob->GetBufferPointer(), byte_code_length); - XESAFERELEASE(shader_blob); + SafeRelease(shader_blob); // Create shader. HRESULT hr = resource_cache_->device()->CreatePixelShader( diff --git a/src/xenia/gpu/d3d11/d3d11_texture_resource.cc b/src/xenia/gpu/d3d11/d3d11_texture_resource.cc index 301638ffd..201d86f56 100644 --- a/src/xenia/gpu/d3d11/d3d11_texture_resource.cc +++ b/src/xenia/gpu/d3d11/d3d11_texture_resource.cc @@ -30,8 +30,8 @@ D3D11TextureResource::D3D11TextureResource( } D3D11TextureResource::~D3D11TextureResource() { - XESAFERELEASE(texture_); - XESAFERELEASE(handle_); + SafeRelease(texture_); + SafeRelease(handle_); } int D3D11TextureResource::CreateHandle() { diff --git a/src/xenia/gpu/d3d11/d3d11_texture_resource.h b/src/xenia/gpu/d3d11/d3d11_texture_resource.h index 4e59662a4..9ca3bd0e5 100644 --- a/src/xenia/gpu/d3d11/d3d11_texture_resource.h +++ b/src/xenia/gpu/d3d11/d3d11_texture_resource.h @@ -10,11 +10,10 @@ #ifndef XENIA_GPU_D3D11_D3D11_TEXTURE_RESOURCE_H_ #define XENIA_GPU_D3D11_D3D11_TEXTURE_RESOURCE_H_ +#include #include #include -#include - namespace xe { namespace gpu { diff --git a/src/xenia/gpu/d3d11/d3d11_window.cc b/src/xenia/gpu/d3d11/d3d11_window.cc index 7b4fa5cbd..192e87225 100644 --- a/src/xenia/gpu/d3d11/d3d11_window.cc +++ b/src/xenia/gpu/d3d11/d3d11_window.cc @@ -42,11 +42,11 @@ D3D11Window::~D3D11Window() { if (context_) { context_->ClearState(); } - XESAFERELEASE(render_target_view_); - XESAFERELEASE(context_); - XESAFERELEASE(swap_chain_); - XESAFERELEASE(device_); - XESAFERELEASE(dxgi_factory_); + SafeRelease(render_target_view_); + SafeRelease(context_); + SafeRelease(swap_chain_); + SafeRelease(device_); + SafeRelease(dxgi_factory_); } int D3D11Window::Initialize(const std::wstring& title, uint32_t width, diff --git a/src/xenia/gpu/d3d11/d3d11_window.h b/src/xenia/gpu/d3d11/d3d11_window.h index 888a797ae..8c6d92052 100644 --- a/src/xenia/gpu/d3d11/d3d11_window.h +++ b/src/xenia/gpu/d3d11/d3d11_window.h @@ -12,10 +12,9 @@ #include +#include #include -#include - namespace xe { namespace gpu { diff --git a/src/xenia/types.h b/src/xenia/types.h index f664e6d12..3d4209a24 100644 --- a/src/xenia/types.h +++ b/src/xenia/types.h @@ -91,10 +91,6 @@ typedef XECACHEALIGN volatile void xe_aligned_void_t; #define XECOUNT(array) (sizeof(array) / sizeof(array[0])) #endif // MSVC -#if XE_PLATFORM_WIN32 -#define XESAFERELEASE(p) if (p) { p->Release(); } -#endif // WIN32 - #define XEFAIL() goto XECLEANUP #define XEEXPECT(expr) if (!(expr) ) { goto XECLEANUP; } #define XEEXPECTTRUE(expr) if (!(expr) ) { goto XECLEANUP; }