[d3d9] Fix reference leak in ProcessVertices

Also fixes a Wine test.
This commit is contained in:
Robin Kertels 2024-03-07 19:17:54 +01:00
parent 807c1075bd
commit 76777ece73
No known key found for this signature in database
GPG Key ID: 3824904F14D40757
3 changed files with 20 additions and 15 deletions

View File

@ -2947,13 +2947,13 @@ namespace dxvk {
slice = slice.subSlice(offset, slice.length() - offset); slice = slice.subSlice(offset, slice.length() - offset);
EmitCs([this, EmitCs([this,
cDecl = ref(decl), cVertexElements = decl->GetElements(),
cVertexCount = VertexCount, cVertexCount = VertexCount,
cStartIndex = SrcStartIndex, cStartIndex = SrcStartIndex,
cInstanceCount = GetInstanceCount(), cInstanceCount = GetInstanceCount(),
cBufferSlice = slice cBufferSlice = slice
](DxvkContext* ctx) mutable { ](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); auto drawInfo = GenerateDrawInfo(D3DPT_POINTLIST, cVertexCount, cInstanceCount);

View File

@ -109,7 +109,7 @@ namespace dxvk {
m_module.opLabel(m_module.allocateId()); 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 uint_t = m_module.defIntType(32, false);
uint32_t float_t = m_module.defFloatType(32); uint32_t float_t = m_module.defFloatType(32);
uint32_t vec4_t = m_module.defVectorType(float_t, 4); uint32_t vec4_t = m_module.defVectorType(float_t, 4);
@ -142,15 +142,22 @@ namespace dxvk {
m_module.decorateBuiltIn(primitiveIdPtr, spv::BuiltInPrimitiveId); m_module.decorateBuiltIn(primitiveIdPtr, spv::BuiltInPrimitiveId);
uint32_t primitiveId = m_module.opLoad(uint_t, primitiveIdPtr); uint32_t primitiveId = m_module.opLoad(uint_t, primitiveIdPtr);
// The size of any given vertex // 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 //The offset of this vertex from the beginning of the buffer
uint32_t thisVertexOffset = m_module.opIMul(uint_t, vertexSize, primitiveId); 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 // Load the slot associated with this element
DxsoSemantic semantic = { DxsoUsage(element.Usage), element.UsageIndex }; DxsoSemantic semantic = { DxsoUsage(element.Usage), element.UsageIndex };
@ -297,9 +304,7 @@ namespace dxvk {
}; };
Rc<DxvkShader> D3D9SWVPEmulator::GetShaderModule(D3D9DeviceEx* pDevice, const D3D9VertexDecl* pDecl) { Rc<DxvkShader> D3D9SWVPEmulator::GetShaderModule(D3D9DeviceEx* pDevice, const D3D9VertexElements& elements) {
auto& elements = pDecl->GetElements();
// Use the shader's unique key for the lookup // Use the shader's unique key for the lookup
{ std::unique_lock<dxvk::mutex> lock(m_mutex); { std::unique_lock<dxvk::mutex> lock(m_mutex);
@ -317,7 +322,7 @@ namespace dxvk {
// This shader has not been compiled yet, so we have to create a // 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. // new module. This takes a while, so we won't lock the structure.
D3D9SWVPEmulatorGenerator generator(name); D3D9SWVPEmulatorGenerator generator(name);
generator.compile(pDecl); generator.compile(elements);
Rc<DxvkShader> shader = generator.finalize(); Rc<DxvkShader> shader = generator.finalize();
shader->setShaderKey(key); shader->setShaderKey(key);

View File

@ -23,7 +23,7 @@ namespace dxvk {
public: public:
Rc<DxvkShader> GetShaderModule(D3D9DeviceEx* pDevice, const D3D9VertexDecl* pDecl); Rc<DxvkShader> GetShaderModule(D3D9DeviceEx* pDevice, const D3D9VertexElements& elements);
private: private: