Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Math3d extensions #2834

Closed
wants to merge 19 commits into from
Closed

Conversation

neobrain
Copy link
Contributor

Build should be fixed now, tested on gcc 4.7.2 and msvc2010

Enhances the feature set of the existing utility Vec3 class by:

  • supporting arbitrary base types for each component (e.g. Vec3, Vec3<int, int, float>)
  • supporting two-component and four-component vectors
  • supporting vectors acting purely on references, thus being effective on memory usage (although I guess the compiler should've done this before already)
  • supporting fast access of individual vector components as a subvector (e.g Vec4::rgb() returns a Vec3Ref consisting of references to the r, g, and b components)
  • supporting more flexible component naming (e.g. "rgba" or "xyzw")

Additionally, this patch

  • cleanly abstracts using Vec3 as a color or as an actual position vector.
  • fixes some confusing oddities of the Vec3 API.
  • might fix bugs caused by incorrect constructor usage (see below for details).

Changes for other people who used the code before:

  • The star operator (_) refers to per-component product now (i.e. Vec2(v1.x_v1.x,v2.y*v2.y)) instead of the dot product. This is more consistent with what other APIs are doing (most notably GLSL/HLSL). For the dot product, a new Dot() function has been introduced. Additionally, Lerp has been made a global function instead of a VecXRef method. Existing code has been fixed to respect these changes.
  • The % operator has been removed because it's not clear what it means. The new Cross() function should be used instead. There was no code using this functionality.
  • The Vec3(u32 rgb) constructor has been removed due to its ambiguity. There have been some cases where the wrong constructor has been actually used, so this might even fix a bug. Anyway, instead the new static member functions Vec3::FromRGB and Vec4::FromRGBA should be used instead.
  • What used to be Vec3 (i.e. a three-component vector acting on floats) is now Vec3f.

@hrydgard
Copy link
Owner

I'm gonna test with LLVM (clang) before merging :)

And just a note for those wondering what this is about, this is mainly for use by neobrain's software renderer.

@solarmystic
Copy link
Contributor

@neobrain

Just out of curiosity, what does this commit do for games in general? Would it benefit any of them? Improve CPU utilzation? GPU utilization? Functionally alter them? Improve compatibility?

It looks like a lot of goobledegook to me, but I'm admittedly still learning about these things.

Sorry.

@neobrain
Copy link
Contributor Author

@solarmystic
Purely maintenance. And it's kind of a requirement for the software renderer to not look like a bloody mess.

@solarmystic
Copy link
Contributor

@neobrain
Ah right, I forgot that you're the one spearheading that one man project.

Kudos to you sir, and carry on.

@thedax
Copy link
Collaborator

thedax commented Jul 18, 2013

Not that it really needed any confirmation, but it's compiling fine in VS2012(with VS2010 libs), so this should be okay to merge.

@neobrain
Copy link
Contributor Author

Critical copy constructor issue fixed in 51683a5. The issue didn't affect any of the existing code in master, but caused a major bug in softgpu, so I wanted to wait with merging until I understood what's going on.

Ready to merge now.

@neobrain
Copy link
Contributor Author

... I have to back out again, I somehow broke the swizzler functionality (it doesn't compile anymore when used).

@neobrain
Copy link
Contributor Author

Alright, ready to merge now. Tested build on gcc 4.7.2 and msvc10 and made sure my softgpu branch actually compiles and works with it.

@dbz400
Copy link
Contributor

dbz400 commented Jul 19, 2013

Thanks @neobrain .Compile all good on msvc2010

Wondering how well the compatibility right now on the softgpu implementation . (Compiling a build to test it )

@hrydgard
Copy link
Owner

Okay, thanks, I'll go test on my mac too before I merge.

@raven02 , neobrains softgpu is very early but seems like a good start.

@dbz400
Copy link
Contributor

dbz400 commented Jul 19, 2013

It is a really good start and the way to archieve 100% compatibility

@hrydgard
Copy link
Owner

Just for reference, here's neobrain's softgpu branch: https://github.com/neobrain/ppsspp/tree/softgpu

We'll probably merge it pretty soon.

@dbz400
Copy link
Contributor

dbz400 commented Jul 19, 2013

Thanks @hrydgard .Btw , bit long time no see @unknownbrackets .

@hrydgard
Copy link
Owner

It builds but it's crashy. Here's a callstack from fate extra:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x00000001002d2a2f in Vec3Ref<float, float, float>::Vec3Ref ()
(gdb) bt
#0 0x00000001002d2a2f in Vec3Ref<float, float, float>::Vec3Ref ()
#1 0x00000001002d2c73 in Vec3<float, float, float>::Vec3 ()
#2 0x00000001002cdfbd in Vec3<float, float, float>::Vec3 ()
#3 0x00000001002e0376 in Vec3<float, float, float>::FromRGB ()
#4 0x000000010028f732 in TransformDrawEngine::ApplyDrawState ()
#5 0x00000001002c870c in TransformDrawEngine::Flush ()
#6 0x000000010027bcff in GLES_GPU::CheckFlushOp ()
#7 0x00000001002798f6 in GLES_GPU::FastRunLoop ()

Here's another one from Lumines:

#0 0x00000001002d293a in std::__1::__tree<std::__1::pair<unsigned int, VertexDecoder*>, std::__1::__map_value_compare<unsigned int, VertexDecoder*, std::__1::less, true>, std::__1::allocator<std::__1::pair<unsigned int, VertexDecoder*> > >::__lower_bound ()
#1 0x00000001002d2636 in std::__1::__tree<std::__1::pair<unsigned int, VertexDecoder*>, std::__1::__map_value_compare<unsigned int, VertexDecoder*, std::__1::less, true>, std::__1::allocator<std::__1::pair<unsigned int, VertexDecoder*> > >::find ()
#2 0x00000001002c81ab in TransformDrawEngine::GetVertexDecoder ()
#3 0x00000001002cc7af in TransformDrawEngine::SetupVertexDecoder ()
#4 0x00000001002c84e7 in TransformDrawEngine::SubmitPrim ()
#5 0x0000000100279c1e in GLES_GPU::ExecuteOp ()
#6 0x0000000100279925 in GLES_GPU::FastRunLoop ()
#7 0x00000001002dd31c in GPUCommon::InterpretList ()
#8 0x00000001002dd7b4 in GPUCommon::ProcessDLQueue ()
#9 0x00000001002dcd40 in GPUCommon::UpdateStall ()
#10 0x000000010016bdb5 in sceGeListUpdateStallAddr ()
#11 0x000000010016ec60 in WrapI_UU<&(sceGeListUpdateStallAddr(unsigned int, unsigned int))> ()
#12 0x00000001001444d0 in CallSyscall ()
#13 0x000000010e8295b3 in ?? ()

@arg274
Copy link

arg274 commented Jul 21, 2013

so is this the software rendering mode or have i mistaken?

@hrydgard
Copy link
Owner

@arg274 , this is some helper code that will be used by neobrains software rendering mode, yes.

The real meat is here: https://github.com/neobrain/ppsspp/tree/softgpu

@hrydgard
Copy link
Owner

Crisis Core:

Don't know why I'm not getting proper line numbers..

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x00000001002d2aff in Vec3Ref<float, float, float>::Vec3Ref ()
(gdb) bt
#0 0x00000001002d2aff in Vec3Ref<float, float, float>::Vec3Ref ()
#1 0x00000001002d2d43 in Vec3<float, float, float>::Vec3 ()
#2 0x00000001002ce08d in Vec3<float, float, float>::Vec3 ()
#3 0x00000001002e0446 in Vec3<float, float, float>::FromRGB ()
#4 0x000000010028f802 in TransformDrawEngine::ApplyDrawState ()
#5 0x00000001002c87dc in TransformDrawEngine::Flush ()
#6 0x000000010027bdcf in GLES_GPU::CheckFlushOp ()
#7 0x00000001002799c6 in GLES_GPU::FastRunLoop ()
#8 0x00000001002dd3ec in GPUCommon::InterpretList ()
#9 0x00000001002dd884 in GPUCommon::ProcessDLQueue ()
#10 0x00000001002dce10 in GPUCommon::UpdateStall ()
#11 0x000000010016be85 in sceGeListUpdateStallAddr ()
#12 0x000000010016ed30 in WrapI_UU<&(sceGeListUpdateStallAddr(unsigned int, unsigned int))> ()
#13 0x00000001001445a0 in CallSyscall ()
#14 0x00000001135b18df in ?? ()

@hrydgard
Copy link
Owner

Lumines again, this time with line numbers:

0x00000001002ec66a in std::__1::less::operator() () at /usr/lib/c++/v1/__functional_base:421
421 bool operator()(const _Pp& __x, const _Key& __y) const
(gdb) bt
#0 0x00000001002ec66a in std::__1::less::operator() () at /usr/lib/c++/v1/__functional_base:421
#1 0x00000001002ec66a in std::__1::__tree<std::__1::pair<unsigned int, VertexDecoder*>, std::__1::__map_value_compare<unsigned int, VertexDecoder*, std::__1::less, true>, std::__1::allocator<std::__1::pair<unsigned int, VertexDecoder*> > >::__lower_bound (this=0x104077050, __v=@0x7fff5fbfca2c, __root=0x5000400020003, __result=0x104077058) at map:421
#2 0x00000001002ec366 in std::__1::__tree<std::__1::pair<unsigned int, VertexDecoder*>, std::__1::__map_value_compare<unsigned int, VertexDecoder*, std::__1::less, true>, std::__1::allocator<std::__1::pair<unsigned int, VertexDecoder*> > >::find (this=0x104077050, __v=@0x7fff5fbfca2c) at __tree:2011
#3 0x00000001002e1e4b in std::__1::map<unsigned int, VertexDecoder*, std::__1::less, std::__1::allocator<std::__1::pair<unsigned int const, VertexDecoder*> > >::find () at /usr/lib/c++/v1/map:892
#4 0x00000001002e1e4b in TransformDrawEngine::GetVertexDecoder (this=0x104077018, vtype=310378782) at /Users/henrik/ppsspp/GPU/GLES/TransformPipeline.cpp:421
#5 0x00000001002e64df in TransformDrawEngine::SetupVertexDecoder (this=0x104077018, vertType=310378782) at /Users/henrik/ppsspp/GPU/GLES/TransformPipeline.cpp:905
#6 0x00000001002e2187 in TransformDrawEngine::SubmitPrim (this=0x104077018, verts=0x112d7ef10, inds=0x0, prim=4, vertexCount=4, vertType=310378782, forceIndexType=-1, bytesRead=0x7fff5fbfccec) at /Users/henrik/ppsspp/GPU/GLES/TransformPipeline.cpp:945
#7 0x0000000100292bce in GLES_GPU::ExecuteOp (this=0x104072200, op=67371012, diff=0) at /Users/henrik/ppsspp/GPU/GLES/DisplayListInterpreter.cpp:407
#8 0x00000001002928d5 in GLES_GPU::FastRunLoop (this=0x104072200, list=@0x104072208) at /Users/henrik/ppsspp/GPU/GLES/DisplayListInterpreter.cpp:331
#9 0x00000001002f71dc in GPUCommon::InterpretList (this=0x104072200, list=@0x104072208) at /Users/henrik/ppsspp/GPU/GPUCommon.cpp:412
#10 0x00000001002f76ec in GPUCommon::ProcessDLQueue (this=0x104072200) at /Users/henrik/ppsspp/GPU/GPUCommon.cpp:496
#11 0x00000001002f6c00 in GPUCommon::UpdateStall (this=0x104072200, listid=0, newstall=1240146768) at /Users/henrik/ppsspp/GPU/GPUCommon.cpp:251
#12 0x000000010017bf91 in sceGeListUpdateStallAddr (displayListID=0, stallAddress=1240146768) at /Users/henrik/ppsspp/Core/HLE/sceGe.cpp:283
#13 0x000000010017efc0 in WrapI_UU<&(sceGeListUpdateStallAddr(unsigned int, unsigned int))> () at FunctionWrappers.h:158
#14 0x0000000100151569 in CallSyscall (op=8126668) at /Users/henrik/ppsspp/Core/HLE/HLE.cpp:489
#15 0x000000010e9af5b3 in ?? ()

@hrydgard
Copy link
Owner

Crisis Core:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x00000001002ec75f in Vec3Ref<float, float, float>::Vec3Ref (this=0x7fff5fbfc938, _x=@0x7fff5fbfc980, _y=@0x7fff5fbfc984, _z=@0x7fff5fbfc988) at Math3D.h:293
293 u(_x), v(_y), w(_z) {}
(gdb) bt
#0 0x00000001002ec75f in Vec3Ref<float, float, float>::Vec3Ref (this=0x7fff5fbfc938, _x=@0x7fff5fbfc980, _y=@0x7fff5fbfc984, _z=@0x7fff5fbfc988) at Math3D.h:293
#1 0x00000001002ec9a3 in Vec3<float, float, float>::Vec3 (this=0x7fff5fbfc938, _x=@0x7fff5fbfc390, _y=@0x7fff5fbfc38c, _z=@0x7fff5fbfc388) at Math3D.h:389
#2 0x00000001002e7ced in Vec3<float, float, float>::Vec3 (this=0x7fff5fbfc938, _x=@0x7fff5fbfc390, _y=@0x7fff5fbfc38c, _z=@0x7fff5fbfc388) at Math3D.h:389
#3 0x00000001002fa496 in Vec3<float, float, float>::FromRGB (rgb=0) at /Users/henrik/ppsspp/GPU/Math3D.cpp:43
#4 0x00000001002a91d2 in TransformDrawEngine::ApplyDrawState (this=0x1018de418, prim=3) at /Users/henrik/ppsspp/GPU/GLES/StateMapping.cpp:149
#5 0x00000001002e23ac in TransformDrawEngine::Flush (this=0x1018de418) at /Users/henrik/ppsspp/GPU/GLES/TransformPipeline.cpp:1117
#6 0x0000000100294d2f in GLES_GPU::CheckFlushOp (this=0x1018d9600, op=2700096480, diff=1920448) at /Users/henrik/ppsspp/GPU/GLES/DisplayListInterpreter.cpp:344
#7 0x00000001002928a6 in GLES_GPU::FastRunLoop (this=0x1018d9600, list=@0x1018d9608) at /Users/henrik/ppsspp/GPU/GLES/DisplayListInterpreter.cpp:329
#8 0x00000001002f71dc in GPUCommon::InterpretList (this=0x1018d9600, list=@0x1018d9608) at /Users/henrik/ppsspp/GPU/GPUCommon.cpp:412
#9 0x00000001002f76ec in GPUCommon::ProcessDLQueue (this=0x1018d9600) at /Users/henrik/ppsspp/GPU/GPUCommon.cpp:496
#10 0x00000001002f6c00 in GPUCommon::UpdateStall (this=0x1018d9600, listid=0, newstall=1219052644) at /Users/henrik/ppsspp/GPU/GPUCommon.cpp:251
#11 0x000000010017bf91 in sceGeListUpdateStallAddr (displayListID=0, stallAddress=1219052644) at /Users/henrik/ppsspp/Core/HLE/sceGe.cpp:283
#12 0x000000010017efc0 in WrapI_UU<&(sceGeListUpdateStallAddr(unsigned int, unsigned int))> () at FunctionWrappers.h:158
#13 0x0000000100151569 in CallSyscall (op=8126668) at /Users/henrik/ppsspp/Core/HLE/HLE.cpp:489
#14 0x00000001135b18df in ?? ()
Current language: auto; currently c++

@hrydgard
Copy link
Owner

Given the crashes, not sure what to do with this. Do you plan to get rid of the Ref stuff? I think it's pretty overkill anyway.

@neobrain
Copy link
Contributor Author

I've fixed the messy VecXRef stuff by removing it (locally), haven't gotten to clean it up yet though.

@neobrain
Copy link
Contributor Author

I'll remove most of the "cool" functionality of this branch, so this pull request is kinda pointless. I'll open another one once the boring changes are rebased on a new branch.

@neobrain neobrain closed this Jul 25, 2013
@arg274
Copy link

arg274 commented Jul 25, 2013

looks like we have 2 wait...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants