Commit graph

298 commits

Author SHA1 Message Date
Luke Usher
56610cd899 Fix heap corruption in NVNetDevice::GetMacAddress
This could cause startup of CxbxR to fail for some users.
2022-07-12 09:40:27 +01:00
RadWolfie
cd09cf8dfd remove emu codebase from gui's side 2022-04-14 00:14:41 -05:00
ergo720
bfa9abbc1b Updated cxbxr projects to use and build with C++20 2022-03-22 00:52:52 +01:00
ergo720
c6ea72dcf4 Use a condition variable to notify interrupts, fixes stuttering in the dashboard 2022-02-18 20:17:22 +01:00
ergo720
06f34134ff Review remarks + use PsCreateSystemThread to start all xbox threads 2022-02-16 18:20:04 +01:00
Fisherman166
886bef5c8a Implement HalEnableSecureTrayEject xbox kernel function. 2021-11-13 17:15:27 -08:00
ergo720
9092f7bbe6 Extended LibusbDevice class + allowed xapi to work with libusb devices 2021-11-01 17:03:40 +01:00
RadWolfie
9bf21223f2 kernel: rename CxbxKrnlCleanup(Ex) to CxbxrKrnlAbort(Ex) 2021-08-30 12:27:03 -05:00
RadWolfie
e1a8391170 imgui: move fps updater functions into imgui ui class 2021-07-31 18:03:40 -05:00
Anthony
b66f04d811 SleepPrecise for more accurate sleeps
We can use it to reduce the amount of spin waiting which burns CPU
Try to sleep as much as we can get away with without overshooting, and then spin wait
Use it for
- VBlank timing
- Frame limiter timing
2021-06-02 21:54:02 +12:00
RadWolfie
000dd6c0a5 ImGui: register functions for individual release purpose and combine them into central call purpose 2021-04-03 14:35:31 -05:00
RadWolfie
9885859916 ImGui: make functional imgui integration along with basic features 2021-04-03 14:35:30 -05:00
Silent
39c938f990
Use Win10 CPU Sets API where supported
Using CPU Sets instead of thread affinity allows to ensure
that the entire physical core is reserved ONLY for the game code,
so even the worker threads and third party libraries inside the process
cannot run code on it.

