[PATCH 2/9] wined3d: Prepare wined3d_format_convert_from_float for > 32bpp formats.
Stefan Dösinger
stefan at codeweavers.com
Sun May 1 13:39:04 CDT 2022
Signed-off-by: Stefan Dösinger <stefan at codeweavers.com>
---
dlls/wined3d/device.c | 7 +++--
dlls/wined3d/resource.c | 16 +++++-----
dlls/wined3d/utils.c | 55 +++++++++++++++++++++++-----------
dlls/wined3d/wined3d_private.h | 4 +--
4 files changed, 53 insertions(+), 29 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 8937c7fc0fc..3e16370a580 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -3436,6 +3436,7 @@ static HRESULT process_vertices_strided(const struct wined3d_device *device, DWO
unsigned int vertex_size;
BOOL do_clip, lighting;
float min_z, max_z;
+ DWORD argb_color[4];
unsigned int i;
BYTE *dest_ptr;
HRESULT hr;
@@ -3689,7 +3690,8 @@ static HRESULT process_vertices_strided(const struct wined3d_device *device, DWO
diffuse_colour = material_diffuse;
}
wined3d_color_clamp(&diffuse_colour, &diffuse_colour, 0.0f, 1.0f);
- *((DWORD *)dest_ptr) = wined3d_format_convert_from_float(output_colour_format, &diffuse_colour);
+ wined3d_format_convert_from_float(output_colour_format, &diffuse_colour, argb_color);
+ *((DWORD *)dest_ptr) = argb_color[0];
dest_ptr += sizeof(DWORD);
}
@@ -3713,7 +3715,8 @@ static HRESULT process_vertices_strided(const struct wined3d_device *device, DWO
}
update_fog_factor(&specular_colour.a, &ls);
wined3d_color_clamp(&specular_colour, &specular_colour, 0.0f, 1.0f);
- *((DWORD *)dest_ptr) = wined3d_format_convert_from_float(output_colour_format, &specular_colour);
+ wined3d_format_convert_from_float(output_colour_format, &specular_colour, argb_color);
+ *((DWORD *)dest_ptr) = argb_color[0];
dest_ptr += sizeof(DWORD);
}
diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index a21949e79fd..cfbb60c3606 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -622,7 +622,7 @@ void wined3d_resource_memory_colour_fill(struct wined3d_resource *resource,
unsigned int w, h, d, x, y, z, bpp;
struct wined3d_box level_box;
uint8_t *dst, *dst2;
- DWORD c;
+ DWORD c[4];
if (resource->type == WINED3D_RTYPE_BUFFER)
{
@@ -646,7 +646,7 @@ void wined3d_resource_memory_colour_fill(struct wined3d_resource *resource,
+ ((box->top / format->block_height) * map->row_pitch)
+ ((box->left / format->block_width) * format->block_byte_count);
- c = wined3d_format_convert_from_float(format, colour);
+ wined3d_format_convert_from_float(format, colour, c);
bpp = format->byte_count;
switch (bpp)
@@ -654,14 +654,14 @@ void wined3d_resource_memory_colour_fill(struct wined3d_resource *resource,
case 1:
for (x = 0; x < w; ++x)
{
- dst[x] = c;
+ dst[x] = c[0];
}
break;
case 2:
for (x = 0; x < w; ++x)
{
- ((WORD *)dst)[x] = c;
+ ((WORD *)dst)[x] = c[0];
}
break;
@@ -670,16 +670,16 @@ void wined3d_resource_memory_colour_fill(struct wined3d_resource *resource,
dst2 = dst;
for (x = 0; x < w; ++x, dst += 3)
{
- dst2[0] = (c ) & 0xff;
- dst2[1] = (c >> 8) & 0xff;
- dst2[2] = (c >> 16) & 0xff;
+ dst2[0] = (c[0] ) & 0xff;
+ dst2[1] = (c[0] >> 8) & 0xff;
+ dst2[2] = (c[0] >> 16) & 0xff;
}
break;
}
case 4:
for (x = 0; x < w; ++x)
{
- ((DWORD *)dst)[x] = c;
+ ((DWORD *)dst)[x] = c[0];
}
break;
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index 401d815a365..23d5a0e30a7 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -6000,8 +6000,12 @@ uint32_t wined3d_format_pack(const struct wined3d_format *format, const struct w
/* Note: It's the caller's responsibility to ensure values can be expressed
* in the requested format. UNORM formats for example can only express values
- * in the range 0.0f -> 1.0f. */
-DWORD wined3d_format_convert_from_float(const struct wined3d_format *format, const struct wined3d_color *color)
+ * in the range 0.0f -> 1.0f.
+ *
+ * The code below assumes that no component crosses the 32 bit boundary (like
+ * e.g. a hypothetical, and totally braindead, B30G30R4 format would.) */
+void wined3d_format_convert_from_float(const struct wined3d_format *format, const struct wined3d_color *color,
+ DWORD ret[4])
{
static const struct
{
@@ -6044,10 +6048,11 @@ DWORD wined3d_format_convert_from_float(const struct wined3d_format *format, con
};
enum wined3d_format_id format_id = format->id;
struct wined3d_color colour_srgb;
+ struct wined3d_uvec4 idx, shift;
unsigned int i;
- DWORD ret;
TRACE("Converting colour %s to format %s.\n", debug_color(color), debug_d3dformat(format_id));
+ memset(ret, 0, sizeof(DWORD) * 4);
for (i = 0; i < ARRAY_SIZE(format_srgb_info); ++i)
{
@@ -6065,14 +6070,23 @@ DWORD wined3d_format_convert_from_float(const struct wined3d_format *format, con
if (format_id != float_conv[i].format_id)
continue;
- ret = ((DWORD)((color->r * float_conv[i].mul.x) + 0.5f)) << float_conv[i].shift.x;
- ret |= ((DWORD)((color->g * float_conv[i].mul.y) + 0.5f)) << float_conv[i].shift.y;
- ret |= ((DWORD)((color->b * float_conv[i].mul.z) + 0.5f)) << float_conv[i].shift.z;
- ret |= ((DWORD)((color->a * float_conv[i].mul.w) + 0.5f)) << float_conv[i].shift.w;
+ idx.x = float_conv[i].shift.x / 32;
+ idx.y = float_conv[i].shift.y / 32;
+ idx.z = float_conv[i].shift.z / 32;
+ idx.w = float_conv[i].shift.w / 32;
+ shift.x = float_conv[i].shift.x % 32;
+ shift.y = float_conv[i].shift.y % 32;
+ shift.z = float_conv[i].shift.z % 32;
+ shift.w = float_conv[i].shift.w % 32;
+
+ ret[idx.x] = ((DWORD)((color->r * float_conv[i].mul.x) + 0.5f)) << shift.x;
+ ret[idx.y] |= ((DWORD)((color->g * float_conv[i].mul.y) + 0.5f)) << shift.y;
+ ret[idx.z] |= ((DWORD)((color->b * float_conv[i].mul.z) + 0.5f)) << shift.z;
+ ret[idx.w] |= ((DWORD)((color->a * float_conv[i].mul.w) + 0.5f)) << shift.w;
- TRACE("Returning 0x%08x.\n", ret);
+ TRACE("Returning 0x%08x 0x%08x 0x%08x 0x%08x.\n", ret[0], ret[1], ret[2], ret[3]);
- return ret;
+ return;
}
for (i = 0; i < ARRAY_SIZE(double_conv); ++i)
@@ -6080,19 +6094,26 @@ DWORD wined3d_format_convert_from_float(const struct wined3d_format *format, con
if (format_id != double_conv[i].format_id)
continue;
- ret = ((DWORD)((color->r * double_conv[i].mul.x) + 0.5)) << double_conv[i].shift.x;
- ret |= ((DWORD)((color->g * double_conv[i].mul.y) + 0.5)) << double_conv[i].shift.y;
- ret |= ((DWORD)((color->b * double_conv[i].mul.z) + 0.5)) << double_conv[i].shift.z;
- ret |= ((DWORD)((color->a * double_conv[i].mul.w) + 0.5)) << double_conv[i].shift.w;
+ idx.x = float_conv[i].shift.x / 32;
+ idx.y = float_conv[i].shift.y / 32;
+ idx.z = float_conv[i].shift.z / 32;
+ idx.w = float_conv[i].shift.w / 32;
+ shift.x = float_conv[i].shift.x % 32;
+ shift.y = float_conv[i].shift.y % 32;
+ shift.z = float_conv[i].shift.z % 32;
+ shift.w = float_conv[i].shift.w % 32;
+
+ ret[idx.x] = ((DWORD)((color->r * double_conv[i].mul.x) + 0.5)) << double_conv[i].shift.x;
+ ret[idx.y] |= ((DWORD)((color->g * double_conv[i].mul.y) + 0.5)) << double_conv[i].shift.y;
+ ret[idx.z] |= ((DWORD)((color->b * double_conv[i].mul.z) + 0.5)) << double_conv[i].shift.z;
+ ret[idx.w] |= ((DWORD)((color->a * double_conv[i].mul.w) + 0.5)) << double_conv[i].shift.w;
- TRACE("Returning 0x%08x.\n", ret);
+ TRACE("Returning 0x%08x 0x%08x 0x%08x 0x%08x.\n", ret[0], ret[1], ret[2], ret[3]);
- return ret;
+ return;
}
FIXME("Conversion for format %s not implemented.\n", debug_d3dformat(format_id));
-
- return 0;
}
static float color_to_float(DWORD color, DWORD size, DWORD offset)
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index e19eb476153..07275fe6359 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -6149,8 +6149,8 @@ void wined3d_format_calculate_pitch(const struct wined3d_format *format, unsigne
unsigned int width, unsigned int height, unsigned int *row_pitch, unsigned int *slice_pitch) DECLSPEC_HIDDEN;
UINT wined3d_format_calculate_size(const struct wined3d_format *format,
UINT alignment, UINT width, UINT height, UINT depth) DECLSPEC_HIDDEN;
-DWORD wined3d_format_convert_from_float(const struct wined3d_format *format,
- const struct wined3d_color *color) DECLSPEC_HIDDEN;
+void wined3d_format_convert_from_float(const struct wined3d_format *format,
+ const struct wined3d_color *color, DWORD ret[4]) DECLSPEC_HIDDEN;
void wined3d_format_copy_data(const struct wined3d_format *format, const uint8_t *src,
unsigned int src_row_pitch, unsigned int src_slice_pitch, uint8_t *dst, unsigned int dst_row_pitch,
unsigned int dst_slice_pitch, unsigned int w, unsigned int h, unsigned int d) DECLSPEC_HIDDEN;
--
2.35.1
More information about the wine-devel
mailing list