Wine-Devel
By thread
wine-devel@list.winehq.org
By month
Messages by month
- ----- 2026 -----
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2002 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2001 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
October 2024
- 14 participants
- 31 messages
Release plans
by Alexandre Julliard
Folks,
Since there has been little activity this week, and I'm travelling on
Friday, I'm going to delay Wine 9.21 until next Friday, November 8.
There will then be a 9.22 release two weeks later, and two weeks after
that, on December 6, the 10.0-rc1 release will mark the beginning of our
annual code freeze period. As usual, the freeze will last until the
final 10.0 is released sometime around mid-January.
--
Alexandre Julliard
julliard(a)winehq.org
Oct. 31, 2024
Re: Helping Wine use 64 bit Mesa OGL drivers for 32-bit Windows applications
by Derek Lesho
Hi Christian,
Thanks for exploring this option, it's great to have a better
understanding of the capabilities/limits of mremap.
First, a few practical questions:
- How would Wine detect the updated mremap, I suppose we would want to
create a test persistent mapping on init and see if mremap works on that
page?
- In my experience Mesa will sometimes return malloc'd pointers from
glMapBuffer when using the transfer helper, which I assume has to do
with buffer textures. If wine blindly uses remap for all glMapBuffer
calls, we'll then end up hitting the private anonymous path, where from
what I understand page faults are use to preserve the old page,
potentially slowing things down, thoughts?
Second, in regards to going forward:
I don't have the final call on what path we end up taking 😅. I think it
would be good if others from wine-devel pitched into what they think,
but here's my opinion:
I think the mremap approach should definitely be pursued since it looks
like such a simple Kernel patch, but it may also be good to pursue a
simple Mesa-Integrated path as well, maybe with Mesa calling into a Wine
library to allocate 32-bit pages, as we support non-linux OS's as well.
Thanks,
Derek
Am 10/30/24 um 14:03 schrieb Christian König:
> Hi guys,
>
> so I looked a bit deeper into the problem of duplicating graphics
> driver mappings with mremap().
>
> This use case of duplicating a mapping into a fixed address is already
> supported quite well using mremap(). This is used by a couple of
> different emulators to re-create the address space like you would find
> it in the specific environment.
>
> The only problem is that this only works for files and shared memory
> at the moment. Graphic driver mappings on the other hand have the
> VM_DONTEXPAND and VM_PFNMAP flag set because their mappings shouldn't
> grow and can also include VRAM.
>
> The attached patch changes this restriction for the mremap() function
> and so also allows duplicating the VMAs of graphics drivers into the
> lower 32bit address space managed by Wine.
>
> I've tested this with some of AMD's GPU unit tests and it actually
> seems to work quite fine.
>
> Derek please let me know if that solution works for you and if you're
> interested in using it. If yes I would go ahead and send the patch to
> the Linux memory management folks for discussion.
>
> Regards,
> Christian.
>
> Am 24.10.24 um 17:06 schrieb Christian König:
>> Darek we are unfortunately both partially right.
>>
>> Linux supports cloning VMAs using mremap() from userspace by using a
>> zero old size, but unfortunately only for SHM areas.
>>
>> See the code in mm/mremap.c:
>> Â Â Â Â Â Â Â /*
>> Â Â Â Â Â Â Â Â * We allow a zero old-len as a special case
>> Â Â Â Â Â Â Â Â * for DOS-emu "duplicate shm area" thing. But
>> Â Â Â Â Â Â Â Â * a zero new-len is nonsensical.
>> Â Â Â Â Â Â Â Â */
>> Â Â Â Â Â Â Â if (!new_len)
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â return ret;
>>
>> Going to take a closer look to figure out what would be necessary to
>> solve that for GPU drivers as well.
>>
>> Regards,
>> Christian.
>>
>> Am 24.10.24 um 14:56 schrieb Christian König:
>>> I haven't tested it but as far as I know that isn't correct.
>>>
>>> As far as I know you can map the same VMA at a different location
>>> even without MREMAP_DONTUNMAP. And yes MREMAP_DONTUNMAP only work
>>> with private mappings, but that isn't needed here.
>>>
>>> Give me a moment to test this.
>>>
>>> Regards,
>>> Christian.
>>>
>>> Am 24.10.24 um 10:03 schrieb Derek Lesho:
>>>> In my last mail I responded to this approach all the way at the
>>>> bottom, so it probably got lost: mremap on Linux as it exists now
>>>> won't work as it only supports private anonymous mappings (in
>>>> conjunction with MREMAP_DONTUNMAP), which GPU mappings are not.
>>>>
>>>> Am 10/24/24 um 01:06 schrieb James Jones:
>>>>> That makes sense. Reading the man page myself, it does seem like:
>>>>>
>>>>> -If the drivers can guarantee they set MAP_SHARED when creating
>>>>> their initial mapping.
>>>>>
>>>>> -If WINE is fine rounding down to page boundaries to deal with
>>>>> mappings of suballocations and either using some lookup structure
>>>>> to avoid duplicate remappings (probably needed to handle unmap
>>>>> anyway per below) or just living with the perf cost and address
>>>>> space overconsumption for duplicate remappings.
>>>>>
>>>>> -If mremap() preserves the cache attributes of the original mapping.
>>>>>
>>>>> Then no GL API change would be needed. WINE would just have to do
>>>>> an if (addrAbove4G) { mremapStuff() } on map and presumably add
>>>>> some tracking to perform an equivalent munmap() when unmapping. I
>>>>> assume WINE already has a bunch of vaddr tracking logic in use to
>>>>> manage the <4G address space as described elsewhere in the thread.
>>>>> That would be pretty ideal from a driver vendor perspective.
>>>>>
>>>>> Does that work?
>>>>>
>>>>> Thanks,
>>>>> -James
>>>>>
>>>>> On 10/23/24 06:12, Christian König wrote:
>>>>>> I haven't read through the whole mail thread, but if you manage
>>>>>> the address space using mmap() then you always run into this issue.
>>>>>>
>>>>>> If you manage the whole 4GiB address space by Wine then you never
>>>>>> run into this issue. You would just allocate some address range
>>>>>> internally and mremap() into that.
>>>>>>
>>>>>> Regards,
>>>>>> Christian.
>>>>>>
>>>>>> Am 22.10.24 um 19:32 schrieb James Jones:
>>>>>>> This sounds interesting, but does it come with the same "Only
>>>>>>> gets 2GB VA" downside Derek pointed out in the thread fork where
>>>>>>> he was responding to Michel?
>>>>>>>
>>>>>>> Thanks,
>>>>>>> -James
>>>>>>>
>>>>>>> On 10/22/24 07:14, Christian König wrote:
>>>>>>>> Hi guys,
>>>>>>>>
>>>>>>>> one theoretical alternative not mentioned in this thread is the
>>>>>>>> use of mremap().
>>>>>>>>
>>>>>>>> In other words you reserve some address space below 2G by using
>>>>>>>> mmap(NULL, length, PROT_NONE, MAP_32BIT | MAP_ANONYMOUS, 0, 0)
>>>>>>>> and then use mremap(addr64bit, 0, length, MREMAP_FIXED,
>>>>>>>> reserved_addr).
>>>>>>>>
>>>>>>>> I haven't tested this but at least in theory it should give you
>>>>>>>> a duplicate of the 64bit mapping in the lower 2G of the address
>>>>>>>> space.
>>>>>>>>
>>>>>>>> Important is that you give 0 as oldsize to mremap() so that the
>>>>>>>> old mapping isn't unmapped but rather just a new mapping of the
>>>>>>>> existing VMA created.
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>> Christian.
>>>>>>>>
>>>>>>>>
>>>>>>>> Am 18.10.24 um 23:55 schrieb Derek Lesho:
>>>>>>>>> Hey everyone 👋,
>>>>>>>>>
>>>>>>>>> I'm Derek from the Wine project, and wanted to start a
>>>>>>>>> discussion with y'all about potentially extending the Mesa OGL
>>>>>>>>> drivers to help us with a functionality gap we're facing.
>>>>>>>>>
>>>>>>>>> Problem Space:
>>>>>>>>>
>>>>>>>>> In the last few years Wine's support for running 32-bit
>>>>>>>>> windows apps in a 64-bit host environment (wow64) has almost
>>>>>>>>> reached feature completion, but there remains a pain point
>>>>>>>>> with OpenGL applications: Namely that Wine can't return a
>>>>>>>>> 64-bit GL implementation's buffer mappings to a 32 bit
>>>>>>>>> application when the address is outside of the 32-bit range.
>>>>>>>>>
>>>>>>>>> Currently, we have a workaround that will copy any changes to
>>>>>>>>> the mapping back to the host upon glBufferUnmap, but this of
>>>>>>>>> course is slow when the implementation directly returns mapped
>>>>>>>>> memory, and doesn't work for GL_PERSISTENT_BIT, where directly
>>>>>>>>> mapped memory is required.
>>>>>>>>>
>>>>>>>>> A few years ago we also faced this problem with Vulkan's,
>>>>>>>>> which was solved through the VK_EXT_map_memory_placed
>>>>>>>>> extension Faith drafted, allowing us to use our Wine-internal
>>>>>>>>> allocator to provide the pages the driver maps to. I'm now
>>>>>>>>> wondering if an GL equivalent would also be seen as feasible
>>>>>>>>> amongst the devs here.
>>>>>>>>>
>>>>>>>>> Proposed solution:
>>>>>>>>>
>>>>>>>>> As the GL backend handles host mapping in its own code, only
>>>>>>>>> giving suballocations from its mappings back to the App, the
>>>>>>>>> problem is a little bit less straight forward in comparison to
>>>>>>>>> our Vulkan solution: If we just allowed the application to set
>>>>>>>>> its own placed mapping when calling glMapBuffer, the driver
>>>>>>>>> might then have to handle moving buffers out of already mapped
>>>>>>>>> ranges, and would lose control over its own memory management
>>>>>>>>> schemes.
>>>>>>>>>
>>>>>>>>> Therefore, I propose a GL extension that allows the GL client
>>>>>>>>> to provide a mapping and unmapping callback to the
>>>>>>>>> implementation, to be used whenever the driver needs to
>>>>>>>>> perform such operations. This way the driver remains in full
>>>>>>>>> control of its memory management affairs, and the amount of
>>>>>>>>> work for an implementation as well as potential for bugs is
>>>>>>>>> kept minimal. I've written a draft implementation in Zink
>>>>>>>>> using map_memory_placed [1] and a corresponding Wine MR
>>>>>>>>> utilizing it [2], and would be curious to hear your thoughts.
>>>>>>>>> I don't have experience in the Mesa codebase, so I apologize
>>>>>>>>> if the branch is a tad messy.
>>>>>>>>>
>>>>>>>>> In theory, the only requirement from drivers from the
>>>>>>>>> extension would be that glMapBuffer always return a pointer
>>>>>>>>> from within a page allocated through the provided callbacks,
>>>>>>>>> so that it can be guaranteed to be positioned within the
>>>>>>>>> required address space. Wine would then use it's existing
>>>>>>>>> workaround for other types of buffers, but as Mesa seems to
>>>>>>>>> often return directly mapped buffers in other cases as well,
>>>>>>>>> Wine could also avoid the slowdown that comes with copying in
>>>>>>>>> these cases as well.
>>>>>>>>>
>>>>>>>>> Why not use Zink?:
>>>>>>>>>
>>>>>>>>> There's also a proposal to use a 32-bit PE build of Zink in
>>>>>>>>> Wine bypassing the need for an extension; I brought this to
>>>>>>>>> discussion in this Wine-Devel thread last week [3], which has
>>>>>>>>> some arguments against this approach.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> If any of you have thoughts, concerns, or questions about this
>>>>>>>>> potential approach, please let me know, thanks!
>>>>>>>>>
>>>>>>>>> 1:
>>>>>>>>> https://gitlab.freedesktop.org/Guy1524/mesa/-/commits/placed_allocation
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> 2: https://gitlab.winehq.org/wine/wine/-/merge_requests/6663
>>>>>>>>>
>>>>>>>>> 3: https://marc.info/?t=172883260300002&r=1&w=2
>>>>>>>>>
>>>>>>>>
>>>>>>
>>>
>>
Oct. 31, 2024
Re: Helping Wine use 64 bit Mesa OGL drivers for 32-bit Windows applications
by Derek Lesho
Oh interesting, thanks for looking into this guys. As far as I
understand it though, this is still not duplicating the mapping, but
setting up a fault handler at the original address to manage access. I
don't think we'd want this since when wine remaps the page/s hosting a
given buffer it also forces all other resources mapped to the same
page/s to go through this presumably slow fault handler. Am I missing
something?
Am 10/24/24 um 18:40 schrieb tblodt(a)icloud.com:
> Wait, apparently this was fully merged in kernel 5.13? The man page is
> simply out of date.
> https://github.com/torvalds/linux/commit/a4609387859f0281951f5e476d9f76d7fb…
>
> ~Theodore
>
>> On Oct 24, 2024, at 9:37 AM, tblodt(a)icloud.com wrote:
>>
>> 
>>> On Oct 24, 2024, at 1:04 AM, Derek Lesho <dlesho(a)codeweavers.com> wrote:
>>>
>>> In my last mail I responded to this approach all the way at the
>>> bottom, so it probably got lost: mremap on Linux as it exists now
>>> won't work as it only supports private anonymous mappings (in
>>> conjunction with MREMAP_DONTUNMAP), which GPU mappings are not.
>>
>> This is seemingly not insurmountable:
>> https://lore.kernel.org/linux-mm/20210303175235.3308220-1-bgeffon(a)google.…
>>
>>
>> ~Theodore
>>
>>
Oct. 24, 2024
Re: Helping Wine use 64 bit Mesa OGL drivers for 32-bit Windows applications
by tblodtï¼ icloud.com
Wait, apparently this was fully merged in kernel 5.13? The man page is simply out of date. https://github.com/torvalds/linux/commit/a4609387859f0281951f5e476d9f76d7fb…
~Theodore
> On Oct 24, 2024, at 9:37 AM, tblodt(a)icloud.com wrote:
>
> 
>>> On Oct 24, 2024, at 1:04 AM, Derek Lesho <dlesho(a)codeweavers.com> wrote:
>>>
>> In my last mail I responded to this approach all the way at the bottom, so it probably got lost: mremap on Linux as it exists now won't work as it only supports private anonymous mappings (in conjunction with MREMAP_DONTUNMAP), which GPU mappings are not.
>
>
> This is seemingly not insurmountable: https://lore.kernel.org/linux-mm/20210303175235.3308220-1-bgeffon(a)google.…
>
> ~Theodore
>
>
Oct. 24, 2024
Re: Helping Wine use 64 bit Mesa OGL drivers for 32-bit Windows applications
by tblodtï¼ icloud.com
> On Oct 24, 2024, at 1:04 AM, Derek Lesho <dlesho(a)codeweavers.com> wrote:
>
> In my last mail I responded to this approach all the way at the bottom, so it probably got lost: mremap on Linux as it exists now won't work as it only supports private anonymous mappings (in conjunction with MREMAP_DONTUNMAP), which GPU mappings are not.
This is seemingly not insurmountable: https://lore.kernel.org/linux-mm/20210303175235.3308220-1-bgeffon(a)google.…
~Theodore
Oct. 24, 2024
Re: Helping Wine use 64 bit Mesa OGL drivers for 32-bit Windows applications
by Derek Lesho
In my last mail I responded to this approach all the way at the bottom,
so it probably got lost: mremap on Linux as it exists now won't work as
it only supports private anonymous mappings (in conjunction with
MREMAP_DONTUNMAP), which GPU mappings are not.
Am 10/24/24 um 01:06 schrieb James Jones:
> That makes sense. Reading the man page myself, it does seem like:
>
> -If the drivers can guarantee they set MAP_SHARED when creating their
> initial mapping.
>
> -If WINE is fine rounding down to page boundaries to deal with
> mappings of suballocations and either using some lookup structure to
> avoid duplicate remappings (probably needed to handle unmap anyway per
> below) or just living with the perf cost and address space
> overconsumption for duplicate remappings.
>
> -If mremap() preserves the cache attributes of the original mapping.
>
> Then no GL API change would be needed. WINE would just have to do an
> if (addrAbove4G) { mremapStuff() } on map and presumably add some
> tracking to perform an equivalent munmap() when unmapping. I assume
> WINE already has a bunch of vaddr tracking logic in use to manage the
> <4G address space as described elsewhere in the thread. That would be
> pretty ideal from a driver vendor perspective.
>
> Does that work?
>
> Thanks,
> -James
>
> On 10/23/24 06:12, Christian König wrote:
>> I haven't read through the whole mail thread, but if you manage the
>> address space using mmap() then you always run into this issue.
>>
>> If you manage the whole 4GiB address space by Wine then you never run
>> into this issue. You would just allocate some address range
>> internally and mremap() into that.
>>
>> Regards,
>> Christian.
>>
>> Am 22.10.24 um 19:32 schrieb James Jones:
>>> This sounds interesting, but does it come with the same "Only gets
>>> 2GB VA" downside Derek pointed out in the thread fork where he was
>>> responding to Michel?
>>>
>>> Thanks,
>>> -James
>>>
>>> On 10/22/24 07:14, Christian König wrote:
>>>> Hi guys,
>>>>
>>>> one theoretical alternative not mentioned in this thread is the use
>>>> of mremap().
>>>>
>>>> In other words you reserve some address space below 2G by using
>>>> mmap(NULL, length, PROT_NONE, MAP_32BIT | MAP_ANONYMOUS, 0, 0) and
>>>> then use mremap(addr64bit, 0, length, MREMAP_FIXED, reserved_addr).
>>>>
>>>> I haven't tested this but at least in theory it should give you a
>>>> duplicate of the 64bit mapping in the lower 2G of the address space.
>>>>
>>>> Important is that you give 0 as oldsize to mremap() so that the old
>>>> mapping isn't unmapped but rather just a new mapping of the
>>>> existing VMA created.
>>>>
>>>> Regards,
>>>> Christian.
>>>>
>>>>
>>>> Am 18.10.24 um 23:55 schrieb Derek Lesho:
>>>>> Hey everyone 👋,
>>>>>
>>>>> I'm Derek from the Wine project, and wanted to start a discussion
>>>>> with y'all about potentially extending the Mesa OGL drivers to
>>>>> help us with a functionality gap we're facing.
>>>>>
>>>>> Problem Space:
>>>>>
>>>>> In the last few years Wine's support for running 32-bit windows
>>>>> apps in a 64-bit host environment (wow64) has almost reached
>>>>> feature completion, but there remains a pain point with OpenGL
>>>>> applications: Namely that Wine can't return a 64-bit GL
>>>>> implementation's buffer mappings to a 32 bit application when the
>>>>> address is outside of the 32-bit range.
>>>>>
>>>>> Currently, we have a workaround that will copy any changes to the
>>>>> mapping back to the host upon glBufferUnmap, but this of course is
>>>>> slow when the implementation directly returns mapped memory, and
>>>>> doesn't work for GL_PERSISTENT_BIT, where directly mapped memory
>>>>> is required.
>>>>>
>>>>> A few years ago we also faced this problem with Vulkan's, which
>>>>> was solved through the VK_EXT_map_memory_placed extension Faith
>>>>> drafted, allowing us to use our Wine-internal allocator to provide
>>>>> the pages the driver maps to. I'm now wondering if an GL
>>>>> equivalent would also be seen as feasible amongst the devs here.
>>>>>
>>>>> Proposed solution:
>>>>>
>>>>> As the GL backend handles host mapping in its own code, only
>>>>> giving suballocations from its mappings back to the App, the
>>>>> problem is a little bit less straight forward in comparison to our
>>>>> Vulkan solution: If we just allowed the application to set its own
>>>>> placed mapping when calling glMapBuffer, the driver might then
>>>>> have to handle moving buffers out of already mapped ranges, and
>>>>> would lose control over its own memory management schemes.
>>>>>
>>>>> Therefore, I propose a GL extension that allows the GL client to
>>>>> provide a mapping and unmapping callback to the implementation, to
>>>>> be used whenever the driver needs to perform such operations. This
>>>>> way the driver remains in full control of its memory management
>>>>> affairs, and the amount of work for an implementation as well as
>>>>> potential for bugs is kept minimal. I've written a draft
>>>>> implementation in Zink using map_memory_placed [1] and a
>>>>> corresponding Wine MR utilizing it [2], and would be curious to
>>>>> hear your thoughts. I don't have experience in the Mesa codebase,
>>>>> so I apologize if the branch is a tad messy.
>>>>>
>>>>> In theory, the only requirement from drivers from the extension
>>>>> would be that glMapBuffer always return a pointer from within a
>>>>> page allocated through the provided callbacks, so that it can be
>>>>> guaranteed to be positioned within the required address space.
>>>>> Wine would then use it's existing workaround for other types of
>>>>> buffers, but as Mesa seems to often return directly mapped buffers
>>>>> in other cases as well, Wine could also avoid the slowdown that
>>>>> comes with copying in these cases as well.
>>>>>
>>>>> Why not use Zink?:
>>>>>
>>>>> There's also a proposal to use a 32-bit PE build of Zink in Wine
>>>>> bypassing the need for an extension; I brought this to discussion
>>>>> in this Wine-Devel thread last week [3], which has some arguments
>>>>> against this approach.
>>>>>
>>>>>
>>>>> If any of you have thoughts, concerns, or questions about this
>>>>> potential approach, please let me know, thanks!
>>>>>
>>>>> 1:
>>>>> https://gitlab.freedesktop.org/Guy1524/mesa/-/commits/placed_allocation
>>>>>
>>>>>
>>>>> 2: https://gitlab.winehq.org/wine/wine/-/merge_requests/6663
>>>>>
>>>>> 3: https://marc.info/?t=172883260300002&r=1&w=2
>>>>>
>>>>
>>
Oct. 24, 2024
Re: Helping Wine use 64 bit Mesa OGL drivers for 32-bit Windows applications
by Paul Gofman
On 10/22/24 18:03, Derek Lesho wrote:
>
> Am 10/21/24 um 11:35 schrieb Michel Dänzer:
>
>> And Wine's solution for this can't be implemented in Mesa?
>
> I think this might actually be possible: In order to accomplish this
> Wine essentially keeps calling mmaps with addresses in its range until
> it finds a free spot. It of course is able to already skip addresses
> it itself has mapped, which spares needlessly calling of mmap for
> nearly every possible page before finding one in cases where the
> address space is almost filled up.
>
> The two practical problems here would be that Mesa wouldn't have
> access to Wine's mapping table without additional plumbing, and
> allocating GPU memory, already a slow operation, might become even
> slower. (If wanted I can try drafting this solution when I get time to
> see, but I'm swamped with Uni work atm).
>
> The other problem is that Wine also has a system of reserved ranges,
> where it reserves certain important page ranges on setup so that no
> other libraries steal them from Wine. As far as I can see in Vanilla
> Wine this isn't a huge portion of the address-space, but if I remember
> correctly there have been considerations in the past to expand these
> ranges to speed up virtual memory allocation instead of working
> through mmap.
>
I am afraid accessing Wine internal mapping ranges is not a feasible
option. One thing that it is very internal Wine detail and can change
any moment, that gets evolved and modified from time to time for
improving Windows compatibility and optimization purposes. Besides the
access to that inside Wine is synchronized inside Wine (also involving
signal masking). TLDR, interfering with that from the outside doesn't
look possible.
Oct. 23, 2024
Re: Helping Wine use 64 bit Mesa OGL drivers for 32-bit Windows applications
by Derek Lesho
Am 10/21/24 um 11:35 schrieb Michel Dänzer:
> And Wine's solution for this can't be implemented in Mesa?
I think this might actually be possible: In order to accomplish this
Wine essentially keeps calling mmaps with addresses in its range until
it finds a free spot. It of course is able to already skip addresses it
itself has mapped, which spares needlessly calling of mmap for nearly
every possible page before finding one in cases where the address space
is almost filled up.
The two practical problems here would be that Mesa wouldn't have access
to Wine's mapping table without additional plumbing, and allocating GPU
memory, already a slow operation, might become even slower. (If wanted I
can try drafting this solution when I get time to see, but I'm swamped
with Uni work atm).
The other problem is that Wine also has a system of reserved ranges,
where it reserves certain important page ranges on setup so that no
other libraries steal them from Wine. As far as I can see in Vanilla
Wine this isn't a huge portion of the address-space, but if I remember
correctly there have been considerations in the past to expand these
ranges to speed up virtual memory allocation instead of working through
mmap.
And then of course there's the question: Do y'all want to have all this
allocation complexity in Mesa, when you're have the Wine library sitting
right next to you able to do it in a way guaranteed to work?
Am 10/21/24 um 16:33 schrieb Jose Fonseca:
> I see a few downsides with the proposed callback:
> - feels like a solution too tailored for WINE
> - there's a layering violation: the application suddenly takes the
> driving seat for a thing deep down in the GL driver
> so I fear Mesa community might regret it doing, and once WINE supports
> there would be outcry if to go back.
Yeah, I'm sensible to this critic, and I also would rather a more
surface level extension if possible, but it seems to me the troubles
with the GL model prohibit it. Also, I would counter that the driver
relying on Wine for what is effectively a glorified mmap most likely
won't cause restrictions or pains in the future.
> IIUC the problem at hand, another way to go about this would be an
> extension that allows applications to get a malloc'ed/valloc'ed memory
> exposed to the GPU as a GL buffer object.
I'll defer to others more knowledgeable than me on the viability of
using host imported memory, but I know we have a fallback path in
Winevulkan using the Vulkan external_host_memory extension, which was
known to be slower than the more direct placed memory solution. I'm
cc'ing Jacek (I hope you don't mind 😅), as they ended up implementing
both Wine's external_host_memory path and placed_memory path for our
WoW64 support, and might have more details on the differences here.
Am 10/21/24 um 23:21 schrieb James Jones:
> All that said, I don't love the idea of callbacks either. Callbacks in
> general are tough to specify and use robustly, and hence should be a
> last resort. E.g., this particular callback might sometimes come from
> the application thread, and sometimes come from some separate
> driver-managed thread. It's hard to validate that all applications can
> handle that properly and wouldn't do something crazy like rely on
> their own TLS data in the callback or try to call back into OpenGL
> from the callback and deadlock themselves, even if these are clearly
> specified as an unsupported actions.
Yeah, I agree it should be a last resort solution. In my draft Wine
implementation, I marshal all calls from driver threads back to a thread
created by Wine for the allocation to work, but having to then define
this in terms of a general extension is quite ugly... I'm curious if
there's a consensus here that Mesa would rather call into a custom Wine
mmap when available, instead of exposing a general extension for other
applications to shoot themselves in the foot with. If so, I hope
Julliard or someone in that area could chime in what they think of the idea.
Am 10/22/24 um 11:15 schrieb Jose Fonseca:
> So, it sounds like something like an OpenGL equivalent of
> VK_EXT_map_memory_placed would be more palatable?
Yes this is the goal, if a similarly straightforward extension for GL is
possible I think everyone would be for it, but I'm not sure that's the
case. To this topic, maybe take a look at the wine-devel thread about
some potential options I started a few weeks ago, where we discuss
potential callback-less alternatives. This link should have relevant
context: https://marc.info/?l=wine-devel&m=172894900019588&w=2
Am 10/22/24 um 16:14 schrieb Christian König:
> Hi guys,
>
> one theoretical alternative not mentioned in this thread is the use of
> mremap().
>
> In other words you reserve some address space below 2G by using
> mmap(NULL, length, PROT_NONE, MAP_32BIT | MAP_ANONYMOUS, 0, 0) and
> then use mremap(addr64bit, 0, length, MREMAP_FIXED, reserved_addr).
>
> I haven't tested this but at least in theory it should give you a
> duplicate of the 64bit mapping in the lower 2G of the address space.
>
> Important is that you give 0 as oldsize to mremap() so that the old
> mapping isn't unmapped but rather just a new mapping of the existing
> VMA created.
>
> Regards,
> Christian.
This unfortunately won't work for the reason that mremap on Linux only
works on anonymous private pages, which GPU mappings are not.
Oct. 23, 2024
Re: Helping Wine use 64 bit Mesa OGL drivers for 32-bit Windows applications
by Derek Lesho
On 10/21/24 11:08, Michel Dänzer wrote:
> On 2024-10-18 23:55, Derek Lesho wrote:
>> Hey everyone 👋,
>>
>> I'm Derek from the Wine project, and wanted to start a discussion with y'all about potentially extending the Mesa OGL drivers to help us with a functionality gap we're facing.
>>
>> Problem Space:
>>
>> In the last few years Wine's support for running 32-bit windows apps in a 64-bit host environment (wow64) has almost reached feature completion, but there remains a pain point with OpenGL applications: Namely that Wine can't return a 64-bit GL implementation's buffer mappings to a 32 bit application when the address is outside of the 32-bit range.
>>
>> Currently, we have a workaround that will copy any changes to the mapping back to the host upon glBufferUnmap, but this of course is slow when the implementation directly returns mapped memory, and doesn't work for GL_PERSISTENT_BIT, where directly mapped memory is required.
>>
>> A few years ago we also faced this problem with Vulkan's, which was solved through the VK_EXT_map_memory_placed extension Faith drafted, allowing us to use our Wine-internal allocator to provide the pages the driver maps to. I'm now wondering if an GL equivalent would also be seen as feasible amongst the devs here.
>>
>> Proposed solution:
>>
>> As the GL backend handles host mapping in its own code, only giving suballocations from its mappings back to the App, the problem is a little bit less straight forward in comparison to our Vulkan solution: If we just allowed the application to set its own placed mapping when calling glMapBuffer, the driver might then have to handle moving buffers out of already mapped ranges, and would lose control over its own memory management schemes.
>>
>> Therefore, I propose a GL extension that allows the GL client to provide a mapping and unmapping callback to the implementation, to be used whenever the driver needs to perform such operations. This way the driver remains in full control of its memory management affairs, and the amount of work for an implementation as well as potential for bugs is kept minimal. I've written a draft implementation in Zink using map_memory_placed [1] and a corresponding Wine MR utilizing it [2], and would be curious to hear your thoughts. I don't have experience in the Mesa codebase, so I apologize if the branch is a tad messy.
>>
>> In theory, the only requirement from drivers from the extension would be that glMapBuffer always return a pointer from within a page allocated through the provided callbacks, so that it can be guaranteed to be positioned within the required address space. Wine would then use it's existing workaround for other types of buffers, but as Mesa seems to often return directly mapped buffers in other cases as well, Wine could also avoid the slowdown that comes with copying in these cases as well.
> Does this really require a callback, or could e.g. a "keep application-visible mappings within 32-bit range" context flag work?
>
>
Unfortunately that wouldn't be quite enough, as linux-mmap's MAP_32BIT
flag only uses the first 2 GBs of address space, and we need to allow
for the use of all 4GB of address space for apps which have activated
the LAA (large address-space aware) flag in their executable.
Oct. 21, 2024
Re: Helping Wine use 64 bit Mesa OGL drivers for 32-bit Windows applications
by Derek Lesho
Hey Timur,
This is actually what Wine has traditionally done, the problem is that
we are moving forward to a new implementation for running 32-bit Windows
apps, where all of Wine's ELF code is 64-bit, and interacts with the
host as a normal 64-bit app. In order to use a 32-bit driver in this
context, we'd have to somehow switch the codepage back to 32-bit on the
unix side again, and then manually load second copies of mesa and its
dependencies like glibc, which would be a lot of effort.
I hope this clears things up, let me know if not
On 10/19/24 17:47, Timur Kristóf wrote:
> Hello Derek,
>
> As I am not working on GL, I don't have anything to contribute to the
> discussion, but I just have a question out of curiosity: what's wrong
> with simply using a driver that is compiled for 32-bit?
>
> Best regards,
> Timur
>
> On Fri, 2024-10-18 at 23:55 +0200, Derek Lesho wrote:
>> Hey everyone 👋,
>>
>> I'm Derek from the Wine project, and wanted to start a discussion
>> with
>> y'all about potentially extending the Mesa OGL drivers to help us
>> with a
>> functionality gap we're facing.
>>
>> Problem Space:
>>
>> In the last few years Wine's support for running 32-bit windows apps
>> in
>> a 64-bit host environment (wow64) has almost reached feature
>> completion,
>> but there remains a pain point with OpenGL applications: Namely that
>> Wine can't return a 64-bit GL implementation's buffer mappings to a
>> 32
>> bit application when the address is outside of the 32-bit range.
>>
>> Currently, we have a workaround that will copy any changes to the
>> mapping back to the host upon glBufferUnmap, but this of course is
>> slow
>> when the implementation directly returns mapped memory, and doesn't
>> work
>> for GL_PERSISTENT_BIT, where directly mapped memory is required.
>>
>> A few years ago we also faced this problem with Vulkan's, which was
>> solved through the VK_EXT_map_memory_placed extension Faith drafted,
>> allowing us to use our Wine-internal allocator to provide the pages
>> the
>> driver maps to. I'm now wondering if an GL equivalent would also be
>> seen
>> as feasible amongst the devs here.
>>
>> Proposed solution:
>>
>> As the GL backend handles host mapping in its own code, only giving
>> suballocations from its mappings back to the App, the problem is a
>> little bit less straight forward in comparison to our Vulkan
>> solution:
>> If we just allowed the application to set its own placed mapping when
>> calling glMapBuffer, the driver might then have to handle moving
>> buffers
>> out of already mapped ranges, and would lose control over its own
>> memory
>> management schemes.
>>
>> Therefore, I propose a GL extension that allows the GL client to
>> provide
>> a mapping and unmapping callback to the implementation, to be used
>> whenever the driver needs to perform such operations. This way the
>> driver remains in full control of its memory management affairs, and
>> the
>> amount of work for an implementation as well as potential for bugs is
>> kept minimal. I've written a draft implementation in Zink using
>> map_memory_placed [1] and a corresponding Wine MR utilizing it [2],
>> and
>> would be curious to hear your thoughts. I don't have experience in
>> the
>> Mesa codebase, so I apologize if the branch is a tad messy.
>>
>> In theory, the only requirement from drivers from the extension would
>> be
>> that glMapBuffer always return a pointer from within a page allocated
>> through the provided callbacks, so that it can be guaranteed to be
>> positioned within the required address space. Wine would then use
>> it's
>> existing workaround for other types of buffers, but as Mesa seems to
>> often return directly mapped buffers in other cases as well, Wine
>> could
>> also avoid the slowdown that comes with copying in these cases as
>> well.
>>
>> Why not use Zink?:
>>
>> There's also a proposal to use a 32-bit PE build of Zink in Wine
>> bypassing the need for an extension; I brought this to discussion in
>> this Wine-Devel thread last week [3], which has some arguments
>> against
>> this approach.
>>
>>
>> If any of you have thoughts, concerns, or questions about this
>> potential
>> approach, please let me know, thanks!
>>
>> 1:
>> https://gitlab.freedesktop.org/Guy1524/mesa/-/commits/placed_allocation
>>
>> 2: https://gitlab.winehq.org/wine/wine/-/merge_requests/6663
>>
>> 3: https://marc.info/?t=172883260300002&r=1&w=2
>>
Oct. 20, 2024