For Windows 7 and 8.1, the existing thread affinity approach is retained.
2021-03-24 19:25:25 +01:00
RadWolfie
6c70627ad2 Move and rename EmuNVNet files into its own network folder 2021-02-27 02:38:47 +00:00
Margen67
456fd3e30a Fix typos, remove whitespace
Convert tabs to spaces.
Make links https where applicable.
2020-12-19 10:33:14 -08:00
patrickvl
561f76c067 Fixes after rebase
Write our viewport constants after copying dirty constants from PGRAPH
Fixes geometry flickering in some titles
Miscellaneous cleanup (renaming, indentation, function inlining)
Start stream offset from slot offset rather than vertex stride
Vertex declaration debug logging
Xbox clamps fog in pixel shader (not vertex shader)
Fix typos
Introduce HostStreamNumber, to use Xbox stream index on host
Pass HostStreamNumber to Activate
Let CountActiveD3DStreams return an actual count
Call ConvertStream with a regular counter instead of pretended stream index
For clarity in ConvertStream, discern between XboxStreamNumber and HostStreamNumber (even though they're the same value)
Don't check CxbxVertexDeclarationNeedsPatching in GetNbrStreams
Remove now unused CxbxVertexDeclarationNeedsPatching
Rename IndexOfStream into StreamIndex
Remove unused DeclPosition
Rename CurrentStreamNumber into XboxStreamIndex
Reduce size of VertexElements array to X_VSH_MAX_ATTRIBUTES (16)
Rename StreamNumber into XboxStreamNumber
Set XboxStreamIndex only once
Assert VertexStreams won't be accessed outside it's size
Assert VertexElements won't be accessed outside it's size
For AUTONORMAL, set UsageIndex to 0 instead of (according to docs) incorrect 1
Derive NeedPatching from XboxVertexElementByteSize, instead of setting it alongside
Set dummy vertex buffers using HostStreamNumber argument name
Clamp output fog in vertex shader HLSL.

Also, cleanup passthrough HLSL to write outputs identical to vertex shader template HLSL
Turns out, the scale and offset we send to the Xbox passthrough program, should just be identity, regardless resolution or scale.

This seems to fix sub-pixel differences, noticeable when F7-toggling passthrough mode between our dedicated HLSL vs the Xbox program.
Let F7 toggle passthrough based rendering between an Xbox (-derived) shader or our dedicated HLSL shader. Also fixed the index of the -96 and -95 (scale and offset) passthrough constants. F7-toggling, you can see a slight sub-pixel difference between the two modes, probably related to how scale and offset are calculated and used differently between the two approaches. With this, we can postpone the decision on how we should handle passthrough mode.
Fixup use render target width rather than backbuffer width
Multiply instead of divide in ReverseScreenspaceTransform
Don't scale Z in passthrough
test case GTA III sprites
Scale viewport X and Y as well as height.
Fixes cases where X and Y are nonzero e.g. DoA3 character select
Tidy and simplify GetViewPortOffsetAndScale a bit
Refactor passthrough HLSL to call reverseScreenspaceTransform, which not only uses offset and scale constants, but is now also configurable to handle RHW transformed positions.

This takes us one step closer to merging passthrough HLSL with our generic vertex shader HLSL
- IVB passes the position register in full (FLOAT4 instead of FLOAT3)
Fixes samples that pack 2d coords and texcoord into position
- Remove POSITIONT semantic, as we don't expect it in our shaders or pass it to the fixed function pipeline
scaley
rhw
Don't scale texcoords by default. Not all texcoords are used for texture fetches
LoadVertexShader_4 avoids trashing EAX parameter
Apply g_RenderScaleFactor to passthrough constants.

Also renamed ViewPort into HostViewPort. Added Comments, fixed typo's, marked unused code.
Extract D3DDevice_SetViewPort into CxbxImpl_SetViewPort

Also fix build
Extract D3DDevice_SetRenderTarget into CxbxImpl_SetRenderTarget, and call that from Direct3D_CreateDevice_End
Split off CxbxUpdateHostTextureScaling()
Typos
Separate setting host textures from texture coord scaling
Call UpdateHostTextures before state apply calls
Fix build
Prepare for more accurate calculation of passthrough constants zero and one (not functional yet).

Plus some cleanup
While at it, implement the conversion of remaining TextureStageStates in a similar way as TextureCoordinateIndex (mentioning known values explicitly in code, LOG_TEST_CASE or EmuLog for unsupported/unexpected input values).
Fix TSS_TCI conversion (and some typos, and reordering of code)
Map texture coordinate indices in fixed function mode only

(cherry picked from commit 32878cac2fc3682ac057af4f74f495d994fa13b8)
- Revert to scaling coordinates for linear textures
- Use texture state to map from stages to texcoord indices
- Add Get method to XboxTextureState

(cherry picked from commit 39dd0144851e49ea2452506293dca5e1f532ac97)
Fix XDK Ripple sample regression in CxbxSetVertexShaderPassthroughProgram, by not setting our own calculations in constant zero and one (and instead rely on Xbox code setting those through pushbuffer commands)
Remove texture normalization from vertex buffer conversion.
Instead, apply the texture scale factor in our vertex shader HLSL
This removed yet another reason for buffer patching, simplifying code more and speeding up rendering a little.

The Ripple XDK sample regressed because of this (or an earlier commit?), which might (or might not) be related to vertex explosions seen in some games.

(That, or it has something to do with the use of non-standard registers for passing in texture coordinates - in any case, a fix for this will probably improve a few games as well).
Set vertex shader constants based on pgraph (and write then to there as well)
Set constant zero and one for passthrough programs
For this, introduce and call CxbxImpl_SetScreenSpaceOffset
Renamed all host update functions to : CxbxUpdateHost...
As it turns out, texture normalization only applies to pre-transformed (X_D3DFVF_XYZRHW) vertex declarations (not just FVF based declarations)!

So, replace final use of VshHandleIsFVF (allowing removal of it's declaration) with GetXboxVertexAttributeFormat(), and update CxbxVertexBufferConverter::ConvertStream to use the Xbox AttributeFormat (instead of decoding FVF's).
With this, there's also no more use for DxbxFVF_GetNumberOfTextureCoordinates nor DxbxFVFToVertexSizeInBytes, so these are now removed as well.

I verified this still renders all XDK samples identically, but some games might improve due to this (especially if they have separate sets of texture-coordinates in a single stream). There's a low chance for regressions.
Remove our final SetFVF call on host, by composing an Xbox vertex attribute format according to the registers that have been written to in CxbxImpl_SetVertexData4f

This also allowed to clean up the code that copies data from g_InlineVertexBuffer_Table to g_InlineVertexBuffer_pData (a pass that we might even be able to skip?)
Extract the code from our D3DDevice_Begin patch towards CxbxImpl_Begin
Rename EmuFlushIVB into CxbxImpl_End
With this, all use of g_InlineVertexBuffer* symbols is limited to XbVertexBuffer.cpp
So, remove all extern declarations on g_InlineVertexBuffer* symbols.

Remove implementation and calls to HLE_write_NV2A_vertex_attribute_slot,
because CxbxSetVertexAttribute already does that with less overhead,
which is already called in CxbxImpl_SetVertexData4f.
Some comments on how we might handle vertex shader constants later on
Disable two LOG_TEST_CASE's
Simplify CxbxSetVertexAttribute
Extract CxbxImpl_SetVertexData4f from our D3DDevice_SetVertexData4f patch
Move the implementation to XbVertexBuffer.cpp
There, extract the part about setting default register values towards a separate function, called CxbxSetVertexAttribute
In CxbxImpl_SetVertexData4f, read starting values for all attributes
For this, refactored HLE_read_NV2A_vertex_attribute_slot into HLE_get_NV2A_vertex_attribute_value_pointer
Convert it's float pointer result to required data type per g_InlineVertexBuffer_Table field.
Use the same function in CxbxSetVertexAttribute to write default attribute values
In CxbxImpl_SetVertexShader, call CxbxSetVertexAttribute to set default values for attributes missing from vertex shader
Remove duplicate reset of g_Xbox_VertexShader_FunctionSlots_StartAddress
Remove bNeedRHWReset remnants
Don't set fixed function mode when we don't know what to do
Fixes Amped menu graphics
Make sure we process stream elements in order of offset
Use clamped reciprocal for defined behavour with rcp(0)
Remove FVF vertex buffer fixups
Reset vertex shader address when setting the passthrough program
Revert "Postpone calling EmuParseVshFunction until after shader cache miss, this should speed up rendering a little"

This reverts commit a4b647e6fe365ca414815afcf813431e7080546d.

Reason : EmuParseVshFunction sets the size needed for ComputeHash, so we can't avoid it!
Silence compiler warning
Reset g_Xbox_VertexShader_FunctionSlots_StartAddress to zero for passthrough mode

Also prepared storing g_Xbox_VertexShader_Ptr (See CXBX_USE_GLOBAL_VERTEXSHADER_POINTER).
Postpone calling EmuParseVshFunction until after shader cache miss, this should speed up rendering a little
Avoid calling trampoline when not assigned
Write binary Xbox shader to our slots for passthrough shaders
Use a version-dependent getter for shader tokens
Make sure EmuParseVshFunction never goes out of bounds (by putting a FLD_FINAL at slot 136 in CxbxSetVertexShaderSlots)
Document vertex shader flags and set more of them in XboxVertexShaderFromFVF
Oops
Took some stuff from NZJenkins dca881d61f
Postpone host update of vertex declaration and shader towards draw-time.
Introduce new fixed-function status boolean
Conversion of FVF to internal vertex shader INCLUDING texture Dimensions.
Avoid treating internal vertex shader as older version
Some more cleanup

Status of this is, that some XDK samples lack geometry, not sure if this is the result of this commit or a prior one. NZJenkins has a branch that shares history with this one, that does show geometry, so perhaps we should mix & match the best parts of these two branches, and continue with the result?!?
Call UpdateViewPortOffsetAndScaleConstants only from CxbxUpdateNativeD3DResources (and after CxbxTransferVertexShaderConstants)
Extracted code into CxbxTransferVertexShaderConstants function, using new (renamed) HLE_read_NV2A_vertex_constant_float4_ptr function
Introduce HLE_read_NV2A_vertex_program_slot and HLE_read_NV2A_vertex_constant_slot functions
Fix missing nv2a registers
Differentiate between two versions of X_D3DVertexShader
In HLE_write_NV2A_vertex_attribute_slot assert failure in pgraph_handle_method()
Call HLE_init_pgraph_plugins() from a better suitable place (EmuD3DInit)
Processed code review comments : Fixed a few typo's, document SetVertexShaderInput test-cases, rename inaccurate symbol names, add more comments, add LOG_TEST_CASE("Limiting FVF to 4 textures")
Start using GetXboxVertexStreamInput everywhere g_Xbox_SetStreamSource was accessed
Removed CreateVertexShader patch and implementation
Cache VertexDeclarations based on hash of their contents
Store FVF based VertexAttributeFormat in global variable
GetXboxVertexAttributeFormat returns a pointer now
A lot of cleanup (like IsValidCurrentShader and VshHandleIsValidShader are no longer needed)
Fix post-processing of elements for D3DDECLMETHOD_CROSSUV (normal tesselation)
Move and rename global variables.

Also, partly picked conversion of tesselation-declarations.
Reorder and comment vertex-shader related types
Removed now-obsolete CxbxVertexShader struct, instead use CxbxVertexDeclaration and renamed all references to that.
Start using GetXboxVertexAttributes, which calls the new (temporary) XboxFVFToXboxVertexAttributeFormat function for FVF vertex shader handles)

