Merge pull request #6900 from hrydgard/gpu-convergence-2

Gpu convergence 2 - break out much of the Spline code into GPU/Common, fixes some minor things
This commit is contained in:
Unknown W. Brackets 2014-09-13 12:06:35 -07:00
commit 5a0f646916
17 changed files with 1346 additions and 1016 deletions

View File

@ -1305,6 +1305,10 @@ add_library(GPU OBJECT
GPU/Common/FramebufferCommon.cpp GPU/Common/FramebufferCommon.cpp
GPU/Common/FramebufferCommon.h GPU/Common/FramebufferCommon.h
GPU/Common/GPUDebugInterface.h GPU/Common/GPUDebugInterface.h
GPU/Common/DrawEngineCommon.cpp
GPU/Common/DrawEngineCommon.h
GPU/Common/SplineCommon.cpp
GPU/Common/SplineCommon.h
GPU/Common/SoftwareTransformCommon.cpp GPU/Common/SoftwareTransformCommon.cpp
GPU/Common/SoftwareTransformCommon.h GPU/Common/SoftwareTransformCommon.h
GPU/Common/VertexDecoderCommon.cpp GPU/Common/VertexDecoderCommon.cpp

View File

@ -0,0 +1,20 @@
// Copyright (c) 2013- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "GPU/Common/DrawEngineCommon.h"
DrawEngineCommon::~DrawEngineCommon() { }

View File

@ -0,0 +1,24 @@
// Copyright (c) 2013- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#pragma once
class DrawEngineCommon {
public:
virtual ~DrawEngineCommon();
};

484
GPU/Common/SplineCommon.cpp Normal file
View File

@ -0,0 +1,484 @@
// Copyright (c) 2013- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <string.h>
#include <algorithm>
#include "Core/Config.h"
#include "GPU/Common/SplineCommon.h"
#include "GPU/ge_constants.h"
#include "GPU/GPUState.h"
#define START_OPEN 1
#define END_OPEN 2
static void CopyQuad(u8 *&dest, const SimpleVertex *v1, const SimpleVertex *v2, const SimpleVertex* v3, const SimpleVertex *v4) {
int vertexSize = sizeof(SimpleVertex);
memcpy(dest, v1, vertexSize);
dest += vertexSize;
memcpy(dest, v2, vertexSize);
dest += vertexSize;
memcpy(dest, v3, vertexSize);
dest += vertexSize;
memcpy(dest, v4, vertexSize);
dest += vertexSize;
}
#undef b2
// Bernstein basis functions
inline float bern0(float x) { return (1 - x) * (1 - x) * (1 - x); }
inline float bern1(float x) { return 3 * x * (1 - x) * (1 - x); }
inline float bern2(float x) { return 3 * x * x * (1 - x); }
inline float bern3(float x) { return x * x * x; }
// Not sure yet if these have any use
inline float bern0deriv(float x) { return -3 * (x - 1) * (x - 1); }
inline float bern1deriv(float x) { return 9 * x * x - 12 * x + 3; }
inline float bern2deriv(float x) { return 3 * (2 - 3 * x) * x; }
inline float bern3deriv(float x) { return 3 * x * x; }
// http://en.wikipedia.org/wiki/Bernstein_polynomial
Vec3Packedf Bernstein3D(const Vec3Packedf p0, const Vec3Packedf p1, const Vec3Packedf p2, const Vec3Packedf p3, float x) {
return p0 * bern0(x) + p1 * bern1(x) + p2 * bern2(x) + p3 * bern3(x);
}
Vec3Packedf Bernstein3DDerivative(const Vec3Packedf p0, const Vec3Packedf p1, const Vec3Packedf p2, const Vec3Packedf p3, float x) {
return p0 * bern0deriv(x) + p1 * bern1deriv(x) + p2 * bern2deriv(x) + p3 * bern3deriv(x);
}
void spline_n_4(int i, float t, float *knot, float *splineVal) {
knot += i + 1;
float t0 = (t - knot[0]);
float t1 = (t - knot[1]);
float t2 = (t - knot[2]);
float f30 = t0/(knot[3]-knot[0]);
float f41 = t1/(knot[4]-knot[1]);
float f52 = t2/(knot[5]-knot[2]);
float f31 = t1/(knot[3]-knot[1]);
float f42 = t2/(knot[4]-knot[2]);
float f32 = t2/(knot[3]-knot[2]);
float a = (1-f30)*(1-f31);
float b = (f31*f41);
float c = (1-f41)*(1-f42);
float d = (f42*f52);
splineVal[0] = a-(a*f32);
splineVal[1] = 1-a-b+((a+b+c-1)*f32);
splineVal[2] = b+((1-b-c-d)*f32);
splineVal[3] = d*f32;
}
// knot should be an array sized n + 5 (n + 1 + 1 + degree (cubic))
void spline_knot(int n, int type, float *knot) {
memset(knot, 0, sizeof(float) * (n + 5));
for (int i = 0; i < n - 1; ++i)
knot[i + 3] = i;
if ((type & 1) == 0) {
knot[0] = -3;
knot[1] = -2;
knot[2] = -1;
}
if ((type & 2) == 0) {
knot[n + 2] = n - 1;
knot[n + 3] = n;
knot[n + 4] = n + 1;
} else {
knot[n + 2] = n - 2;
knot[n + 3] = n - 2;
knot[n + 4] = n - 2;
}
}
void _SplinePatchLowQuality(u8 *&dest, int &count, const SplinePatchLocal &spatch, u32 origVertType) {
const float third = 1.0f / 3.0f;
// Fast and easy way - just draw the control points, generate some very basic normal vector substitutes.
// Very inaccurate but okay for Loco Roco. Maybe should keep it as an option because it's fast.
const int tile_min_u = (spatch.type_u & START_OPEN) ? 0 : 1;
const int tile_min_v = (spatch.type_v & START_OPEN) ? 0 : 1;
const int tile_max_u = (spatch.type_u & END_OPEN) ? spatch.count_u - 1 : spatch.count_u - 2;
const int tile_max_v = (spatch.type_v & END_OPEN) ? spatch.count_v - 1 : spatch.count_v - 2;
for (int tile_v = tile_min_v; tile_v < tile_max_v; ++tile_v) {
for (int tile_u = tile_min_u; tile_u < tile_max_u; ++tile_u) {
int point_index = tile_u + tile_v * spatch.count_u;
SimpleVertex v0 = *spatch.points[point_index];
SimpleVertex v1 = *spatch.points[point_index + 1];
SimpleVertex v2 = *spatch.points[point_index + spatch.count_u];
SimpleVertex v3 = *spatch.points[point_index + spatch.count_u + 1];
// Generate UV. TODO: Do this even if UV specified in control points?
if ((origVertType & GE_VTYPE_TC_MASK) == 0) {
float u = tile_u * third;
float v = tile_v * third;
v0.uv[0] = u;
v0.uv[1] = v;
v1.uv[0] = u + third;
v1.uv[1] = v;
v2.uv[0] = u;
v2.uv[1] = v + third;
v3.uv[0] = u + third;
v3.uv[1] = v + third;
}
// Generate normal if lighting is enabled (otherwise there's no point).
// This is a really poor quality algorithm, we get facet normals.
if (gstate.isLightingEnabled()) {
Vec3Packedf norm = Cross(v1.pos - v0.pos, v2.pos - v0.pos);
norm.Normalize();
if (gstate.patchfacing & 1)
norm *= -1.0f;
v0.nrm = norm;
v1.nrm = norm;
v2.nrm = norm;
v3.nrm = norm;
}
CopyQuad(dest, &v0, &v1, &v2, &v3);
count += 6;
}
}
}
void _SplinePatchFullQuality(u8 *&dest, int &count, const SplinePatchLocal &spatch, u32 origVertType, int patch_cap) {
// Full (mostly) correct tessellation of spline patches.
// Not very fast.
// First, generate knot vectors.
int n = spatch.count_u - 1;
int m = spatch.count_v - 1;
float *knot_u = new float[n + 5];
float *knot_v = new float[m + 5];
spline_knot(n, spatch.type_u, knot_u);
spline_knot(m, spatch.type_v, knot_v);
// Increase tesselation based on the size. Should be approximately right?
// JPCSP is wrong at least because their method results in square loco roco.
int patch_div_s = (spatch.count_u - 3) * gstate.getPatchDivisionU() / 3;
int patch_div_t = (spatch.count_v - 3) * gstate.getPatchDivisionV() / 3;
if (patch_div_s <= 0) patch_div_s = 1;
if (patch_div_t <= 0) patch_div_t = 1;
// TODO: Remove this cap when spline_s has been optimized.
if (patch_div_s > patch_cap) patch_div_s = patch_cap;
if (patch_div_t > patch_cap) patch_div_t = patch_cap;
// First compute all the vertices and put them in an array
SimpleVertex *vertices = new SimpleVertex[(patch_div_s + 1) * (patch_div_t + 1)];
float tu_width = 1.0f + (spatch.count_u - 4) * 1.0f / 3.0f;
float tv_height = 1.0f + (spatch.count_v - 4) * 1.0f / 3.0f;
bool computeNormals = gstate.isLightingEnabled();
for (int tile_v = 0; tile_v < patch_div_t + 1; tile_v++) {
float v = ((float)tile_v * (float)(m - 2) / (float)(patch_div_t + 0.00001f)); // epsilon to prevent division by 0 in spline_s
if (v < 0.0f)
v = 0.0f;
for (int tile_u = 0; tile_u < patch_div_s + 1; tile_u++) {
float u = ((float)tile_u * (float)(n - 2) / (float)(patch_div_s + 0.00001f));
if (u < 0.0f)
u = 0.0f;
SimpleVertex *vert = &vertices[tile_v * (patch_div_s + 1) + tile_u];
vert->pos.SetZero();
if (origVertType & GE_VTYPE_NRM_MASK) {
vert->nrm.SetZero();
}
else {
vert->nrm.SetZero();
vert->nrm.z = 1.0f;
}
if (origVertType & GE_VTYPE_COL_MASK) {
memset(vert->color, 0, 4);
}
else {
memcpy(vert->color, spatch.points[0]->color, 4);
}
if (origVertType & GE_VTYPE_TC_MASK) {
vert->uv[0] = 0.0f;
vert->uv[1] = 0.0f;
}
else {
vert->uv[0] = tu_width * ((float)tile_u / (float)patch_div_s);
vert->uv[1] = tv_height * ((float)tile_v / (float)patch_div_t);
}
// Collect influences from surrounding control points.
float u_weights[4];
float v_weights[4];
int iu = (int)u;
int iv = (int)v;
spline_n_4(iu, u, knot_u, u_weights);
spline_n_4(iv, v, knot_v, v_weights);
// Handle degenerate patches. without this, spatch.points[] may read outside the number of initialized points.
int patch_w = std::min(spatch.count_u, 4);
int patch_h = std::min(spatch.count_v, 4);
for (int ii = 0; ii < patch_w; ++ii) {
for (int jj = 0; jj < patch_h; ++jj) {
float u_spline = u_weights[ii];
float v_spline = v_weights[jj];
float f = u_spline * v_spline;
if (f > 0.0f) {
int idx = spatch.count_u * (iv + jj) + (iu + ii);
SimpleVertex *a = spatch.points[idx];
vert->pos += a->pos * f;
if (origVertType & GE_VTYPE_TC_MASK) {
vert->uv[0] += a->uv[0] * f;
vert->uv[1] += a->uv[1] * f;
}
if (origVertType & GE_VTYPE_COL_MASK) {
vert->color[0] += a->color[0] * f;
vert->color[1] += a->color[1] * f;
vert->color[2] += a->color[2] * f;
vert->color[3] += a->color[3] * f;
}
if (origVertType & GE_VTYPE_NRM_MASK) {
vert->nrm += a->nrm * f;
}
}
}
}
if (origVertType & GE_VTYPE_NRM_MASK) {
vert->nrm.Normalize();
}
}
}
delete[] knot_u;
delete[] knot_v;
// Hacky normal generation through central difference.
if (gstate.isLightingEnabled() && (origVertType & GE_VTYPE_NRM_MASK) == 0) {
for (int v = 0; v < patch_div_t + 1; v++) {
for (int u = 0; u < patch_div_s + 1; u++) {
int l = std::max(0, u - 1);
int t = std::max(0, v - 1);
int r = std::min(patch_div_s, u + 1);
int b = std::min(patch_div_t, v + 1);
const Vec3Packedf &right = vertices[v * (patch_div_s + 1) + r].pos - vertices[v * (patch_div_s + 1) + l].pos;
const Vec3Packedf &down = vertices[b * (patch_div_s + 1) + u].pos - vertices[t * (patch_div_s + 1) + u].pos;
vertices[v * (patch_div_s + 1) + u].nrm = Cross(right, down).Normalized();
if (gstate.patchfacing & 1) {
vertices[v * (patch_div_s + 1) + u].nrm *= -1.0f;
}
}
}
}
// Tesselate. TODO: Use indices so we only need to emit 4 vertices per pair of triangles instead of six.
for (int tile_v = 0; tile_v < patch_div_t; ++tile_v) {
for (int tile_u = 0; tile_u < patch_div_s; ++tile_u) {
float u = ((float)tile_u / (float)patch_div_s);
float v = ((float)tile_v / (float)patch_div_t);
SimpleVertex *v0 = &vertices[tile_v * (patch_div_s + 1) + tile_u];
SimpleVertex *v1 = &vertices[tile_v * (patch_div_s + 1) + tile_u + 1];
SimpleVertex *v2 = &vertices[(tile_v + 1) * (patch_div_s + 1) + tile_u];
SimpleVertex *v3 = &vertices[(tile_v + 1) * (patch_div_s + 1) + tile_u + 1];
CopyQuad(dest, v0, v1, v2, v3);
count += 6;
}
}
delete[] vertices;
}
void TesselateSplinePatch(u8 *&dest, int &count, const SplinePatchLocal &spatch, u32 origVertType) {
switch (g_Config.iSplineBezierQuality) {
case LOW_QUALITY:
_SplinePatchLowQuality(dest, count, spatch, origVertType);
break;
case MEDIUM_QUALITY:
_SplinePatchFullQuality(dest, count, spatch, origVertType, 8);
break;
case HIGH_QUALITY:
_SplinePatchFullQuality(dest, count, spatch, origVertType, 64);
break;
}
}
void _BezierPatchLowQuality(u8 *&dest, int &count, int tess_u, int tess_v, const BezierPatch &patch, u32 origVertType) {
const float third = 1.0f / 3.0f;
// Fast and easy way - just draw the control points, generate some very basic normal vector subsitutes.
// Very inaccurate though but okay for Loco Roco. Maybe should keep it as an option.
float u_base = patch.u_index / 3.0f;
float v_base = patch.v_index / 3.0f;
for (int tile_v = 0; tile_v < 3; tile_v++) {
for (int tile_u = 0; tile_u < 3; tile_u++) {
int point_index = tile_u + tile_v * 4;
SimpleVertex v0 = *patch.points[point_index];
SimpleVertex v1 = *patch.points[point_index + 1];
SimpleVertex v2 = *patch.points[point_index + 4];
SimpleVertex v3 = *patch.points[point_index + 5];
// Generate UV. TODO: Do this even if UV specified in control points?
if ((origVertType & GE_VTYPE_TC_MASK) == 0) {
float u = u_base + tile_u * third;
float v = v_base + tile_v * third;
v0.uv[0] = u;
v0.uv[1] = v;
v1.uv[0] = u + third;
v1.uv[1] = v;
v2.uv[0] = u;
v2.uv[1] = v + third;
v3.uv[0] = u + third;
v3.uv[1] = v + third;
}
// Generate normal if lighting is enabled (otherwise there's no point).
// This is a really poor quality algorithm, we get facet normals.
if (gstate.isLightingEnabled()) {
Vec3Packedf norm = Cross(v1.pos - v0.pos, v2.pos - v0.pos);
norm.Normalize();
if (gstate.patchfacing & 1)
norm *= -1.0f;
v0.nrm = norm;
v1.nrm = norm;
v2.nrm = norm;
v3.nrm = norm;
}
CopyQuad(dest, &v0, &v1, &v2, &v3);
count += 6;
}
}
}
void _BezierPatchHighQuality(u8 *&dest, int &count, int tess_u, int tess_v, const BezierPatch &patch, u32 origVertType) {
const float third = 1.0f / 3.0f;
// Full correct tesselation of bezier patches.
// Note: Does not handle splines correctly.
// First compute all the vertices and put them in an array
SimpleVertex *vertices = new SimpleVertex[(tess_u + 1) * (tess_v + 1)];
Vec3Packedf *horiz = new Vec3Packedf[(tess_u + 1) * 4];
Vec3Packedf *horiz2 = horiz + (tess_u + 1) * 1;
Vec3Packedf *horiz3 = horiz + (tess_u + 1) * 2;
Vec3Packedf *horiz4 = horiz + (tess_u + 1) * 3;
// Precompute the horizontal curves to we only have to evaluate the vertical ones.
for (int i = 0; i < tess_u + 1; i++) {
float u = ((float)i / (float)tess_u);
horiz[i] = Bernstein3D(patch.points[0]->pos, patch.points[1]->pos, patch.points[2]->pos, patch.points[3]->pos, u);
horiz2[i] = Bernstein3D(patch.points[4]->pos, patch.points[5]->pos, patch.points[6]->pos, patch.points[7]->pos, u);
horiz3[i] = Bernstein3D(patch.points[8]->pos, patch.points[9]->pos, patch.points[10]->pos, patch.points[11]->pos, u);
horiz4[i] = Bernstein3D(patch.points[12]->pos, patch.points[13]->pos, patch.points[14]->pos, patch.points[15]->pos, u);
}
bool computeNormals = gstate.isLightingEnabled();
for (int tile_v = 0; tile_v < tess_v + 1; ++tile_v) {
for (int tile_u = 0; tile_u < tess_u + 1; ++tile_u) {
float u = ((float)tile_u / (float)tess_u);
float v = ((float)tile_v / (float)tess_v);
float bu = u;
float bv = v;
// TODO: Should be able to precompute the four curves per U, then just Bernstein per V. Will benefit large tesselation factors.
const Vec3Packedf &pos1 = horiz[tile_u];
const Vec3Packedf &pos2 = horiz2[tile_u];
const Vec3Packedf &pos3 = horiz3[tile_u];
const Vec3Packedf &pos4 = horiz4[tile_u];
SimpleVertex &vert = vertices[tile_v * (tess_u + 1) + tile_u];
if (computeNormals) {
Vec3Packedf derivU1 = Bernstein3DDerivative(patch.points[0]->pos, patch.points[1]->pos, patch.points[2]->pos, patch.points[3]->pos, bu);
Vec3Packedf derivU2 = Bernstein3DDerivative(patch.points[4]->pos, patch.points[5]->pos, patch.points[6]->pos, patch.points[7]->pos, bu);
Vec3Packedf derivU3 = Bernstein3DDerivative(patch.points[8]->pos, patch.points[9]->pos, patch.points[10]->pos, patch.points[11]->pos, bu);
Vec3Packedf derivU4 = Bernstein3DDerivative(patch.points[12]->pos, patch.points[13]->pos, patch.points[14]->pos, patch.points[15]->pos, bu);
Vec3Packedf derivU = Bernstein3D(derivU1, derivU2, derivU3, derivU4, bv);
Vec3Packedf derivV = Bernstein3DDerivative(pos1, pos2, pos3, pos4, bv);
// TODO: Interpolate normals instead of generating them, if available?
vert.nrm = Cross(derivU, derivV).Normalized();
if (gstate.patchfacing & 1)
vert.nrm *= -1.0f;
}
else {
vert.nrm.SetZero();
}
vert.pos = Bernstein3D(pos1, pos2, pos3, pos4, bv);
if ((origVertType & GE_VTYPE_TC_MASK) == 0) {
// Generate texcoord
vert.uv[0] = u + patch.u_index * third;
vert.uv[1] = v + patch.v_index * third;
} else {
// Sample UV from control points
patch.sampleTexUV(u, v, vert.uv[0], vert.uv[1]);
}
if (origVertType & GE_VTYPE_COL_MASK) {
patch.sampleColor(u, v, vert.color);
} else {
memcpy(vert.color, patch.points[0]->color, 4);
}
}
}
delete[] horiz;
// Tesselate. TODO: Use indices so we only need to emit 4 vertices per pair of triangles instead of six.
for (int tile_v = 0; tile_v < tess_v; ++tile_v) {
for (int tile_u = 0; tile_u < tess_u; ++tile_u) {
float u = ((float)tile_u / (float)tess_u);
float v = ((float)tile_v / (float)tess_v);
const SimpleVertex *v0 = &vertices[tile_v * (tess_u + 1) + tile_u];
const SimpleVertex *v1 = &vertices[tile_v * (tess_u + 1) + tile_u + 1];
const SimpleVertex *v2 = &vertices[(tile_v + 1) * (tess_u + 1) + tile_u];
const SimpleVertex *v3 = &vertices[(tile_v + 1) * (tess_u + 1) + tile_u + 1];
CopyQuad(dest, v0, v1, v2, v3);
count += 6;
}
}
delete[] vertices;
}
void TesselateBezierPatch(u8 *&dest, int &count, int tess_u, int tess_v, const BezierPatch &patch, u32 origVertType) {
switch (g_Config.iSplineBezierQuality) {
case LOW_QUALITY:
_BezierPatchLowQuality(dest, count, tess_u, tess_v, patch, origVertType);
break;
case MEDIUM_QUALITY:
case HIGH_QUALITY:
_BezierPatchHighQuality(dest, count, tess_u, tess_v, patch, origVertType);
break;
}
}

View File

@ -27,3 +27,140 @@ struct SimpleVertex {
Vec3Packedf nrm; Vec3Packedf nrm;
Vec3Packedf pos; Vec3Packedf pos;
}; };
inline float lerp(float a, float b, float x) {
return a + x * (b - a);
}
// SLOW!
inline void lerpColor(u8 a[4], u8 b[4], float x, u8 out[4]) {
for (int i = 0; i < 4; i++) {
out[i] = (u8)((float)a[i] + x * ((float)b[i] - (float)a[i]));
}
}
// We decode all vertices into a common format for easy interpolation and stuff.
// Not fast but can be optimized later.
struct BezierPatch {
SimpleVertex *points[16];
// These are used to generate UVs.
int u_index, v_index;
// Interpolate colors between control points (bilinear, should be good enough).
void sampleColor(float u, float v, u8 color[4]) const {
u *= 3.0f;
v *= 3.0f;
int iu = (int)floorf(u);
int iv = (int)floorf(v);
int iu2 = iu + 1;
int iv2 = iv + 1;
float fracU = u - iu;
float fracV = v - iv;
if (iu2 > 3) iu2 = 3;
if (iv2 > 3) iv2 = 3;
int tl = iu + 4 * iv;
int tr = iu2 + 4 * iv;
int bl = iu + 4 * iv2;
int br = iu2 + 4 * iv2;
u8 upperColor[4], lowerColor[4];
lerpColor(points[tl]->color, points[tr]->color, fracU, upperColor);
lerpColor(points[bl]->color, points[br]->color, fracU, lowerColor);
lerpColor(upperColor, lowerColor, fracV, color);
}
void sampleTexUV(float u, float v, float &tu, float &tv) const {
u *= 3.0f;
v *= 3.0f;
int iu = (int)floorf(u);
int iv = (int)floorf(v);
int iu2 = iu + 1;
int iv2 = iv + 1;
float fracU = u - iu;
float fracV = v - iv;
if (iu2 > 3) iu2 = 3;
if (iv2 > 3) iv2 = 3;
int tl = iu + 4 * iv;
int tr = iu2 + 4 * iv;
int bl = iu + 4 * iv2;
int br = iu2 + 4 * iv2;
float upperTU = lerp(points[tl]->uv[0], points[tr]->uv[0], fracU);
float upperTV = lerp(points[tl]->uv[1], points[tr]->uv[1], fracU);
float lowerTU = lerp(points[bl]->uv[0], points[br]->uv[0], fracU);
float lowerTV = lerp(points[bl]->uv[1], points[br]->uv[1], fracU);
tu = lerp(upperTU, lowerTU, fracV);
tv = lerp(upperTV, lowerTV, fracV);
}
};
struct SplinePatchLocal {
SimpleVertex **points;
int count_u;
int count_v;
int type_u;
int type_v;
/*
// Interpolate colors between control points (bilinear, should be good enough).
void sampleColor(float u, float v, u8 color[4]) const {
u *= 3.0f;
v *= 3.0f;
int iu = (int)floorf(u);
int iv = (int)floorf(v);
int iu2 = iu + 1;
int iv2 = iv + 1;
float fracU = u - iu;
float fracV = v - iv;
if (iu2 >= count_u) iu2 = count_u - 1;
if (iv2 >= count_v) iv2 = count_v - 1;
int tl = iu + count_u * iv;
int tr = iu2 + count_u * iv;
int bl = iu + count_u * iv2;
int br = iu2 + count_u * iv2;
u8 upperColor[4], lowerColor[4];
lerpColor(points[tl]->color, points[tr]->color, fracU, upperColor);
lerpColor(points[bl]->color, points[br]->color, fracU, lowerColor);
lerpColor(upperColor, lowerColor, fracV, color);
}
void sampleTexUV(float u, float v, float &tu, float &tv) const {
u *= 3.0f;
v *= 3.0f;
int iu = (int)floorf(u);
int iv = (int)floorf(v);
int iu2 = iu + 1;
int iv2 = iv + 1;
float fracU = u - iu;
float fracV = v - iv;
if (iu2 >= count_u) iu2 = count_u - 1;
if (iv2 >= count_v) iv2 = count_v - 1;
int tl = iu + count_u * iv;
int tr = iu2 + count_u * iv;
int bl = iu + count_u * iv2;
int br = iu2 + count_u * iv2;
float upperTU = lerp(points[tl]->uv[0], points[tr]->uv[0], fracU);
float upperTV = lerp(points[tl]->uv[1], points[tr]->uv[1], fracU);
float lowerTU = lerp(points[bl]->uv[0], points[br]->uv[0], fracU);
float lowerTV = lerp(points[bl]->uv[1], points[br]->uv[1], fracU);
tu = lerp(upperTU, lowerTU, fracV);
tv = lerp(upperTV, lowerTV, fracV);
}*/
};
enum quality {
LOW_QUALITY = 0,
MEDIUM_QUALITY = 1,
HIGH_QUALITY = 2,
};
void TesselateSplinePatch(u8 *&dest, int &count, const SplinePatchLocal &spatch, u32 origVertType);
void TesselateBezierPatch(u8 *&dest, int &count, int tess_u, int tess_v, const BezierPatch &patch, u32 origVertType);

