Skip to content

Commit

Permalink
[d3d9] Fix reference leak in ProcessVertices
Browse files Browse the repository at this point in the history
Also fixes a Wine test.
  • Loading branch information
K0bin committed Mar 7, 2024
1 parent e3c9ab4 commit 75e2f94
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
12 changes: 6 additions & 6 deletions src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2938,13 +2938,13 @@ namespace dxvk {
slice = slice.subSlice(offset, slice.length() - offset);

EmitCs([this,
cDecl = ref(decl),
cVertexCount = VertexCount,
cStartIndex = SrcStartIndex,
cInstanceCount = GetInstanceCount(),
cBufferSlice = slice
cVertexElements = decl->GetElements(),
cVertexCount = VertexCount,
cStartIndex = SrcStartIndex,
cInstanceCount = GetInstanceCount(),
cBufferSlice = slice
](DxvkContext* ctx) mutable {
Rc<DxvkShader> shader = m_swvpEmulator.GetShaderModule(this, cDecl);
Rc<DxvkShader> shader = m_swvpEmulator.GetShaderModule(this, cVertexElements);

auto drawInfo = GenerateDrawInfo(D3DPT_POINTLIST, cVertexCount, cInstanceCount);

Expand Down
21 changes: 13 additions & 8 deletions src/d3d9/d3d9_swvp_emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace dxvk {
m_module.opLabel(m_module.allocateId());
}

void compile(const D3D9VertexDecl* pDecl) {
void compile(const D3D9VertexElements& elements) {
uint32_t uint_t = m_module.defIntType(32, false);
uint32_t float_t = m_module.defFloatType(32);
uint32_t vec4_t = m_module.defVectorType(float_t, 4);
Expand Down Expand Up @@ -142,15 +142,22 @@ namespace dxvk {
m_module.decorateBuiltIn(primitiveIdPtr, spv::BuiltInPrimitiveId);

uint32_t primitiveId = m_module.opLoad(uint_t, primitiveIdPtr);

// The size of any given vertex
uint32_t vertexSize = m_module.constu32(pDecl->GetSize(0) / sizeof(uint32_t));
uint32_t size = 0;
for (const auto& element : elements) {
if (element.Stream == 0 && element.Type != D3DDECLTYPE_UNUSED) {
size = std::max(size, element.Offset + GetDecltypeSize(D3DDECLTYPE(element.Type)));
}
}

uint32_t vertexSize = m_module.constu32(size / sizeof(uint32_t));

//The offset of this vertex from the beginning of the buffer
uint32_t thisVertexOffset = m_module.opIMul(uint_t, vertexSize, primitiveId);


for (auto& element : pDecl->GetElements()) {
for (auto& element : elements) {
// Load the slot associated with this element
DxsoSemantic semantic = { DxsoUsage(element.Usage), element.UsageIndex };

Expand Down Expand Up @@ -297,9 +304,7 @@ namespace dxvk {

};

Rc<DxvkShader> D3D9SWVPEmulator::GetShaderModule(D3D9DeviceEx* pDevice, const D3D9VertexDecl* pDecl) {
auto& elements = pDecl->GetElements();

Rc<DxvkShader> D3D9SWVPEmulator::GetShaderModule(D3D9DeviceEx* pDevice, const D3D9VertexElements& elements) {
// Use the shader's unique key for the lookup
{ std::unique_lock<dxvk::mutex> lock(m_mutex);

Expand All @@ -317,7 +322,7 @@ namespace dxvk {
// This shader has not been compiled yet, so we have to create a
// new module. This takes a while, so we won't lock the structure.
D3D9SWVPEmulatorGenerator generator(name);
generator.compile(pDecl);
generator.compile(elements);
Rc<DxvkShader> shader = generator.finalize();

shader->setShaderKey(key);
Expand Down
2 changes: 1 addition & 1 deletion src/d3d9/d3d9_swvp_emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace dxvk {

public:

Rc<DxvkShader> GetShaderModule(D3D9DeviceEx* pDevice, const D3D9VertexDecl* pDecl);
Rc<DxvkShader> GetShaderModule(D3D9DeviceEx* pDevice, const D3D9VertexElements& elements);

private:

Expand Down

0 comments on commit 75e2f94

Please sign in to comment.