Skip to content

Commit

Permalink
[d3d9] COM Overhaul, fix memory/resource leaks in reset/deletion/stat…
Browse files Browse the repository at this point in the history
…eblocks

Fixes and matches ref-counting for device child resources to native d3d9.
Fixes memory and resource leaks in stateblocks, deletion and device resetting.
  • Loading branch information
Joshua-Ashton committed Dec 16, 2019
1 parent 8e7964e commit 2f2342e
Show file tree
Hide file tree
Showing 27 changed files with 196 additions and 150 deletions.
7 changes: 2 additions & 5 deletions src/d3d9/d3d9_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ namespace dxvk {

};

inline D3D9CommonBuffer* GetCommonBuffer(D3D9VertexBuffer* pResource) {
return pResource != nullptr ? pResource->GetCommonBuffer() : nullptr;
}

using D3D9IndexBufferBase = D3D9Buffer<IDirect3DIndexBuffer9>;
class D3D9IndexBuffer final : public D3D9IndexBufferBase {

Expand All @@ -88,7 +84,8 @@ namespace dxvk {

};

inline D3D9CommonBuffer* GetCommonBuffer(D3D9IndexBuffer* pResource) {
template <typename T>
inline D3D9CommonBuffer* GetCommonBuffer(const T& pResource) {
return pResource != nullptr ? pResource->GetCommonBuffer() : nullptr;
}

Expand Down
1 change: 1 addition & 0 deletions src/d3d9/d3d9_common_buffer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "d3d9_common_buffer.h"

#include "d3d9_device.h"
#include "d3d9_util.h"

namespace dxvk {
Expand Down
1 change: 1 addition & 0 deletions src/d3d9/d3d9_common_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../dxvk/dxvk_device.h"

#include "d3d9_device_child.h"
#include "d3d9_format.h"

namespace dxvk {

Expand Down
14 changes: 14 additions & 0 deletions src/d3d9/d3d9_common_texture.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "d3d9_common_texture.h"

#include "d3d9_util.h"
#include "d3d9_device.h"

#include <algorithm>

Expand Down Expand Up @@ -290,6 +292,18 @@ namespace dxvk {
}


void D3D9CommonTexture::RecreateSampledView(UINT Lod) {
// This will be a no-op for SYSTEMMEM types given we
// don't expose the cap to allow texturing with them.
if (unlikely(m_mapMode == D3D9_COMMON_TEXTURE_MAP_MODE_SYSTEMMEM))
return;

const D3D9_VK_FORMAT_MAPPING formatInfo = m_device->LookupFormat(m_desc.Format);

m_views.Sample = CreateColorViewPair(formatInfo, AllLayers, VK_IMAGE_USAGE_SAMPLED_BIT, Lod);
}


BOOL D3D9CommonTexture::DetermineShadowState() const {
static std::array<D3D9Format, 3> blacklist = {
D3D9Format::INTZ, D3D9Format::DF16, D3D9Format::DF24
Expand Down
16 changes: 5 additions & 11 deletions src/d3d9/d3d9_common_texture.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#pragma once

#include "d3d9_device.h"
#include "d3d9_format.h"
#include "d3d9_util.h"
#include "d3d9_caps.h"

#include "../dxvk/dxvk_device.h"

namespace dxvk {

class D3D9DeviceEx;

/**
* \brief Image memory mapping mode
*
Expand Down Expand Up @@ -300,16 +303,7 @@ namespace dxvk {
* Recreates the main view of the sampler w/ a specific LOD.
* SetLOD only works on MANAGED textures so this is A-okay.
*/
void RecreateSampledView(UINT Lod) {
// This will be a no-op for SYSTEMMEM types given we
// don't expose the cap to allow texturing with them.
if (unlikely(m_mapMode == D3D9_COMMON_TEXTURE_MAP_MODE_SYSTEMMEM))
return;

const D3D9_VK_FORMAT_MAPPING formatInfo = m_device->LookupFormat(m_desc.Format);

m_views.Sample = CreateColorViewPair(formatInfo, AllLayers, VK_IMAGE_USAGE_SAMPLED_BIT, Lod);
}
void RecreateSampledView(UINT Lod);

/**
* \brief Extent
Expand Down
2 changes: 2 additions & 0 deletions src/d3d9/d3d9_constant_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "d3d9_caps.h"

#include "../dxvk/dxvk_buffer.h"

#include "../dxso/dxso_isgn.h"

#include "../util/util_math.h"
Expand Down

0 comments on commit 2f2342e

Please sign in to comment.