View File

@ -1,4 +1,3 @@
// Copyright (c) 2013- PPSSPP Project. // Copyright (c) 2013- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify

View File

@ -63,9 +63,9 @@ struct CommandTableEntry {
static const CommandTableEntry commandTable[] = { static const CommandTableEntry commandTable[] = {
// Changes that dirty the framebuffer // Changes that dirty the framebuffer
{GE_CMD_FRAMEBUFPTR, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_FRAMEBUFPTR, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_FramebufType},
{GE_CMD_FRAMEBUFWIDTH, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_FRAMEBUFWIDTH, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_FramebufType},
{GE_CMD_FRAMEBUFPIXFORMAT, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_FRAMEBUFPIXFORMAT, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_FramebufType},
{GE_CMD_ZBUFPTR, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_ZBUFPTR, FLAG_FLUSHBEFOREONCHANGE},
{GE_CMD_ZBUFWIDTH, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_ZBUFWIDTH, FLAG_FLUSHBEFOREONCHANGE},
@ -79,56 +79,56 @@ static const CommandTableEntry commandTable[] = {
{GE_CMD_MAXZ, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_MAXZ, FLAG_FLUSHBEFOREONCHANGE},
// Changes that dirty texture scaling. // Changes that dirty texture scaling.
{GE_CMD_TEXMAPMODE, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, { GE_CMD_TEXMAPMODE, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexMapMode },
{GE_CMD_TEXSCALEU, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, { GE_CMD_TEXSCALEU, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexScaleU },
{GE_CMD_TEXSCALEV, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, { GE_CMD_TEXSCALEV, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexScaleV },
{GE_CMD_TEXOFFSETU, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, { GE_CMD_TEXOFFSETU, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexOffsetU },
{GE_CMD_TEXOFFSETV, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, { GE_CMD_TEXOFFSETV, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexOffsetV },
// Changes that dirty the current texture. Really should be possible to avoid executing these if we compile // Changes that dirty the current texture. Really should be possible to avoid executing these if we compile
// by adding some more flags. // by adding some more flags.
{GE_CMD_TEXSIZE0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTE}, {GE_CMD_TEXSIZE0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTE, &DIRECTX9_GPU::Execute_TexSize0},
{GE_CMD_TEXSIZE1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXSIZE1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexSizeN},
{GE_CMD_TEXSIZE2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXSIZE2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexSizeN},
{GE_CMD_TEXSIZE3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXSIZE3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexSizeN},
{GE_CMD_TEXSIZE4, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXSIZE4, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexSizeN},
{GE_CMD_TEXSIZE5, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXSIZE5, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexSizeN},
{GE_CMD_TEXSIZE6, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXSIZE6, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexSizeN},
{GE_CMD_TEXSIZE7, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXSIZE7, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexSizeN},
{GE_CMD_TEXFORMAT, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXFORMAT, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexFormat},
{GE_CMD_TEXLEVEL, FLAG_EXECUTE}, // we don't support this anyway, no need to flush. {GE_CMD_TEXLEVEL, FLAG_EXECUTE, &DIRECTX9_GPU::Execute_TexLevel},
{GE_CMD_TEXADDR0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXADDR0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexAddr0},
{GE_CMD_TEXADDR1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXADDR1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexAddrN},
{GE_CMD_TEXADDR2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXADDR2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexAddrN},
{GE_CMD_TEXADDR3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXADDR3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexAddrN},
{GE_CMD_TEXADDR4, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXADDR4, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexAddrN},
{GE_CMD_TEXADDR5, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXADDR5, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexAddrN},
{GE_CMD_TEXADDR6, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXADDR6, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexAddrN},
{GE_CMD_TEXADDR7, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXADDR7, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexAddrN},
{GE_CMD_TEXBUFWIDTH0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXBUFWIDTH0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexBufw0},
{GE_CMD_TEXBUFWIDTH1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXBUFWIDTH1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexBufwN},
{GE_CMD_TEXBUFWIDTH2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXBUFWIDTH2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexBufwN},
{GE_CMD_TEXBUFWIDTH3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXBUFWIDTH3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexBufwN},
{GE_CMD_TEXBUFWIDTH4, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXBUFWIDTH4, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexBufwN},
{GE_CMD_TEXBUFWIDTH5, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXBUFWIDTH5, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexBufwN},
{GE_CMD_TEXBUFWIDTH6, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXBUFWIDTH6, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexBufwN},
{GE_CMD_TEXBUFWIDTH7, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXBUFWIDTH7, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexBufwN},
{GE_CMD_CLUTADDR, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_CLUTADDR, FLAG_FLUSHBEFOREONCHANGE},
{GE_CMD_CLUTADDRUPPER, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_CLUTADDRUPPER, FLAG_FLUSHBEFOREONCHANGE},
{GE_CMD_CLUTFORMAT, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_CLUTFORMAT, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_ClutFormat},
// These affect the fragment shader so need flushing. // These affect the fragment shader so need flushing.
{GE_CMD_CLEARMODE, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_CLEARMODE, FLAG_FLUSHBEFOREONCHANGE},
{GE_CMD_TEXTUREMAPENABLE, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_TEXTUREMAPENABLE, FLAG_FLUSHBEFOREONCHANGE},
{GE_CMD_FOGENABLE, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_FOGENABLE, FLAG_FLUSHBEFOREONCHANGE},
{GE_CMD_TEXMODE, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXMODE, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexParamType},
{GE_CMD_TEXSHADELS, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_TEXSHADELS, FLAG_FLUSHBEFOREONCHANGE},
{GE_CMD_SHADEMODE, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_SHADEMODE, FLAG_FLUSHBEFOREONCHANGE},
{GE_CMD_TEXFUNC, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_TEXFUNC, FLAG_FLUSHBEFOREONCHANGE},
{GE_CMD_COLORTEST, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_COLORTEST, FLAG_FLUSHBEFOREONCHANGE},
{GE_CMD_ALPHATESTENABLE, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_ALPHATESTENABLE, FLAG_FLUSHBEFOREONCHANGE},
{GE_CMD_COLORTESTENABLE, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_COLORTESTENABLE, FLAG_FLUSHBEFOREONCHANGE},
{GE_CMD_COLORTESTMASK, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_COLORTESTMASK, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_ColorTestMask},
// These change the vertex shader so need flushing. // These change the vertex shader so need flushing.
{GE_CMD_REVERSENORMAL, FLAG_FLUSHBEFOREONCHANGE}, // TODO: This one is actually processed during vertex decoding which is wrong. {GE_CMD_REVERSENORMAL, FLAG_FLUSHBEFOREONCHANGE}, // TODO: This one is actually processed during vertex decoding which is wrong.
@ -145,13 +145,13 @@ static const CommandTableEntry commandTable[] = {
// This changes both shaders so need flushing. // This changes both shaders so need flushing.
{GE_CMD_LIGHTMODE, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_LIGHTMODE, FLAG_FLUSHBEFOREONCHANGE},
{GE_CMD_TEXFILTER, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXFILTER, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexParamType},
{GE_CMD_TEXWRAP, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXWRAP, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexParamType},
// Uniform changes // Uniform changes
{GE_CMD_ALPHATEST, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_ALPHATEST, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_AlphaTest},
{GE_CMD_COLORREF, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_COLORREF, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_ColorRef},
{GE_CMD_TEXENVCOLOR, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_TEXENVCOLOR, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_TexEnvColor},
// Simple render state changes. Handled in StateMapping.cpp. // Simple render state changes. Handled in StateMapping.cpp.
{GE_CMD_OFFSETX, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_OFFSETX, FLAG_FLUSHBEFOREONCHANGE},
@ -160,7 +160,7 @@ static const CommandTableEntry commandTable[] = {
{GE_CMD_CULLFACEENABLE, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_CULLFACEENABLE, FLAG_FLUSHBEFOREONCHANGE},
{GE_CMD_DITHERENABLE, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_DITHERENABLE, FLAG_FLUSHBEFOREONCHANGE},
{GE_CMD_STENCILOP, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_STENCILOP, FLAG_FLUSHBEFOREONCHANGE},
{GE_CMD_STENCILTEST, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_STENCILTEST, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_StencilTest},
{GE_CMD_STENCILTESTENABLE, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_STENCILTESTENABLE, FLAG_FLUSHBEFOREONCHANGE},
{GE_CMD_ALPHABLENDENABLE, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_ALPHABLENDENABLE, FLAG_FLUSHBEFOREONCHANGE},
{GE_CMD_BLENDMODE, FLAG_FLUSHBEFOREONCHANGE}, {GE_CMD_BLENDMODE, FLAG_FLUSHBEFOREONCHANGE},
@ -204,12 +204,12 @@ static const CommandTableEntry commandTable[] = {
{GE_CMD_VIEWPORTZ2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_ViewportType}, {GE_CMD_VIEWPORTZ2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_ViewportType},
// Region // Region
{GE_CMD_REGION1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_REGION1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Region},
{GE_CMD_REGION2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_REGION2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Region},
// Scissor // Scissor
{GE_CMD_SCISSOR1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_SCISSOR1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Scissor},
{GE_CMD_SCISSOR2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_SCISSOR2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Scissor},
// These dirty various vertex shader uniforms. Could embed information about that in this table and call dirtyuniform directly, hm... // These dirty various vertex shader uniforms. Could embed information about that in this table and call dirtyuniform directly, hm...
{GE_CMD_AMBIENTCOLOR, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_AMBIENTCOLOR, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE},
@ -222,67 +222,67 @@ static const CommandTableEntry commandTable[] = {
{GE_CMD_MATERIALSPECULARCOEF, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_MATERIALSPECULARCOEF, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE},
// These precompute a value. not sure if worth it. Also dirty uniforms, which could be table-ized to avoid execute. // These precompute a value. not sure if worth it. Also dirty uniforms, which could be table-ized to avoid execute.
{GE_CMD_LX0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LX0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light0Param},
{GE_CMD_LY0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LY0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light0Param},
{GE_CMD_LZ0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LZ0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light0Param},
{GE_CMD_LX1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LX1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light1Param},
{GE_CMD_LY1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LY1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light1Param},
{GE_CMD_LZ1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LZ1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light1Param},
{GE_CMD_LX2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LX2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light2Param},
{GE_CMD_LY2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LY2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light2Param},
{GE_CMD_LZ2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LZ2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light2Param},
{GE_CMD_LX3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LX3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light3Param},
{GE_CMD_LY3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LY3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light3Param},
{GE_CMD_LZ3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LZ3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light3Param},
{GE_CMD_LDX0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LDX0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light0Param},
{GE_CMD_LDY0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LDY0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light0Param},
{GE_CMD_LDZ0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LDZ0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light0Param},
{GE_CMD_LDX1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LDX1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light1Param},
{GE_CMD_LDY1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LDY1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light1Param},
{GE_CMD_LDZ1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LDZ1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light1Param},
{GE_CMD_LDX2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LDX2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light2Param},
{GE_CMD_LDY2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LDY2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light2Param},
{GE_CMD_LDZ2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LDZ2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light2Param},
{GE_CMD_LDX3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LDX3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light3Param},
{GE_CMD_LDY3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LDY3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light3Param},
{GE_CMD_LDZ3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LDZ3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light3Param},
{GE_CMD_LKA0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKA0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light0Param},
{GE_CMD_LKB0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKB0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light0Param},
{GE_CMD_LKC0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKC0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light0Param},
{GE_CMD_LKA1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKA1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light1Param},
{GE_CMD_LKB1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKB1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light1Param},
{GE_CMD_LKC1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKC1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light1Param},
{GE_CMD_LKA2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKA2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light2Param},
{GE_CMD_LKB2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKB2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light2Param},
{GE_CMD_LKC2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKC2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light2Param},
{GE_CMD_LKA3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKA3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light3Param},
{GE_CMD_LKB3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKB3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light3Param},
{GE_CMD_LKC3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKC3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light3Param},
{GE_CMD_LKS0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKS0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light0Param},
{GE_CMD_LKS1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKS1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light1Param},
{GE_CMD_LKS2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKS2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light2Param},
{GE_CMD_LKS3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKS3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light3Param},
{GE_CMD_LKO0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKO0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light0Param},
{GE_CMD_LKO1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKO1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light1Param},
{GE_CMD_LKO2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKO2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light2Param},
{GE_CMD_LKO3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LKO3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light3Param},
{GE_CMD_LAC0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LAC0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light0Param},
{GE_CMD_LDC0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LDC0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light0Param},
{GE_CMD_LSC0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LSC0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light0Param},
{GE_CMD_LAC1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LAC1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light1Param},
{GE_CMD_LDC1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LDC1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light1Param},
{GE_CMD_LSC1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LSC1, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light1Param},
{GE_CMD_LAC2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LAC2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light2Param},
{GE_CMD_LDC2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LDC2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light2Param},
{GE_CMD_LSC2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LSC2, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light2Param},
{GE_CMD_LAC3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LAC3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light3Param},
{GE_CMD_LDC3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LDC3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light3Param},
{GE_CMD_LSC3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE}, {GE_CMD_LSC3, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_Light3Param},
// Ignored commands // Ignored commands
{GE_CMD_CLIPENABLE, 0}, {GE_CMD_CLIPENABLE, 0},
@ -317,15 +317,15 @@ static const CommandTableEntry commandTable[] = {
// Changing the vertex type requires us to flush. // Changing the vertex type requires us to flush.
{GE_CMD_VERTEXTYPE, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_VertexType}, {GE_CMD_VERTEXTYPE, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, &DIRECTX9_GPU::Execute_VertexType},
{GE_CMD_BEZIER, FLAG_FLUSHBEFORE | FLAG_EXECUTE}, {GE_CMD_BEZIER, FLAG_FLUSHBEFORE | FLAG_EXECUTE, &DIRECTX9_GPU::Execute_Bezier},
{GE_CMD_SPLINE, FLAG_FLUSHBEFORE | FLAG_EXECUTE}, {GE_CMD_SPLINE, FLAG_FLUSHBEFORE | FLAG_EXECUTE, &DIRECTX9_GPU::Execute_Spline},
// These two are actually processed in CMD_END. // These two are actually processed in CMD_END.
{GE_CMD_SIGNAL, FLAG_FLUSHBEFORE}, {GE_CMD_SIGNAL, FLAG_FLUSHBEFORE},
{GE_CMD_FINISH, FLAG_FLUSHBEFORE}, {GE_CMD_FINISH, FLAG_FLUSHBEFORE},
// Changes that trigger data copies. Only flushing on change for LOADCLUT must be a bit of a hack... // Changes that trigger data copies. Only flushing on change for LOADCLUT must be a bit of a hack...
{GE_CMD_LOADCLUT, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTE}, {GE_CMD_LOADCLUT, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTE, &DIRECTX9_GPU::Execute_LoadClut},
{GE_CMD_TRANSFERSTART, FLAG_FLUSHBEFORE | FLAG_EXECUTE | FLAG_READS_PC}, {GE_CMD_TRANSFERSTART, FLAG_FLUSHBEFORE | FLAG_EXECUTE | FLAG_READS_PC},
// We don't use the dither table. // We don't use the dither table.
@ -684,6 +684,163 @@ void DIRECTX9_GPU::Execute_VertexTypeSkinning(u32 op, u32 diff) {
} }
} }
void DIRECTX9_GPU::Execute_Prim(u32 op, u32 diff) {
// This drives all drawing. All other state we just buffer up, then we apply it only
// when it's time to draw. As most PSP games set state redundantly ALL THE TIME, this is a huge optimization.
u32 data = op & 0xFFFFFF;
u32 count = data & 0xFFFF;
GEPrimitiveType prim = static_cast<GEPrimitiveType>(data >> 16);
if (count == 0)
return;
// Discard AA lines as we can't do anything that makes sense with these anyway. The SW plugin might, though.
if (gstate.isAntiAliasEnabled()) {
// Discard AA lines in DOA
if (prim == GE_PRIM_LINE_STRIP)
return;
// Discard AA lines in Summon Night 5
if ((prim == GE_PRIM_LINES) && gstate.isSkinningEnabled())
return;
}
// This also make skipping drawing very effective.
framebufferManager_.SetRenderFrameBuffer();
if (gstate_c.skipDrawReason & (SKIPDRAW_SKIPFRAME | SKIPDRAW_NON_DISPLAYED_FB)) {
transformDraw_.SetupVertexDecoder(gstate.vertType);
// Rough estimate, not sure what's correct.
int vertexCost = transformDraw_.EstimatePerVertexCost();
cyclesExecuted += vertexCost * count;
return;
}
if (!Memory::IsValidAddress(gstate_c.vertexAddr)) {
ERROR_LOG_REPORT(G3D, "Bad vertex address %08x!", gstate_c.vertexAddr);
return;
}
void *verts = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
void *inds = 0;
if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
if (!Memory::IsValidAddress(gstate_c.indexAddr)) {
ERROR_LOG_REPORT(G3D, "Bad index address %08x!", gstate_c.indexAddr);
return;
}
inds = Memory::GetPointerUnchecked(gstate_c.indexAddr);
}
#ifndef MOBILE_DEVICE
if (prim > GE_PRIM_RECTANGLES) {
ERROR_LOG_REPORT_ONCE(reportPrim, G3D, "Unexpected prim type: %d", prim);
}
#endif
int bytesRead = 0;
transformDraw_.SubmitPrim(verts, inds, prim, count, gstate.vertType, &bytesRead);
int vertexCost = transformDraw_.EstimatePerVertexCost();
gpuStats.vertexGPUCycles += vertexCost * count;
cyclesExecuted += vertexCost * count;
// After drawing, we advance the vertexAddr (when non indexed) or indexAddr (when indexed).
// Some games rely on this, they don't bother reloading VADDR and IADDR.
// The VADDR/IADDR registers are NOT updated.
if (inds) {
int indexSize = 1;
if ((gstate.vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_16BIT)
indexSize = 2;
gstate_c.indexAddr += count * indexSize;
} else {
gstate_c.vertexAddr += bytesRead;
}
}
void DIRECTX9_GPU::Execute_Bezier(u32 op, u32 diff) {
// This also make skipping drawing very effective.
framebufferManager_.SetRenderFrameBuffer();
if (gstate_c.skipDrawReason & (SKIPDRAW_SKIPFRAME | SKIPDRAW_NON_DISPLAYED_FB)) {
// TODO: Should this eat some cycles? Probably yes. Not sure if important.
return;
}
if (!Memory::IsValidAddress(gstate_c.vertexAddr)) {
ERROR_LOG_REPORT(G3D, "Bad vertex address %08x!", gstate_c.vertexAddr);
return;
}
void *control_points = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
void *indices = NULL;
if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
if (!Memory::IsValidAddress(gstate_c.indexAddr)) {
ERROR_LOG_REPORT(G3D, "Bad index address %08x!", gstate_c.indexAddr);
return;
}
indices = Memory::GetPointerUnchecked(gstate_c.indexAddr);
}
if (gstate.getPatchPrimitiveType() != GE_PATCHPRIM_TRIANGLES) {
ERROR_LOG_REPORT(G3D, "Unsupported patch primitive %x", gstate.getPatchPrimitiveType());
return;
}
if (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) {
DEBUG_LOG_REPORT(G3D, "Bezier + morph: %i", (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) >> GE_VTYPE_MORPHCOUNT_SHIFT);
}
if (vertTypeIsSkinningEnabled(gstate.vertType)) {
DEBUG_LOG_REPORT(G3D, "Bezier + skinning: %i", vertTypeGetNumBoneWeights(gstate.vertType));
}
GEPatchPrimType patchPrim = gstate.getPatchPrimitiveType();
int bz_ucount = op & 0xFF;
int bz_vcount = (op >> 8) & 0xFF;
transformDraw_.SubmitBezier(control_points, indices, bz_ucount, bz_vcount, patchPrim, gstate.vertType);
}
void DIRECTX9_GPU::Execute_Spline(u32 op, u32 diff) {
// This also make skipping drawing very effective.
framebufferManager_.SetRenderFrameBuffer();
if (gstate_c.skipDrawReason & (SKIPDRAW_SKIPFRAME | SKIPDRAW_NON_DISPLAYED_FB)) {
// TODO: Should this eat some cycles? Probably yes. Not sure if important.
return;
}
if (!Memory::IsValidAddress(gstate_c.vertexAddr)) {
ERROR_LOG_REPORT(G3D, "Bad vertex address %08x!", gstate_c.vertexAddr);
return;
}
void *control_points = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
void *indices = NULL;
if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
if (!Memory::IsValidAddress(gstate_c.indexAddr)) {
ERROR_LOG_REPORT(G3D, "Bad index address %08x!", gstate_c.indexAddr);
return;
}
indices = Memory::GetPointerUnchecked(gstate_c.indexAddr);
}
if (gstate.getPatchPrimitiveType() != GE_PATCHPRIM_TRIANGLES) {
ERROR_LOG_REPORT(G3D, "Unsupported patch primitive %x", gstate.getPatchPrimitiveType());
return;
}
if (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) {
DEBUG_LOG_REPORT(G3D, "Spline + morph: %i", (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) >> GE_VTYPE_MORPHCOUNT_SHIFT);
}
if (vertTypeIsSkinningEnabled(gstate.vertType)) {
DEBUG_LOG_REPORT(G3D, "Spline + skinning: %i", vertTypeGetNumBoneWeights(gstate.vertType));
}
int sp_ucount = op & 0xFF;
int sp_vcount = (op >> 8) & 0xFF;
int sp_utype = (op >> 16) & 0x3;
int sp_vtype = (op >> 18) & 0x3;
GEPatchPrimType patchPrim = gstate.getPatchPrimitiveType();
transformDraw_.SubmitSpline(control_points, indices, sp_ucount, sp_vcount, sp_utype, sp_vtype, patchPrim, gstate.vertType);
}
void DIRECTX9_GPU::Execute_ViewportType(u32 op, u32 diff) { void DIRECTX9_GPU::Execute_ViewportType(u32 op, u32 diff) {
gstate_c.framebufChanged = true; gstate_c.framebufChanged = true;
gstate_c.textureChanged |= TEXCHANGE_PARAMSONLY; gstate_c.textureChanged |= TEXCHANGE_PARAMSONLY;
@ -695,6 +852,175 @@ void DIRECTX9_GPU::Execute_ViewportType(u32 op, u32 diff) {
} }
} }
void DIRECTX9_GPU::Execute_Region(u32 op, u32 diff) {
gstate_c.framebufChanged = true;
gstate_c.textureChanged |= TEXCHANGE_PARAMSONLY;
}
void DIRECTX9_GPU::Execute_Scissor(u32 op, u32 diff) {
gstate_c.framebufChanged = true;
gstate_c.textureChanged |= TEXCHANGE_PARAMSONLY;
}
void DIRECTX9_GPU::Execute_FramebufType(u32 op, u32 diff) {
gstate_c.framebufChanged = true;
gstate_c.textureChanged |= TEXCHANGE_PARAMSONLY;
}
void DIRECTX9_GPU::Execute_TexScaleU(u32 op, u32 diff) {
gstate_c.uv.uScale = getFloat24(op);
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
}
void DIRECTX9_GPU::Execute_TexScaleV(u32 op, u32 diff) {
gstate_c.uv.vScale = getFloat24(op);
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
}
void DIRECTX9_GPU::Execute_TexOffsetU(u32 op, u32 diff) {
gstate_c.uv.uOff = getFloat24(op);
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
}
void DIRECTX9_GPU::Execute_TexOffsetV(u32 op, u32 diff) {
gstate_c.uv.vOff = getFloat24(op);
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
}
void DIRECTX9_GPU::Execute_TexAddr0(u32 op, u32 diff) {
gstate_c.textureChanged = TEXCHANGE_UPDATED;
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
}
void DIRECTX9_GPU::Execute_TexAddrN(u32 op, u32 diff) {
gstate_c.textureChanged |= TEXCHANGE_PARAMSONLY;
}
void DIRECTX9_GPU::Execute_TexBufw0(u32 op, u32 diff) {
gstate_c.textureChanged = TEXCHANGE_UPDATED;
}
void DIRECTX9_GPU::Execute_TexBufwN(u32 op, u32 diff) {
gstate_c.textureChanged |= TEXCHANGE_PARAMSONLY;
}
void DIRECTX9_GPU::Execute_TexSize0(u32 op, u32 diff) {
// Render to texture may have overridden the width/height.
// Don't reset it unless the size is different / the texture has changed.
if (diff || gstate_c.textureChanged != TEXCHANGE_UNCHANGED) {
gstate_c.curTextureWidth = gstate.getTextureWidth(0);
gstate_c.curTextureHeight = gstate.getTextureHeight(0);
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
// We will need to reset the texture now.
gstate_c.textureChanged |= TEXCHANGE_PARAMSONLY;
}
}
void DIRECTX9_GPU::Execute_TexSizeN(u32 op, u32 diff) {
gstate_c.textureChanged |= TEXCHANGE_PARAMSONLY;
}
void DIRECTX9_GPU::Execute_TexFormat(u32 op, u32 diff) {
gstate_c.textureChanged = TEXCHANGE_UPDATED;
}
void DIRECTX9_GPU::Execute_TexMapMode(u32 op, u32 diff) {
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
}
void DIRECTX9_GPU::Execute_TexParamType(u32 op, u32 diff) {
gstate_c.textureChanged |= TEXCHANGE_PARAMSONLY;
}
void DIRECTX9_GPU::Execute_TexEnvColor(u32 op, u32 diff) {
shaderManager_->DirtyUniform(DIRTY_TEXENV);
}
void DIRECTX9_GPU::Execute_TexLevel(u32 op, u32 diff) {
// I had hoped that this would let us avoid excessively flushing in Gran Turismo, but not so,
// as the game switches rapidly between modes 0 and 1.
/*
if (gstate.getTexLevelMode() == GE_TEXLEVEL_MODE_CONST) {
gstate.texlevel ^= diff;
Flush();
gstate.texlevel ^= diff;
}
*/
gstate_c.textureChanged |= TEXCHANGE_PARAMSONLY;
}
void DIRECTX9_GPU::Execute_LoadClut(u32 op, u32 diff) {
gstate_c.textureChanged |= TEXCHANGE_PARAMSONLY;
textureCache_.LoadClut();
// This could be used to "dirty" textures with clut.
}
void DIRECTX9_GPU::Execute_ClutFormat(u32 op, u32 diff) {
gstate_c.textureChanged |= TEXCHANGE_PARAMSONLY;
// This could be used to "dirty" textures with clut.
}
void DIRECTX9_GPU::Execute_Ambient(u32 op, u32 diff) {
shaderManager_->DirtyUniform(DIRTY_AMBIENT);
}
void DIRECTX9_GPU::Execute_MaterialDiffuse(u32 op, u32 diff) {
shaderManager_->DirtyUniform(DIRTY_MATDIFFUSE);
}
void DIRECTX9_GPU::Execute_MaterialEmissive(u32 op, u32 diff) {
shaderManager_->DirtyUniform(DIRTY_MATEMISSIVE);
}
void DIRECTX9_GPU::Execute_MaterialAmbient(u32 op, u32 diff) {
shaderManager_->DirtyUniform(DIRTY_MATAMBIENTALPHA);
}
void DIRECTX9_GPU::Execute_MaterialSpecular(u32 op, u32 diff) {
shaderManager_->DirtyUniform(DIRTY_MATSPECULAR);
}
void DIRECTX9_GPU::Execute_Light0Param(u32 op, u32 diff) {
shaderManager_->DirtyUniform(DIRTY_LIGHT0);
}
void DIRECTX9_GPU::Execute_Light1Param(u32 op, u32 diff) {
shaderManager_->DirtyUniform(DIRTY_LIGHT1);
}
void DIRECTX9_GPU::Execute_Light2Param(u32 op, u32 diff) {
shaderManager_->DirtyUniform(DIRTY_LIGHT2);
}
void DIRECTX9_GPU::Execute_Light3Param(u32 op, u32 diff) {
shaderManager_->DirtyUniform(DIRTY_LIGHT3);
}
void DIRECTX9_GPU::Execute_FogColor(u32 op, u32 diff) {
shaderManager_->DirtyUniform(DIRTY_FOGCOLOR);
}
void DIRECTX9_GPU::Execute_FogCoef(u32 op, u32 diff) {
shaderManager_->DirtyUniform(DIRTY_FOGCOEF);
}
void DIRECTX9_GPU::Execute_ColorTestMask(u32 op, u32 diff) {
shaderManager_->DirtyUniform(DIRTY_ALPHACOLORMASK);
}
void DIRECTX9_GPU::Execute_AlphaTest(u32 op, u32 diff) {
shaderManager_->DirtyUniform(DIRTY_ALPHACOLORREF);
shaderManager_->DirtyUniform(DIRTY_ALPHACOLORMASK);
}
void DIRECTX9_GPU::Execute_StencilTest(u32 op, u32 diff) {
shaderManager_->DirtyUniform(DIRTY_STENCILREPLACEVALUE);
}
void DIRECTX9_GPU::Execute_ColorRef(u32 op, u32 diff) {
shaderManager_->DirtyUniform(DIRTY_ALPHACOLORREF);
}
void DIRECTX9_GPU::Execute_WorldMtxNum(u32 op, u32 diff) { void DIRECTX9_GPU::Execute_WorldMtxNum(u32 op, u32 diff) {
// This is almost always followed by GE_CMD_WORLDMATRIXDATA. // This is almost always followed by GE_CMD_WORLDMATRIXDATA.
const u32_le *src = (const u32_le *)Memory::GetPointer(currentList->pc + 4); const u32_le *src = (const u32_le *)Memory::GetPointer(currentList->pc + 4);
@ -921,162 +1247,25 @@ void DIRECTX9_GPU::Execute_Generic(u32 op, u32 diff) {
case GE_CMD_BASE: case GE_CMD_BASE:
break; break;
case GE_CMD_VADDR:
Execute_Vaddr(op, diff);
break;
case GE_CMD_IADDR:
Execute_Iaddr(op, diff);
break;
case GE_CMD_PRIM: case GE_CMD_PRIM:
{ Execute_Prim(op, diff);
// This drives all drawing. All other state we just buffer up, then we apply it only
// when it's time to draw. As most PSP games set state redundantly ALL THE TIME, this is a huge optimization.
u32 count = data & 0xFFFF;
GEPrimitiveType prim = static_cast<GEPrimitiveType>(data >> 16);
if (count == 0)
break;
// Discard AA lines as we can't do anything that makes sense with these anyway. The SW plugin might, though.
if (gstate.isAntiAliasEnabled()) {
// Discard AA lines in DOA
if (prim == GE_PRIM_LINE_STRIP)
break;
// Discard AA lines in Summon Night 5
if ((prim == GE_PRIM_LINES) && vertTypeIsSkinningEnabled(gstate.vertType))
break;
}
// This also make skipping drawing very effective.
framebufferManager_.SetRenderFrameBuffer();
if (gstate_c.skipDrawReason & (SKIPDRAW_SKIPFRAME | SKIPDRAW_NON_DISPLAYED_FB)) {
transformDraw_.SetupVertexDecoder(gstate.vertType);
// Rough estimate, not sure what's correct.
int vertexCost = transformDraw_.EstimatePerVertexCost();
cyclesExecuted += vertexCost * count;
return;
}
if (!Memory::IsValidAddress(gstate_c.vertexAddr)) {
ERROR_LOG_REPORT(G3D, "Bad vertex address %08x!", gstate_c.vertexAddr);
break;
}
void *verts = Memory::GetPointer(gstate_c.vertexAddr);
void *inds = 0;
if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
if (!Memory::IsValidAddress(gstate_c.indexAddr)) {
ERROR_LOG_REPORT(G3D, "Bad index address %08x!", gstate_c.indexAddr);
break;
}
inds = Memory::GetPointer(gstate_c.indexAddr);
}
int bytesRead;
transformDraw_.SubmitPrim(verts, inds, prim, count, gstate.vertType, &bytesRead);
int vertexCost = transformDraw_.EstimatePerVertexCost();
gpuStats.vertexGPUCycles += vertexCost * count;
cyclesExecuted += vertexCost * count;
// After drawing, we advance the vertexAddr (when non indexed) or indexAddr (when indexed).
// Some games rely on this, they don't bother reloading VADDR and IADDR.
// The VADDR/IADDR registers are NOT updated.
if (inds) {
int indexSize = 1;
if ((gstate.vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_16BIT)
indexSize = 2;
gstate_c.indexAddr += count * indexSize;
} else {
gstate_c.vertexAddr += bytesRead;
}
}
break; break;
// The arrow and other rotary items in Puzbob are bezier patches, strangely enough. // The arrow and other rotary items in Puzbob are bezier patches, strangely enough.
case GE_CMD_BEZIER: case GE_CMD_BEZIER:
{ Execute_Bezier(op, diff);
// This also make skipping drawing very effective.
framebufferManager_.SetRenderFrameBuffer();
if (gstate_c.skipDrawReason & (SKIPDRAW_SKIPFRAME | SKIPDRAW_NON_DISPLAYED_FB)) {
// TODO: Should this eat some cycles? Probably yes. Not sure if important.
return;
}
if (!Memory::IsValidAddress(gstate_c.vertexAddr)) {
ERROR_LOG_REPORT(G3D, "Bad vertex address %08x!", gstate_c.vertexAddr);
break;
}
void *control_points = Memory::GetPointer(gstate_c.vertexAddr);
void *indices = NULL;
if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
if (!Memory::IsValidAddress(gstate_c.indexAddr)) {
ERROR_LOG_REPORT(G3D, "Bad index address %08x!", gstate_c.indexAddr);
break;
}
indices = Memory::GetPointer(gstate_c.indexAddr);
}
if (gstate.getPatchPrimitiveType() != GE_PATCHPRIM_TRIANGLES) {
ERROR_LOG_REPORT(G3D, "Unsupported patch primitive %x", gstate.getPatchPrimitiveType());
break;
}
if (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) {
DEBUG_LOG_REPORT(G3D, "Bezier + morph: %i", (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) >> GE_VTYPE_MORPHCOUNT_SHIFT);
}
if (vertTypeIsSkinningEnabled(gstate.vertType)) {
DEBUG_LOG_REPORT(G3D, "Bezier + skinning: %i", vertTypeGetNumBoneWeights(gstate.vertType));
}
GEPatchPrimType patchPrim = gstate.getPatchPrimitiveType();
int bz_ucount = data & 0xFF;
int bz_vcount = (data >> 8) & 0xFF;
transformDraw_.SubmitBezier(control_points, indices, bz_ucount, bz_vcount, patchPrim, gstate.vertType);
}
break; break;
case GE_CMD_SPLINE: case GE_CMD_SPLINE:
{ Execute_Spline(op, diff);
// This also make skipping drawing very effective.
framebufferManager_.SetRenderFrameBuffer();
if (gstate_c.skipDrawReason & (SKIPDRAW_SKIPFRAME | SKIPDRAW_NON_DISPLAYED_FB)) {
// TODO: Should this eat some cycles? Probably yes. Not sure if important.
return;
}
if (!Memory::IsValidAddress(gstate_c.vertexAddr)) {
ERROR_LOG_REPORT(G3D, "Bad vertex address %08x!", gstate_c.vertexAddr);
break;
}
void *control_points = Memory::GetPointer(gstate_c.vertexAddr);
void *indices = NULL;
if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
if (!Memory::IsValidAddress(gstate_c.indexAddr)) {
ERROR_LOG_REPORT(G3D, "Bad index address %08x!", gstate_c.indexAddr);
break;
}
indices = Memory::GetPointer(gstate_c.indexAddr);
}
if (gstate.getPatchPrimitiveType() != GE_PATCHPRIM_TRIANGLES) {
ERROR_LOG_REPORT(G3D, "Unsupported patch primitive %x", gstate.getPatchPrimitiveType());
break;
}
if (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) {
DEBUG_LOG_REPORT(G3D, "Spline + morph: %i", (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) >> GE_VTYPE_MORPHCOUNT_SHIFT);
}
if (vertTypeIsSkinningEnabled(gstate.vertType)) {
DEBUG_LOG_REPORT(G3D, "Spline + skinning: %i", vertTypeGetNumBoneWeights(gstate.vertType));
}
int sp_ucount = data & 0xFF;
int sp_vcount = (data >> 8) & 0xFF;
int sp_utype = (data >> 16) & 0x3;
int sp_vtype = (data >> 18) & 0x3;
GEPatchPrimType patchPrim = gstate.getPatchPrimitiveType();
transformDraw_.SubmitSpline(control_points, indices, sp_ucount, sp_vcount, sp_utype, sp_vtype, patchPrim, gstate.vertType);
}
break; break;
case GE_CMD_BOUNDINGBOX: case GE_CMD_BOUNDINGBOX:
@ -1106,10 +1295,7 @@ void DIRECTX9_GPU::Execute_Generic(u32 op, u32 diff) {
case GE_CMD_REGION1: case GE_CMD_REGION1:
case GE_CMD_REGION2: case GE_CMD_REGION2:
if (diff) { Execute_Region(op, diff);
gstate_c.framebufChanged = true;
gstate_c.textureChanged = TEXCHANGE_UPDATED;
}
break; break;
case GE_CMD_CLIPENABLE: case GE_CMD_CLIPENABLE:
@ -1155,38 +1341,14 @@ void DIRECTX9_GPU::Execute_Generic(u32 op, u32 diff) {
case GE_CMD_OFFSETY: case GE_CMD_OFFSETY:
break; break;
case GE_CMD_TEXSCALEU: case GE_CMD_TEXSCALEU: Execute_TexScaleU(op, diff); break;
if (diff) { case GE_CMD_TEXSCALEV: Execute_TexScaleV(op, diff); break;
gstate_c.uv.uScale = getFloat24(data); case GE_CMD_TEXOFFSETU: Execute_TexOffsetU(op, diff); break;
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET); case GE_CMD_TEXOFFSETV: Execute_TexOffsetV(op, diff); break;
}
break;
case GE_CMD_TEXSCALEV:
if (diff) {
gstate_c.uv.vScale = getFloat24(data);
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
}
break;
case GE_CMD_TEXOFFSETU:
if (diff) {
gstate_c.uv.uOff = getFloat24(data);
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
}
break;
case GE_CMD_TEXOFFSETV:
if (diff) {
gstate_c.uv.vOff = getFloat24(data);
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
}
break;
case GE_CMD_SCISSOR1: case GE_CMD_SCISSOR1:
case GE_CMD_SCISSOR2: case GE_CMD_SCISSOR2:
if (diff) Execute_Scissor(op, diff);
gstate_c.framebufChanged = true;
break; break;
/// ///
@ -1197,13 +1359,13 @@ void DIRECTX9_GPU::Execute_Generic(u32 op, u32 diff) {
case GE_CMD_FRAMEBUFPTR: case GE_CMD_FRAMEBUFPTR:
case GE_CMD_FRAMEBUFWIDTH: case GE_CMD_FRAMEBUFWIDTH:
case GE_CMD_FRAMEBUFPIXFORMAT: case GE_CMD_FRAMEBUFPIXFORMAT:
if (diff) { Execute_FramebufType(op, diff);
gstate_c.framebufChanged = true;
gstate_c.textureChanged = TEXCHANGE_UPDATED;
}
break; break;
case GE_CMD_TEXADDR0: case GE_CMD_TEXADDR0:
Execute_TexAddr0(op, diff);
break;
case GE_CMD_TEXADDR1: case GE_CMD_TEXADDR1:
case GE_CMD_TEXADDR2: case GE_CMD_TEXADDR2:
case GE_CMD_TEXADDR3: case GE_CMD_TEXADDR3:
@ -1211,13 +1373,13 @@ void DIRECTX9_GPU::Execute_Generic(u32 op, u32 diff) {
case GE_CMD_TEXADDR5: case GE_CMD_TEXADDR5:
case GE_CMD_TEXADDR6: case GE_CMD_TEXADDR6:
case GE_CMD_TEXADDR7: case GE_CMD_TEXADDR7:
if (diff) { Execute_TexAddrN(op, diff);
gstate_c.textureChanged = TEXCHANGE_UPDATED;
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
}
break; break;
case GE_CMD_TEXBUFWIDTH0: case GE_CMD_TEXBUFWIDTH0:
Execute_TexAddr0(op, diff);
break;
case GE_CMD_TEXBUFWIDTH1: case GE_CMD_TEXBUFWIDTH1:
case GE_CMD_TEXBUFWIDTH2: case GE_CMD_TEXBUFWIDTH2:
case GE_CMD_TEXBUFWIDTH3: case GE_CMD_TEXBUFWIDTH3:
@ -1225,30 +1387,24 @@ void DIRECTX9_GPU::Execute_Generic(u32 op, u32 diff) {
case GE_CMD_TEXBUFWIDTH5: case GE_CMD_TEXBUFWIDTH5:
case GE_CMD_TEXBUFWIDTH6: case GE_CMD_TEXBUFWIDTH6:
case GE_CMD_TEXBUFWIDTH7: case GE_CMD_TEXBUFWIDTH7:
if (diff) { Execute_TexBufwN(op, diff);
gstate_c.textureChanged = TEXCHANGE_UPDATED; break;
}
case GE_CMD_CLUTFORMAT:
Execute_ClutFormat(op, diff);
break; break;
case GE_CMD_CLUTADDR: case GE_CMD_CLUTADDR:
case GE_CMD_CLUTADDRUPPER: case GE_CMD_CLUTADDRUPPER:
case GE_CMD_CLUTFORMAT: // Hm, LOADCLUT actually changes the CLUT so no need to dirty here.
if (diff) {
gstate_c.textureChanged = TEXCHANGE_UPDATED;
}
// This could be used to "dirty" textures with clut.
break; break;
case GE_CMD_LOADCLUT: case GE_CMD_LOADCLUT:
gstate_c.textureChanged = TEXCHANGE_UPDATED; Execute_LoadClut(op, diff);
textureCache_.LoadClut();
// This could be used to "dirty" textures with clut.
break; break;
case GE_CMD_TEXMAPMODE: case GE_CMD_TEXMAPMODE:
if (diff) { Execute_TexMapMode(op, diff);
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
}
break; break;
case GE_CMD_TEXSHADELS: case GE_CMD_TEXSHADELS:
@ -1278,10 +1434,9 @@ void DIRECTX9_GPU::Execute_Generic(u32 op, u32 diff) {
} }
case GE_CMD_TEXSIZE0: case GE_CMD_TEXSIZE0:
gstate_c.curTextureWidth = gstate.getTextureWidth(0); Execute_TexSize0(op, diff);
gstate_c.curTextureHeight = gstate.getTextureHeight(0); break;
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
//fall thru - ignoring the mipmap sizes for now
case GE_CMD_TEXSIZE1: case GE_CMD_TEXSIZE1:
case GE_CMD_TEXSIZE2: case GE_CMD_TEXSIZE2:
case GE_CMD_TEXSIZE3: case GE_CMD_TEXSIZE3:
@ -1289,7 +1444,7 @@ void DIRECTX9_GPU::Execute_Generic(u32 op, u32 diff) {
case GE_CMD_TEXSIZE5: case GE_CMD_TEXSIZE5:
case GE_CMD_TEXSIZE6: case GE_CMD_TEXSIZE6:
case GE_CMD_TEXSIZE7: case GE_CMD_TEXSIZE7:
gstate_c.textureChanged = TEXCHANGE_UPDATED; Execute_TexSizeN(op, diff);
break; break;
case GE_CMD_ZBUFPTR: case GE_CMD_ZBUFPTR:
@ -1377,10 +1532,7 @@ void DIRECTX9_GPU::Execute_Generic(u32 op, u32 diff) {
case GE_CMD_VIEWPORTY2: case GE_CMD_VIEWPORTY2:
case GE_CMD_VIEWPORTZ1: case GE_CMD_VIEWPORTZ1:
case GE_CMD_VIEWPORTZ2: case GE_CMD_VIEWPORTZ2:
if (diff) { Execute_ViewportType(op, diff);
gstate_c.framebufChanged = true;
gstate_c.textureChanged = TEXCHANGE_UPDATED;
}
break; break;
case GE_CMD_LIGHTENABLE0: case GE_CMD_LIGHTENABLE0:
@ -1445,12 +1597,14 @@ void DIRECTX9_GPU::Execute_Generic(u32 op, u32 diff) {
case GE_CMD_TEXFLUSH: case GE_CMD_TEXFLUSH:
break; break;
case GE_CMD_TEXMODE:
case GE_CMD_TEXFORMAT: case GE_CMD_TEXFORMAT:
Execute_TexFormat(op, diff);
break;
case GE_CMD_TEXMODE:
case GE_CMD_TEXFILTER: case GE_CMD_TEXFILTER:
case GE_CMD_TEXWRAP: case GE_CMD_TEXWRAP:
if (diff) Execute_TexParamType(op, diff);
gstate_c.textureChanged = true;
break; break;
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
@ -1501,12 +1655,7 @@ void DIRECTX9_GPU::Execute_Generic(u32 op, u32 diff) {
break; break;
case GE_CMD_TEXLEVEL: case GE_CMD_TEXLEVEL:
if (data == 1) Execute_TexLevel(op, diff);
WARN_LOG_REPORT_ONCE(texLevel1, G3D, "Unsupported texture level bias settings: %06x", data);
else if (data != 0)
WARN_LOG_REPORT_ONCE(texLevel2, G3D, "Unsupported texture level bias settings: %06x", data);
if (diff)
gstate_c.textureChanged = true;
break; break;
case GE_CMD_VSCX: case GE_CMD_VSCX:

View File

@ -87,9 +87,48 @@ public:
void Execute_Generic(u32 op, u32 diff); void Execute_Generic(u32 op, u32 diff);
void Execute_Vaddr(u32 op, u32 diff); void Execute_Vaddr(u32 op, u32 diff);
void Execute_Iaddr(u32 op, u32 diff); void Execute_Iaddr(u32 op, u32 diff);
void Execute_Prim(u32 op, u32 diff);
void Execute_Bezier(u32 op, u32 diff);
void Execute_Spline(u32 op, u32 diff);
void Execute_VertexType(u32 op, u32 diff); void Execute_VertexType(u32 op, u32 diff);
void Execute_VertexTypeSkinning(u32 op, u32 diff); void Execute_VertexTypeSkinning(u32 op, u32 diff);
void Execute_Region(u32 op, u32 diff);
void Execute_Scissor(u32 op, u32 diff);
void Execute_FramebufType(u32 op, u32 diff);
void Execute_ViewportType(u32 op, u32 diff); void Execute_ViewportType(u32 op, u32 diff);
void Execute_TexScaleU(u32 op, u32 diff);
void Execute_TexScaleV(u32 op, u32 diff);
void Execute_TexOffsetU(u32 op, u32 diff);
void Execute_TexOffsetV(u32 op, u32 diff);
void Execute_TexAddr0(u32 op, u32 diff);
void Execute_TexAddrN(u32 op, u32 diff);
void Execute_TexBufw0(u32 op, u32 diff);
void Execute_TexBufwN(u32 op, u32 diff);
void Execute_TexSize0(u32 op, u32 diff);
void Execute_TexSizeN(u32 op, u32 diff);
void Execute_TexFormat(u32 op, u32 diff);
void Execute_TexMapMode(u32 op, u32 diff);
void Execute_TexParamType(u32 op, u32 diff);
void Execute_TexEnvColor(u32 op, u32 diff);
void Execute_TexLevel(u32 op, u32 diff);
void Execute_LoadClut(u32 op, u32 diff);
void Execute_ClutFormat(u32 op, u32 diff);
void Execute_Ambient(u32 op, u32 diff);
void Execute_MaterialDiffuse(u32 op, u32 diff);
void Execute_MaterialEmissive(u32 op, u32 diff);
void Execute_MaterialAmbient(u32 op, u32 diff);
void Execute_MaterialSpecular(u32 op, u32 diff);
void Execute_Light0Param(u32 op, u32 diff);
void Execute_Light1Param(u32 op, u32 diff);
void Execute_Light2Param(u32 op, u32 diff);
void Execute_Light3Param(u32 op, u32 diff);
void Execute_FogColor(u32 op, u32 diff);
void Execute_FogCoef(u32 op, u32 diff);
void Execute_ColorTestMask(u32 op, u32 diff);
void Execute_AlphaTest(u32 op, u32 diff);
void Execute_StencilTest(u32 op, u32 diff);
void Execute_ColorRef(u32 op, u32 diff);
void Execute_WorldMtxNum(u32 op, u32 diff); void Execute_WorldMtxNum(u32 op, u32 diff);
void Execute_WorldMtxData(u32 op, u32 diff); void Execute_WorldMtxData(u32 op, u32 diff);
void Execute_ViewMtxNum(u32 op, u32 diff); void Execute_ViewMtxNum(u32 op, u32 diff);

View File

@ -132,33 +132,7 @@ u32 TransformDrawEngineDX9::NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *
return NormalizeVertices(outPtr, bufPtr, inPtr, dec, lowerBound, upperBound, vertType); return NormalizeVertices(outPtr, bufPtr, inPtr, dec, lowerBound, upperBound, vertType);
} }
// Spline implementation copied and modified from neobrain's softgpu (orphis code?) void TransformDrawEngineDX9::SubmitSpline(void* control_points, void* indices, int count_u, int count_v, int type_u, int type_v, GEPatchPrimType prim_type, u32 vertType) {
#define START_OPEN_U 1
#define END_OPEN_U 2
#define START_OPEN_V 4
#define END_OPEN_V 8
// We decode all vertices into a common format for easy interpolation and stuff.
// Not fast but can be optimized later.
struct HWSplinePatch {
u8 *points[16];
int type;
// We need to generate both UVs and normals later...
// float u0, v0, u1, v1;
};
static void CopyTriangle(u8 *&dest, u8 *v1, u8 *v2, u8 * v3, int vertexSize) {
memcpy(dest, v1, vertexSize);
dest += vertexSize;
memcpy(dest, v2, vertexSize);
dest += vertexSize;
memcpy(dest, v3, vertexSize);
dest += vertexSize;
}
void TransformDrawEngineDX9::SubmitSpline(void* control_points, void* indices, int count_u, int count_v, int type_u, int type_v, GEPatchPrimType prim_type, u32 vertex_type) {
Flush(); Flush();
if (prim_type != GE_PATCHPRIM_TRIANGLES) { if (prim_type != GE_PATCHPRIM_TRIANGLES) {
@ -166,94 +140,165 @@ void TransformDrawEngineDX9::SubmitSpline(void* control_points, void* indices, i
return; return;
} }
// We're not actually going to decode, only reshuffle.
VertexDecoder *vdecoder = GetVertexDecoder(vertex_type);
int undecodedVertexSize = vdecoder->VertexSize();
const DecVtxFormat & vtxfmt = vdecoder->GetDecVtxFmt();
u16 index_lower_bound = 0; u16 index_lower_bound = 0;
u16 index_upper_bound = count_u * count_v - 1; u16 index_upper_bound = count_u * count_v - 1;
bool indices_16bit = (vertex_type & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_16BIT; bool indices_16bit = (vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_16BIT;
u8* indices8 = (u8*)indices; const u8* indices8 = (const u8*)indices;
u16* indices16 = (u16*)indices; const u16* indices16 = (const u16*)indices;
if (indices) if (indices)
GetIndexBounds(indices, count_u*count_v, vertex_type, &index_lower_bound, &index_upper_bound); GetIndexBounds(indices, count_u*count_v, vertType, &index_lower_bound, &index_upper_bound);
int num_patches_u = count_u - 3; // Simplify away bones and morph before proceeding
int num_patches_v = count_v - 3; SimpleVertex *simplified_control_points = (SimpleVertex *)(decoded + 65536 * 12);
u8 *temp_buffer = decoded + 65536 * 24;
u32 origVertType = vertType;
vertType = NormalizeVertices((u8 *)simplified_control_points, temp_buffer, (u8 *)control_points, index_lower_bound, index_upper_bound, vertType);
VertexDecoder *vdecoder = GetVertexDecoder(vertType);
int vertexSize = vdecoder->VertexSize();
if (vertexSize != sizeof(SimpleVertex)) {
ERROR_LOG(G3D, "Something went really wrong, vertex size: %i vs %i", vertexSize, (int)sizeof(SimpleVertex));
}
const DecVtxFormat& vtxfmt = vdecoder->GetDecVtxFmt();
// TODO: Do something less idiotic to manage this buffer // TODO: Do something less idiotic to manage this buffer
HWSplinePatch* patches = new HWSplinePatch[num_patches_u * num_patches_v]; SimpleVertex **points = new SimpleVertex *[count_u * count_v];
for (int patch_u = 0; patch_u < num_patches_u; ++patch_u) {
for (int patch_v = 0; patch_v < num_patches_v; ++patch_v) {
HWSplinePatch& patch = patches[patch_u + patch_v * num_patches_u];
for (int point = 0; point < 16; ++point) { // Make an array of pointers to the control points, to get rid of indices.
int idx = (patch_u + point%4) + (patch_v + point/4) * count_u; for (int idx = 0; idx < count_u * count_v; idx++) {
if (indices) if (indices)
patch.points[point] = (u8 *)control_points + undecodedVertexSize * (indices_16bit ? indices16[idx] : indices8[idx]); points[idx] = simplified_control_points + (indices_16bit ? indices16[idx] : indices8[idx]);
else else
patch.points[point] = (u8 *)control_points + undecodedVertexSize * idx; points[idx] = simplified_control_points + idx;
}
patch.type = (type_u | (type_v<<2));
if (patch_u != 0) patch.type &= ~START_OPEN_U;
if (patch_v != 0) patch.type &= ~START_OPEN_V;
if (patch_u != num_patches_u-1) patch.type &= ~END_OPEN_U;
if (patch_v != num_patches_v-1) patch.type &= ~END_OPEN_V;
}
} }
u8 *decoded2 = decoded + 65536 * 24; u8 *decoded2 = decoded + 65536 * 36;
int count = 0; int count = 0;
u8 *dest = decoded2; u8 *dest = decoded2;
for (int patch_idx = 0; patch_idx < num_patches_u*num_patches_v; ++patch_idx) { SplinePatchLocal patch;
HWSplinePatch& patch = patches[patch_idx]; patch.type_u = type_u;
patch.type_v = type_v;
patch.count_u = count_u;
patch.count_v = count_v;
patch.points = points;
// TODO: Should do actual patch subdivision instead of just drawing the control points! TesselateSplinePatch(dest, count, patch, origVertType);
const int tile_min_u = (patch.type & START_OPEN_U) ? 0 : 1;
const int tile_min_v = (patch.type & START_OPEN_V) ? 0 : 1;
const int tile_max_u = (patch.type & END_OPEN_U) ? 3 : 2;
const int tile_max_v = (patch.type & END_OPEN_V) ? 3 : 2;
for (int tile_u = tile_min_u; tile_u < tile_max_u; ++tile_u) {
for (int tile_v = tile_min_v; tile_v < tile_max_v; ++tile_v) {
int point_index = tile_u + tile_v*4;
u8 *v0 = patch.points[point_index]; delete[] points;
u8 *v1 = patch.points[point_index+1];
u8 *v2 = patch.points[point_index+4];
u8 *v3 = patch.points[point_index+5];
// TODO: Insert UVs and normals if not present. u32 vertTypeWithIndex16 = (vertType & ~GE_VTYPE_IDX_MASK) | GE_VTYPE_IDX_16BIT;
CopyTriangle(dest, v0, v2, v1, undecodedVertexSize);
CopyTriangle(dest, v1, v2, v3, undecodedVertexSize); UVScale prevUVScale;
count += 6; if (g_Config.bPrescaleUV) {
// We scaled during Normalize already so let's turn it off when drawing.
prevUVScale = gstate_c.uv;
gstate_c.uv.uScale = 1.0f;
gstate_c.uv.vScale = 1.0f;
gstate_c.uv.uOff = 0;
gstate_c.uv.vOff = 0;
} }
} SubmitPrim(decoded2, quadIndices_, GE_PRIM_TRIANGLES, count, vertTypeWithIndex16, 0);
}
delete[] patches;
u32 vertTypeWithoutIndex = vertex_type & ~GE_VTYPE_IDX_MASK;
SubmitPrim(decoded2, 0, GE_PRIM_TRIANGLES, count, vertTypeWithoutIndex, 0);
Flush(); Flush();
if (g_Config.bPrescaleUV) {
gstate_c.uv = prevUVScale;
}
} }
// TODO void TransformDrawEngineDX9::SubmitBezier(void* control_points, void* indices, int count_u, int count_v, GEPatchPrimType prim_type, u32 vertType) {
void TransformDrawEngineDX9::SubmitBezier(void* control_points, void* indices, int count_u, int count_v, GEPatchPrimType prim_type, u32 vertex_type) { Flush();
if (prim_type != GE_PATCHPRIM_TRIANGLES) { if (prim_type != GE_PATCHPRIM_TRIANGLES) {
// Only triangles supported! // Only triangles supported!
return; return;
} }
// We're not actually going to decode, only reshuffle. u16 index_lower_bound = 0;
//VertexDecoder vdecoder; u16 index_upper_bound = count_u * count_v - 1;
//vdecoder.SetVertexType(vertex_type); bool indices_16bit = (vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_16BIT;
const u8* indices8 = (const u8*)indices;
const u16* indices16 = (const u16*)indices;
if (indices)
GetIndexBounds(indices, count_u*count_v, vertType, &index_lower_bound, &index_upper_bound);
// Simplify away bones and morph before proceeding
SimpleVertex *simplified_control_points = (SimpleVertex *)(decoded + 65536 * 12);
u8 *temp_buffer = decoded + 65536 * 24;
u32 origVertType = vertType;
vertType = NormalizeVertices((u8 *)simplified_control_points, temp_buffer, (u8 *)control_points, index_lower_bound, index_upper_bound, vertType);
VertexDecoder *vdecoder = GetVertexDecoder(vertType);
int vertexSize = vdecoder->VertexSize();
if (vertexSize != sizeof(SimpleVertex)) {
ERROR_LOG(G3D, "Something went really wrong, vertex size: %i vs %i", vertexSize, (int)sizeof(SimpleVertex));
}
const DecVtxFormat& vtxfmt = vdecoder->GetDecVtxFmt();
// Bezier patches share less control points than spline patches. Otherwise they are pretty much the same (except bezier don't support the open/close thing)
int num_patches_u = (count_u - 1) / 3;
int num_patches_v = (count_v - 1) / 3;
BezierPatch* patches = new BezierPatch[num_patches_u * num_patches_v];
for (int patch_u = 0; patch_u < num_patches_u; patch_u++) {
for (int patch_v = 0; patch_v < num_patches_v; patch_v++) {
BezierPatch& patch = patches[patch_u + patch_v * num_patches_u];
for (int point = 0; point < 16; ++point) {
int idx = (patch_u * 3 + point%4) + (patch_v * 3 + point/4) * count_u;
if (indices)
patch.points[point] = simplified_control_points + (indices_16bit ? indices16[idx] : indices8[idx]);
else
patch.points[point] = simplified_control_points + idx;
}
patch.u_index = patch_u * 3;
patch.v_index = patch_v * 3;
}
}
u8 *decoded2 = decoded + 65536 * 36;
int count = 0;
u8 *dest = decoded2;
// Simple approximation of the real tesselation factor.
// We shouldn't really split up into separate 4x4 patches, instead we should do something that works
// like the splines, so we subdivide across the whole "mega-patch".
if (num_patches_u == 0) num_patches_u = 1;
if (num_patches_v == 0) num_patches_v = 1;
int tess_u = gstate.getPatchDivisionU() / num_patches_u;
int tess_v = gstate.getPatchDivisionV() / num_patches_v;
if (tess_u < 4) tess_u = 4;
if (tess_v < 4) tess_v = 4;
for (int patch_idx = 0; patch_idx < num_patches_u*num_patches_v; ++patch_idx) {
BezierPatch& patch = patches[patch_idx];
TesselateBezierPatch(dest, count, tess_u, tess_v, patch, origVertType);
}
delete[] patches;
u32 vertTypeWithIndex16 = (vertType & ~GE_VTYPE_IDX_MASK) | GE_VTYPE_IDX_16BIT;
UVScale prevUVScale;
if (g_Config.bPrescaleUV) {
// We scaled during Normalize already so let's turn it off when drawing.
prevUVScale = gstate_c.uv;
gstate_c.uv.uScale = 1.0f;
gstate_c.uv.vScale = 1.0f;
gstate_c.uv.uOff = 0;
gstate_c.uv.vOff = 0;
}
SubmitPrim(decoded2, quadIndices_, GE_PRIM_TRIANGLES, count, vertTypeWithIndex16, 0);
Flush(); Flush();
if (g_Config.bPrescaleUV) {
gstate_c.uv = prevUVScale;
}
} }
}; };

View File

@ -786,7 +786,7 @@ void TextureCacheDX9::UpdateCurrentClut() {
if (gstate.getClutPaletteFormat() == GE_CMODE_16BIT_ABGR4444 && gstate.isClutIndexSimple()) { if (gstate.getClutPaletteFormat() == GE_CMODE_16BIT_ABGR4444 && gstate.isClutIndexSimple()) {
const u16_le *clut = GetCurrentClut<u16_le>(); const u16_le *clut = GetCurrentClut<u16_le>();
clutAlphaLinear_ = true; clutAlphaLinear_ = true;
clutAlphaLinearColor_ = clut[15] & 0xFFF0; clutAlphaLinearColor_ = clut[15] & 0x0FFF;
for (int i = 0; i < 16; ++i) { for (int i = 0; i < 16; ++i) {
if ((clut[i] >> 12) != i) { if ((clut[i] >> 12) != i) {
clutAlphaLinear_ = false; clutAlphaLinear_ = false;

View File

@ -24,6 +24,7 @@
#include "GPU/Common/GPUDebugInterface.h" #include "GPU/Common/GPUDebugInterface.h"
#include "GPU/Common/IndexGenerator.h" #include "GPU/Common/IndexGenerator.h"
#include "GPU/Common/VertexDecoderCommon.h" #include "GPU/Common/VertexDecoderCommon.h"
#include "GPU/Common/DrawEngineCommon.h"
struct DecVtxFormat; struct DecVtxFormat;
@ -102,7 +103,7 @@ public:
}; };
// Handles transform, lighting and drawing. // Handles transform, lighting and drawing.
class TransformDrawEngineDX9 { class TransformDrawEngineDX9 : public DrawEngineCommon {
public: public:
TransformDrawEngineDX9(); TransformDrawEngineDX9();
virtual ~TransformDrawEngineDX9(); virtual ~TransformDrawEngineDX9();

View File

@ -25,12 +25,6 @@
// Here's how to evaluate them fast: // Here's how to evaluate them fast:
// http://and-what-happened.blogspot.se/2012/07/evaluating-b-splines-aka-basis-splines.html // http://and-what-happened.blogspot.se/2012/07/evaluating-b-splines-aka-basis-splines.html
enum quality {
LOW_QUALITY = 0,
MEDIUM_QUALITY = 1,
HIGH_QUALITY = 2,
};
// This normalizes a set of vertices in any format to SimpleVertex format, by processing away morphing AND skinning. // This normalizes a set of vertices in any format to SimpleVertex format, by processing away morphing AND skinning.
// The rest of the transform pipeline like lighting will go as normal, either hardware or software. // The rest of the transform pipeline like lighting will go as normal, either hardware or software.
// The implementation is initially a bit inefficient but shouldn't be a big deal. // The implementation is initially a bit inefficient but shouldn't be a big deal.
@ -140,589 +134,6 @@ u32 TransformDrawEngine::NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inP
return NormalizeVertices(outPtr, bufPtr, inPtr, dec, lowerBound, upperBound, vertType); return NormalizeVertices(outPtr, bufPtr, inPtr, dec, lowerBound, upperBound, vertType);
} }
#define START_OPEN 1
#define END_OPEN 2
static float lerp(float a, float b, float x) {
return a + x * (b - a);
}
static void lerpColor(u8 a[4], u8 b[4], float x, u8 out[4]) {
for (int i = 0; i < 4; i++) {
out[i] = (float)a[i] + x * ((float)b[i] - (float)a[i]);
}
}
// We decode all vertices into a common format for easy interpolation and stuff.
// Not fast but can be optimized later.
struct BezierPatch {
SimpleVertex *points[16];
// These are used to generate UVs.
int u_index, v_index;
// Interpolate colors between control points (bilinear, should be good enough).
void sampleColor(float u, float v, u8 color[4]) const {
u *= 3.0f;
v *= 3.0f;
int iu = (int)floorf(u);
int iv = (int)floorf(v);
int iu2 = iu + 1;
int iv2 = iv + 1;
float fracU = u - iu;
float fracV = v - iv;
if (iu2 > 3) iu2 = 3;
if (iv2 > 3) iv2 = 3;
int tl = iu + 4 * iv;
int tr = iu2 + 4 * iv;
int bl = iu + 4 * iv2;
int br = iu2 + 4 * iv2;
u8 upperColor[4], lowerColor[4];
lerpColor(points[tl]->color, points[tr]->color, fracU, upperColor);
lerpColor(points[bl]->color, points[br]->color, fracU, lowerColor);
lerpColor(upperColor, lowerColor, fracV, color);
}
void sampleTexUV(float u, float v, float &tu, float &tv) const {
u *= 3.0f;
v *= 3.0f;
int iu = (int)floorf(u);
int iv = (int)floorf(v);
int iu2 = iu + 1;
int iv2 = iv + 1;
float fracU = u - iu;
float fracV = v - iv;
if (iu2 > 3) iu2 = 3;
if (iv2 > 3) iv2 = 3;
int tl = iu + 4 * iv;
int tr = iu2 + 4 * iv;
int bl = iu + 4 * iv2;
int br = iu2 + 4 * iv2;
float upperTU = lerp(points[tl]->uv[0], points[tr]->uv[0], fracU);
float upperTV = lerp(points[tl]->uv[1], points[tr]->uv[1], fracU);
float lowerTU = lerp(points[bl]->uv[0], points[br]->uv[0], fracU);
float lowerTV = lerp(points[bl]->uv[1], points[br]->uv[1], fracU);
tu = lerp(upperTU, lowerTU, fracV);
tv = lerp(upperTV, lowerTV, fracV);
}
};
struct SplinePatchLocal {
SimpleVertex **points;
int count_u;
int count_v;
int type_u;
int type_v;
/*
// Interpolate colors between control points (bilinear, should be good enough).
void sampleColor(float u, float v, u8 color[4]) const {
u *= 3.0f;
v *= 3.0f;
int iu = (int)floorf(u);
int iv = (int)floorf(v);
int iu2 = iu + 1;
int iv2 = iv + 1;
float fracU = u - iu;
float fracV = v - iv;
if (iu2 >= count_u) iu2 = count_u - 1;
if (iv2 >= count_v) iv2 = count_v - 1;
int tl = iu + count_u * iv;
int tr = iu2 + count_u * iv;
int bl = iu + count_u * iv2;
int br = iu2 + count_u * iv2;
u8 upperColor[4], lowerColor[4];
lerpColor(points[tl]->color, points[tr]->color, fracU, upperColor);
lerpColor(points[bl]->color, points[br]->color, fracU, lowerColor);
lerpColor(upperColor, lowerColor, fracV, color);
}
void sampleTexUV(float u, float v, float &tu, float &tv) const {
u *= 3.0f;
v *= 3.0f;
int iu = (int)floorf(u);
int iv = (int)floorf(v);
int iu2 = iu + 1;
int iv2 = iv + 1;
float fracU = u - iu;
float fracV = v - iv;
if (iu2 >= count_u) iu2 = count_u - 1;
if (iv2 >= count_v) iv2 = count_v - 1;
int tl = iu + count_u * iv;
int tr = iu2 + count_u * iv;
int bl = iu + count_u * iv2;
int br = iu2 + count_u * iv2;
float upperTU = lerp(points[tl]->uv[0], points[tr]->uv[0], fracU);
float upperTV = lerp(points[tl]->uv[1], points[tr]->uv[1], fracU);
float lowerTU = lerp(points[bl]->uv[0], points[br]->uv[0], fracU);
float lowerTV = lerp(points[bl]->uv[1], points[br]->uv[1], fracU);
tu = lerp(upperTU, lowerTU, fracV);
tv = lerp(upperTV, lowerTV, fracV);
}*/
};
static void CopyQuad(u8 *&dest, const SimpleVertex *v1, const SimpleVertex *v2, const SimpleVertex* v3, const SimpleVertex *v4) {
int vertexSize = sizeof(SimpleVertex);
memcpy(dest, v1, vertexSize);
dest += vertexSize;
memcpy(dest, v2, vertexSize);
dest += vertexSize;
memcpy(dest, v3, vertexSize);
dest += vertexSize;
memcpy(dest, v4, vertexSize);
dest += vertexSize;
}
#undef b2
// Bernstein basis functions
inline float bern0(float x) { return (1 - x) * (1 - x) * (1 - x); }
inline float bern1(float x) { return 3 * x * (1 - x) * (1 - x); }
inline float bern2(float x) { return 3 * x * x * (1 - x); }
inline float bern3(float x) { return x * x * x; }
// Not sure yet if these have any use
inline float bern0deriv(float x) { return -3 * (x - 1) * (x - 1); }
inline float bern1deriv(float x) { return 9 * x * x - 12 * x + 3; }
inline float bern2deriv(float x) { return 3 * (2 - 3 * x) * x; }
inline float bern3deriv(float x) { return 3 * x * x; }
// http://en.wikipedia.org/wiki/Bernstein_polynomial
Vec3Packedf Bernstein3D(const Vec3Packedf p0, const Vec3Packedf p1, const Vec3Packedf p2, const Vec3Packedf p3, float x) {
return p0 * bern0(x) + p1 * bern1(x) + p2 * bern2(x) + p3 * bern3(x);
}
Vec3Packedf Bernstein3DDerivative(const Vec3Packedf p0, const Vec3Packedf p1, const Vec3Packedf p2, const Vec3Packedf p3, float x) {
return p0 * bern0deriv(x) + p1 * bern1deriv(x) + p2 * bern2deriv(x) + p3 * bern3deriv(x);
}
void spline_n_4(int i, float t, float *knot, float *splineVal) {
knot += i + 1;
float t0 = (t - knot[0]);
float t1 = (t - knot[1]);
float t2 = (t - knot[2]);
float f30 = t0/(knot[3]-knot[0]);
float f41 = t1/(knot[4]-knot[1]);
float f52 = t2/(knot[5]-knot[2]);
float f31 = t1/(knot[3]-knot[1]);
float f42 = t2/(knot[4]-knot[2]);
float f32 = t2/(knot[3]-knot[2]);
float a = (1-f30)*(1-f31);
float b = (f31*f41);
float c = (1-f41)*(1-f42);
float d = (f42*f52);
splineVal[0] = a-(a*f32);
splineVal[1] = 1-a-b+((a+b+c-1)*f32);
splineVal[2] = b+((1-b-c-d)*f32);
splineVal[3] = d*f32;
}
// knot should be an array sized n + 5 (n + 1 + 1 + degree (cubic))
void spline_knot(int n, int type, float *knot) {
memset(knot, 0, sizeof(float) * (n + 5));
for (int i = 0; i < n - 1; ++i)
knot[i + 3] = i;
if ((type & 1) == 0) {
knot[0] = -3;
knot[1] = -2;
knot[2] = -1;
}
if ((type & 2) == 0) {
knot[n + 2] = n - 1;
knot[n + 3] = n;
knot[n + 4] = n + 1;
} else {
knot[n + 2] = n - 2;
knot[n + 3] = n - 2;
knot[n + 4] = n - 2;
}
}
void _SplinePatchLowQuality(u8 *&dest, int &count, const SplinePatchLocal &spatch, u32 origVertType) {
const float third = 1.0f / 3.0f;
// Fast and easy way - just draw the control points, generate some very basic normal vector substitutes.
// Very inaccurate but okay for Loco Roco. Maybe should keep it as an option because it's fast.
const int tile_min_u = (spatch.type_u & START_OPEN) ? 0 : 1;
const int tile_min_v = (spatch.type_v & START_OPEN) ? 0 : 1;
const int tile_max_u = (spatch.type_u & END_OPEN) ? spatch.count_u - 1 : spatch.count_u - 2;
const int tile_max_v = (spatch.type_v & END_OPEN) ? spatch.count_v - 1 : spatch.count_v - 2;
for (int tile_v = tile_min_v; tile_v < tile_max_v; ++tile_v) {
for (int tile_u = tile_min_u; tile_u < tile_max_u; ++tile_u) {
int point_index = tile_u + tile_v * spatch.count_u;
SimpleVertex v0 = *spatch.points[point_index];
SimpleVertex v1 = *spatch.points[point_index + 1];
SimpleVertex v2 = *spatch.points[point_index + spatch.count_u];
SimpleVertex v3 = *spatch.points[point_index + spatch.count_u + 1];
// Generate UV. TODO: Do this even if UV specified in control points?
if ((origVertType & GE_VTYPE_TC_MASK) == 0) {
float u = tile_u * third;
float v = tile_v * third;
v0.uv[0] = u;
v0.uv[1] = v;
v1.uv[0] = u + third;
v1.uv[1] = v;
v2.uv[0] = u;
v2.uv[1] = v + third;
v3.uv[0] = u + third;
v3.uv[1] = v + third;
}
// Generate normal if lighting is enabled (otherwise there's no point).
// This is a really poor quality algorithm, we get facet normals.
if (gstate.isLightingEnabled()) {
Vec3Packedf norm = Cross(v1.pos - v0.pos, v2.pos - v0.pos);
norm.Normalize();
if (gstate.patchfacing & 1)
norm *= -1.0f;
v0.nrm = norm;
v1.nrm = norm;
v2.nrm = norm;
v3.nrm = norm;
}
CopyQuad(dest, &v0, &v1, &v2, &v3);
count += 6;
}
}
}
void _SplinePatchFullQuality(u8 *&dest, int &count, const SplinePatchLocal &spatch, u32 origVertType, int patch_cap) {
// Full (mostly) correct tessellation of spline patches.
// Not very fast.
// First, generate knot vectors.
int n = spatch.count_u - 1;
int m = spatch.count_v - 1;
float *knot_u = new float[n + 5];
float *knot_v = new float[m + 5];
spline_knot(n, spatch.type_u, knot_u);
spline_knot(m, spatch.type_v, knot_v);
// Increase tesselation based on the size. Should be approximately right?
// JPCSP is wrong at least because their method results in square loco roco.
int patch_div_s = (spatch.count_u - 3) * gstate.getPatchDivisionU() / 3;
int patch_div_t = (spatch.count_v - 3) * gstate.getPatchDivisionV() / 3;
if (patch_div_s <= 0) patch_div_s = 1;
if (patch_div_t <= 0) patch_div_t = 1;
// TODO: Remove this cap when spline_s has been optimized.
if (patch_div_s > patch_cap) patch_div_s = patch_cap;
if (patch_div_t > patch_cap) patch_div_t = patch_cap;
// First compute all the vertices and put them in an array
SimpleVertex *vertices = new SimpleVertex[(patch_div_s + 1) * (patch_div_t + 1)];
float tu_width = 1.0f + (spatch.count_u - 4) * 1.0f / 3.0f;
float tv_height = 1.0f + (spatch.count_v - 4) * 1.0f / 3.0f;
bool computeNormals = gstate.isLightingEnabled();
for (int tile_v = 0; tile_v < patch_div_t + 1; tile_v++) {
float v = ((float)tile_v * (float)(m - 2) / (float)(patch_div_t + 0.00001f)); // epsilon to prevent division by 0 in spline_s
if (v < 0.0f)
v = 0.0f;
for (int tile_u = 0; tile_u < patch_div_s + 1; tile_u++) {
float u = ((float)tile_u * (float)(n - 2) / (float)(patch_div_s + 0.00001f));
if (u < 0.0f)
u = 0.0f;
SimpleVertex *vert = &vertices[tile_v * (patch_div_s + 1) + tile_u];
vert->pos.SetZero();
if (origVertType & GE_VTYPE_NRM_MASK) {
vert->nrm.SetZero();
}
else {
vert->nrm.SetZero();
vert->nrm.z = 1.0f;
}
if (origVertType & GE_VTYPE_COL_MASK) {
memset(vert->color, 0, 4);
}
else {
memcpy(vert->color, spatch.points[0]->color, 4);
}
if (origVertType & GE_VTYPE_TC_MASK) {
vert->uv[0] = 0.0f;
vert->uv[1] = 0.0f;
}
else {
vert->uv[0] = tu_width * ((float)tile_u / (float)patch_div_s);
vert->uv[1] = tv_height * ((float)tile_v / (float)patch_div_t);
}
// Collect influences from surrounding control points.
float u_weights[4];
float v_weights[4];
int iu = (int)u;
int iv = (int)v;
spline_n_4(iu, u, knot_u, u_weights);
spline_n_4(iv, v, knot_v, v_weights);
// Handle degenerate patches. without this, spatch.points[] may read outside the number of initialized points.
int patch_w = std::min(spatch.count_u, 4);
int patch_h = std::min(spatch.count_v, 4);
for (int ii = 0; ii < patch_w; ++ii) {
for (int jj = 0; jj < patch_h; ++jj) {
float u_spline = u_weights[ii];
float v_spline = v_weights[jj];
float f = u_spline * v_spline;
if (f > 0.0f) {
int idx = spatch.count_u * (iv + jj) + (iu + ii);
SimpleVertex *a = spatch.points[idx];
vert->pos += a->pos * f;
if (origVertType & GE_VTYPE_TC_MASK) {
vert->uv[0] += a->uv[0] * f;
vert->uv[1] += a->uv[1] * f;
}
if (origVertType & GE_VTYPE_COL_MASK) {
vert->color[0] += a->color[0] * f;
vert->color[1] += a->color[1] * f;
vert->color[2] += a->color[2] * f;
vert->color[3] += a->color[3] * f;
}
if (origVertType & GE_VTYPE_NRM_MASK) {
vert->nrm += a->nrm * f;
}
}
}
}
if (origVertType & GE_VTYPE_NRM_MASK) {
vert->nrm.Normalize();
}
}
}
delete[] knot_u;
delete[] knot_v;
// Hacky normal generation through central difference.
if (gstate.isLightingEnabled() && (origVertType & GE_VTYPE_NRM_MASK) == 0) {
for (int v = 0; v < patch_div_t + 1; v++) {
for (int u = 0; u < patch_div_s + 1; u++) {
int l = std::max(0, u - 1);
int t = std::max(0, v - 1);
int r = std::min(patch_div_s, u + 1);
int b = std::min(patch_div_t, v + 1);
const Vec3Packedf &right = vertices[v * (patch_div_s + 1) + r].pos - vertices[v * (patch_div_s + 1) + l].pos;
const Vec3Packedf &down = vertices[b * (patch_div_s + 1) + u].pos - vertices[t * (patch_div_s + 1) + u].pos;
vertices[v * (patch_div_s + 1) + u].nrm = Cross(right, down).Normalized();
if (gstate.patchfacing & 1) {
vertices[v * (patch_div_s + 1) + u].nrm *= -1.0f;
}
}
}
}
// Tesselate. TODO: Use indices so we only need to emit 4 vertices per pair of triangles instead of six.
for (int tile_v = 0; tile_v < patch_div_t; ++tile_v) {
for (int tile_u = 0; tile_u < patch_div_s; ++tile_u) {
float u = ((float)tile_u / (float)patch_div_s);
float v = ((float)tile_v / (float)patch_div_t);
SimpleVertex *v0 = &vertices[tile_v * (patch_div_s + 1) + tile_u];
SimpleVertex *v1 = &vertices[tile_v * (patch_div_s + 1) + tile_u + 1];
SimpleVertex *v2 = &vertices[(tile_v + 1) * (patch_div_s + 1) + tile_u];
SimpleVertex *v3 = &vertices[(tile_v + 1) * (patch_div_s + 1) + tile_u + 1];
CopyQuad(dest, v0, v1, v2, v3);
count += 6;
}
}
delete[] vertices;
}
void TesselateSplinePatch(u8 *&dest, int &count, const SplinePatchLocal &spatch, u32 origVertType) {
switch (g_Config.iSplineBezierQuality) {
case LOW_QUALITY:
_SplinePatchLowQuality(dest, count, spatch, origVertType);
break;
case MEDIUM_QUALITY:
_SplinePatchFullQuality(dest, count, spatch, origVertType, 8);
break;
case HIGH_QUALITY:
_SplinePatchFullQuality(dest, count, spatch, origVertType, 64);
break;
}
}
void _BezierPatchLowQuality(u8 *&dest, int &count, int tess_u, int tess_v, const BezierPatch &patch, u32 origVertType) {
const float third = 1.0f / 3.0f;
// Fast and easy way - just draw the control points, generate some very basic normal vector subsitutes.
// Very inaccurate though but okay for Loco Roco. Maybe should keep it as an option.
float u_base = patch.u_index / 3.0f;
float v_base = patch.v_index / 3.0f;
for (int tile_v = 0; tile_v < 3; tile_v++) {
for (int tile_u = 0; tile_u < 3; tile_u++) {
int point_index = tile_u + tile_v * 4;
SimpleVertex v0 = *patch.points[point_index];
SimpleVertex v1 = *patch.points[point_index + 1];
SimpleVertex v2 = *patch.points[point_index + 4];
SimpleVertex v3 = *patch.points[point_index + 5];
// Generate UV. TODO: Do this even if UV specified in control points?
if ((origVertType & GE_VTYPE_TC_MASK) == 0) {
float u = u_base + tile_u * third;
float v = v_base + tile_v * third;
v0.uv[0] = u;
v0.uv[1] = v;
v1.uv[0] = u + third;
v1.uv[1] = v;
v2.uv[0] = u;
v2.uv[1] = v + third;
v3.uv[0] = u + third;
v3.uv[1] = v + third;
}
// Generate normal if lighting is enabled (otherwise there's no point).
// This is a really poor quality algorithm, we get facet normals.
if (gstate.isLightingEnabled()) {
Vec3Packedf norm = Cross(v1.pos - v0.pos, v2.pos - v0.pos);
norm.Normalize();
if (gstate.patchfacing & 1)
norm *= -1.0f;
v0.nrm = norm;
v1.nrm = norm;
v2.nrm = norm;
v3.nrm = norm;
}
CopyQuad(dest, &v0, &v1, &v2, &v3);
count += 6;
}
}
}
void _BezierPatchHighQuality(u8 *&dest, int &count, int tess_u, int tess_v, const BezierPatch &patch, u32 origVertType) {
const float third = 1.0f / 3.0f;
// Full correct tesselation of bezier patches.
// Note: Does not handle splines correctly.
// First compute all the vertices and put them in an array
SimpleVertex *vertices = new SimpleVertex[(tess_u + 1) * (tess_v + 1)];
Vec3Packedf *horiz = new Vec3Packedf[(tess_u + 1) * 4];
Vec3Packedf *horiz2 = horiz + (tess_u + 1) * 1;
Vec3Packedf *horiz3 = horiz + (tess_u + 1) * 2;
Vec3Packedf *horiz4 = horiz + (tess_u + 1) * 3;
// Precompute the horizontal curves to we only have to evaluate the vertical ones.
for (int i = 0; i < tess_u + 1; i++) {
float u = ((float)i / (float)tess_u);
horiz[i] = Bernstein3D(patch.points[0]->pos, patch.points[1]->pos, patch.points[2]->pos, patch.points[3]->pos, u);
horiz2[i] = Bernstein3D(patch.points[4]->pos, patch.points[5]->pos, patch.points[6]->pos, patch.points[7]->pos, u);
horiz3[i] = Bernstein3D(patch.points[8]->pos, patch.points[9]->pos, patch.points[10]->pos, patch.points[11]->pos, u);
horiz4[i] = Bernstein3D(patch.points[12]->pos, patch.points[13]->pos, patch.points[14]->pos, patch.points[15]->pos, u);
}
bool computeNormals = gstate.isLightingEnabled();
for (int tile_v = 0; tile_v < tess_v + 1; ++tile_v) {
for (int tile_u = 0; tile_u < tess_u + 1; ++tile_u) {
float u = ((float)tile_u / (float)tess_u);
float v = ((float)tile_v / (float)tess_v);
float bu = u;
float bv = v;
// TODO: Should be able to precompute the four curves per U, then just Bernstein per V. Will benefit large tesselation factors.
const Vec3Packedf &pos1 = horiz[tile_u];
const Vec3Packedf &pos2 = horiz2[tile_u];
const Vec3Packedf &pos3 = horiz3[tile_u];
const Vec3Packedf &pos4 = horiz4[tile_u];
SimpleVertex &vert = vertices[tile_v * (tess_u + 1) + tile_u];
if (computeNormals) {
Vec3Packedf derivU1 = Bernstein3DDerivative(patch.points[0]->pos, patch.points[1]->pos, patch.points[2]->pos, patch.points[3]->pos, bu);
Vec3Packedf derivU2 = Bernstein3DDerivative(patch.points[4]->pos, patch.points[5]->pos, patch.points[6]->pos, patch.points[7]->pos, bu);
Vec3Packedf derivU3 = Bernstein3DDerivative(patch.points[8]->pos, patch.points[9]->pos, patch.points[10]->pos, patch.points[11]->pos, bu);
Vec3Packedf derivU4 = Bernstein3DDerivative(patch.points[12]->pos, patch.points[13]->pos, patch.points[14]->pos, patch.points[15]->pos, bu);
Vec3Packedf derivU = Bernstein3D(derivU1, derivU2, derivU3, derivU4, bv);
Vec3Packedf derivV = Bernstein3DDerivative(pos1, pos2, pos3, pos4, bv);
// TODO: Interpolate normals instead of generating them, if available?
vert.nrm = Cross(derivU, derivV).Normalized();
if (gstate.patchfacing & 1)
vert.nrm *= -1.0f;
}
else {
vert.nrm.SetZero();
}
vert.pos = Bernstein3D(pos1, pos2, pos3, pos4, bv);
if ((origVertType & GE_VTYPE_TC_MASK) == 0) {
// Generate texcoord
vert.uv[0] = u + patch.u_index * third;
vert.uv[1] = v + patch.v_index * third;
} else {
// Sample UV from control points
patch.sampleTexUV(u, v, vert.uv[0], vert.uv[1]);
}
if (origVertType & GE_VTYPE_COL_MASK) {
patch.sampleColor(u, v, vert.color);
} else {
memcpy(vert.color, patch.points[0]->color, 4);
}
}
}
delete[] horiz;
// Tesselate. TODO: Use indices so we only need to emit 4 vertices per pair of triangles instead of six.
for (int tile_v = 0; tile_v < tess_v; ++tile_v) {
for (int tile_u = 0; tile_u < tess_u; ++tile_u) {
float u = ((float)tile_u / (float)tess_u);
float v = ((float)tile_v / (float)tess_v);
const SimpleVertex *v0 = &vertices[tile_v * (tess_u + 1) + tile_u];
const SimpleVertex *v1 = &vertices[tile_v * (tess_u + 1) + tile_u + 1];
const SimpleVertex *v2 = &vertices[(tile_v + 1) * (tess_u + 1) + tile_u];
const SimpleVertex *v3 = &vertices[(tile_v + 1) * (tess_u + 1) + tile_u + 1];
CopyQuad(dest, v0, v1, v2, v3);
count += 6;
}
}
delete[] vertices;
}
void TesselateBezierPatch(u8 *&dest, int &count, int tess_u, int tess_v, const BezierPatch &patch, u32 origVertType) {
switch (g_Config.iSplineBezierQuality) {
case LOW_QUALITY:
_BezierPatchLowQuality(dest, count, tess_u, tess_v, patch, origVertType);
break;
case MEDIUM_QUALITY:
case HIGH_QUALITY:
_BezierPatchHighQuality(dest, count, tess_u, tess_v, patch, origVertType);
break;
}
}
void TransformDrawEngine::SubmitSpline(void* control_points, void* indices, int count_u, int count_v, int type_u, int type_v, GEPatchPrimType prim_type, u32 vertType) { void TransformDrawEngine::SubmitSpline(void* control_points, void* indices, int count_u, int count_v, int type_u, int type_v, GEPatchPrimType prim_type, u32 vertType) {
Flush(); Flush();

View File

@ -22,6 +22,7 @@
#include "GPU/Common/GPUDebugInterface.h" #include "GPU/Common/GPUDebugInterface.h"
#include "GPU/Common/IndexGenerator.h" #include "GPU/Common/IndexGenerator.h"
#include "GPU/Common/VertexDecoderCommon.h" #include "GPU/Common/VertexDecoderCommon.h"
#include "GPU/Common/DrawEngineCommon.h"
#include "gfx/gl_common.h" #include "gfx/gl_common.h"
#include "gfx/gl_lost_manager.h" #include "gfx/gl_lost_manager.h"
@ -98,7 +99,7 @@ public:
}; };
// Handles transform, lighting and drawing. // Handles transform, lighting and drawing.
class TransformDrawEngine : public GfxResourceHolder { class TransformDrawEngine : public DrawEngineCommon, public GfxResourceHolder {
public: public:
TransformDrawEngine(); TransformDrawEngine();
virtual ~TransformDrawEngine(); virtual ~TransformDrawEngine();

View File

@ -161,6 +161,7 @@
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\ext\xbrz\xbrz.h" /> <ClInclude Include="..\ext\xbrz\xbrz.h" />
<ClInclude Include="Common\DrawEngineCommon.h" />
<ClInclude Include="Common\FramebufferCommon.h" /> <ClInclude Include="Common\FramebufferCommon.h" />
<ClInclude Include="Common\GPUDebugInterface.h" /> <ClInclude Include="Common\GPUDebugInterface.h" />
<ClInclude Include="Common\IndexGenerator.h" /> <ClInclude Include="Common\IndexGenerator.h" />
@ -218,9 +219,11 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\ext\xbrz\xbrz.cpp" /> <ClCompile Include="..\ext\xbrz\xbrz.cpp" />
<ClCompile Include="Common\DrawEngineCommon.cpp" />
<ClCompile Include="Common\FramebufferCommon.cpp" /> <ClCompile Include="Common\FramebufferCommon.cpp" />
<ClCompile Include="Common\IndexGenerator.cpp" /> <ClCompile Include="Common\IndexGenerator.cpp" />
<ClCompile Include="Common\PostShader.cpp" /> <ClCompile Include="Common\PostShader.cpp" />
<ClCompile Include="Common\SplineCommon.cpp" />
<ClCompile Include="Common\TextureDecoderNEON.cpp"> <ClCompile Include="Common\TextureDecoderNEON.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>

View File

@ -174,6 +174,9 @@
<ClInclude Include="Common\SoftwareTransformCommon.h"> <ClInclude Include="Common\SoftwareTransformCommon.h">
<Filter>Common</Filter> <Filter>Common</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Common\DrawEngineCommon.h">
<Filter>Common</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Math3D.cpp"> <ClCompile Include="Math3D.cpp">
@ -269,9 +272,6 @@
<ClCompile Include="GeDisasm.cpp"> <ClCompile Include="GeDisasm.cpp">
<Filter>Common</Filter> <Filter>Common</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="GLES\Spline.cpp">
<Filter>GLES</Filter>
</ClCompile>
<ClCompile Include="..\ext\xbrz\xbrz.cpp"> <ClCompile Include="..\ext\xbrz\xbrz.cpp">
<Filter>Common</Filter> <Filter>Common</Filter>
</ClCompile> </ClCompile>
@ -326,6 +326,15 @@
<ClCompile Include="Common\SoftwareTransformCommon.cpp"> <ClCompile Include="Common\SoftwareTransformCommon.cpp">
<Filter>Common</Filter> <Filter>Common</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Common\DrawEngineCommon.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="GLES\Spline.cpp">
<Filter>GLES</Filter>
</ClCompile>
<ClCompile Include="Common\SplineCommon.cpp">
<Filter>Common</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="CMakeLists.txt" /> <None Include="CMakeLists.txt" />

View File

@ -49,6 +49,8 @@ SOURCES += $$P/GPU/GeDisasm.cpp \ # GPU
$$P/GPU/Common/SoftwareTransformCommon.cpp \ $$P/GPU/Common/SoftwareTransformCommon.cpp \
$$P/GPU/Common/PostShader.cpp \ $$P/GPU/Common/PostShader.cpp \
$$P/GPU/Common/FramebufferCommon.cpp \ $$P/GPU/Common/FramebufferCommon.cpp \
$$P/GPU/Common/SplineCommon.cpp \
$$P/GPU/Common/DrawEngineCommon.cpp \
$$P/ext/xxhash.c \ # xxHash $$P/ext/xxhash.c \ # xxHash
$$P/ext/xbrz/*.cpp # XBRZ $$P/ext/xbrz/*.cpp # XBRZ

View File

@ -141,6 +141,8 @@ EXEC_AND_LIB_FILES := \
$(SRC)/GPU/Common/SoftwareTransformCommon.cpp.arm \ $(SRC)/GPU/Common/SoftwareTransformCommon.cpp.arm \
$(SRC)/GPU/Common/VertexDecoderCommon.cpp.arm \ $(SRC)/GPU/Common/VertexDecoderCommon.cpp.arm \
$(SRC)/GPU/Common/TextureCacheCommon.cpp.arm \ $(SRC)/GPU/Common/TextureCacheCommon.cpp.arm \
$(SRC)/GPU/Common/SplineCommon.cpp.arm \
$(SRC)/GPU/Common/DrawEngineCommon.cpp.arm \
$(SRC)/GPU/Common/TransformCommon.cpp.arm \ $(SRC)/GPU/Common/TransformCommon.cpp.arm \
$(SRC)/GPU/Common/TextureDecoder.cpp \ $(SRC)/GPU/Common/TextureDecoder.cpp \
$(SRC)/GPU/Common/PostShader.cpp \ $(SRC)/GPU/Common/PostShader.cpp \