Direct3D + Cg progress, the plugin is still not working due to some missing features.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2494 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
XTra.KrazzY 2009-03-01 01:09:32 +00:00
parent e004800e68
commit 3234bca193
13 changed files with 719 additions and 26 deletions

238
Externals/Cg/cgD3D10.h vendored Normal file
View File

@ -0,0 +1,238 @@
/*
*
* Copyright (c) 2008-2009, NVIDIA Corporation.
*
*
*
* NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
* of your agreement to the following terms, and your use, installation,
* modification or redistribution of this NVIDIA software constitutes
* acceptance of these terms. If you do not agree with these terms, please do
* not use, install, modify or redistribute this NVIDIA software.
*
*
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, NVIDIA grants you a personal, non-exclusive license,
* under NVIDIA's copyrights in this original NVIDIA software (the "NVIDIA
* Software"), to use, reproduce, modify and redistribute the NVIDIA
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the NVIDIA Software, you must retain the
* copyright notice of NVIDIA, this notice and the following text and
* disclaimers in all such redistributions of the NVIDIA Software. Neither the
* name, trademarks, service marks nor logos of NVIDIA Corporation may be used
* to endorse or promote products derived from the NVIDIA Software without
* specific prior written permission from NVIDIA. Except as expressly stated
* in this notice, no other rights or licenses express or implied, are granted
* by NVIDIA herein, including but not limited to any patent rights that may be
* infringed by your derivative works or by other works in which the NVIDIA
* Software may be incorporated. No hardware is licensed hereunder.
*
*
*
* THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
* EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
*
*
*
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
* PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
* REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
* HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
* NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __CGD3D10_H__
#define __CGD3D10_H__
#ifdef _WIN32
#pragma once
#include <windows.h>
#include <d3d10.h>
#include "Cg/cg.h"
// Set up for either Win32 import/export/lib.
#ifdef CGD3D10DLL_EXPORTS
#define CGD3D10DLL_API __declspec(dllexport)
#elif defined (CG_LIB)
#define CGD3D10DLL_API
#else
#define CGD3D10DLL_API __declspec(dllimport)
#endif
#ifndef CGD3D10ENTRY
# ifdef _WIN32
# define CGD3D10ENTRY __cdecl
# else
# define CGD3D10ENTRY
# endif
#endif
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef CGD3D10_EXPLICIT
/* ----- D3D Device Control ----- */
CGD3D10DLL_API ID3D10Device * CGD3D10ENTRY
cgD3D10GetDevice(
CGcontext Context
);
CGD3D10DLL_API HRESULT CGD3D10ENTRY
cgD3D10SetDevice(
CGcontext Context,
ID3D10Device * pDevice
);
/* ----- Texture Functions ----- */
CGD3D10DLL_API void CGD3D10ENTRY
cgD3D10SetTextureParameter(
CGparameter Parameter,
ID3D10Resource * pTexture
);
CGD3D10DLL_API void CGD3D10ENTRY
cgD3D10SetSamplerStateParameter(
CGparameter Parameter,
ID3D10SamplerState * pSamplerState
);
CGD3D10DLL_API void CGD3D10ENTRY
cgD3D10SetTextureSamplerStateParameter(
CGparameter Parameter,
ID3D10Resource * pTexture,
ID3D10SamplerState * pSamplerState
);
/* ----- Shader Management ----- */
CGD3D10DLL_API HRESULT CGD3D10ENTRY
cgD3D10LoadProgram(
CGprogram Program,
UINT Flags
);
CGD3D10DLL_API ID3D10Blob * CGD3D10ENTRY
cgD3D10GetCompiledProgram(
CGprogram Program
);
CGD3D10DLL_API ID3D10Blob * CGD3D10ENTRY
cgD3D10GetProgramErrors(
CGprogram Program
);
CGD3D10DLL_API CGbool CGD3D10ENTRY
cgD3D10IsProgramLoaded(
CGprogram Program
);
CGD3D10DLL_API HRESULT CGD3D10ENTRY
cgD3D10BindProgram(
CGprogram Program
);
CGD3D10DLL_API void CGD3D10ENTRY
cgD3D10UnloadProgram(
CGprogram Program
);
/* ----- Buffer Management ----- */
CGD3D10DLL_API ID3D10Buffer * CGD3D10ENTRY
cgD3D10GetBufferByIndex(
CGprogram Program,
UINT Index
);
/* ----- CgFX ----- */
CGD3D10DLL_API void CGD3D10ENTRY
cgD3D10RegisterStates(
CGcontext Context
);
CGD3D10DLL_API void CGD3D10ENTRY
cgD3D10SetManageTextureParameters(
CGcontext Context,
CGbool Flag
);
CGD3D10DLL_API CGbool CGD3D10ENTRY
cgD3D10GetManageTextureParameters(
CGcontext Context
);
CGD3D10DLL_API ID3D10Blob * CGD3D10ENTRY
cgD3D10GetIASignatureByPass(
CGpass Pass
);
/* ----- Profile Options ----- */
CGD3D10DLL_API CGprofile CGD3D10ENTRY
cgD3D10GetLatestVertexProfile();
CGD3D10DLL_API CGprofile CGD3D10ENTRY
cgD3D10GetLatestGeometryProfile();
CGD3D10DLL_API CGprofile CGD3D10ENTRY
cgD3D10GetLatestPixelProfile();
CGD3D10DLL_API CGbool CGD3D10ENTRY
cgD3D10IsProfileSupported(
CGprofile Profile
);
/* ----- Utility Functions ----- */
CGD3D10DLL_API DWORD CGD3D10ENTRY
cgD3D10TypeToSize(
CGtype Type
);
CGD3D10DLL_API HRESULT CGD3D10ENTRY
cgD3D10GetLastError();
CGD3D10DLL_API const char ** CGD3D10ENTRY
cgD3D10GetOptimalOptions(
CGprofile Profile
);
CGD3D10DLL_API const char * CGD3D10ENTRY
cgD3D10TranslateCGerror(
CGerror Error
);
CGD3D10DLL_API const char * CGD3D10ENTRY
cgD3D10TranslateHRESULT(
HRESULT hr
);
#endif // #ifndef CGD3D10_EXPLICIT
#ifdef __cplusplus
}; // extern "C"
#endif
#endif // #ifdef _WIN32
#endif // #ifndef __CGD3D10_H__

