d3dx9_36 [try 2]: Save multiplications and divisions to improve performance
David Adam
david.adam.cnrs at gmail.com
Thu Jun 25 16:45:52 CDT 2015
Hi,
I added a test with 65000 sides. All the test pass with a native d3dx9_36
dll.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20150625/6260c51c/attachment.html>
-------------- next part --------------
From b347a300814cfa032905584e06384c17ee39ad56 Mon Sep 17 00:00:00 2001
From: David Adam <david.adam.cnrs at gmail.com>
Date: Thu, 25 Jun 2015 11:11:29 -1000
Subject: d3dx9_36: Save multiplications and divisions to improve performance
---
dlls/d3dx9_36/mesh.c | 10 ++++++----
dlls/d3dx9_36/tests/mesh.c | 11 +++++++----
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/dlls/d3dx9_36/mesh.c b/dlls/d3dx9_36/mesh.c
index 746b479..5be54d2 100644
--- a/dlls/d3dx9_36/mesh.c
+++ b/dlls/d3dx9_36/mesh.c
@@ -4563,7 +4563,7 @@ HRESULT WINAPI D3DXCreatePolygon(struct IDirect3DDevice9 *device, float length,
struct vertex *vertices;
WORD (*faces)[3];
DWORD (*adjacency_buf)[3];
- float scale;
+ float angle, scale;
unsigned int i;
TRACE("device %p, length %f, sides %u, mesh %p, adjacency %p.\n",
@@ -4591,7 +4591,9 @@ HRESULT WINAPI D3DXCreatePolygon(struct IDirect3DDevice9 *device, float length,
return hr;
}
- scale = 0.5f * length / sinf(D3DX_PI / sides);
+ angle = D3DX_PI / sides;
+ scale = 0.5f * length / sinf(angle);
+ angle *= 2.0f;
vertices[0].position.x = 0.0f;
vertices[0].position.y = 0.0f;
@@ -4602,8 +4604,8 @@ HRESULT WINAPI D3DXCreatePolygon(struct IDirect3DDevice9 *device, float length,
for (i = 0; i < sides; ++i)
{
- vertices[i + 1].position.x = cosf(2.0f * D3DX_PI * i / sides) * scale;
- vertices[i + 1].position.y = sinf(2.0f * D3DX_PI * i / sides) * scale;
+ vertices[i + 1].position.x = cosf(angle * i) * scale;
+ vertices[i + 1].position.y = sinf(angle * i) * scale;
vertices[i + 1].position.z = 0.0f;
vertices[i + 1].normal.x = 0.0f;
vertices[i + 1].normal.y = 0.0f;
diff --git a/dlls/d3dx9_36/tests/mesh.c b/dlls/d3dx9_36/tests/mesh.c
index dac0f60..2a3ad2b 100644
--- a/dlls/d3dx9_36/tests/mesh.c
+++ b/dlls/d3dx9_36/tests/mesh.c
@@ -2605,12 +2605,14 @@ static void D3DXCreateBoxTest(void)
static BOOL compute_polygon(struct mesh *mesh, float length, unsigned int sides)
{
unsigned int i;
- float scale;
+ float angle, scale;
if (!new_mesh(mesh, sides + 1, sides))
return FALSE;
- scale = 0.5f * length / sinf(D3DX_PI / sides);
+ angle = D3DX_PI / sides;
+ scale = 0.5f * length / sinf(angle);
+ angle *= 2.0f;
mesh->vertices[0].position.x = 0.0f;
mesh->vertices[0].position.y = 0.0f;
@@ -2621,8 +2623,8 @@ static BOOL compute_polygon(struct mesh *mesh, float length, unsigned int sides)
for (i = 0; i < sides; ++i)
{
- mesh->vertices[i + 1].position.x = cosf(2.0f * D3DX_PI * i / sides) * scale;
- mesh->vertices[i + 1].position.y = sinf(2.0f * D3DX_PI * i / sides) * scale;
+ mesh->vertices[i + 1].position.x = cosf(angle * i) * scale;
+ mesh->vertices[i + 1].position.y = sinf(angle * i) * scale;
mesh->vertices[i + 1].position.z = 0.0f;
mesh->vertices[i + 1].normal.x = 0.0f;
mesh->vertices[i + 1].normal.y = 0.0f;
@@ -2750,6 +2752,7 @@ static void D3DXCreatePolygonTest(void)
test_polygon(device, 10.0f, 5);
test_polygon(device, 10.0f, 10);
test_polygon(device, 20.0f, 10);
+ test_polygon(device, 20.0f, 65000);
IDirect3DDevice9_Release(device);
IDirect3D9_Release(d3d);
--
2.1.4
More information about the wine-patches
mailing list