Also removed the now-obsolete SetCxbxVertexShaderHandle() and SetCxbxVertexDeclaration() functions
Introduce GetXboxVertexShader and GetXboxVertexAttributes getters (both not yet used)
In D3DDevice_SwitchTexture use a switch statement instead of an array plus for-loop
Implement our patch on SetVertexShaderInput and introduce GetXboxVertexStreamInput, a getter that honors this g_Xbox_SetStreamSource override (not yet used)
Disabled patches on D3DDevice_GetVertexShaderInput and D3DDevice_SetVertexShaderInputDirect.
Call trampoline in D3DDevice_SetVertexShaderInput (and add a LOG_TEST_CASE)
Disabled patch on D3DDevice_SelectVertexShaderDirect (since all it does, is forward to D3DDevice_SelectVertexShader, which we DO patch)
Call trampoline in D3DDevice_SetVertexShader
CxbxImpl_LoadVertexShader must not skip first program DWORD
Explicit padding in X_VERTEXSHADERINPUT to avoid potential alignment issue
Make Xb2PCRegisterType more compact, and let it support D3DDECLUSAGE_POSITIONT
WIP
Introduce CxbxFVFToXboxVertexAttributeFormat, a function that converts an Xbox FVF handle to the Xbox Vertex attribute format struct. This, so that in a next step we can convert the Xbox Vertex attribute format struct to a CxbxVertexDeclaration (or maybe just straight to a host declaration)
Implement CxbxImpl_LoadVertexShader much closer to reality
Define X_D3DVertexShader.Flags values
CxbxImpl_SelectVertexShader : Only store Handle when it's non-NULL (which must always be a VertexShader, so LOG_TEST_CASE when not)
Use CxbxSetVertexShaderSlots tooling function to reduce duplicate code
2020-11-02 21:39:40 +01:00
Luke Usher
03d864c465 emux86: update flash read function with a better explaination 2020-10-17 22:37:01 +01:00
Luke Usher
4665bd0c3f emux86: fix bad bios rom mapping
Prevents a crash in Shenmue II
2020-10-17 16:05:17 +01:00
ergo720
13bd79f930
Use fixed width types for xbox types + restructured kernel header files (#1969)
* VOID -> void_xt

* CHAR, CCHAR -> char_xt, cchar_xt

* UCHAR -> uchar_xt

* BYTE, BOOLEAN -> byte_xt, boolean_xt

* Fix bogus intellisense errors in the kernel headers

* SHORT, CSHORT, USHORT -> short_xt, cshort_xt, ushort_xt

* LONG -> long_xt

* WORD, DWORD -> word_xt, dword_xt

* HRESULT -> hresult_xt

* ULONG -> ulong_xt

* SIZE_T, ACCESS_MASK, PHYSICAL_ADDRESS -> size_xt, access_mask_xt, physical_address_xt

* UINT, INT -> uint_xt, int_xt

* LONG_PTR, ULONG_PTR, INT_PTR -> long_ptr_xt, ulong_ptr_xt, int_ptr_xt

* LONGLONG, ULONGLONG -> longlong_xt, ulonglong_xt

* WCHAR, QUAD, BOOL, FLOAT -> wchar_xt, quad_xt, bool_xt, float_xt

* Updated types in xonline.h + reverted some type changes + moved kernel header files in cxbxr source tree

* Use char16_t instead of wchar_t for wchar_xt xbox type

* Fixed macro redefinition warnings from ntstatus macros in types.h
  Fixed macro redefinition warnings from NT_SUCCESS and FIELD_OFFSET
  Fixed macro redefinition warnings from the REG_ macros used by the eeprom

* NTSTATUS -> ntstatus_xt
2020-10-06 05:33:16 -05:00
ergo720
b304e538c6
Introduce xbox namespace + deduplicate xbox types (#1942)
* Introduced new xbox namespace + moved inside it xbox pointer/address types

* Replaced xboxkrnl namespace with xbox namespace

* Moved kernel types from xboxkrnl.h to xbox_types.h

* Replaced XTL namespace with xbox namespace

* Fix a conflict with the VOID macro imported by Windows.h

* Fixed misalignment issues + renamed xtl_prefix
2020-08-24 13:29:48 -05:00
RadWolfie
3550fa4ed1 setup force source files to lf line ending and renormalize 2020-08-22 20:17:07 -05:00
RadWolfie
8861b845d7 chrono: replace duration_cast to duration 2020-08-20 15:51:12 -05:00
RadWolfie
e0f6d75cd0 chrono: use steady_clock than high_resolution_clock 2020-08-20 14:50:02 -05:00
ergo720
f46bcd6875 Use xboxkrnl namespace inside xboxkrnl header file 2020-08-18 17:02:19 +02:00
Luke Usher
2695d91496
Merge pull request #1913 from RadWolfie/improve-compiler-support
Improve SEH/VEH support for compilers
2020-08-18 14:55:08 +01:00
RadWolfie
3e7ac34987 pcap delay load module require SEH 2020-06-07 23:27:08 -05:00
RadWolfie
b5358508d6 update Windows' SEH, fix overflow exception, and non-Windows platform support 2020-06-07 23:27:08 -05:00
Fisherman166
857b8f933e Rewrite HalReadSMCTrayState to match original kernel implementation. Keeps the TRAY_OPEN hack for the time being. 2020-06-06 13:27:54 -07:00
ergo720
f1255cb89b Allow the memory manager to work again with the non-loader approach 2020-04-14 20:24:18 -05:00
PatrickvL
ca6423b484 Reviving my more-than-a-year-old Loader branch, by copying over various things (nothing functional yet) 2020-04-14 20:24:16 -05:00
darkf
b8be2efa97 Include missing headers 2020-04-07 02:44:39 -07:00
darkf
fed6245e48 Fix erroneous macro definitions 2020-04-07 02:44:38 -07:00
Luke Usher
d1018cb773 nvnet: Accept only broadcast and targeted traffic, not multicast
Fixes XNET warnings when using Debug XDK libraries
2019-12-14 11:25:35 +00:00
Luke Usher
b59107a956 nvnet: cleanup + bug fixes 2019-11-12 20:14:27 +00:00
Luke Usher
18e0311f00 Fix an issue where multicast packets were not captured 2019-11-12 20:14:27 +00:00
patrickvl
fedd9fbf67 Cleaned up and expanded upon commented test-case 2019-10-28 09:31:38 +01:00
PatrickvL
a6c0353c5b Fix a large part of XTL-hell (#1731)
* Rename g_CurrentXboxVertexShaderHandle to g_Xbox_VertexShader_Handle

* Remove CxbxDrawContext.XboxVertexShaderHandle field, and replaced reads from this field by g_Xbox_VertexShader_Handle (since all writes to this field used that as source)

* Removed commented-out #include's

* Removed duplicate DEF_VSH_* defines, replaced usage by existing X_D3DVSD_*() defines.

* Removed commented-out #include's from src/vsbc

* Removed nearly all "namespace XTL"-wrappers around #includes; Instead, wrap applicable contents of these included files in namespace XTL. Removed all now-obsolete "XTL::" prefixes.

* Moved all host D3D9 symbols outside of namespace XTL (finally!)

* Removed all "using namespace XTL;" occurences (except one, which is marked with a TODO)

* Restored Unix EOL style (to avoid large diffs with upstream)

* Moved CxbxInitAudio outside XTL namespace (this was the last Cxbx* symbol in XTL)

* Removed final "using namespace XTL" occurence by cleaner wrapping of logging intrinsics inside and outside namespace XTL.

* Prefix a few Xbox types with X_ (and avoid compile-error by removing the now-obsolete duplicate of X_D3DCALLBACK).
Also nicely indent all Direct3D9 alias defines, introduced when porting from Direct3D8. Who knows, one day we might re-define them once again to port to more recent Direct3D versions?

* Made EmuXTL.h obsolete, by #include'ing specific headers instead of it.

* Removed unused #include's of EmuFS.h

* Remove #pragma once, when there's already an include guard present.

* Delete EmuXTL.h and XOnline.cpp, keep but disable XOnline.h for documentation purposes.

* Fix all compiler warnings that have no functional impact. What's left requires more research

* Remove GetVersion, retain Wine check
2019-09-24 16:25:52 -05:00
PatrickvL
eb4db9a27a Moving, reordering, renaming and other cleanup of D3D symbols (all taken from my Vsh_unpatching branch) 2019-09-12 09:34:58 +02:00
ergo720
d8b0075c93 New input gui (#1713) 2019-09-05 16:10:09 -05:00
ergo720
fd4bcb39ff Added error log level 2019-07-20 21:53:15 +02:00
Luke Usher
26f7bb130a Small, but significant performance tweaks 2019-07-12 20:48:38 +01:00
gellis713
0be1370d0b Removes _XBOXKRNL_XXXX defines and dependency in xboxkrnl/xboxkrnl.h 2019-07-05 18:45:36 -05:00
Luke Usher
87d6ae65f1 Fix a deadlock when some LTCG titles attempt to wait for vertical blank 2019-06-26 21:00:28 +01:00
Luke Usher
a934d7619c
Revert "Prevent NVNet hogging cpu" 2019-06-10 18:42:02 +01:00
Anthony Miles
1611559087 Remove DBG_PRINTF and remaining usages 2019-06-10 21:46:49 +12:00
Anthony Miles
9a7ded6a53 Replace DBG_PRINTF with EmuLog 2019-06-07 23:26:26 +12:00
Margen67
1a92e63866 Update http documentation links to https and fix (some) dead ones 2019-05-12 02:36:50 -07:00
RadWolfie
d3caface5d fix VS 2019 compiler 2019-05-04 15:06:06 -05:00
Luke Usher
deb5268df8 Prevent NVNet hogging cpu 2019-05-01 08:18:16 +01:00
Luke Usher
aeca3d3d92 Use standard types from cstdint rather than custom typedefs 2019-03-27 15:54:17 +00:00