From 34b1d13c29bf3d5f1488e430681d35cf426d36ba Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 7 Sep 2014 13:07:12 -0700 Subject: [PATCH] d3d: Release vertex decls on shutdown. --- GPU/Directx9/TransformPipelineDX9.cpp | 28 ++++++++++++++------------- GPU/Directx9/TransformPipelineDX9.h | 2 ++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/GPU/Directx9/TransformPipelineDX9.cpp b/GPU/Directx9/TransformPipelineDX9.cpp index 354b15d984..42f96f7bef 100644 --- a/GPU/Directx9/TransformPipelineDX9.cpp +++ b/GPU/Directx9/TransformPipelineDX9.cpp @@ -177,6 +177,10 @@ TransformDrawEngineDX9::~TransformDrawEngineDX9() { FreeMemoryPages(transformed, TRANSFORMED_VERTEX_BUFFER_SIZE); FreeMemoryPages(transformedExpanded, 3 * TRANSFORMED_VERTEX_BUFFER_SIZE); + for (auto decl = vertexDeclMap_.begin(); decl != vertexDeclMap_.end(); ++decl) { + decl->second->Release(); + } + delete [] quadIndices_; for (auto iter = decoderMap_.begin(); iter != decoderMap_.end(); iter++) { @@ -229,10 +233,6 @@ static void VertexAttribSetup(D3DVERTEXELEMENT9 * VertexElement, u8 fmt, u8 offs VertexElement->UsageIndex = usage_index; } -static IDirect3DVertexDeclaration9* pHardwareVertexDecl = NULL; -static std::map vertexDeclMap; -static D3DVERTEXELEMENT9 VertexElements[8]; - // TODO: Use VBO and get rid of the vertexData pointers - with that, we will supply only offsets static void LogDecFmtForDraw(const DecVtxFormat &decFmt) { // Vertices Elements orders @@ -269,12 +269,12 @@ static void LogDecFmtForDraw(const DecVtxFormat &decFmt) { //pD3Ddevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); } -static void SetupDecFmtForDraw(LinkedShaderDX9 *program, const DecVtxFormat &decFmt, u32 pspFmt) { - auto vertexDeclCached = vertexDeclMap.find(pspFmt); +IDirect3DVertexDeclaration9 *TransformDrawEngineDX9::SetupDecFmtForDraw(LinkedShaderDX9 *program, const DecVtxFormat &decFmt, u32 pspFmt) { + auto vertexDeclCached = vertexDeclMap_.find(pspFmt); - if (vertexDeclCached==vertexDeclMap.end()) { - D3DVERTEXELEMENT9 * VertexElement = &VertexElements[0]; - int offset = 0; + if (vertexDeclCached == vertexDeclMap_.end()) { + D3DVERTEXELEMENT9 VertexElements[8]; + D3DVERTEXELEMENT9 *VertexElement = &VertexElements[0]; // Vertices Elements orders // WEIGHT @@ -320,7 +320,8 @@ static void SetupDecFmtForDraw(LinkedShaderDX9 *program, const DecVtxFormat &dec D3DVERTEXELEMENT9 end = D3DDECL_END(); memcpy(VertexElement, &end, sizeof(D3DVERTEXELEMENT9)); - // Create declaration + // Create declaration + IDirect3DVertexDeclaration9 *pHardwareVertexDecl; HRESULT hr = pD3Ddevice->CreateVertexDeclaration( VertexElements, &pHardwareVertexDecl ); if (FAILED(hr)) { // Log @@ -329,10 +330,11 @@ static void SetupDecFmtForDraw(LinkedShaderDX9 *program, const DecVtxFormat &dec } // Add it to map - vertexDeclMap[pspFmt] = pHardwareVertexDecl; + vertexDeclMap_[pspFmt] = pHardwareVertexDecl; + return pHardwareVertexDecl; } else { // Set it from map - pHardwareVertexDecl = vertexDeclCached->second; + return vertexDeclCached->second; } } @@ -1218,7 +1220,7 @@ rotateVBO: DEBUG_LOG(G3D, "Flush prim %i! %i verts in one go", prim, vertexCount); - SetupDecFmtForDraw(program, dec_->GetDecVtxFmt(), dec_->VertexType()); + IDirect3DVertexDeclaration9 *pHardwareVertexDecl = SetupDecFmtForDraw(program, dec_->GetDecVtxFmt(), dec_->VertexType()); if (pHardwareVertexDecl) { pD3Ddevice->SetVertexDeclaration(pHardwareVertexDecl); diff --git a/GPU/Directx9/TransformPipelineDX9.h b/GPU/Directx9/TransformPipelineDX9.h index 77d1ab0d93..05760e5e2a 100644 --- a/GPU/Directx9/TransformPipelineDX9.h +++ b/GPU/Directx9/TransformPipelineDX9.h @@ -142,6 +142,7 @@ private: void SoftwareTransformAndDraw(int prim, u8 *decoded, LinkedShaderDX9 *program, int vertexCount, u32 vertexType, void *inds, int indexType, const DecVtxFormat &decVtxFormat, int maxIndex); void ApplyDrawState(int prim); bool IsReallyAClear(int numVerts) const; + IDirect3DVertexDeclaration9 *SetupDecFmtForDraw(LinkedShaderDX9 *program, const DecVtxFormat &decFmt, u32 pspFmt); // Preprocessing for spline/bezier u32 NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, VertexDecoderDX9 *dec, int lowerBound, int upperBound, u32 vertType); @@ -184,6 +185,7 @@ private: TransformedVertex *transformedExpanded; std::map vai_; + std::map vertexDeclMap_; // Fixed index buffer for easy quad generation from spline/bezier u16 *quadIndices_;