mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 21:39:52 +00:00
[Gpu] Sync with gles
Conflicts: GPU/Directx9/FramebufferDX9.cpp GPU/Directx9/FramebufferDX9.h GPU/Directx9/TransformPipelineDX9.cpp
This commit is contained in:
parent
6ee39c9abd
commit
49cc8e7312
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <set>
|
||||
|
||||
#include "d3d9.h"
|
||||
|
||||
#include "GPU/Directx9/helper/fbo.h"
|
||||
@ -98,7 +100,8 @@ public:
|
||||
}
|
||||
|
||||
void DrawPixels(const u8 *framebuf, GEBufferFormat pixelFormat, int linesize);
|
||||
void DrawActiveTexture(float x, float y, float w, float h, bool flip = false, float uscale = 1.0f, float vscale = 1.0f);
|
||||
|
||||
void DrawActiveTexture(LPDIRECT3DTEXTURE9 tex, float x, float y, float w, float h, float destW, float destH, bool flip = false, float uscale = 1.0f, float vscale = 1.0f);
|
||||
|
||||
void DestroyAllFBOs();
|
||||
void DecimateFBOs();
|
||||
@ -108,13 +111,16 @@ public:
|
||||
void Resized();
|
||||
void DeviceLost();
|
||||
void CopyDisplayToOutput();
|
||||
void SetRenderFrameBuffer(); // Uses parameters computed from gstate
|
||||
void UpdateFromMemory(u32 addr, int size);
|
||||
void SetRenderFrameBuffer(); // Uses parameters computed from gstate
|
||||
void UpdateFromMemory(u32 addr, int size, bool safe);
|
||||
|
||||
void ReadFramebufferToMemory(VirtualFramebufferDX9 *vfb, bool sync = true);
|
||||
|
||||
// TODO: Break out into some form of FBO manager
|
||||
VirtualFramebufferDX9 *GetDisplayFBO();
|
||||
VirtualFramebufferDX9 *GetVFBAt(u32 addr);
|
||||
VirtualFramebufferDX9 *GetDisplayVFB() {
|
||||
return GetVFBAt(displayFramebufPtr_);
|
||||
}
|
||||
void SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format);
|
||||
size_t NumVFBs() const { return vfbs_.size(); }
|
||||
|
||||
@ -132,10 +138,19 @@ public:
|
||||
return displayFramebuf_ ? (0x04000000 | displayFramebuf_->fb_address) : 0;
|
||||
}
|
||||
|
||||
void NotifyFramebufferCopy(u32 src, u32 dest, int size);
|
||||
|
||||
void DestroyFramebuf(VirtualFramebufferDX9 *vfb);
|
||||
|
||||
bool GetCurrentFramebuffer(GPUDebugBuffer &buffer);
|
||||
bool GetCurrentDepthbuffer(GPUDebugBuffer &buffer);
|
||||
bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer);
|
||||
|
||||
private:
|
||||
u32 ramDisplayFramebufPtr_; // workaround for MotoGP insanity
|
||||
void CompileDraw2DProgram();
|
||||
void DestroyDraw2DProgram();
|
||||
|
||||
void SetNumExtraFBOs(int num);
|
||||
u32 displayFramebufPtr_;
|
||||
u32 displayStride_;
|
||||
GEBufferFormat displayFormat_;
|
||||
@ -151,24 +166,35 @@ private:
|
||||
|
||||
// Used by ReadFramebufferToMemory
|
||||
void BlitFramebuffer_(VirtualFramebufferDX9 *src, VirtualFramebufferDX9 *dst, bool flip = false, float upscale = 1.0f, float vscale = 1.0f);
|
||||
std::vector<VirtualFramebufferDX9 *> bvfbs_; // blitting FBOs
|
||||
//void PackFramebufferDirectx9_(VirtualFramebufferDX9 *vfb);
|
||||
void PackFramebufferAsync_(VirtualFramebufferDX9 *vfb);
|
||||
void PackFramebufferSync_(VirtualFramebufferDX9 *vfb);
|
||||
void PackFramebufferDirectx9_(VirtualFramebufferDX9 *vfb);
|
||||
|
||||
// Used by DrawPixels
|
||||
LPDIRECT3DTEXTURE9 drawPixelsTex_;
|
||||
GEBufferFormat drawPixelsTexFormat_;
|
||||
|
||||
u8 *convBuf;
|
||||
GLSLProgram *draw2dprogram;
|
||||
|
||||
int plainColorLoc_;
|
||||
|
||||
TextureCacheDX9 *textureCache_;
|
||||
ShaderManagerDX9 *shaderManager_;
|
||||
bool usePostShader_;
|
||||
bool postShaderAtOutputResolution_;
|
||||
|
||||
// Used by post-processing shader
|
||||
std::vector<FBO *> extraFBOs_;
|
||||
|
||||
bool resized_;
|
||||
bool useBufferedRendering_;
|
||||
|
||||
std::vector<VirtualFramebufferDX9 *> bvfbs_; // blitting FBOs
|
||||
|
||||
std::set<std::pair<u32, u32>> knownFramebufferCopies_;
|
||||
|
||||
#if 0
|
||||
AsyncPBO *pixelBufObj_; //this isn't that large
|
||||
u8 currentPBO_;
|
||||
#endif
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -475,7 +475,7 @@ bool DIRECTX9_GPU::FramebufferDirty() {
|
||||
// Allow it to process fully before deciding if it's dirty.
|
||||
SyncThread();
|
||||
}
|
||||
VirtualFramebufferDX9 *vfb = framebufferManager_.GetDisplayFBO();
|
||||
VirtualFramebufferDX9 *vfb = framebufferManager_.GetDisplayVFB();
|
||||
if (vfb) {
|
||||
bool dirty = vfb->dirtyAfterDisplay;
|
||||
vfb->dirtyAfterDisplay = false;
|
||||
@ -492,7 +492,7 @@ bool DIRECTX9_GPU::FramebufferReallyDirty() {
|
||||
SyncThread();
|
||||
}
|
||||
|
||||
VirtualFramebufferDX9 *vfb = framebufferManager_.GetDisplayFBO();
|
||||
VirtualFramebufferDX9 *vfb = framebufferManager_.GetDisplayVFB();
|
||||
if (vfb) {
|
||||
bool dirty = vfb->reallyDirtyAfterDisplay;
|
||||
vfb->reallyDirtyAfterDisplay = false;
|
||||
@ -514,7 +514,7 @@ void DIRECTX9_GPU::CopyDisplayToOutputInternal() {
|
||||
framebufferManager_.CopyDisplayToOutput();
|
||||
framebufferManager_.EndFrame();
|
||||
|
||||
shaderManager_->EndFrame();
|
||||
// shaderManager_->EndFrame();
|
||||
|
||||
gstate_c.textureChanged = TEXCHANGE_UPDATED;
|
||||
}
|
||||
@ -681,9 +681,9 @@ void DIRECTX9_GPU::ExecuteOp(u32 op, u32 diff) {
|
||||
}
|
||||
|
||||
// TODO: Get rid of this old horror...
|
||||
int bz_ucount = data & 0xFF;
|
||||
int bz_vcount = (data >> 8) & 0xFF;
|
||||
transformDraw_.DrawBezier(bz_ucount, bz_vcount);
|
||||
// int bz_ucount = data & 0xFF;
|
||||
// int bz_vcount = (data >> 8) & 0xFF;
|
||||
// transformDraw_.DrawBezier(bz_ucount, bz_vcount);
|
||||
|
||||
// And instead use this.
|
||||
// GEPatchPrimType patchPrim = gstate.getPatchPrimitiveType();
|
||||
@ -1308,7 +1308,7 @@ void DIRECTX9_GPU::InvalidateCacheInternal(u32 addr, int size, GPUInvalidationTy
|
||||
textureCache_.InvalidateAll(type);
|
||||
|
||||
if (type != GPU_INVALIDATE_ALL)
|
||||
framebufferManager_.UpdateFromMemory(addr, size);
|
||||
framebufferManager_.UpdateFromMemory(addr, size, false);
|
||||
}
|
||||
|
||||
bool DIRECTX9_GPU::PerformMemoryCopy(u32 dest, u32 src, int size) {
|
||||
@ -1359,4 +1359,12 @@ void DIRECTX9_GPU::DoState(PointerWrap &p) {
|
||||
shaderManager_->ClearCache(true);
|
||||
}
|
||||
|
||||
bool DIRECTX9_GPU::GetCurrentFramebuffer(GPUDebugBuffer &buffer) { return false; }
|
||||
bool DIRECTX9_GPU::GetCurrentDepthbuffer(GPUDebugBuffer &buffer) { return false; }
|
||||
bool DIRECTX9_GPU::GetCurrentStencilbuffer(GPUDebugBuffer &buffer) { return false; }
|
||||
|
||||
void DIRECTX9_GPU::ClearShaderCache() {
|
||||
shaderManager_->ClearCache(true);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -38,7 +38,8 @@ public:
|
||||
DIRECTX9_GPU();
|
||||
~DIRECTX9_GPU();
|
||||
virtual void InitClear();
|
||||
virtual void PreExecuteOp(u32 op, u32 diff);
|
||||
virtual void PreExecuteOp(u32 op, u32 diff);
|
||||
void ExecuteOpInternal(u32 op, u32 diff);
|
||||
virtual void ExecuteOp(u32 op, u32 diff);
|
||||
|
||||
virtual void SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format);
|
||||
@ -59,6 +60,7 @@ public:
|
||||
|
||||
// Called by the window system if the window size changed. This will be reflected in PSPCoreParam.pixel*.
|
||||
virtual void Resized();
|
||||
virtual void ClearShaderCache();
|
||||
virtual bool DecodeTexture(u8* dest, GPUgstate state) {
|
||||
return textureCache_.DecodeTexture(dest, state);
|
||||
}
|
||||
@ -71,6 +73,10 @@ public:
|
||||
}
|
||||
std::vector<FramebufferInfo> GetFramebufferList();
|
||||
|
||||
bool GetCurrentFramebuffer(GPUDebugBuffer &buffer);
|
||||
bool GetCurrentDepthbuffer(GPUDebugBuffer &buffer);
|
||||
bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer);
|
||||
bool GetCurrentTexture(GPUDebugBuffer &buffer);
|
||||
protected:
|
||||
virtual void FastRunLoop(DisplayList &list);
|
||||
virtual void ProcessEvent(GPUEvent ev);
|
||||
|
@ -519,7 +519,7 @@ void ShaderManagerDX9::DirtyShader() {
|
||||
shaderSwitchDirty_ = 0;
|
||||
}
|
||||
|
||||
void ShaderManagerDX9::EndFrame() { // disables vertex arrays
|
||||
void ShaderManagerDX9::DirtyLastShader() { // disables vertex arrays
|
||||
if (lastShader_)
|
||||
lastShader_->stop();
|
||||
lastShader_ = 0;
|
||||
|
@ -31,6 +31,19 @@ class PSShader;
|
||||
class VSShader;
|
||||
void ConvertProjMatrixToD3D(Matrix4x4 & in);
|
||||
|
||||
// Pre-fetched attrs and uniforms
|
||||
enum {
|
||||
ATTR_POSITION = 0,
|
||||
ATTR_TEXCOORD = 1,
|
||||
ATTR_NORMAL = 2,
|
||||
ATTR_W1 = 3,
|
||||
ATTR_W2 = 4,
|
||||
ATTR_COLOR0 = 5,
|
||||
ATTR_COLOR1 = 6,
|
||||
|
||||
ATTR_COUNT,
|
||||
};
|
||||
|
||||
class LinkedShaderDX9
|
||||
{
|
||||
protected:
|
||||
@ -62,6 +75,9 @@ public:
|
||||
|
||||
u32 dirtyUniforms;
|
||||
|
||||
// Present attributes in the shader.
|
||||
int attrMask; // 1 << ATTR_ ... or-ed together.
|
||||
|
||||
// Pre-fetched attrs and uniforms
|
||||
D3DXHANDLE a_position;
|
||||
D3DXHANDLE a_color0;
|
||||
@ -199,7 +215,7 @@ public:
|
||||
void DirtyUniform(u32 what) {
|
||||
globalDirty_ |= what;
|
||||
}
|
||||
void EndFrame(); // disables vertex arrays
|
||||
void DirtyLastShader(); // disables vertex arrays
|
||||
|
||||
int NumVertexShaders() const { return (int)vsCache_.size(); }
|
||||
int NumFragmentShaders() const { return (int)fsCache_.size(); }
|
||||
|
@ -21,56 +21,6 @@
|
||||
|
||||
namespace DX9 {
|
||||
|
||||
// Just to get something on the screen, we'll just not subdivide correctly.
|
||||
void TransformDrawEngineDX9::DrawBezier(int ucount, int vcount) {
|
||||
u16 indices[3 * 3 * 6];
|
||||
|
||||
static bool reported = false;
|
||||
if (!reported) {
|
||||
Reporting::ReportMessage("Unsupported bezier curve");
|
||||
reported = true;
|
||||
}
|
||||
|
||||
// if (gstate.patchprimitive)
|
||||
// Generate indices for a rectangular mesh.
|
||||
int c = 0;
|
||||
for (int y = 0; y < 3; y++) {
|
||||
for (int x = 0; x < 3; x++) {
|
||||
indices[c++] = y * 3 + x;
|
||||
indices[c++] = y * 3 + x + 1;
|
||||
indices[c++] = (y + 1) * 3 + x + 1;
|
||||
indices[c++] = (y + 1) * 3 + x + 1;
|
||||
indices[c++] = (y + 1) * 3 + x;
|
||||
indices[c++] = y * 3 + x;
|
||||
}
|
||||
}
|
||||
|
||||
// We are free to use the "decoded" buffer here.
|
||||
// Let's split it into two to get a second buffer, there's enough space.
|
||||
u8 *decoded2 = decoded + 65536 * 24;
|
||||
|
||||
// Alright, now for the vertex data.
|
||||
// For now, we will simply inject UVs.
|
||||
|
||||
float customUV[4 * 4 * 2];
|
||||
for (int y = 0; y < 4; y++) {
|
||||
for (int x = 0; x < 4; x++) {
|
||||
customUV[(y * 4 + x) * 2 + 0] = (float)x/3.0f;
|
||||
customUV[(y * 4 + x) * 2 + 1] = (float)y/3.0f;
|
||||
}
|
||||
}
|
||||
|
||||
if (!vertTypeGetTexCoordMask(gstate.vertType)) {
|
||||
VertexDecoderDX9 *dec = GetVertexDecoder(gstate.vertType);
|
||||
dec->SetVertexType(gstate.vertType);
|
||||
u32 newVertType = dec->InjectUVs(decoded2, Memory::GetPointer(gstate_c.vertexAddr), customUV, 16);
|
||||
SubmitPrim(decoded2, &indices[0], GE_PRIM_TRIANGLES, c, newVertType, GE_VTYPE_IDX_16BIT, 0);
|
||||
} else {
|
||||
SubmitPrim(Memory::GetPointer(gstate_c.vertexAddr), &indices[0], GE_PRIM_TRIANGLES, c, gstate.vertType, GE_VTYPE_IDX_16BIT, 0);
|
||||
}
|
||||
Flush(); // as our vertex storage here is temporary, it will only survive one draw.
|
||||
}
|
||||
|
||||
|
||||
// Spline implementation copied and modified from neobrain's softgpu (orphis code?)
|
||||
|
||||
|
@ -15,6 +15,55 @@
|
||||
// Official git repository and contact information can be found at
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
|
||||
|
||||
// Ideas for speeding things up on mobile OpenGL ES implementations
|
||||
//
|
||||
// Use superbuffers! Yes I just invented that name.
|
||||
//
|
||||
// The idea is to avoid respecifying the vertex format between every draw call (multiple glVertexAttribPointer ...)
|
||||
// by combining the contents of multiple draw calls into one buffer, as long as
|
||||
// they have exactly the same output vertex format. (different input formats is fine! This way
|
||||
// we can combine the data for multiple draws with different numbers of bones, as we consider numbones < 4 to be = 4)
|
||||
// into one VBO.
|
||||
//
|
||||
// This will likely be a win because I believe that between every change of VBO + glVertexAttribPointer*N, the driver will
|
||||
// perform a lot of validation, probably at draw call time, while all the validation can be skipped if the only thing
|
||||
// that changes between two draw calls is simple state or texture or a matrix etc, not anything vertex related.
|
||||
// Also the driver will have to manage hundreds instead of thousands of VBOs in games like GTA.
|
||||
//
|
||||
// * Every 10 frames or something, do the following:
|
||||
// - Frame 1:
|
||||
// + Mark all drawn buffers with in-frame sequence numbers (alternatively,
|
||||
// just log them in an array)
|
||||
// - Frame 2 (beginning?):
|
||||
// + Take adjacent buffers that have the same output vertex format, and add them
|
||||
// to a list of buffers to combine. Create said buffers with appropriate sizes
|
||||
// and precompute the offsets that the draws should be written into.
|
||||
// - Frame 2 (end):
|
||||
// + Actually do the work of combining the buffers. This probably means re-decoding
|
||||
// the vertices into a new one. Will also have to apply index offsets.
|
||||
//
|
||||
// Also need to change the drawing code so that we don't glBindBuffer and respecify glVAP if
|
||||
// two subsequent drawcalls come from the same superbuffer.
|
||||
//
|
||||
// Or we ignore all of this including vertex caching and simply find a way to do highly optimized vertex streaming,
|
||||
// like Dolphin is trying to. That will likely never be able to reach the same speed as perfectly optimized
|
||||
// superbuffers though. For this we will have to JIT the vertex decoder but that's not too hard.
|
||||
//
|
||||
// Now, when do we delete superbuffers? Maybe when half the buffers within have been killed?
|
||||
//
|
||||
// Another idea for GTA which switches textures a lot while not changing much other state is to use ES 3 Array
|
||||
// textures, if they are the same size (even if they aren't, might be okay to simply resize the textures to match
|
||||
// if they're just a multiple of 2 away) or something. Then we'd have to add a W texture coordinate to choose the
|
||||
// texture within the bound texture array to the vertex data when merging into superbuffers.
|
||||
//
|
||||
// There are even more things to try. For games that do matrix palette skinning by quickly switching bones and
|
||||
// just drawing a few triangles per call (NBA, FF:CC, Tekken 6 etc) we could even collect matrices, upload them
|
||||
// all at once, writing matrix indices into the vertices in addition to the weights, and then doing a single
|
||||
// draw call with specially generated shader to draw the whole mesh. This code will be seriously complex though.
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/timeutil.h"
|
||||
|
||||
#include "Common/MemoryUtil.h"
|
||||
@ -49,7 +98,11 @@ const D3DPRIMITIVETYPE glprim[8] = {
|
||||
D3DPT_TRIANGLELIST,
|
||||
D3DPT_TRIANGLESTRIP,
|
||||
D3DPT_TRIANGLEFAN,
|
||||
#ifndef _XBOX
|
||||
D3DPT_TRIANGLELIST, // With OpenGL ES we have to expand sprites into triangles, tripling the data instead of doubling. sigh. OpenGL ES, Y U NO SUPPORT GL_QUADS?
|
||||
#else
|
||||
D3DPT_TRIANGLELIST,
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifndef _XBOX
|
||||
@ -76,12 +129,21 @@ enum {
|
||||
TRANSFORMED_VERTEX_BUFFER_SIZE = VERTEX_BUFFER_MAX * sizeof(TransformedVertex)
|
||||
};
|
||||
|
||||
#define QUAD_INDICES_MAX 32768
|
||||
|
||||
#define VERTEXCACHE_DECIMATION_INTERVAL 17
|
||||
|
||||
#ifndef _XBOX
|
||||
// Check for max first as clamping to max is more common than min when lighting.
|
||||
inline float clamp(float in, float min, float max) {
|
||||
return in < min ? min : (in > max ? max : in);
|
||||
return in > max ? max : (in < min ? min : in);
|
||||
}
|
||||
#else
|
||||
inline float clamp(float in, float min, float max) {
|
||||
in = __fsel( in - min , in, min );
|
||||
return __fsel( in - max, max, in );
|
||||
}
|
||||
#endif
|
||||
|
||||
TransformDrawEngineDX9::TransformDrawEngineDX9()
|
||||
: collectedVerts(0),
|
||||
@ -94,14 +156,24 @@ TransformDrawEngineDX9::TransformDrawEngineDX9()
|
||||
numDrawCalls(0),
|
||||
vertexCountInDrawCalls(0),
|
||||
uvScale(0) {
|
||||
decimationCounter_ = VERTEXCACHE_DECIMATION_INTERVAL;
|
||||
// Allocate nicely aligned memory. Maybe graphics drivers will
|
||||
// appreciate it.
|
||||
// All this is a LOT of memory, need to see if we can cut down somehow.
|
||||
decoded = (u8 *)AllocateMemoryPages(DECODED_VERTEX_BUFFER_SIZE);
|
||||
decIndex = (u16 *)AllocateMemoryPages(DECODED_INDEX_BUFFER_SIZE);
|
||||
transformed = (TransformedVertex *)AllocateMemoryPages(TRANSFORMED_VERTEX_BUFFER_SIZE);
|
||||
transformedExpanded = (TransformedVertex *)AllocateMemoryPages(3 * TRANSFORMED_VERTEX_BUFFER_SIZE);
|
||||
decimationCounter_ = VERTEXCACHE_DECIMATION_INTERVAL;
|
||||
// Allocate nicely aligned memory. Maybe graphics drivers will
|
||||
// appreciate it.
|
||||
// All this is a LOT of memory, need to see if we can cut down somehow.
|
||||
decoded = (u8 *)AllocateMemoryPages(DECODED_VERTEX_BUFFER_SIZE);
|
||||
decIndex = (u16 *)AllocateMemoryPages(DECODED_INDEX_BUFFER_SIZE);
|
||||
transformed = (TransformedVertex *)AllocateMemoryPages(TRANSFORMED_VERTEX_BUFFER_SIZE);
|
||||
transformedExpanded = (TransformedVertex *)AllocateMemoryPages(3 * TRANSFORMED_VERTEX_BUFFER_SIZE);
|
||||
quadIndices_ = new u16[6 * QUAD_INDICES_MAX];
|
||||
|
||||
for (int i = 0; i < QUAD_INDICES_MAX; i++) {
|
||||
quadIndices_[i * 6 + 0] = i * 4;
|
||||
quadIndices_[i * 6 + 1] = i * 4 + 2;
|
||||
quadIndices_[i * 6 + 2] = i * 4 + 1;
|
||||
quadIndices_[i * 6 + 3] = i * 4 + 1;
|
||||
quadIndices_[i * 6 + 4] = i * 4 + 2;
|
||||
quadIndices_[i * 6 + 5] = i * 4 + 3;
|
||||
}
|
||||
|
||||
if (g_Config.bPrescaleUV) {
|
||||
uvScale = new UVScale[MAX_DEFERRED_DRAW_CALLS];
|
||||
@ -117,6 +189,8 @@ TransformDrawEngineDX9::~TransformDrawEngineDX9() {
|
||||
FreeMemoryPages(transformed, TRANSFORMED_VERTEX_BUFFER_SIZE);
|
||||
FreeMemoryPages(transformedExpanded, 3 * TRANSFORMED_VERTEX_BUFFER_SIZE);
|
||||
|
||||
delete [] quadIndices_;
|
||||
|
||||
for (auto iter = decoderMap_.begin(); iter != decoderMap_.end(); iter++) {
|
||||
delete iter->second;
|
||||
}
|
||||
@ -413,7 +487,7 @@ void TransformDrawEngineDX9::SoftwareTransformAndDraw(
|
||||
float v[3] = {0, 0, 0};
|
||||
float c0[4] = {1, 1, 1, 1};
|
||||
float c1[4] = {0, 0, 0, 0};
|
||||
float uv[3] = {0, 0, 0};
|
||||
float uv[3] = {0, 0, 1};
|
||||
float fogCoef = 1.0f;
|
||||
|
||||
if (throughmode) {
|
||||
@ -448,7 +522,7 @@ void TransformDrawEngineDX9::SoftwareTransformAndDraw(
|
||||
if (reader.hasNormal())
|
||||
reader.ReadNrm(nrm);
|
||||
|
||||
if ((vertType & GE_VTYPE_WEIGHT_MASK) == GE_VTYPE_WEIGHT_NONE) {
|
||||
if (!vertTypeIsSkinningEnabled(vertType)) {
|
||||
Vec3ByMatrix43(out, pos, gstate.worldMatrix);
|
||||
if (reader.hasNormal()) {
|
||||
Norm3ByMatrix43(norm, nrm, gstate.worldMatrix);
|
||||
@ -460,9 +534,7 @@ void TransformDrawEngineDX9::SoftwareTransformAndDraw(
|
||||
// Skinning
|
||||
Vec3f psum(0,0,0);
|
||||
Vec3f nsum(0,0,0);
|
||||
int nweights = ((vertType & GE_VTYPE_WEIGHTCOUNT_MASK) >> GE_VTYPE_WEIGHTCOUNT_SHIFT) + 1;
|
||||
for (int i = 0; i < nweights; i++)
|
||||
{
|
||||
for (int i = 0; i < vertTypeGetNumBoneWeights(vertType); i++) {
|
||||
if (weights[i] != 0.0f) {
|
||||
Vec3ByMatrix43(out, pos, gstate.boneMatrix+i*12);
|
||||
Vec3f tpos(out);
|
||||
@ -602,6 +674,7 @@ void TransformDrawEngineDX9::SoftwareTransformAndDraw(
|
||||
ERROR_LOG_REPORT(G3D, "Impossible UV gen mode? %d", gstate.getUVGenMode());
|
||||
break;
|
||||
}
|
||||
|
||||
uv[0] = uv[0] * widthFactor;
|
||||
uv[1] = uv[1] * heightFactor;
|
||||
|
||||
@ -640,11 +713,14 @@ void TransformDrawEngineDX9::SoftwareTransformAndDraw(
|
||||
drawBuffer = transformedExpanded;
|
||||
TransformedVertex *trans = &transformedExpanded[0];
|
||||
TransformedVertex saved;
|
||||
u32 stencilValue;
|
||||
for (int i = 0; i < vertexCount; i += 2) {
|
||||
int index = ((const u16*)inds)[i];
|
||||
saved = transformed[index];
|
||||
int index2 = ((const u16*)inds)[i + 1];
|
||||
TransformedVertex &transVtx = transformed[index2];
|
||||
if (i == 0)
|
||||
stencilValue = transVtx.color0[3];
|
||||
// We have to turn the rectangle into two triangles, so 6 points. Sigh.
|
||||
|
||||
// bottom right
|
||||
@ -674,6 +750,7 @@ void TransformDrawEngineDX9::SoftwareTransformAndDraw(
|
||||
// Apparently, non-through RotateUV just breaks things.
|
||||
// If we find a game where it helps, we'll just have to figure out how they differ.
|
||||
// Possibly, it has something to do with flipped viewport Y axis, which a few games use.
|
||||
// One game might be one of the Metal Gear ones, can't find the issue right now though.
|
||||
// else
|
||||
// RotateUV(trans);
|
||||
|
||||
@ -686,6 +763,12 @@ void TransformDrawEngineDX9::SoftwareTransformAndDraw(
|
||||
|
||||
numTrans += 6;
|
||||
}
|
||||
|
||||
// We don't know the color until here, so we have to do it now, instead of in StateMapping.
|
||||
// Might want to reconsider the order of things later...
|
||||
if (gstate.isModeClear() && gstate.isClearModeAlphaMask()) {
|
||||
dxstate.stencilFunc.set(D3DCMP_ALWAYS, stencilValue, 255);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -806,6 +889,9 @@ void TransformDrawEngineDX9::SubmitPrim(void *verts, void *inds, GEPrimitiveType
|
||||
}
|
||||
|
||||
void TransformDrawEngineDX9::DecodeVerts() {
|
||||
UVScale origUV;
|
||||
if (uvScale)
|
||||
origUV = gstate_c.uv;
|
||||
for (int i = 0; i < numDrawCalls; i++) {
|
||||
const DeferredDrawCall &dc = drawCalls[i];
|
||||
|
||||
@ -835,7 +921,7 @@ void TransformDrawEngineDX9::DecodeVerts() {
|
||||
while (j < numDrawCalls) {
|
||||
if (drawCalls[j].verts != dc.verts)
|
||||
break;
|
||||
if (uvScale && memcmp(&uvScale[j], &uvScale[i], sizeof(uvScale[0]) != 0))
|
||||
if (uvScale && memcmp(&uvScale[j], &uvScale[i], sizeof(uvScale[0])) != 0)
|
||||
break;
|
||||
|
||||
indexLowerBound = std::min(indexLowerBound, (int)drawCalls[j].indexLowerBound);
|
||||
@ -876,6 +962,8 @@ void TransformDrawEngineDX9::DecodeVerts() {
|
||||
// Force to points (0)
|
||||
indexGen.AddPrim(GE_PRIM_POINTS, 0);
|
||||
}
|
||||
if (uvScale)
|
||||
gstate_c.uv = origUV;
|
||||
}
|
||||
|
||||
u32 TransformDrawEngineDX9::ComputeHash() {
|
||||
@ -993,6 +1081,7 @@ void TransformDrawEngineDX9::DoFlush() {
|
||||
LPDIRECT3DINDEXBUFFER9 ib_ = NULL;
|
||||
|
||||
int vertexCount = 0;
|
||||
int maxIndex = 0;
|
||||
bool useElements = true;
|
||||
|
||||
// Cannot cache vertex data with morph enabled.
|
||||
@ -1019,6 +1108,7 @@ void TransformDrawEngineDX9::DoFlush() {
|
||||
DecodeVerts(); // writes to indexGen
|
||||
vai->numVerts = indexGen.VertexCount();
|
||||
vai->prim = indexGen.Prim();
|
||||
vai->maxIndex = indexGen.MaxIndex();
|
||||
goto rotateVBO;
|
||||
}
|
||||
|
||||
@ -1065,6 +1155,7 @@ void TransformDrawEngineDX9::DoFlush() {
|
||||
DecodeVerts();
|
||||
vai->numVerts = indexGen.VertexCount();
|
||||
vai->prim = indexGen.Prim();
|
||||
vai->maxIndex = indexGen.MaxIndex();
|
||||
useElements = !indexGen.SeenOnlyPurePrims();
|
||||
if (!useElements && indexGen.PureCount()) {
|
||||
vai->numVerts = indexGen.PureCount();
|
||||
@ -1097,7 +1188,8 @@ void TransformDrawEngineDX9::DoFlush() {
|
||||
vb_ = vai->vbo;
|
||||
ib_ = vai->ebo;
|
||||
vertexCount = vai->numVerts;
|
||||
prim = static_cast<GEPrimitiveType>(vai->prim);
|
||||
maxIndex = vai->maxIndex;
|
||||
prim = static_cast<GEPrimitiveType>(vai->prim);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1114,7 +1206,9 @@ void TransformDrawEngineDX9::DoFlush() {
|
||||
ib_ = vai->ebo;
|
||||
|
||||
vertexCount = vai->numVerts;
|
||||
prim = static_cast<GEPrimitiveType>(vai->prim);
|
||||
|
||||
maxIndex = vai->maxIndex;
|
||||
prim = static_cast<GEPrimitiveType>(vai->prim);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1135,7 +1229,8 @@ void TransformDrawEngineDX9::DoFlush() {
|
||||
rotateVBO:
|
||||
gpuStats.numUncachedVertsDrawn += indexGen.VertexCount();
|
||||
useElements = !indexGen.SeenOnlyPurePrims();
|
||||
vertexCount = indexGen.VertexCount();
|
||||
vertexCount = indexGen.VertexCount();
|
||||
maxIndex = indexGen.MaxIndex();
|
||||
if (!useElements && indexGen.PureCount()) {
|
||||
vertexCount = indexGen.PureCount();
|
||||
}
|
||||
@ -1191,5 +1286,51 @@ rotateVBO:
|
||||
host->GPUNotifyDraw();
|
||||
#endif
|
||||
}
|
||||
bool TransformDrawEngineDX9::TestBoundingBox(void* control_points, int vertexCount, u32 vertType) {
|
||||
// Simplify away bones and morph before proceeding
|
||||
|
||||
}
|
||||
/*
|
||||
SimpleVertex *corners = (SimpleVertex *)(decoded + 65536 * 12);
|
||||
u8 *temp_buffer = decoded + 65536 * 24;
|
||||
|
||||
u32 origVertType = vertType;
|
||||
vertType = NormalizeVertices((u8 *)corners, temp_buffer, (u8 *)control_points, 0, vertexCount, vertType);
|
||||
|
||||
for (int cube = 0; cube < vertexCount / 8; cube++) {
|
||||
// For each cube...
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
const SimpleVertex &vert = corners[cube * 8 + i];
|
||||
|
||||
// To world space...
|
||||
float worldPos[3];
|
||||
Vec3ByMatrix43(worldPos, (float *)&vert.pos.x, gstate.worldMatrix);
|
||||
|
||||
// To view space...
|
||||
float viewPos[3];
|
||||
Vec3ByMatrix43(viewPos, worldPos, gstate.viewMatrix);
|
||||
|
||||
// And finally to screen space.
|
||||
float frustumPos[4];
|
||||
Vec3ByMatrix44(frustumPos, viewPos, gstate.projMatrix);
|
||||
|
||||
// Project to 2D
|
||||
float x = frustumPos[0] / frustumPos[3];
|
||||
float y = frustumPos[1] / frustumPos[3];
|
||||
|
||||
// Rescale 2d position
|
||||
// ...
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// Let's think. A better approach might be to take the edges of the drawing region and the projection
|
||||
// matrix to build a frustum pyramid, and then clip the cube against those planes. If all vertices fail the same test,
|
||||
// the cube is out. Otherwise it's in.
|
||||
// TODO....
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -80,8 +80,9 @@ public:
|
||||
LPDIRECT3DINDEXBUFFER9 ebo;
|
||||
|
||||
|
||||
// Precalculated parameter for drawdrawElements
|
||||
// Precalculated parameter for drawRangeElements
|
||||
u16 numVerts;
|
||||
u16 maxIndex;
|
||||
s8 prim;
|
||||
|
||||
// ID information
|
||||
@ -98,12 +99,11 @@ class TransformDrawEngineDX9 {
|
||||
public:
|
||||
TransformDrawEngineDX9();
|
||||
virtual ~TransformDrawEngineDX9();
|
||||
void SubmitPrim(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertexType, int forceIndexType, int *bytesRead);
|
||||
void SubmitSpline(void* control_points, void* indices, int count_u, int count_v, int type_u, int type_v, GEPatchPrimType prim_type, u32 vertex_type);
|
||||
void SubmitBezier(void* control_points, void* indices, int count_u, int count_v, GEPatchPrimType prim_type, u32 vertex_type);
|
||||
|
||||
// legacy
|
||||
void DrawBezier(int ucount, int vcount);
|
||||
|
||||
void SubmitPrim(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertType, int forceIndexType, int *bytesRead);
|
||||
void SubmitSpline(void* control_points, void* indices, int count_u, int count_v, int type_u, int type_v, GEPatchPrimType prim_type, u32 vertType);
|
||||
void SubmitBezier(void* control_points, void* indices, int count_u, int count_v, GEPatchPrimType prim_type, u32 vertType);
|
||||
bool TestBoundingBox(void* control_points, int vertexCount, u32 vertType);
|
||||
|
||||
void DecodeVerts();
|
||||
void SetShaderManager(ShaderManagerDX9 *shaderManager) {
|
||||
@ -140,6 +140,9 @@ private:
|
||||
void ApplyDrawState(int prim);
|
||||
bool IsReallyAClear(int numVerts) const;
|
||||
|
||||
// Preprocessing for spline/bezier
|
||||
u32 NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, u32 vertType);
|
||||
|
||||
// drawcall ID
|
||||
u32 ComputeFastDCID();
|
||||
u32 ComputeHash(); // Reads deferred vertex data.
|
||||
@ -177,6 +180,9 @@ private:
|
||||
TransformedVertex *transformedExpanded;
|
||||
|
||||
std::map<u32, VertexArrayInfoDX9 *> vai_;
|
||||
|
||||
// Fixed index buffer for easy quad generation from spline/bezier
|
||||
u16 *quadIndices_;
|
||||
|
||||
// Other
|
||||
ShaderManagerDX9 *shaderManager_;
|
||||
|
@ -89,6 +89,11 @@ void fbo_bind_as_render_target(FBO *fbo) {
|
||||
pD3Ddevice->SetDepthStencilSurface(fbo->depthstencil);
|
||||
}
|
||||
|
||||
|
||||
LPDIRECT3DTEXTURE9 fbo_get_color_texture(FBO *fbo) {
|
||||
return fbo->tex;
|
||||
}
|
||||
|
||||
void fbo_bind_for_read(FBO *fbo) {
|
||||
// pD3Ddevice->SetRenderTarget(0, fbo->surf);
|
||||
}
|
||||
|
@ -35,6 +35,8 @@ void fbo_destroy(FBO *fbo);
|
||||
void fbo_get_dimensions(FBO *fbo, int *w, int *h);
|
||||
void fbo_resolve(FBO *fbo);
|
||||
|
||||
LPDIRECT3DTEXTURE9 fbo_get_color_texture(FBO *fbo);
|
||||
|
||||
void * fbo_get_rtt(FBO *fbo);
|
||||
|
||||
// To get default depth and rt surface
|
||||
|
@ -31,7 +31,7 @@ static const char * vscode =
|
||||
" VS_OUT main( VS_IN In ) "
|
||||
" { "
|
||||
" VS_OUT Out; "
|
||||
" Out.ProjPos = mul( matWVP, In.ObjPos ); " // Transform vertex into
|
||||
" Out.ProjPos = In.ObjPos; " // Transform vertex into
|
||||
" Out.Uv = In.Uv; "
|
||||
" return Out; " // Transfer color
|
||||
" } ";
|
||||
|
Loading…
Reference in New Issue
Block a user