BIN
Externals/Cg/cgD3D9.dll vendored Normal file

Binary file not shown.

317
Externals/Cg/cgD3D9.h vendored Normal file
View File

@ -0,0 +1,317 @@
/*
*
* Copyright (c) 2002-2009, NVIDIA Corporation.
*
*
*
* NVIDIA Corporation("NVIDIA") supplies this software to you in consideration
* of your agreement to the following terms, and your use, installation,
* modification or redistribution of this NVIDIA software constitutes
* acceptance of these terms. If you do not agree with these terms, please do
* not use, install, modify or redistribute this NVIDIA software.
*
*
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, NVIDIA grants you a personal, non-exclusive license,
* under NVIDIA's copyrights in this original NVIDIA software (the "NVIDIA
* Software"), to use, reproduce, modify and redistribute the NVIDIA
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the NVIDIA Software, you must retain the
* copyright notice of NVIDIA, this notice and the following text and
* disclaimers in all such redistributions of the NVIDIA Software. Neither the
* name, trademarks, service marks nor logos of NVIDIA Corporation may be used
* to endorse or promote products derived from the NVIDIA Software without
* specific prior written permission from NVIDIA. Except as expressly stated
* in this notice, no other rights or licenses express or implied, are granted
* by NVIDIA herein, including but not limited to any patent rights that may be
* infringed by your derivative works or by other works in which the NVIDIA
* Software may be incorporated. No hardware is licensed hereunder.
*
*
*
* THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR ITS USE AND OPERATION
* EITHER ALONE OR IN COMBINATION WITH OTHER PRODUCTS.
*
*
*
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOST
* PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY OUT OF THE USE,
* REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE NVIDIA SOFTWARE,
* HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
* NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF NVIDIA HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef CGD3D9_INCLUDED
#define CGD3D9_INCLUDED
#ifdef _WIN32
#pragma once
#include "cg.h"
#include <d3d9.h>
#include <d3dx9.h>
// Set up for either Win32 import/export/lib.
#include <windows.h>
#ifdef CGD3D9DLL_EXPORTS
#define CGD3D9DLL_API __declspec(dllexport)
#elif defined (CG_LIB)
#define CGD3D9DLL_API
#else
#define CGD3D9DLL_API __declspec(dllimport)
#endif
#ifndef CGD3D9ENTRY
# ifdef _WIN32
# define CGD3D9ENTRY __cdecl
# else
# define CGD3D9ENTRY
# endif
#endif
/*---------------------------------------------------------------------------
// CGerrors that will be fed to cgSetError
// Use cgD3D9TranslateCGerror() to translate these errors into strings.
---------------------------------------------------------------------------*/
enum cgD3D9Errors
{
cgD3D9Failed = 1000,
cgD3D9DebugTrace = 1001,
};
/*---------------------------------------------------------------------------
// HRESULTs specific to cgD3D9. When the CGerror is set to cgD3D9Failed
// cgD3D9GetLastError will return an HRESULT that could be one these.
// Use cgD3D9TranslateHRESULT() to translate these errors into strings.
---------------------------------------------------------------------------*/
static const HRESULT CGD3D9ERR_NOTLOADED = MAKE_HRESULT(1, 0x877, 1);
static const HRESULT CGD3D9ERR_NODEVICE = MAKE_HRESULT(1, 0x877, 2);
static const HRESULT CGD3D9ERR_NOTSAMPLER = MAKE_HRESULT(1, 0x877, 3);
static const HRESULT CGD3D9ERR_INVALIDPROFILE = MAKE_HRESULT(1, 0x877, 4);
static const HRESULT CGD3D9ERR_NULLVALUE = MAKE_HRESULT(1, 0x877, 5);
static const HRESULT CGD3D9ERR_OUTOFRANGE = MAKE_HRESULT(1, 0x877, 6);
static const HRESULT CGD3D9ERR_NOTUNIFORM = MAKE_HRESULT(1, 0x877, 7);
static const HRESULT CGD3D9ERR_NOTMATRIX = MAKE_HRESULT(1, 0x877, 8);
static const HRESULT CGD3D9ERR_INVALIDPARAM = MAKE_HRESULT(1, 0x877, 9);
/*---------------------------------------------------------------------------
// Other error return values
---------------------------------------------------------------------------*/
static const DWORD CGD3D9_INVALID_USAGE = 0xFF;
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef CGD3D9_EXPLICIT
/*---------------------------------------------------------------------------
// Minimal Interface
---------------------------------------------------------------------------*/
CGD3D9DLL_API DWORD CGD3D9ENTRY
cgD3D9TypeToSize(
CGtype type
);
CGD3D9DLL_API BYTE CGD3D9ENTRY
cgD3D9ResourceToDeclUsage(
CGresource resource
);
CGD3D9DLL_API CGbool CGD3D9ENTRY
cgD3D9GetVertexDeclaration(
CGprogram prog,
D3DVERTEXELEMENT9 decl[MAXD3DDECLLENGTH]
);
CGD3D9DLL_API CGbool CGD3D9ENTRY
cgD3D9ValidateVertexDeclaration(
CGprogram prog,
const D3DVERTEXELEMENT9* decl
);
/*---------------------------------------------------------------------------
// Expanded Interface
---------------------------------------------------------------------------*/
/* ----- D3D Device Control ----------- */
CGD3D9DLL_API IDirect3DDevice9 * CGD3D9ENTRY
cgD3D9GetDevice();
CGD3D9DLL_API HRESULT CGD3D9ENTRY
cgD3D9SetDevice(
IDirect3DDevice9* pDevice
);
/* ----- Shader Management ----------- */
CGD3D9DLL_API HRESULT CGD3D9ENTRY
cgD3D9LoadProgram(
CGprogram prog,
CGbool paramShadowing,
DWORD assemFlags
);
CGD3D9DLL_API HRESULT CGD3D9ENTRY
cgD3D9UnloadProgram(
CGprogram prog
);
CGD3D9DLL_API CGbool CGD3D9ENTRY
cgD3D9IsProgramLoaded(
CGprogram prog
);
CGD3D9DLL_API HRESULT CGD3D9ENTRY
cgD3D9BindProgram(
CGprogram prog
);
/* ----- Parameter Management ----------- */
CGD3D9DLL_API HRESULT CGD3D9ENTRY
cgD3D9SetUniform(
CGparameter param,
const void* floats
);
CGD3D9DLL_API HRESULT CGD3D9ENTRY
cgD3D9SetUniformArray(
CGparameter param,
DWORD offset,
DWORD numItems,
const void* values
);
CGD3D9DLL_API HRESULT CGD3D9ENTRY
cgD3D9SetUniformMatrix(
CGparameter param,
const D3DMATRIX* matrix
);
CGD3D9DLL_API HRESULT CGD3D9ENTRY
cgD3D9SetUniformMatrixArray(
CGparameter param,
DWORD offset,
DWORD numItems,
const D3DMATRIX* matrices
);
CGD3D9DLL_API HRESULT CGD3D9ENTRY
cgD3D9SetTexture(
CGparameter param,
IDirect3DBaseTexture9* tex
);
CGD3D9DLL_API HRESULT CGD3D9ENTRY
cgD3D9SetSamplerState(
CGparameter param,
D3DSAMPLERSTATETYPE type,
DWORD value
);
CGD3D9DLL_API HRESULT CGD3D9ENTRY
cgD3D9SetTextureWrapMode(
CGparameter param,
DWORD value
);
/* ----- Parameter Management (Shadowing) ----------- */
CGD3D9DLL_API HRESULT CGD3D9ENTRY
cgD3D9EnableParameterShadowing(
CGprogram prog,
CGbool enable
);
CGD3D9DLL_API CGbool CGD3D9ENTRY
cgD3D9IsParameterShadowingEnabled(
CGprogram prog
);
/* --------- Profile Options ----------------- */
CGD3D9DLL_API CGprofile CGD3D9ENTRY
cgD3D9GetLatestVertexProfile();
CGD3D9DLL_API CGprofile CGD3D9ENTRY
cgD3D9GetLatestPixelProfile();
CGD3D9DLL_API const char * * CGD3D9ENTRY
cgD3D9GetOptimalOptions(
CGprofile profile
);
CGD3D9DLL_API CGbool CGD3D9ENTRY
cgD3D9IsProfileSupported(
CGprofile profile
);
/* --------- Error reporting ----------------- */
CGD3D9DLL_API HRESULT CGD3D9ENTRY
cgD3D9GetLastError();
CGD3D9DLL_API const char * CGD3D9ENTRY
cgD3D9TranslateCGerror(
CGerror error
);
CGD3D9DLL_API const char * CGD3D9ENTRY
cgD3D9TranslateHRESULT(
HRESULT hr
);
CGD3D9DLL_API void CGD3D9ENTRY
cgD3D9EnableDebugTracing(
CGbool enable
);
/* --------- CgFX support -------------------- */
CGD3D9DLL_API void CGD3D9ENTRY
cgD3D9RegisterStates(
CGcontext ctx
);
CGD3D9DLL_API void CGD3D9ENTRY
cgD3D9SetManageTextureParameters(
CGcontext ctx,
CGbool flag
);
CGD3D9DLL_API CGbool CGD3D9ENTRY
cgD3D9GetManageTextureParameters(
CGcontext ctx
);
CGD3D9DLL_API IDirect3DBaseTexture9 * CGD3D9ENTRY
cgD3D9GetTextureParameter(
CGparameter param
);
CGD3D9DLL_API void CGD3D9ENTRY
cgD3D9SetTextureParameter(
CGparameter param,
IDirect3DBaseTexture9 *tex
);
CGD3D9DLL_API void CGD3D9ENTRY
cgD3D9UnloadAllPrograms( void );
#endif
#ifdef __cplusplus
};
#endif
#endif // _WIN32
#endif

BIN
Externals/Cg/cgD3D9.lib vendored Normal file

Binary file not shown.

BIN
Externals/Cg64/cgD3D9.dll vendored Normal file

Binary file not shown.

BIN
Externals/Cg64/cgD3D9.lib vendored Normal file

Binary file not shown.

View File

@ -93,10 +93,11 @@
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalOptions="&quot;..\..\core\common\win32\release\common.lib&quot;" AdditionalOptions="&quot;..\..\core\common\win32\release\common.lib&quot;"
AdditionalDependencies="dsound.lib odbc32.lib odbccp32.lib comctl32.lib d3d9.lib d3dx9.lib winmm.lib" AdditionalDependencies="dsound.lib odbc32.lib odbccp32.lib comctl32.lib d3d9.lib cg.lib d3dx9.lib winmm.lib"
OutputFile="..\..\..\Binary\Win32\Plugins\Plugin_VideoDX9.dll" OutputFile="..\..\..\Binary\Win32\Plugins\Plugin_VideoDX9.dll"
LinkIncremental="1" LinkIncremental="1"
SuppressStartupBanner="true" SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\..\..\Externals\Cg"
GenerateManifest="false" GenerateManifest="false"
ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb" ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb"
RandomizedBaseAddress="1" RandomizedBaseAddress="1"
@ -166,7 +167,7 @@
FavorSizeOrSpeed="1" FavorSizeOrSpeed="1"
OmitFramePointers="false" OmitFramePointers="false"
WholeProgramOptimization="true" WholeProgramOptimization="true"
AdditionalIncludeDirectories="../../PluginSpecs;../../Core/Common/Src;../../Core/VideoCommon/Src;" AdditionalIncludeDirectories="../../../Externals;../../PluginSpecs;../../Core/Common/Src;../../Core/VideoCommon/Src"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;VIDEO_DIRECTX9_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;VIDEO_DIRECTX9_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0"
StringPooling="true" StringPooling="true"
ExceptionHandling="1" ExceptionHandling="1"
@ -201,10 +202,11 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="dsound.lib odbc32.lib odbccp32.lib comctl32.lib d3d9.lib d3dx9.lib winmm.lib" AdditionalDependencies="cg.lib cgD3D9.lib dsound.lib odbc32.lib odbccp32.lib comctl32.lib d3d9.lib d3dx9.lib winmm.lib"
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_VideoDX9.dll" OutputFile="..\..\..\Binary\x64\Plugins\Plugin_VideoDX9.dll"
LinkIncremental="1" LinkIncremental="1"
SuppressStartupBanner="true" SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\..\..\Externals\Cg64"
GenerateManifest="false" GenerateManifest="false"
ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb" ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb"
RandomizedBaseAddress="1" RandomizedBaseAddress="1"
@ -299,10 +301,11 @@
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalOptions="&quot;..\..\core\common\win32\debug\common.lib&quot;" AdditionalOptions="&quot;..\..\core\common\win32\debug\common.lib&quot;"
AdditionalDependencies="dsound.lib odbc32.lib odbccp32.lib comctl32.lib d3d9.lib d3dx9.lib winmm.lib" AdditionalDependencies="dsound.lib odbc32.lib odbccp32.lib comctl32.lib d3d9.lib cg.lib d3dx9.lib winmm.lib"
OutputFile="..\..\..\Binary\Win32/Plugins\Plugin_VideoDX9D.dll" OutputFile="..\..\..\Binary\Win32/Plugins\Plugin_VideoDX9D.dll"
LinkIncremental="1" LinkIncremental="1"
SuppressStartupBanner="true" SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\..\..\Externals\Cg"
GenerateManifest="false" GenerateManifest="false"
GenerateDebugInformation="true" GenerateDebugInformation="true"
ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb" ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb"
@ -367,7 +370,7 @@
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories="../../PluginSpecs;../../Core/Common/Src;../../Core/VideoCommon/Src;" AdditionalIncludeDirectories="../../../Externals;../../PluginSpecs;../../Core/Common/Src;../../Core/VideoCommon/Src"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;VIDEO_DIRECTX9_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;VIDEO_DIRECTX9_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
RuntimeLibrary="1" RuntimeLibrary="1"
@ -397,10 +400,11 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="dsound.lib odbc32.lib odbccp32.lib comctl32.lib d3d9.lib d3dx9.lib winmm.lib" AdditionalDependencies="cg.lib cgD3D9.lib dsound.lib odbc32.lib odbccp32.lib comctl32.lib d3d9.lib d3dx9.lib winmm.lib"
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_VideoDX9D.dll" OutputFile="..\..\..\Binary\x64\Plugins\Plugin_VideoDX9D.dll"
LinkIncremental="1" LinkIncremental="1"
SuppressStartupBanner="true" SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\..\..\Externals\Cg64"
GenerateManifest="false" GenerateManifest="false"
GenerateDebugInformation="true" GenerateDebugInformation="true"
ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb" ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb"
@ -505,10 +509,11 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="dsound.lib odbc32.lib odbccp32.lib comctl32.lib d3d9.lib d3dx9.lib winmm.lib" AdditionalDependencies="dsound.lib odbc32.lib odbccp32.lib comctl32.lib d3d9.lib cg.lib d3dx9.lib winmm.lib"
OutputFile="..\..\..\Binary\Win32\Plugins\Plugin_VideoDX9DF.dll" OutputFile="..\..\..\Binary\Win32\Plugins\Plugin_VideoDX9DF.dll"
LinkIncremental="1" LinkIncremental="1"
SuppressStartupBanner="true" SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\..\..\Externals\Cg"
GenerateManifest="false" GenerateManifest="false"
IgnoreDefaultLibraryNames="LIBCMTD.lib" IgnoreDefaultLibraryNames="LIBCMTD.lib"
ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb" ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb"
@ -579,7 +584,7 @@
FavorSizeOrSpeed="1" FavorSizeOrSpeed="1"
OmitFramePointers="false" OmitFramePointers="false"
WholeProgramOptimization="true" WholeProgramOptimization="true"
AdditionalIncludeDirectories="../../PluginSpecs;../../Core/Common/Src;../../Core/VideoCommon/Src;" AdditionalIncludeDirectories="../../../Externals;../../PluginSpecs;../../Core/Common/Src;../../Core/VideoCommon/Src"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;VIDEO_DIRECTX9_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0;;DEBUGFAST" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;VIDEO_DIRECTX9_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0;;DEBUGFAST"
StringPooling="true" StringPooling="true"
ExceptionHandling="1" ExceptionHandling="1"
@ -614,10 +619,11 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="dsound.lib odbc32.lib odbccp32.lib comctl32.lib d3d9.lib d3dx9.lib winmm.lib" AdditionalDependencies="cg.lib cgD3D9.lib dsound.lib odbc32.lib odbccp32.lib comctl32.lib d3d9.lib d3dx9.lib winmm.lib"
OutputFile="..\..\..\Binary\x64\Plugins\Plugin_VideoDX9DF.dll" OutputFile="..\..\..\Binary\x64\Plugins\Plugin_VideoDX9DF.dll"
LinkIncremental="1" LinkIncremental="1"
SuppressStartupBanner="true" SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\..\..\Externals\Cg64"
GenerateManifest="false" GenerateManifest="false"
GenerateDebugInformation="true" GenerateDebugInformation="true"
ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb" ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb"

