From: Matteo Bruni Subject: Re: [PATCH 1/5] d3d9: Support drawing from D3DPOOL_SYSTEMMEM vertex buffers. Message-Id: Date: Thu, 13 Dec 2018 18:22:25 +0100 In-Reply-To: References: <20181212160958.18212-1-mbruni@codeweavers.com> On Thu, Dec 13, 2018 at 3:07 PM Józef Kucia wrote: > > On Wed, Dec 12, 2018 at 5:10 PM Matteo Bruni wrote: > > +static void d3d9_device_upload_sysmem_buffers(struct d3d9_device *device, > > + unsigned int start_vertex, unsigned int vertex_count) > > +{ > > + struct wined3d_box box = {0, 0, 0, 1, 0, 1}; > > + struct d3d9_vertexbuffer *d3d9_buffer; > > + unsigned int i, offset, stride, map; > > + struct wined3d_buffer *dst_buffer; > > + HRESULT hr; > > + > > + map = device->upload_map; > > + while (map) > > + { > > + i = ffs(map) - 1; > > + map ^= 1u << i; > > + > > + if (FAILED(hr = wined3d_device_get_stream_source(device->wined3d_device, i, &dst_buffer, &offset, &stride))) > > + ERR("Failed to get stream source.\n"); > > + d3d9_buffer = wined3d_buffer_get_parent(dst_buffer); > > + box.left = offset + start_vertex * stride; > > + box.right = box.left + vertex_count * stride; > > + if (FAILED(hr = wined3d_device_copy_sub_resource_region(device->wined3d_device, > > + wined3d_buffer_get_resource(dst_buffer), 0, box.left, 0, 0, > > + wined3d_buffer_get_resource(d3d9_buffer->wined3d_buffer), 0, &box, 0))) > > + ERR("Failed to update buffer.\n"); > > + } > > +} > > It looks like this might stall the rendering pipeline frequently, i.e. > we will be updating the same draw buffers continuously between > subsequent draw calls with system memory buffers. I am not sure how > important it is in practice. That is true. I'm not sure either, I don't expect performance with SYSMEM buffer draws to be critical and restoring functionality is more important anyway. But yes, I think this is fine for a first pass, but probably a TODO comment somewhere would have been nice. FWIW if it turns out we need the performance, my preferred way of getting that would involve some wined3d work. Specifically, adding support to the NOOVERWRITE / DISCARD flags to wined3d_device_copy_sub_resource_region(), mirroring CopySubresourceRegion1() from d3d11.1.