Re: d3dx9: Implement converting and copying surface data in D3DXLoadSurfaceFromMemory (review please)
On Sun, Aug 30, 2009 at 12:56:26PM +0200, Tony Wasserka wrote: I think it would be better to store this in surface.c since I can't think of anything else that would need this. D3DXCheckTextureRequirements in texture.c will make use of the format table, since it also needs information about bits per component and component ordering. You are right, but it would be neat to have them all grouped like they are in d3dx9tex.h. I seem to remember one additional thing from the MSDN: The alpha channel has a specific behavior when it is added (RGB - RGBA), it is set to either 0.0 or 1.0. 1.0 makes sense. I think other channels are set to 0.0 if they are added. Better test this though.
Re: d3dx9: Implement converting and copying surface data in D3DXLoadSurfaceFromMemory (review please)
On Wed, Aug 26, 2009 at 12:10:36PM +0200, Tony Wasserka wrote: +BYTE abits, rbits, gbits, bbits; +BYTE ashift, rshift, gshift, bshift; +DWORD amask, rmask, gmask, bmask; If you make those into arrays you will be able to cut down on the code size, and the compiler might like it better. I think it would be better to store this in surface.c since I can't think of anything else that would need this.
Re: [PATCH 3/7] d3dx9: Implement D3DXCheckTextureRequirements.
Hi! On Fri, Sep 19, 2008 at 07:04:04PM +0200, Henri Verbeet wrote: 2008/9/19 Philip Nilsson [EMAIL PROTECTED]: +hr = IDirect3DDevice9_GetDirect3D(device, d3d9); +if (hr != D3D_OK || !device) +return D3DERR_INVALIDCALL; + +IDirect3D9_GetAdapterDisplayMode(d3d9, D3DADAPTER_DEFAULT, d3ddm); + +/* TODO: Use something more advanced that looks more like what's in MSDN. */ +hr = IDirect3D9_CheckDeviceFormat(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, usage, D3DRTYPE_TEXTURE, *format); You shouldn't guess the adapter, device type, etc., but use whatever the device was created with. IDirect3DDevice9_GetCreationParameters() should help there. Thanks, I didn't know there was a way. It doesn't matter in the test though as I control the creation there, right? +if (hr != D3D_OK) { +if (usage D3DUSAGE_DEPTHSTENCIL) { +switch (*format) { ... +} +IDirect3D9_Release(d3d9); +} I'm not sure about the big switch statement there, but I do know that just changing the format isn't enough. There's no guarantee the new format will work, or if there is any format that will support that specific set of usage flags at all. Yes, it doesn't take much for it to go wrong. It's basically just correct for my settings. A huge table containing the 12 different channels I know of might come in handy. I'm not looking forward to filling it out though. (I do however have some interesting ideas for the selection, so I'll do it as soon as I can.) Regards.
Re: [PATCH 7/7] d3dx9/tests: Test D3DXCreateTexture.
On Fri, Sep 19, 2008 at 07:10:29PM +0200, Henri Verbeet wrote: I think it would be a good idea to test the parameters (format, width, height, miplevels) of the created texture. I used to do that, but most of the things you can check are just duplicates of the checks in D3DCheckTextureRequirements, and I think CreateTexture would fail if it couldn't fulfil the new requirements. I think the only thing that's left is format checking, but that's not very easy to check beyond general kind of format.
Re: [PATCH 6/7] d3dx9/tests: Test D3DXCheckTextureRequirements.
On Fri, Sep 19, 2008 at 07:07:18PM +0200, Henri Verbeet wrote: 2008/9/19 Philip Nilsson [EMAIL PROTECTED]: This one could use some more work, but I think the tests will pass in most cases (except in strange environments without support for common formats). The tests should pass everywhere. I agree, I'll add some more checks to make sure the tests will only be run if they can pass on the current setup (or find a set of parameters that will allow the tests to run). I think you should be testing for consistency between CheckDeviceFormat() and D3DXCheckTextureRequirements(). What do you mean?
Re: wined3d: universal surface convertor function for unsigned integer color formats(5th attempt)
On Thu, Jul 24, 2008 at 08:14:40PM +0400, Victor Eremin wrote: Supports conversion between most of unsigned color argb/xrgb surface formats (D3DFMT_A8R8G8B8, D3DFMT_A8R3G3B2, etc), and luminosity color formats (D3DFMT_L8, etc), excluding D3DFMT_A16R16G16B16, D3DFMT_A8P8, D3DFMT_P8 and D3DFMT_A1. luminosity to argb/xrgb (and vice versa) conversions are not supported dlls/wined3d/surface_base.c| 218 ++- I think it would be a better idea to put most of the functions in utils.c, as they are utilities, and may have utility in other places (for example argb_to_fmt does something similar, although I'm not sure if more format conversion is neccessary.) +inline BYTE getMaskShift(DWORD mask){ Most functions here do not use camelCase. +void mask_erase(DWORD dstMask, BYTE pixelSize, I'd make all functions static that have no use outside their file to get nicer warnings (function unused) and smaller binaries. I wonder how static and inline interacts... +/* + * Warning: this won't convert all formats + */ The FIXMEs should be enough. struct d3dfmt_convertor_desc convertors[] = { -{WINED3DFMT_R32F, WINED3DFMT_R16F,convert_r32f_r16f}, +{WINED3DFMT_R32F, WINED3DFMT_R16F,convert_r32f_r16f} }; I think my neckbeard just caught fire! A lot of tests would be nice (although I guess most of the functionality is already tested.) I hope this is somewhat helpful.
Re: wined3d: universal surface convertor function for unsigned integer color formats
On Mon, Jul 14, 2008 at 02:51:42AM +0400, Victor Eremin wrote: Converter function supports conversion between most of unsigned color argb/xrgb surface formats (like D3DFMT_A8R8G8B8, D3DFMT_A8R3G3B2, and so on), and between luminosity color formats (D3DFMT_L8, etc), excluding D3DFMT_A16R16G16B16, D3DFMT_A8P8, D3DFMT_P8 and D3DFMT_A1. Conversion from rgba to luminosity (and vice versa) is not currently implemented. The patch removes Cannot find coverter FIXMEs from Ancient Evil and Stranded 2 games. Patch also fixes water glitches in Stranded 2 game. I've attached my pixel conversion function which uses the table in utils.c. Hope you find it useful although I haven't really polished it. /* Counts the number of leading zeros in a mask, returns 0 if the mask is zero. */ static unsigned int count_zeros(unsigned int mask) { unsigned int count; if (!mask) return 0; for (count = 0; !(mask 1); ++count) { mask = 1; } return count; } /* Scales a value masked by one mask to another. */ static DWORD convert_channel(DWORD src, DWORD srcmask, DWORD dstmask) { src = src srcmask; src = count_zeros(srcmask); src *= (dstmask count_zeros(dstmask)) / (srcmask count_zeros(srcmask)); src = count_zeros(dstmask); return src; } static DWORD get_mask(DWORD value, DWORD mask) { return (value mask) count_zeros(mask); } static DWORD put_mask(DWORD value, DWORD mask) { return (value count_zeros(mask)) mask; } /* MSDN states that the default value is 1 for missing channels; and that * D3DFMT_A8 is the exception where the missing channels are 0. * * I assume 1 means 1 in every bit. */ static DWORD convert_pixel(DWORD srcword, const StaticPixelFormatDesc* srcentry, const StaticPixelFormatDesc* dstentry) { DWORD pixel = 0; if (srcentry-alphaMask dstentry-alphaMask) pixel |= convert_channel(srcword, srcentry-alphaMask, dstentry-alphaMask); else pixel |= dstentry-alphaMask; if (srcentry-redMask dstentry-redMask) pixel |= convert_channel(srcword, srcentry-redMask, dstentry-redMask); else pixel |= dstentry-redMask; if (srcentry-greenMask dstentry-greenMask) pixel |= convert_channel(srcword, srcentry-greenMask, dstentry-greenMask); else pixel |= dstentry-greenMask; if (srcentry-blueMask dstentry-blueMask) pixel |= convert_channel(srcword, srcentry-blueMask, dstentry-blueMask); else pixel |= dstentry-blueMask; return pixel; } DWORD convert_pixelformat(DWORD pixel, WINED3DFORMAT srcformat, WINED3DFORMAT dstformat) { const StaticPixelFormatDesc* srcentry = getFormatDescEntry(srcformat, NULL, NULL); const StaticPixelFormatDesc* dstentry = getFormatDescEntry(dstformat, NULL, NULL); if (!srcentry) { FIXME(Unsupported pixelformat.\n); return 0; } if (!dstentry) { FIXME(Unsupported pixelformat.\n); return 0; } return convert_pixel(pixel, srcentry, dstentry); } static UINT get_pixel(const LPCVOID data, UINT bpp, const RECT* const rect, UINT pitch, UINT x, UINT y) { DWORD pixel = 0; memcpy(pixel, (char*)data + (rect-top + y) * pitch + (rect-left + x) * bpp, bpp); return pixel; }
Re: Review request: real async for GetAsyncKeyState (bug #5623)
On Wed, May 07, 2008 at 08:49:34PM +0200, Rafał Miłecki wrote: Hi, This is my first wine patch and fix for bug #5623. This was tested and works fine however I suspect this is not clean enought for commiting to master. -- Rafał Miłecki Applying this patch causes my Wine to fail with: (the second time, as it runs some font metric stuff once first) err:process:start_wineboot failed to create wineboot event, expect trouble err:font:WineEngInit Failed to create font mutex err:system:get_volatile_regkey Can't create wine registry branch err:system:get_volatile_regkey Can't create wine registry branch err:system:get_volatile_regkey Can't create wine registry branch err:system:get_volatile_regkey Can't create wine registry branch err:system:get_volatile_regkey Can't create wine registry branch err:system:get_volatile_regkey Can't create wine registry branch err:rpc:DllMain Failed to create master mutex err:winecfg:initialize RegOpenKey failed on wine config key (6) err:winecfg:WinMain initialization failed, aborting I assumed this was due to something that didn't recompile, but I made the tree clean and reconfigured it, and compiled again. No change. I will investigate a bit further as this patch might be useful for an application I have some problems with (I think it uses GetAsyncKeyState for modifiers). -- Philip Nilsson
Re: d3dx9: Texturing functions
On Sat, Apr 19, 2008 at 10:11:06AM +0200, [EMAIL PROTECTED] wrote: So, the first thing I want to make sure is that we redirect the function calls correctly in order to reduce double coding. This means on the one hand that we should call the Extended versions of each function from inside of the simpler ones (most default parameters for the Ex functions are on MSDN) and on the other hand that we unify all D3DXCreateTextureFromXXEx functions somehow. I don't know how Resources are stored internally, but I guess the simplest would be to redirect all of them to D3DXCreateTextureFromFileInMemory, i.e. when D3DXCreateTextureFromFile is called we read the file into memory and call the InMemory function. I hope this shouldn't be too hard to be applied to the resource function either. Of course, this should also be done at the corresponding Surface, Volume and cube texture functions. Also, I haven't looked too much into it yet, but I guess we could go even a step further and define the CreateTextuteFromXX calls like this: 1. Redirect to the corresponding D3DXCreateXFromFileInMemoryEx call 2. Call D3DXCheckXRequirements 3. Call IDirect3DDevice9::CreateTexture 4. Lock its surface 5. Call LoadSurfaceFromFileEx with it This would reduce most of our coding work on LoadSurfaceFromFileEx. However, there are still plenty of formats supported by the texturing functions and thus, plenty of work for us to do. IIRC we once came to the decision to use libraries like libpng or so to reduce that work, too, so we'd just need to implement formats like .dds. I can't remember what the differences are between the CreateTexture and LoadSurface functions, but this is what I'd do for the LoadSurface functions: LoadSurfaceFromMemory (read data with the specified pixel format) LoadSurfaceFromFileInMemory (parse image format, read actual data into memory) LoadSurfaceFromFile (open file, read contents into memory) LoadSurfaceFromResource (open resource, read contents into memory) LoadSurfaceFromSurface (read image data from a surface) This would mean two huge chunks of code: One which parses image formats (LoadSurfaceFromFileInMemory), and one which handles all the resizing, conversion, filtering and stuff (LoadSurfaceFromMemory). -- Philip Nilsson
Re: d3dx9_36: Add stubs and implementations for D3DXCreateTexturexx
On Sun, Apr 13, 2008 at 06:22:29PM +0200, [EMAIL PROTECTED] wrote: Hi, Are you still working on the texture functions? I'd need them for completing my ID3DXSprite implementation, so if you don't mind I could complete your started patches. Best regards, Tony I have a hacky implementation of D3DXLoadSurfaceFromMemory and D3DXLoadSurfaceFromSurface, as well as a pretty good implementation of D3DXCreateTexture and D3DXCheckTextureRequirements. I'll send in the patch for the last two when I have time, and have looked it over a final time. I pretty much abandoned the first two, because there's got to be a whole lot of code somewhere in the tree already. It does work in some cases, however. Attached in case it might be helpful. -- Philip Nilsson struct d3dformat { unsigned int id; unsigned int amask; unsigned int rmask; unsigned int gmask; unsigned int bmask; unsigned int bytespp; }; /* TODO: Use the one in dlls/wined3d/utils.c */ struct d3dformat surface_formats[] = { {D3DFMT_A8R8G8B8, 0xff00, 0x00ff, 0xff00, 0x00ff, 4}, {D3DFMT_X8R8G8B8, 0x, 0x00ff, 0xff00, 0x00ff, 4}, {D3DFMT_R5G6B5, 0x, 0xf800, 0x07e0, 0x001f, 2}, {D3DFMT_A4R4G4B4, 0xf000, 0x0f00, 0x00f0, 0x000f, 2}, }; static struct d3dformat* find_format(const unsigned int format) { unsigned int i = 0; for (i = 0; i sizeof(surface_formats); ++i) { if (surface_formats[i].id == format) return surface_formats[i]; } return NULL; } /* XXX: From dlls/wined3d/utils.c */ /* This small helper function is used to convert a bitmask into the number of masked bits */ unsigned int count_bits(unsigned int mask) { unsigned int count; for (count = 0; mask; ++count) { mask = mask - 1; } return count; } static void do_magic_stuff(unsigned int* const dest, const unsigned int destmask, const unsigned int src, const unsigned int srcmask) { if (destmask == srcmask) { *dest = (*dest ~destmask) | (src srcmask); } else { unsigned int srcoff = count_bits(srcmask); unsigned int destoff = count_bits(destmask); /* Find out the maximum values the masks can hold. */ unsigned int srcmax = srcmask srcoff; unsigned int destmax = destmask destoff; /* Calculate a new scaled value. */ unsigned int newvalue = (float)((float)((src srcmask) srcoff) / (float)srcmax * (float)destmax); /* Clear the field first. */ /* Shift it into position. */ /* Remove any possible stray bits. */ /* Add it to the return value. */ *dest = (*dest ~destmask) | ((newvalue destoff) destmask); } } /* Translate a single pixel from one pixel format to another. * Pixels are passed in as 32-bit integers, the output pixel as a pointer. */ static void translate_pixel(unsigned int* const dest, const struct d3dformat* const destformat, const unsigned int src, const struct d3dformat* const srcformat) { /* Find the formats in the format table. */ do_magic_stuff(dest, destformat-rmask, src, srcformat-rmask); do_magic_stuff(dest, destformat-gmask, src, srcformat-gmask); do_magic_stuff(dest, destformat-bmask, src, srcformat-bmask); do_magic_stuff(dest, destformat-amask, src, srcformat-amask); } static HRESULT convert_memory( void* const dest, /* Destination buffer. */ const D3DFORMAT destfmt, /* Destination buffer format. */ const RECT* const destrect, /* Destination buffer rectangle. */ unsigned int destsurfacewidth, unsigned int destsurfaceheight, const void* const src, /* Source buffer. */ const D3DFORMAT srcfmt, /* Source buffer format. */ const RECT* const srcrect, /* Source buffer size. */ DWORD filter) { struct d3dformat* srcformat = find_format(srcfmt); struct d3dformat* destformat = find_format(destfmt); if (!srcformat || !destformat) { ERR(Unsupported format (%d or %d).\n, srcfmt, destfmt); return 0; } if (destrect == NULL || (srcrect-left == destrect-left srcrect-right == destrect-right srcrect-top == destrect-top srcrect-bottom == destrect-bottom)) { unsigned int x, y; /* I assume the rects are the same size here. */ /* I further assume that srcrect-left and srcrect-top are 0. */ /* Don't access destrect as it might be NULL. */ for (y = 0; y srcrect-bottom; ++y) { for (x = 0; x srcrect-right; ++x) { unsigned int srcpixel = 0; unsigned int destpixel = 0; unsigned int offset = y * srcrect-right + x; /* srcw == destw */ memcpy(srcpixel, (char*)src + offset * srcformat-bytespp, srcformat-bytespp); translate_pixel(destpixel, destformat, srcpixel, srcformat); /* I hope endianness
Re: wined3d: Initialize maxAttribs in case it isn't changed by glGetIntegerv.
On Sat, Mar 22, 2008 at 08:04:52PM +0100, Stefan Dösinger wrote: Am Samstag, 22. März 2008 18:28:52 schrieb Philip Nilsson: glGetIntegerv I've seen this behavior very old drivers(87.xx), but I am kinda puzzled why it happens with the new drivers. The patch is OK, but we should investigate why the call fails for you It appears to do nothing whichever enum I query. It doesn't even care if it's fed (-1, NULL). I'll try some things.