View File

@ -27,6 +27,9 @@
#include "BPMemory.h" #include "BPMemory.h"
#include "XFMemory.h" #include "XFMemory.h"
#include <Cg/cg.h>
#include <Cg/cgD3D9.h>
PixelShaderCache::PSCache PixelShaderCache::PixelShaders; PixelShaderCache::PSCache PixelShaderCache::PixelShaders;
void SetPSConstant4f(int const_number, float f1, float f2, float f3, float f4) void SetPSConstant4f(int const_number, float f1, float f2, float f3, float f4)
@ -58,7 +61,8 @@ void PixelShaderCache::SetShader()
if (D3D::GetShaderVersion() < 2) if (D3D::GetShaderVersion() < 2)
return; // we are screwed return; // we are screwed
static LPDIRECT3DPIXELSHADER9 lastShader = 0; //static LPDIRECT3DPIXELSHADER9 lastShader = 0;
static CGprogram lastShader = NULL;
DVSTARTPROFILE(); DVSTARTPROFILE();
PIXELSHADERUID uid; PIXELSHADERUID uid;
@ -73,14 +77,17 @@ void PixelShaderCache::SetShader()
PSCacheEntry &entry = iter->second; PSCacheEntry &entry = iter->second;
if (!lastShader || entry.shader != lastShader) if (!lastShader || entry.shader != lastShader)
{ {
D3D::dev->SetPixelShader(entry.shader); //D3D::dev->SetPixelShader(entry.shader);
cgD3D9LoadProgram(entry.shader, false, 0);
cgD3D9BindProgram(entry.shader);
lastShader = entry.shader; lastShader = entry.shader;
} }
return; return;
} }
const char *code = GeneratePixelShader(PixelShaderManager::GetTextureMask(), false, false); const char *code = GeneratePixelShader(PixelShaderManager::GetTextureMask(), false, false);
LPDIRECT3DPIXELSHADER9 shader = D3D::CompilePixelShader(code, (int)(strlen(code))); //LPDIRECT3DPIXELSHADER9 shader = D3D::CompilePixelShader(code, (int)(strlen(code)));
CGprogram shader = CompileCgShader(code);
if (shader) if (shader)
{ {
//Make an entry in the table //Make an entry in the table
@ -89,13 +96,48 @@ void PixelShaderCache::SetShader()
newentry.frameCount = frameCount; newentry.frameCount = frameCount;
PixelShaders[uid] = newentry; PixelShaders[uid] = newentry;
// There seems to be an unknown Cg error here for some reason
///PanicAlert("Load pShader");
cgD3D9LoadProgram(shader, false, 0);
cgD3D9BindProgram(shader);
///PanicAlert("Loaded pShader");
INCSTAT(stats.numPixelShadersCreated); INCSTAT(stats.numPixelShadersCreated);
SETSTAT(stats.numPixelShadersAlive, (int)PixelShaders.size()); SETSTAT(stats.numPixelShadersAlive, (int)PixelShaders.size());
} else
PanicAlert("Failed to compile Pixel Shader:\n\n%s", code);
//D3D::dev->SetPixelShader(shader);
}
CGprogram PixelShaderCache::CompileCgShader(const char *pstrprogram)
{
char stropt[64];
//sprintf(stropt, "MaxLocalParams=256,MaxInstructions=%d", s_nMaxVertexInstructions);
//const char *opts[] = {"-profileopts", stropt, "-O2", "-q", NULL};
const char **opts = cgD3D9GetOptimalOptions(g_cgvProf);
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgfProf, "main", opts);
if (!cgIsProgram(tempprog) || cgGetError() != CG_NO_ERROR) {
ERROR_LOG(VIDEO, "Failed to create ps %s:\n", cgGetLastListing(g_cgcontext));
ERROR_LOG(VIDEO, pstrprogram);
return false;
} }
D3D::dev->SetPixelShader(shader); // This looks evil - we modify the program through the const char * we got from cgGetProgramString!
// It SHOULD not have any nasty side effects though - but you never know...
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
char *plocal = strstr(pcompiledprog, "program.local");
while (plocal != NULL) {
const char *penv = " program.env";
memcpy(plocal, penv, 13);
plocal = strstr(plocal+13, "program.local");
}
return tempprog;
} }
void PixelShaderCache::Cleanup() void PixelShaderCache::Cleanup()
{ {
PSCache::iterator iter; PSCache::iterator iter;

View File

@ -25,6 +25,9 @@
#include "PixelShaderGen.h" #include "PixelShaderGen.h"
#include "VertexShaderGen.h" #include "VertexShaderGen.h"
#include <Cg/cg.h>
#include <Cg/cgD3D9.h>
typedef u32 tevhash; typedef u32 tevhash;
tevhash GetCurrentTEV(); tevhash GetCurrentTEV();
@ -33,7 +36,8 @@ class PixelShaderCache
{ {
struct PSCacheEntry struct PSCacheEntry
{ {
LPDIRECT3DPIXELSHADER9 shader; //LPDIRECT3DPIXELSHADER9 shader;
CGprogram shader;
int frameCount; int frameCount;
PSCacheEntry() PSCacheEntry()
@ -43,8 +47,12 @@ class PixelShaderCache
} }
void Destroy() void Destroy()
{ {
if (shader) if (shader) {
shader->Release(); cgD3D9UnloadProgram(shader);
cgDestroyProgram(shader);
// shader->Release();
}
} }
}; };
@ -57,6 +65,7 @@ public:
static void Cleanup(); static void Cleanup();
static void Shutdown(); static void Shutdown();
static void SetShader(); static void SetShader();
static CGprogram CompileCgShader(const char *pstrprogram);
}; };

View File

@ -38,6 +38,13 @@
#include "Utils.h" #include "Utils.h"
#include "EmuWindow.h" #include "EmuWindow.h"
#include <Cg/cg.h>
#include <Cg/cgD3D9.h>
CGcontext g_cgcontext;
CGprofile g_cgvProf;
CGprofile g_cgfProf;
float Renderer::m_x; float Renderer::m_x;
float Renderer::m_y; float Renderer::m_y;
float Renderer::m_width; float Renderer::m_width;
@ -64,6 +71,15 @@ struct Message
static std::list<Message> s_listMsgs; static std::list<Message> s_listMsgs;
void HandleCgError(CGcontext ctx, CGerror err, void* appdata)
{
PanicAlert("Cg error: %s\n", cgGetErrorString(err));
const char* listing = cgGetLastListing(g_cgcontext);
if (listing != NULL) {
PanicAlert("last listing: %s\n", listing);
}
}
void Renderer::Init(SVideoInitialize &_VideoInitialize) void Renderer::Init(SVideoInitialize &_VideoInitialize)
{ {
EmuWindow::SetSize(g_Res[g_Config.iWindowedRes][0], g_Res[g_Config.iWindowedRes][1]); EmuWindow::SetSize(g_Res[g_Config.iWindowedRes][0], g_Res[g_Config.iWindowedRes][1]);
@ -73,6 +89,15 @@ void Renderer::Init(SVideoInitialize &_VideoInitialize)
D3DVIEWPORT9 vp; D3DVIEWPORT9 vp;
D3D::dev->GetViewport(&vp); D3D::dev->GetViewport(&vp);
g_cgcontext = cgCreateContext();
cgGetError();
cgSetErrorHandler(HandleCgError, NULL);
cgD3D9SetDevice(D3D::dev);
g_cgvProf = cgD3D9GetLatestVertexProfile();
g_cgfProf = cgD3D9GetLatestPixelProfile();
m_x = 0; m_x = 0;
m_y = 0; m_y = 0;
m_width = (float)vp.Width; m_width = (float)vp.Width;
@ -104,6 +129,10 @@ void Renderer::Init(SVideoInitialize &_VideoInitialize)
void Renderer::Shutdown() void Renderer::Shutdown()
{ {
cgD3D9SetDevice(NULL);
cgDestroyContext(g_cgcontext);
g_cgcontext = NULL;
D3D::font.Shutdown(); D3D::font.Shutdown();
D3D::EndFrame(); D3D::EndFrame();
D3D::Close(); D3D::Close();

View File

@ -24,6 +24,11 @@
#include "pluginspecs_video.h" #include "pluginspecs_video.h"
#include "D3DBase.h" #include "D3DBase.h"
#include <Cg/cg.h>
extern CGcontext g_cgcontext;
extern CGprofile g_cgvProf, g_cgfProf;
class Renderer class Renderer
{ {
// screen offset // screen offset

View File

@ -27,6 +27,9 @@
#include "BPMemory.h" #include "BPMemory.h"
#include "XFMemory.h" #include "XFMemory.h"
#include <Cg/cg.h>
#include <Cg/cgD3D9.h>
VertexShaderCache::VSCache VertexShaderCache::vshaders; VertexShaderCache::VSCache VertexShaderCache::vshaders;
void SetVSConstant4f(int const_number, float f1, float f2, float f3, float f4) void SetVSConstant4f(int const_number, float f1, float f2, float f3, float f4)
@ -58,11 +61,11 @@ void VertexShaderCache::Shutdown()
void VertexShaderCache::SetShader(u32 components) void VertexShaderCache::SetShader(u32 components)
{ {
static LPDIRECT3DVERTEXSHADER9 shader = NULL; static CGprogram shader = NULL;
if (D3D::GetShaderVersion() < 2) if (D3D::GetShaderVersion() < 2)
return; // we are screwed return; // we are screwed
static LPDIRECT3DVERTEXSHADER9 lastShader = 0; static CGprogram lastShader = NULL;
DVSTARTPROFILE(); DVSTARTPROFILE();
VERTEXSHADERUID uid; VERTEXSHADERUID uid;
@ -77,14 +80,17 @@ void VertexShaderCache::SetShader(u32 components)
VSCacheEntry &entry = iter->second; VSCacheEntry &entry = iter->second;
if (!lastShader || entry.shader != lastShader) if (!lastShader || entry.shader != lastShader)
{ {
D3D::dev->SetVertexShader(entry.shader); //D3D::dev->SetVertexShader(entry.shader);
cgD3D9LoadProgram(entry.shader, false, 0);
cgD3D9BindProgram(entry.shader);
lastShader = entry.shader; lastShader = entry.shader;
} }
return; return;
} }
const char *code = GenerateVertexShader(components, false); const char *code = GenerateVertexShader(components, false);
shader = D3D::CompileVertexShader(code, (int)strlen(code)); //shader = D3D::CompileVertexShader(code, (int)strlen(code));
shader = CompileCgShader(code);
if (shader) if (shader)
{ {
//Make an entry in the table //Make an entry in the table
@ -92,12 +98,45 @@ void VertexShaderCache::SetShader(u32 components)
entry.shader = shader; entry.shader = shader;
entry.frameCount = frameCount; entry.frameCount = frameCount;
vshaders[uid] = entry; vshaders[uid] = entry;
// There seems to be an unknown Cg error here for some reason
///PanicAlert("Load vShader");
cgD3D9LoadProgram(shader, false, 0);
cgD3D9BindProgram(shader);
///PanicAlert("Loaded vShader");
INCSTAT(stats.numVertexShadersCreated);
SETSTAT(stats.numVertexShadersAlive, (int)vshaders.size());
} else
PanicAlert("Failed to compile Vertex Shader:\n\n%s", code);
//D3D::dev->SetVertexShader(shader);
}
CGprogram VertexShaderCache::CompileCgShader(const char *pstrprogram)
{
char stropt[64];
//sprintf(stropt, "MaxLocalParams=256,MaxInstructions=%d", s_nMaxVertexInstructions);
//const char *opts[] = {"-profileopts", stropt, "-O2", "-q", NULL};
const char **opts = cgD3D9GetOptimalOptions(g_cgvProf);
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgvProf, "main", opts);
if (!cgIsProgram(tempprog) || cgGetError() != CG_NO_ERROR) {
ERROR_LOG(VIDEO, "Failed to load vs %s:\n", cgGetLastListing(g_cgcontext));
ERROR_LOG(VIDEO, pstrprogram);
return NULL;
} }
D3D::dev->SetVertexShader(shader); // This looks evil - we modify the program through the const char * we got from cgGetProgramString!
// It SHOULD not have any nasty side effects though - but you never know...
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
char *plocal = strstr(pcompiledprog, "program.local");
while (plocal != NULL) {
const char* penv = " program.env";
memcpy(plocal, penv, 13);
plocal = strstr(plocal + 13, "program.local");
}
INCSTAT(stats.numVertexShadersCreated); return tempprog;
SETSTAT(stats.numVertexShadersAlive, (int)vshaders.size());
} }
void VertexShaderCache::Cleanup() void VertexShaderCache::Cleanup()

View File

@ -25,11 +25,15 @@
#include "D3DBase.h" #include "D3DBase.h"
#include "VertexShaderGen.h" #include "VertexShaderGen.h"
#include <Cg/cg.h>
#include <Cg/cgD3D9.h>
class VertexShaderCache class VertexShaderCache
{ {
struct VSCacheEntry struct VSCacheEntry
{ {
LPDIRECT3DVERTEXSHADER9 shader; //LPDIRECT3DVERTEXSHADER9 shader;
CGprogram shader;
int frameCount; int frameCount;
VSCacheEntry() VSCacheEntry()
{ {
@ -38,8 +42,11 @@ class VertexShaderCache
} }
void Destroy() void Destroy()
{ {
if (shader) if (shader) {
shader->Release(); cgD3D9UnloadProgram(shader);
cgDestroyProgram(shader);
// shader->Release();
}
} }
}; };
@ -52,6 +59,7 @@ public:
static void Cleanup(); static void Cleanup();
static void Shutdown(); static void Shutdown();
static void SetShader(u32 components); static void SetShader(u32 components);
static CGprogram CompileCgShader(const char *pstrprogram);
}; };
#endif // _VERTEXSHADERCACHE_H #endif // _VERTEXSHADERCACHE_H