mirror of
https://github.com/celisej567/cool-source-archive.git
synced 2025-12-31 17:48:37 +03:00
added shaderapidx9, raised shader constants and updated .gitignore
This commit is contained in:
328
.gitignore
vendored
328
.gitignore
vendored
@@ -1,38 +1,300 @@
|
||||
# Files to ignore when considering what GIT should commit.
|
||||
#Ignore my HL2 Install Directory
|
||||
/HL2_base/
|
||||
|
||||
# Visual Studio
|
||||
.vs/
|
||||
*.suo
|
||||
*.user
|
||||
*.sln.docstates
|
||||
*.obj
|
||||
*.pch
|
||||
*.tlog
|
||||
*.log
|
||||
*.scc
|
||||
*.exp
|
||||
*.ilk
|
||||
*.lastbuildstate
|
||||
vc100.pdb
|
||||
ipch
|
||||
*.sdf
|
||||
*.opensdf
|
||||
*.idb
|
||||
*.vcxproj
|
||||
*.filters
|
||||
*.vpc_crc
|
||||
*.sln
|
||||
#Ignore the sapi folder.
|
||||
src/utils/sapi51/
|
||||
|
||||
#Specifically Ignore Builds
|
||||
game/*/bin/
|
||||
game/bin/*.exe
|
||||
game/bin/*.dll
|
||||
game/bin/*/*.dll
|
||||
installer/files/hlvr/bin/
|
||||
installer/output/*.exe
|
||||
installer/output/*.zip
|
||||
|
||||
#Not Marulu's DLL
|
||||
!d3d9.dll
|
||||
|
||||
#Ignore list, made of the many untracked files
|
||||
game/*/cfg/config.cfg
|
||||
game/*/cfg/server_blacklist.txt
|
||||
game/*/gamestate.txt
|
||||
game/*/maps/graphs/
|
||||
game/*/save/
|
||||
game/*/screenshots/
|
||||
game/*/downloadlists/
|
||||
game/*/stats.txt
|
||||
game/*/voice_ban.dt
|
||||
src/game/client/Release_*/
|
||||
src/game/server/Release_*/
|
||||
mapdev/
|
||||
decompiled 0.42/
|
||||
*.sentinel
|
||||
|
||||
#Lib files that are generated by game.sln
|
||||
src/lib/public/mathlib.lib
|
||||
src/lib/public/raytrace.lib
|
||||
src/lib/public/tier1.lib
|
||||
src/lib/public/vgui_controls.lib
|
||||
|
||||
# OSX/Linux build products
|
||||
*.mak
|
||||
*.mak.vpc_crc
|
||||
*.xcodeproj/
|
||||
obj*/
|
||||
!devtools/*.mak
|
||||
!utils/smdlexp/smdlexp.mak
|
||||
|
||||
# Linux VPC products
|
||||
compile_commands.json
|
||||
*.project
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug_*/
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease_*/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
bld/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# DNX
|
||||
project.lock.json
|
||||
artifacts/
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# TODO: Comment the next line if you want to checkin your web deploy settings
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/packages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/packages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/packages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignoreable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
node_modules/
|
||||
orleans.codegen.cs
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# Solutions must be rebuilt by each user, per-machine
|
||||
*.vcxproj
|
||||
*.vcxproj.filters
|
||||
*.vcxproj.vpc_crc
|
||||
*.sln
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
176
materialsystem/shaderapidx9/ShaderShadowDx10.h
Normal file
176
materialsystem/shaderapidx9/ShaderShadowDx10.h
Normal file
@@ -0,0 +1,176 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERSHADOWDX10_H
|
||||
#define SHADERSHADOWDX10_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
#include "shaderapi/ishadershadow.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The empty shader shadow
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderShadowDx10 : public IShaderShadow
|
||||
{
|
||||
public:
|
||||
CShaderShadowDx10();
|
||||
virtual ~CShaderShadowDx10();
|
||||
|
||||
// Sets the default *shadow* state
|
||||
void SetDefaultState();
|
||||
|
||||
// Methods related to depth buffering
|
||||
void DepthFunc( ShaderDepthFunc_t depthFunc );
|
||||
void EnableDepthWrites( bool bEnable );
|
||||
void EnableDepthTest( bool bEnable );
|
||||
void EnablePolyOffset( PolygonOffsetMode_t nOffsetMode );
|
||||
|
||||
// Suppresses/activates color writing
|
||||
void EnableColorWrites( bool bEnable );
|
||||
void EnableAlphaWrites( bool bEnable );
|
||||
|
||||
// Methods related to alpha blending
|
||||
void EnableBlending( bool bEnable );
|
||||
void BlendFunc( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor );
|
||||
|
||||
// Alpha testing
|
||||
void EnableAlphaTest( bool bEnable );
|
||||
void AlphaFunc( ShaderAlphaFunc_t alphaFunc, float alphaRef /* [0-1] */ );
|
||||
|
||||
// Wireframe/filled polygons
|
||||
void PolyMode( ShaderPolyModeFace_t face, ShaderPolyMode_t polyMode );
|
||||
|
||||
// Back face culling
|
||||
void EnableCulling( bool bEnable );
|
||||
|
||||
// constant color + transparency
|
||||
void EnableConstantColor( bool bEnable );
|
||||
|
||||
// Indicates the vertex format for use with a vertex shader
|
||||
// The flags to pass in here come from the VertexFormatFlags_t enum
|
||||
// If pTexCoordDimensions is *not* specified, we assume all coordinates
|
||||
// are 2-dimensional
|
||||
void VertexShaderVertexFormat( unsigned int flags,
|
||||
int numTexCoords, int* pTexCoordDimensions,
|
||||
int userDataSize );
|
||||
|
||||
// Indicates we're going to light the model
|
||||
void EnableLighting( bool bEnable );
|
||||
void EnableSpecular( bool bEnable );
|
||||
|
||||
// vertex blending
|
||||
void EnableVertexBlend( bool bEnable );
|
||||
|
||||
// per texture unit stuff
|
||||
void OverbrightValue( TextureStage_t stage, float value );
|
||||
void EnableTexture( Sampler_t stage, bool bEnable );
|
||||
void EnableTexGen( TextureStage_t stage, bool bEnable );
|
||||
void TexGen( TextureStage_t stage, ShaderTexGenParam_t param );
|
||||
|
||||
// alternate method of specifying per-texture unit stuff, more flexible and more complicated
|
||||
// Can be used to specify different operation per channel (alpha/color)...
|
||||
void EnableCustomPixelPipe( bool bEnable );
|
||||
void CustomTextureStages( int stageCount );
|
||||
void CustomTextureOperation( TextureStage_t stage, ShaderTexChannel_t channel,
|
||||
ShaderTexOp_t op, ShaderTexArg_t arg1, ShaderTexArg_t arg2 );
|
||||
|
||||
// indicates what per-vertex data we're providing
|
||||
void DrawFlags( unsigned int drawFlags );
|
||||
|
||||
// A simpler method of dealing with alpha modulation
|
||||
void EnableAlphaPipe( bool bEnable );
|
||||
void EnableConstantAlpha( bool bEnable );
|
||||
void EnableVertexAlpha( bool bEnable );
|
||||
void EnableTextureAlpha( TextureStage_t stage, bool bEnable );
|
||||
|
||||
// GR - Separate alpha blending
|
||||
void EnableBlendingSeparateAlpha( bool bEnable );
|
||||
void BlendFuncSeparateAlpha( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor );
|
||||
|
||||
// Sets the vertex and pixel shaders
|
||||
void SetVertexShader( const char *pFileName, int vshIndex );
|
||||
void SetPixelShader( const char *pFileName, int pshIndex );
|
||||
|
||||
// Convert from linear to gamma color space on writes to frame buffer.
|
||||
void EnableSRGBWrite( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
void EnableSRGBRead( Sampler_t stage, bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
virtual void FogMode( ShaderFogMode_t fogMode )
|
||||
{
|
||||
}
|
||||
virtual void SetDiffuseMaterialSource( ShaderMaterialSource_t materialSource )
|
||||
{
|
||||
}
|
||||
|
||||
virtual void SetMorphFormat( MorphFormat_t flags )
|
||||
{
|
||||
}
|
||||
|
||||
virtual void EnableStencil( bool bEnable )
|
||||
{
|
||||
}
|
||||
virtual void StencilFunc( ShaderStencilFunc_t stencilFunc )
|
||||
{
|
||||
}
|
||||
virtual void StencilPassOp( ShaderStencilOp_t stencilOp )
|
||||
{
|
||||
}
|
||||
virtual void StencilFailOp( ShaderStencilOp_t stencilOp )
|
||||
{
|
||||
}
|
||||
virtual void StencilDepthFailOp( ShaderStencilOp_t stencilOp )
|
||||
{
|
||||
}
|
||||
virtual void StencilReference( int nReference )
|
||||
{
|
||||
}
|
||||
virtual void StencilMask( int nMask )
|
||||
{
|
||||
}
|
||||
virtual void StencilWriteMask( int nMask )
|
||||
{
|
||||
}
|
||||
|
||||
virtual void DisableFogGammaCorrection( bool bDisable )
|
||||
{
|
||||
//FIXME: empty for now.
|
||||
}
|
||||
virtual void FogMode( ShaderFogMode_t fogMode, bool bVertexFog )
|
||||
{
|
||||
//FIXME: empty for now.
|
||||
}
|
||||
|
||||
// Alpha to coverage
|
||||
void EnableAlphaToCoverage( bool bEnable );
|
||||
|
||||
void SetShadowDepthFiltering( Sampler_t stage );
|
||||
|
||||
// More alpha blending state
|
||||
void BlendOp( ShaderBlendOp_t blendOp );
|
||||
void BlendOpSeparateAlpha( ShaderBlendOp_t blendOp );
|
||||
|
||||
bool m_IsTranslucent;
|
||||
bool m_IsAlphaTested;
|
||||
bool m_bIsDepthWriteEnabled;
|
||||
bool m_bUsesVertexAndPixelShaders;
|
||||
};
|
||||
|
||||
|
||||
extern CShaderShadowDx10* g_pShaderShadowDx10;
|
||||
|
||||
#endif // SHADERSHADOWDX10_H
|
||||
1924
materialsystem/shaderapidx9/TransitionTable.cpp
Normal file
1924
materialsystem/shaderapidx9/TransitionTable.cpp
Normal file
File diff suppressed because it is too large
Load Diff
407
materialsystem/shaderapidx9/TransitionTable.h
Normal file
407
materialsystem/shaderapidx9/TransitionTable.h
Normal file
@@ -0,0 +1,407 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef TRANSITION_TABLE_H
|
||||
#define TRANSITION_TABLE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "utlvector.h"
|
||||
#include "shadershadowdx8.h"
|
||||
#include "UtlSortVector.h"
|
||||
#include "checksum_crc.h"
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
|
||||
// Required for DEBUG_BOARD_STATE
|
||||
#include "shaderapidx8_global.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
struct IDirect3DStateBlock9;
|
||||
//-----------------------------------------------------------------------------
|
||||
// Enumeration for ApplyStateFunc_ts
|
||||
//-----------------------------------------------------------------------------
|
||||
// Any function that does not require a texture stage
|
||||
// NOTE: If you change this, change the function table s_pRenderFunctionTable[] below!!
|
||||
enum RenderStateFunc_t
|
||||
{
|
||||
RENDER_STATE_DepthTest = 0,
|
||||
RENDER_STATE_ZWriteEnable,
|
||||
RENDER_STATE_ColorWriteEnable,
|
||||
RENDER_STATE_AlphaTest,
|
||||
RENDER_STATE_FillMode,
|
||||
RENDER_STATE_Lighting,
|
||||
RENDER_STATE_SpecularEnable,
|
||||
RENDER_STATE_SRGBWriteEnable,
|
||||
RENDER_STATE_AlphaBlend,
|
||||
RENDER_STATE_SeparateAlphaBlend,
|
||||
RENDER_STATE_CullEnable,
|
||||
RENDER_STATE_VertexBlendEnable,
|
||||
RENDER_STATE_FogMode,
|
||||
RENDER_STATE_ActivateFixedFunction,
|
||||
RENDER_STATE_TextureEnable,
|
||||
RENDER_STATE_DiffuseMaterialSource,
|
||||
RENDER_STATE_DisableFogGammaCorrection,
|
||||
RENDER_STATE_EnableAlphaToCoverage,
|
||||
|
||||
RENDER_STATE_COUNT,
|
||||
};
|
||||
|
||||
|
||||
// Any function that requires a texture stage
|
||||
// NOTE: If you change this, change the function table s_pTextureFunctionTable[] below!!
|
||||
enum TextureStateFunc_t
|
||||
{
|
||||
TEXTURE_STATE_TexCoordIndex = 0,
|
||||
TEXTURE_STATE_SRGBReadEnable,
|
||||
TEXTURE_STATE_Fetch4Enable,
|
||||
#ifdef DX_TO_GL_ABSTRACTION
|
||||
TEXTURE_STATE_ShadowFilterEnable,
|
||||
#endif
|
||||
// Fixed function states
|
||||
TEXTURE_STATE_ColorTextureStage,
|
||||
TEXTURE_STATE_AlphaTextureStage,
|
||||
TEXTURE_STATE_COUNT
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Types related to transition table entries
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef void (*ApplyStateFunc_t)( const ShadowState_t& shadowState, int arg );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The DX8 implementation of the transition table
|
||||
//-----------------------------------------------------------------------------
|
||||
class CTransitionTable
|
||||
{
|
||||
public:
|
||||
struct CurrentTextureStageState_t
|
||||
{
|
||||
D3DTEXTUREOP m_ColorOp;
|
||||
int m_ColorArg1;
|
||||
int m_ColorArg2;
|
||||
D3DTEXTUREOP m_AlphaOp;
|
||||
int m_AlphaArg1;
|
||||
int m_AlphaArg2;
|
||||
};
|
||||
struct CurrentSamplerState_t
|
||||
{
|
||||
bool m_SRGBReadEnable;
|
||||
bool m_Fetch4Enable;
|
||||
bool m_ShadowFilterEnable;
|
||||
};
|
||||
struct CurrentState_t
|
||||
{
|
||||
// Everything in this 'CurrentState' structure is a state whose value we don't care about
|
||||
// under certain circumstances, (which therefore can diverge from the shadow state),
|
||||
// or states which we override in the dynamic pass.
|
||||
|
||||
// Alpha state
|
||||
bool m_AlphaBlendEnable;
|
||||
D3DBLEND m_SrcBlend;
|
||||
D3DBLEND m_DestBlend;
|
||||
D3DBLENDOP m_BlendOp;
|
||||
|
||||
// GR - Separate alpha state
|
||||
bool m_SeparateAlphaBlendEnable;
|
||||
D3DBLEND m_SrcBlendAlpha;
|
||||
D3DBLEND m_DestBlendAlpha;
|
||||
D3DBLENDOP m_BlendOpAlpha;
|
||||
|
||||
// Depth testing states
|
||||
D3DZBUFFERTYPE m_ZEnable;
|
||||
D3DCMPFUNC m_ZFunc;
|
||||
PolygonOffsetMode_t m_ZBias;
|
||||
|
||||
// Alpha testing states
|
||||
bool m_AlphaTestEnable;
|
||||
D3DCMPFUNC m_AlphaFunc;
|
||||
int m_AlphaRef;
|
||||
|
||||
bool m_ForceDepthFuncEquals;
|
||||
bool m_bOverrideDepthEnable;
|
||||
D3DZBUFFERTYPE m_OverrideZWriteEnable;
|
||||
|
||||
bool m_bOverrideAlphaWriteEnable;
|
||||
bool m_bOverriddenAlphaWriteValue;
|
||||
bool m_bOverrideColorWriteEnable;
|
||||
bool m_bOverriddenColorWriteValue;
|
||||
DWORD m_ColorWriteEnable;
|
||||
|
||||
bool m_bLinearColorSpaceFrameBufferEnable;
|
||||
|
||||
bool m_StencilEnable;
|
||||
D3DCMPFUNC m_StencilFunc;
|
||||
int m_StencilRef;
|
||||
int m_StencilMask;
|
||||
DWORD m_StencilFail;
|
||||
DWORD m_StencilZFail;
|
||||
DWORD m_StencilPass;
|
||||
int m_StencilWriteMask;
|
||||
|
||||
// Texture stage state
|
||||
CurrentTextureStageState_t m_TextureStage[MAX_TEXTURE_STAGES];
|
||||
CurrentSamplerState_t m_SamplerState[MAX_SAMPLERS];
|
||||
};
|
||||
|
||||
public:
|
||||
// constructor, destructor
|
||||
CTransitionTable( );
|
||||
virtual ~CTransitionTable();
|
||||
|
||||
// Initialization, shutdown
|
||||
bool Init( );
|
||||
void Shutdown( );
|
||||
|
||||
// Resets the snapshots...
|
||||
void Reset();
|
||||
|
||||
// Takes a snapshot
|
||||
StateSnapshot_t TakeSnapshot( );
|
||||
|
||||
// Take startup snapshot
|
||||
void TakeDefaultStateSnapshot( );
|
||||
|
||||
// Makes the board state match the snapshot
|
||||
void UseSnapshot( StateSnapshot_t snapshotId );
|
||||
|
||||
// Cause the board to match the default state snapshot
|
||||
void UseDefaultState();
|
||||
|
||||
// Snapshotted state overrides
|
||||
void ForceDepthFuncEquals( bool bEnable );
|
||||
void OverrideDepthEnable( bool bEnable, bool bDepthEnable );
|
||||
void OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable );
|
||||
void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable );
|
||||
void EnableLinearColorSpaceFrameBuffer( bool bEnable );
|
||||
|
||||
// Returns a particular snapshot
|
||||
const ShadowState_t &GetSnapshot( StateSnapshot_t snapshotId ) const;
|
||||
const ShadowShaderState_t &GetSnapshotShader( StateSnapshot_t snapshotId ) const;
|
||||
|
||||
// Gets the current shadow state
|
||||
const ShadowState_t *CurrentShadowState() const;
|
||||
const ShadowShaderState_t *CurrentShadowShaderState() const;
|
||||
|
||||
// Return the current shapshot
|
||||
int CurrentSnapshot() const { return m_CurrentSnapshotId; }
|
||||
|
||||
CurrentState_t& CurrentState() { return m_CurrentState; }
|
||||
|
||||
#ifdef DEBUG_BOARD_STATE
|
||||
ShadowState_t& BoardState() { return m_BoardState; }
|
||||
ShadowShaderState_t& BoardShaderState() { return m_BoardShaderState; }
|
||||
#endif
|
||||
|
||||
// The following are meant to be used by the transition table only
|
||||
public:
|
||||
// Applies alpha blending
|
||||
void ApplyAlphaBlend( const ShadowState_t& state );
|
||||
// GR - separate alpha blend
|
||||
void ApplySeparateAlphaBlend( const ShadowState_t& state );
|
||||
void ApplyAlphaTest( const ShadowState_t& state );
|
||||
void ApplyDepthTest( const ShadowState_t& state );
|
||||
|
||||
// Applies alpha texture op
|
||||
void ApplyColorTextureStage( const ShadowState_t& state, int stage );
|
||||
void ApplyAlphaTextureStage( const ShadowState_t& state, int stage );
|
||||
|
||||
void ApplySRGBWriteEnable( const ShadowState_t& state );
|
||||
private:
|
||||
enum
|
||||
{
|
||||
INVALID_TRANSITION_OP = 0xFFFFFF
|
||||
};
|
||||
|
||||
typedef short ShadowStateId_t;
|
||||
|
||||
// For the transition table
|
||||
struct TransitionList_t
|
||||
{
|
||||
unsigned int m_FirstOperation : 24;
|
||||
unsigned int m_NumOperations : 8;
|
||||
};
|
||||
|
||||
union TransitionOp_t
|
||||
{
|
||||
unsigned char m_nBits;
|
||||
struct
|
||||
{
|
||||
unsigned char m_nOpCode : 7;
|
||||
unsigned char m_bIsTextureCode : 1;
|
||||
} m_nInfo;
|
||||
};
|
||||
|
||||
struct SnapshotShaderState_t
|
||||
{
|
||||
ShadowShaderState_t m_ShaderState;
|
||||
ShadowStateId_t m_ShadowStateId;
|
||||
unsigned short m_nReserved; // Pad to 2 ints
|
||||
unsigned int m_nReserved2;
|
||||
};
|
||||
|
||||
struct ShadowStateDictEntry_t
|
||||
{
|
||||
CRC32_t m_nChecksum;
|
||||
ShadowStateId_t m_nShadowStateId;
|
||||
};
|
||||
|
||||
struct SnapshotDictEntry_t
|
||||
{
|
||||
CRC32_t m_nChecksum;
|
||||
StateSnapshot_t m_nSnapshot;
|
||||
};
|
||||
|
||||
class ShadowStateDictLessFunc
|
||||
{
|
||||
public:
|
||||
bool Less( const ShadowStateDictEntry_t &src1, const ShadowStateDictEntry_t &src2, void *pCtx );
|
||||
};
|
||||
|
||||
class SnapshotDictLessFunc
|
||||
{
|
||||
public:
|
||||
bool Less( const SnapshotDictEntry_t &src1, const SnapshotDictEntry_t &src2, void *pCtx );
|
||||
};
|
||||
|
||||
class UniqueSnapshotLessFunc
|
||||
{
|
||||
public:
|
||||
bool Less( const TransitionList_t &src1, const TransitionList_t &src2, void *pCtx );
|
||||
};
|
||||
|
||||
CurrentTextureStageState_t &TextureStage( int stage ) { return m_CurrentState.m_TextureStage[stage]; }
|
||||
const CurrentTextureStageState_t &TextureStage( int stage ) const { return m_CurrentState.m_TextureStage[stage]; }
|
||||
|
||||
CurrentSamplerState_t &SamplerState( int stage ) { return m_CurrentState.m_SamplerState[stage]; }
|
||||
const CurrentSamplerState_t &SamplerState( int stage ) const { return m_CurrentState.m_SamplerState[stage]; }
|
||||
|
||||
// creates state snapshots
|
||||
ShadowStateId_t CreateShadowState( const ShadowState_t ¤tState );
|
||||
StateSnapshot_t CreateStateSnapshot( ShadowStateId_t shadowStateId, const ShadowShaderState_t& currentShaderState );
|
||||
|
||||
// finds state snapshots
|
||||
ShadowStateId_t FindShadowState( const ShadowState_t& currentState ) const;
|
||||
StateSnapshot_t FindStateSnapshot( ShadowStateId_t id, const ShadowShaderState_t& currentState ) const;
|
||||
|
||||
// Finds identical transition lists
|
||||
unsigned int FindIdenticalTransitionList( unsigned int firstElem,
|
||||
unsigned short numOps, unsigned int nFirstTest ) const;
|
||||
|
||||
// Adds a transition
|
||||
void AddTransition( RenderStateFunc_t func );
|
||||
void AddTextureTransition( TextureStateFunc_t func, int stage );
|
||||
|
||||
// Apply a transition
|
||||
void ApplyTransition( TransitionList_t& list, int snapshot );
|
||||
|
||||
// Creates an entry in the transition table
|
||||
void CreateTransitionTableEntry( int to, int from );
|
||||
|
||||
// Checks if a state is valid
|
||||
bool TestShadowState( const ShadowState_t& state, const ShadowShaderState_t &shaderState );
|
||||
|
||||
// Perform state block overrides
|
||||
void PerformShadowStateOverrides( );
|
||||
|
||||
// Applies the transition list
|
||||
void ApplyTransitionList( int snapshot, int nFirstOp, int nOpCount );
|
||||
|
||||
// Apply shader state (stuff that doesn't lie in the transition table)
|
||||
void ApplyShaderState( const ShadowState_t &shadowState, const ShadowShaderState_t &shaderState );
|
||||
|
||||
// Wrapper for the non-standard transitions for stateblock + non-stateblock cases
|
||||
int CreateNormalTransitions( const ShadowState_t& fromState, const ShadowState_t& toState, bool bForce );
|
||||
|
||||
// State setting methods
|
||||
void SetZEnable( D3DZBUFFERTYPE nEnable );
|
||||
void SetZFunc( D3DCMPFUNC nCmpFunc );
|
||||
|
||||
private:
|
||||
// Sets up the default state
|
||||
StateSnapshot_t m_DefaultStateSnapshot;
|
||||
TransitionList_t m_DefaultTransition;
|
||||
ShadowState_t m_DefaultShadowState;
|
||||
|
||||
// The current snapshot id
|
||||
ShadowStateId_t m_CurrentShadowId;
|
||||
StateSnapshot_t m_CurrentSnapshotId;
|
||||
|
||||
// Maintains a list of all used snapshot transition states
|
||||
CUtlVector< ShadowState_t > m_ShadowStateList;
|
||||
|
||||
// Lookup table for fast snapshot finding
|
||||
CUtlSortVector< ShadowStateDictEntry_t, ShadowStateDictLessFunc > m_ShadowStateDict;
|
||||
|
||||
// The snapshot transition table
|
||||
CUtlVector< CUtlVector< TransitionList_t > > m_TransitionTable;
|
||||
|
||||
// List of unique transitions
|
||||
CUtlSortVector< TransitionList_t, UniqueSnapshotLessFunc > m_UniqueTransitions;
|
||||
|
||||
// Stores all state transition operations
|
||||
CUtlVector< TransitionOp_t > m_TransitionOps;
|
||||
|
||||
// Stores all state for a particular snapshot
|
||||
CUtlVector< SnapshotShaderState_t > m_SnapshotList;
|
||||
|
||||
// Lookup table for fast snapshot finding
|
||||
CUtlSortVector< SnapshotDictEntry_t, SnapshotDictLessFunc > m_SnapshotDict;
|
||||
|
||||
// The current board state.
|
||||
CurrentState_t m_CurrentState;
|
||||
|
||||
#ifdef DEBUG_BOARD_STATE
|
||||
// Maintains the total shadow state
|
||||
ShadowState_t m_BoardState;
|
||||
ShadowShaderState_t m_BoardShaderState;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inline methods
|
||||
//-----------------------------------------------------------------------------
|
||||
inline const ShadowState_t &CTransitionTable::GetSnapshot( StateSnapshot_t snapshotId ) const
|
||||
{
|
||||
Assert( (snapshotId >= 0) && (snapshotId < m_SnapshotList.Count()) );
|
||||
return m_ShadowStateList[m_SnapshotList[snapshotId].m_ShadowStateId];
|
||||
}
|
||||
|
||||
inline const ShadowShaderState_t &CTransitionTable::GetSnapshotShader( StateSnapshot_t snapshotId ) const
|
||||
{
|
||||
Assert( (snapshotId >= 0) && (snapshotId < m_SnapshotList.Count()) );
|
||||
return m_SnapshotList[snapshotId].m_ShaderState;
|
||||
}
|
||||
|
||||
inline const ShadowState_t *CTransitionTable::CurrentShadowState() const
|
||||
{
|
||||
if ( m_CurrentShadowId == -1 )
|
||||
return NULL;
|
||||
|
||||
Assert( (m_CurrentShadowId >= 0) && (m_CurrentShadowId < m_ShadowStateList.Count()) );
|
||||
return &m_ShadowStateList[m_CurrentShadowId];
|
||||
}
|
||||
|
||||
inline const ShadowShaderState_t *CTransitionTable::CurrentShadowShaderState() const
|
||||
{
|
||||
if ( m_CurrentShadowId == -1 )
|
||||
return NULL;
|
||||
|
||||
Assert( (m_CurrentShadowId >= 0) && (m_CurrentShadowId < m_ShadowStateList.Count()) );
|
||||
return &m_SnapshotList[m_CurrentShadowId].m_ShaderState;
|
||||
}
|
||||
|
||||
|
||||
#endif // TRANSITION_TABLE_H
|
||||
727
materialsystem/shaderapidx9/colorformatdx8.cpp
Normal file
727
materialsystem/shaderapidx9/colorformatdx8.cpp
Normal file
@@ -0,0 +1,727 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#define DISABLE_PROTECTED_THINGS
|
||||
#include "togl/rendermechanism.h"
|
||||
#include "locald3dtypes.h"
|
||||
#include "colorformatdx8.h"
|
||||
#include "shaderapidx8_global.h"
|
||||
#include "bitmap/imageformat.h"
|
||||
#include "shaderapi/ishaderutil.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "tier1/strtools.h"
|
||||
#include "shaderdevicedx8.h"
|
||||
|
||||
|
||||
// Must be last
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Figures out what texture formats we support
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// globals
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Texture formats supported by DX driver[vertextexture][render target][non filterable]
|
||||
static D3DFORMAT g_D3DColorFormat[NUM_IMAGE_FORMATS][2][2][2];
|
||||
static UINT g_DisplayAdapter;
|
||||
static D3DDEVTYPE g_DeviceType;
|
||||
static ImageFormat g_DeviceFormat;
|
||||
static bool g_bSupportsD24S8;
|
||||
static bool g_bSupportsD24X8;
|
||||
static bool g_bSupportsD16;
|
||||
static bool g_bSupportsD24X4S4;
|
||||
static bool g_bSupportsD15S1;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Determines what formats we actually *do* support
|
||||
//-----------------------------------------------------------------------------
|
||||
static bool TestTextureFormat( D3DFORMAT format, bool bIsRenderTarget,
|
||||
bool bIsVertexTexture, bool bIsFilterableRequired )
|
||||
{
|
||||
int nUsage = bIsRenderTarget ? D3DUSAGE_RENDERTARGET : 0;
|
||||
if ( bIsVertexTexture )
|
||||
{
|
||||
// vertex textures never need filtering
|
||||
nUsage |= D3DUSAGE_QUERY_VERTEXTEXTURE;
|
||||
}
|
||||
if ( bIsFilterableRequired )
|
||||
{
|
||||
nUsage |= D3DUSAGE_QUERY_FILTER;
|
||||
}
|
||||
|
||||
HRESULT hr;
|
||||
|
||||
// IHV depth texture formats require a slightly different check...
|
||||
if ( !IsX360() && bIsRenderTarget && ( ( format == NVFMT_RAWZ ) || ( format == NVFMT_INTZ ) ||
|
||||
( format == D3DFMT_D16 ) || ( format == D3DFMT_D24S8 ) ||
|
||||
( format == ATIFMT_D16 ) || ( format == ATIFMT_D24S8 ) ) )
|
||||
{
|
||||
hr = D3D()->CheckDeviceFormat(
|
||||
g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ),
|
||||
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, format );
|
||||
}
|
||||
else if ( !IsX360() || !bIsRenderTarget )
|
||||
{
|
||||
// See if we can do it!
|
||||
hr = D3D()->CheckDeviceFormat(
|
||||
g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ),
|
||||
nUsage, D3DRTYPE_TEXTURE, format );
|
||||
}
|
||||
else // 360
|
||||
{
|
||||
// 360 can only validate render targets as surface display format
|
||||
hr = D3D()->CheckDeviceFormat( g_DisplayAdapter, g_DeviceType, format, 0, D3DRTYPE_SURFACE, format );
|
||||
}
|
||||
|
||||
return SUCCEEDED( hr );
|
||||
}
|
||||
|
||||
D3DFORMAT GetNearestD3DColorFormat( ImageFormat fmt,
|
||||
bool isRenderTarget, bool bIsVertexTexture,
|
||||
bool bIsFilterableRequired)
|
||||
{
|
||||
switch(fmt)
|
||||
{
|
||||
case IMAGE_FORMAT_RGBA8888:
|
||||
case IMAGE_FORMAT_ABGR8888:
|
||||
case IMAGE_FORMAT_ARGB8888:
|
||||
case IMAGE_FORMAT_BGRA8888:
|
||||
if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8R8G8B8;
|
||||
if (TestTextureFormat(D3DFMT_A4R4G4B4, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A4R4G4B4;
|
||||
break;
|
||||
|
||||
#if defined( _X360 )
|
||||
case IMAGE_FORMAT_LINEAR_RGBA8888:
|
||||
case IMAGE_FORMAT_LINEAR_ABGR8888:
|
||||
case IMAGE_FORMAT_LINEAR_ARGB8888:
|
||||
case IMAGE_FORMAT_LINEAR_BGRA8888:
|
||||
// same as above - all xxxx8888 RGBA ordering funnels to d3d a8r8g8b8
|
||||
if ( TestTextureFormat( D3DFMT_LIN_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_LIN_A8R8G8B8;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined( _X360 )
|
||||
case IMAGE_FORMAT_LINEAR_BGRX8888:
|
||||
if ( TestTextureFormat( D3DFMT_LIN_X8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_LIN_X8R8G8B8;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case IMAGE_FORMAT_BGRX8888:
|
||||
// We want this format to return exactly it's equivalent so that
|
||||
// when we create render targets to blit to from the framebuffer,
|
||||
// the CopyRect won't fail due to format mismatches.
|
||||
if (TestTextureFormat(D3DFMT_X8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_X8R8G8B8;
|
||||
|
||||
// fall through. . . .
|
||||
case IMAGE_FORMAT_RGB888:
|
||||
case IMAGE_FORMAT_BGR888:
|
||||
#if !defined( _X360 )
|
||||
if (TestTextureFormat(D3DFMT_R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_R8G8B8;
|
||||
#endif
|
||||
if (TestTextureFormat(D3DFMT_X8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_X8R8G8B8;
|
||||
if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8R8G8B8;
|
||||
if (TestTextureFormat(D3DFMT_R5G6B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_R5G6B5;
|
||||
if (TestTextureFormat(D3DFMT_X1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_X1R5G5B5;
|
||||
if (TestTextureFormat(D3DFMT_A1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A1R5G5B5;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_BGR565:
|
||||
case IMAGE_FORMAT_RGB565:
|
||||
if (TestTextureFormat(D3DFMT_R5G6B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_R5G6B5;
|
||||
if (TestTextureFormat(D3DFMT_X1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_X1R5G5B5;
|
||||
if (TestTextureFormat(D3DFMT_A1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A1R5G5B5;
|
||||
#if !defined( _X360 )
|
||||
if (TestTextureFormat(D3DFMT_R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_R8G8B8;
|
||||
#endif
|
||||
if (TestTextureFormat(D3DFMT_X8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_X8R8G8B8;
|
||||
if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8R8G8B8;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_BGRX5551:
|
||||
if (TestTextureFormat(D3DFMT_X1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_X1R5G5B5;
|
||||
if (TestTextureFormat(D3DFMT_A1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A1R5G5B5;
|
||||
if (TestTextureFormat(D3DFMT_R5G6B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_R5G6B5;
|
||||
#if !defined( _X360 )
|
||||
if (TestTextureFormat(D3DFMT_R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_R8G8B8;
|
||||
#endif
|
||||
if (TestTextureFormat(D3DFMT_X8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_X8R8G8B8;
|
||||
if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8R8G8B8;
|
||||
break;
|
||||
|
||||
#if defined( _X360 )
|
||||
case IMAGE_FORMAT_LINEAR_BGRX5551:
|
||||
if ( TestTextureFormat( D3DFMT_LIN_X1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_LIN_X1R5G5B5;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case IMAGE_FORMAT_BGRA5551:
|
||||
if (TestTextureFormat(D3DFMT_A1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A1R5G5B5;
|
||||
if (TestTextureFormat(D3DFMT_A4R4G4B4, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A4R4G4B4;
|
||||
if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8R8G8B8;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_BGRA4444:
|
||||
if (TestTextureFormat(D3DFMT_A4R4G4B4, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A4R4G4B4;
|
||||
if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8R8G8B8;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_I8:
|
||||
if (TestTextureFormat(D3DFMT_L8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_L8;
|
||||
if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8R8G8B8;
|
||||
break;
|
||||
|
||||
#if defined( _X360 )
|
||||
case IMAGE_FORMAT_LINEAR_I8:
|
||||
if ( TestTextureFormat( D3DFMT_LIN_L8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_LIN_L8;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case IMAGE_FORMAT_IA88:
|
||||
if (TestTextureFormat(D3DFMT_A8L8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8L8;
|
||||
if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8R8G8B8;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_A8:
|
||||
if (TestTextureFormat(D3DFMT_A8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8;
|
||||
if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8R8G8B8;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_DXT1:
|
||||
case IMAGE_FORMAT_DXT1_ONEBITALPHA:
|
||||
case IMAGE_FORMAT_DXT1_RUNTIME:
|
||||
if (TestTextureFormat(D3DFMT_DXT1, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_DXT1;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_DXT3:
|
||||
if (TestTextureFormat(D3DFMT_DXT3, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ))
|
||||
return D3DFMT_DXT3;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_DXT5:
|
||||
case IMAGE_FORMAT_DXT5_RUNTIME:
|
||||
if (TestTextureFormat(D3DFMT_DXT5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ))
|
||||
return D3DFMT_DXT5;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_UV88:
|
||||
if (TestTextureFormat(D3DFMT_V8U8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ))
|
||||
return D3DFMT_V8U8;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_UVWQ8888:
|
||||
if (TestTextureFormat(D3DFMT_Q8W8V8U8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ))
|
||||
return D3DFMT_Q8W8V8U8;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_UVLX8888:
|
||||
if (TestTextureFormat(D3DFMT_X8L8V8U8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ))
|
||||
return D3DFMT_X8L8V8U8;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_RGBA16161616F:
|
||||
if ( TestTextureFormat( D3DFMT_A16B16G16R16F, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_A16B16G16R16F;
|
||||
if ( TestTextureFormat( D3DFMT_A16B16G16R16, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_A16B16G16R16;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_RGBA16161616:
|
||||
if ( TestTextureFormat( D3DFMT_A16B16G16R16, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_A16B16G16R16;
|
||||
if ( TestTextureFormat( D3DFMT_A16B16G16R16F, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_A16B16G16R16F;
|
||||
break;
|
||||
|
||||
#if defined( _X360 )
|
||||
case IMAGE_FORMAT_LINEAR_RGBA16161616:
|
||||
if ( TestTextureFormat( D3DFMT_LIN_A16B16G16R16, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_LIN_A16B16G16R16;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case IMAGE_FORMAT_R32F:
|
||||
if ( TestTextureFormat( D3DFMT_R32F, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_R32F;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_RGBA32323232F:
|
||||
if ( TestTextureFormat( D3DFMT_A32B32G32R32F, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_A32B32G32R32F;
|
||||
break;
|
||||
|
||||
#if defined( _X360 )
|
||||
case IMAGE_FORMAT_X360_DST16:
|
||||
return D3DFMT_D16;
|
||||
|
||||
case IMAGE_FORMAT_X360_DST24:
|
||||
return D3DFMT_D24S8;
|
||||
|
||||
case IMAGE_FORMAT_X360_DST24F:
|
||||
return D3DFMT_D24FS8;
|
||||
|
||||
case IMAGE_FORMAT_LE_BGRX8888:
|
||||
return D3DFMT_LE_X8R8G8B8;
|
||||
|
||||
case IMAGE_FORMAT_LE_BGRA8888:
|
||||
return D3DFMT_LE_A8R8G8B8;
|
||||
#endif
|
||||
|
||||
// nVidia overloads DST formats as texture formats
|
||||
case IMAGE_FORMAT_NV_DST16:
|
||||
if ( TestTextureFormat( D3DFMT_D16, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_D16;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_NV_DST24:
|
||||
if ( TestTextureFormat( D3DFMT_D24S8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_D24S8;
|
||||
break;
|
||||
case IMAGE_FORMAT_NV_INTZ:
|
||||
if ( TestTextureFormat( NVFMT_INTZ, isRenderTarget, bIsVertexTexture, false ) )
|
||||
return NVFMT_INTZ;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_NV_RAWZ:
|
||||
if ( TestTextureFormat( NVFMT_RAWZ, isRenderTarget, bIsVertexTexture, false ) )
|
||||
return NVFMT_RAWZ;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_NV_NULL:
|
||||
if ( TestTextureFormat( NVFMT_NULL, isRenderTarget, bIsVertexTexture, false ) )
|
||||
return NVFMT_NULL;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_ATI_DST16:
|
||||
if ( TestTextureFormat( ATIFMT_D16, isRenderTarget, bIsVertexTexture, false ) )
|
||||
return ATIFMT_D16;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_ATI_DST24:
|
||||
if ( TestTextureFormat( ATIFMT_D24S8, isRenderTarget, bIsVertexTexture, false ) )
|
||||
return ATIFMT_D24S8;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_ATI2N:
|
||||
if ( TestTextureFormat( ATIFMT_ATI2N, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return ATIFMT_ATI2N;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_ATI1N:
|
||||
if ( TestTextureFormat( ATIFMT_ATI1N, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return ATIFMT_ATI1N;
|
||||
break;
|
||||
}
|
||||
|
||||
return D3DFMT_UNKNOWN;
|
||||
}
|
||||
|
||||
void InitializeColorInformation( UINT displayAdapter, D3DDEVTYPE deviceType,
|
||||
ImageFormat displayFormat )
|
||||
{
|
||||
g_DisplayAdapter = displayAdapter;
|
||||
g_DeviceType = deviceType;
|
||||
g_DeviceFormat = displayFormat;
|
||||
|
||||
int fmt = 0;
|
||||
while ( fmt < NUM_IMAGE_FORMATS )
|
||||
{
|
||||
for ( int nVertexTexture = 0; nVertexTexture <= 1; ++nVertexTexture )
|
||||
{
|
||||
for ( int nRenderTarget = 0; nRenderTarget <= 1; ++nRenderTarget )
|
||||
{
|
||||
for ( int nFilterable = 0; nFilterable <= 1; ++nFilterable )
|
||||
{
|
||||
g_D3DColorFormat[fmt][nVertexTexture][nRenderTarget][nFilterable] =
|
||||
GetNearestD3DColorFormat( (ImageFormat)fmt, nRenderTarget != 0, nVertexTexture != 0, nFilterable != 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
++fmt;
|
||||
}
|
||||
|
||||
// Check the depth formats
|
||||
HRESULT hr = D3D()->CheckDeviceFormat(
|
||||
g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ),
|
||||
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24S8 );
|
||||
g_bSupportsD24S8 = !FAILED(hr);
|
||||
|
||||
hr = D3D()->CheckDeviceFormat(
|
||||
g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ),
|
||||
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X8 );
|
||||
g_bSupportsD24X8 = !FAILED(hr);
|
||||
|
||||
hr = D3D()->CheckDeviceFormat(
|
||||
g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ),
|
||||
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16 );
|
||||
g_bSupportsD16 = !FAILED(hr);
|
||||
|
||||
#if !defined( _X360 )
|
||||
hr = D3D()->CheckDeviceFormat(
|
||||
g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ),
|
||||
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X4S4 );
|
||||
g_bSupportsD24X4S4 = !FAILED(hr);
|
||||
#else
|
||||
g_bSupportsD24X4S4 = false;
|
||||
#endif
|
||||
|
||||
#if !defined( _X360 )
|
||||
hr = D3D()->CheckDeviceFormat(
|
||||
g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ),
|
||||
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D15S1 );
|
||||
g_bSupportsD15S1 = !FAILED(hr);
|
||||
#else
|
||||
g_bSupportsD15S1 = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns true if compressed textures are supported
|
||||
//-----------------------------------------------------------------------------
|
||||
bool D3DSupportsCompressedTextures()
|
||||
{
|
||||
return (g_D3DColorFormat[IMAGE_FORMAT_DXT1][0][0][0] != D3DFMT_UNKNOWN) &&
|
||||
(g_D3DColorFormat[IMAGE_FORMAT_DXT3][0][0][0] != D3DFMT_UNKNOWN) &&
|
||||
(g_D3DColorFormat[IMAGE_FORMAT_DXT5][0][0][0] != D3DFMT_UNKNOWN);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns closest supported format
|
||||
//-----------------------------------------------------------------------------
|
||||
ImageFormat FindNearestSupportedFormat( ImageFormat format, bool bIsVertexTexture, bool bIsRenderTarget, bool bFilterableRequired )
|
||||
{
|
||||
return ImageLoader::D3DFormatToImageFormat( g_D3DColorFormat[format][bIsVertexTexture][bIsRenderTarget][bFilterableRequired] );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns true if compressed textures are supported
|
||||
//-----------------------------------------------------------------------------
|
||||
bool D3DSupportsDepthTexture(D3DFORMAT format)
|
||||
{
|
||||
// See if we can do it!
|
||||
HRESULT hr = D3D()->CheckDeviceFormat(
|
||||
g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat(g_DeviceFormat),
|
||||
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, format);
|
||||
|
||||
return !FAILED(hr);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns true if the depth format is compatible with the display
|
||||
//-----------------------------------------------------------------------------
|
||||
static inline bool IsDepthFormatCompatible( int nAdapter, ImageFormat displayFormat, ImageFormat renderTargetFormat, D3DFORMAT depthFormat )
|
||||
{
|
||||
D3DFORMAT d3dDisplayFormat = ImageLoader::ImageFormatToD3DFormat( displayFormat );
|
||||
D3DFORMAT d3dRenderTargetFormat = ImageLoader::ImageFormatToD3DFormat( renderTargetFormat );
|
||||
|
||||
// Verify that the depth format is compatible.
|
||||
HRESULT hr = D3D()->CheckDepthStencilMatch( nAdapter, DX8_DEVTYPE,
|
||||
d3dDisplayFormat, d3dRenderTargetFormat, depthFormat);
|
||||
return !FAILED(hr);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Finds the nearest supported depth buffer format
|
||||
//-----------------------------------------------------------------------------
|
||||
D3DFORMAT FindNearestSupportedDepthFormat( int nAdapter, ImageFormat displayFormat, ImageFormat renderTargetFormat, D3DFORMAT depthFormat )
|
||||
{
|
||||
// This is the default case, used for rendering to the main render target
|
||||
Assert( displayFormat != IMAGE_FORMAT_UNKNOWN && renderTargetFormat != IMAGE_FORMAT_UNKNOWN );
|
||||
|
||||
switch (depthFormat)
|
||||
{
|
||||
#if defined( _X360 )
|
||||
case D3DFMT_D24FS8:
|
||||
return D3DFMT_D24FS8;
|
||||
|
||||
case D3DFMT_LIN_D24S8:
|
||||
if ( g_bSupportsD24S8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_LIN_D24S8 ) )
|
||||
return D3DFMT_LIN_D24S8;
|
||||
#endif
|
||||
case D3DFMT_D24S8:
|
||||
if ( g_bSupportsD24S8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24S8 ) )
|
||||
return D3DFMT_D24S8;
|
||||
#if !defined( _X360 )
|
||||
if ( g_bSupportsD24X4S4 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24X4S4 ) )
|
||||
return D3DFMT_D24X4S4;
|
||||
if ( g_bSupportsD15S1 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D15S1 ) )
|
||||
return D3DFMT_D15S1;
|
||||
#endif
|
||||
if ( g_bSupportsD24X8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24X8 ) )
|
||||
return D3DFMT_D24X8;
|
||||
if ( g_bSupportsD16 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D16 ) )
|
||||
return D3DFMT_D16;
|
||||
break;
|
||||
|
||||
case D3DFMT_D24X8:
|
||||
if ( g_bSupportsD24X8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24X8 ) )
|
||||
return D3DFMT_D24X8;
|
||||
if ( g_bSupportsD24S8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24S8 ) )
|
||||
return D3DFMT_D24S8;
|
||||
#if !defined( _X360 )
|
||||
if ( g_bSupportsD24X4S4 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24X4S4 ) )
|
||||
return D3DFMT_D24X4S4;
|
||||
#endif
|
||||
if ( g_bSupportsD16 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D16 ) )
|
||||
return D3DFMT_D16;
|
||||
#if !defined( _X360 )
|
||||
if ( g_bSupportsD15S1 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D15S1 ) )
|
||||
return D3DFMT_D15S1;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case D3DFMT_D16:
|
||||
if ( g_bSupportsD16 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D16 ) )
|
||||
return D3DFMT_D16;
|
||||
#if !defined( _X360 )
|
||||
if ( g_bSupportsD15S1 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D15S1 ) )
|
||||
return D3DFMT_D15S1;
|
||||
#endif
|
||||
if ( g_bSupportsD24X8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24X8 ) )
|
||||
return D3DFMT_D24X8;
|
||||
if ( g_bSupportsD24S8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24S8 ) )
|
||||
return D3DFMT_D24S8;
|
||||
#if !defined( _X360 )
|
||||
if ( g_bSupportsD24X4S4 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24X4S4 ) )
|
||||
return D3DFMT_D24X4S4;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
Assert( 0 );
|
||||
return D3DFMT_D16;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Is a display buffer valid?
|
||||
//-----------------------------------------------------------------------------
|
||||
static inline bool IsFrameBufferFormatValid( UINT displayAdapter, D3DDEVTYPE deviceType,
|
||||
D3DFORMAT displayFormat, D3DFORMAT backBufferFormat, bool bIsWindowed )
|
||||
{
|
||||
HRESULT hr = D3D()->CheckDeviceType( displayAdapter, deviceType, displayFormat,
|
||||
backBufferFormat, bIsWindowed );
|
||||
return !FAILED(hr);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Finds the nearest supported frame buffer format
|
||||
//-----------------------------------------------------------------------------
|
||||
ImageFormat FindNearestSupportedBackBufferFormat( UINT displayAdapter,
|
||||
D3DDEVTYPE deviceType, ImageFormat displayFormat, ImageFormat backBufferFormat, bool bIsWindowed )
|
||||
{
|
||||
D3DFORMAT d3dDisplayFormat = ImageLoader::ImageFormatToD3DFormat( displayFormat );
|
||||
switch (backBufferFormat)
|
||||
{
|
||||
case IMAGE_FORMAT_RGBA8888:
|
||||
case IMAGE_FORMAT_ABGR8888:
|
||||
case IMAGE_FORMAT_ARGB8888:
|
||||
case IMAGE_FORMAT_BGRA8888:
|
||||
case IMAGE_FORMAT_BGRA4444: // This is not supported ever; bump up to 32 bit
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA8888;
|
||||
|
||||
// Bye, bye dest alpha
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX8888;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_R5G6B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGR565;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA5551;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX5551;
|
||||
|
||||
return IMAGE_FORMAT_UNKNOWN;
|
||||
|
||||
case IMAGE_FORMAT_RGB888:
|
||||
case IMAGE_FORMAT_BGR888:
|
||||
case IMAGE_FORMAT_RGB888_BLUESCREEN:
|
||||
case IMAGE_FORMAT_BGRX8888:
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX8888;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA8888;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_R5G6B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGR565;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA5551;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX5551;
|
||||
|
||||
return IMAGE_FORMAT_UNKNOWN;
|
||||
|
||||
case IMAGE_FORMAT_RGB565:
|
||||
case IMAGE_FORMAT_BGR565:
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_R5G6B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGR565;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA5551;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX5551;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX8888;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA8888;
|
||||
|
||||
return IMAGE_FORMAT_UNKNOWN;
|
||||
|
||||
case IMAGE_FORMAT_BGRX5551:
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX5551;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA5551;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_R5G6B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGR565;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX8888;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA8888;
|
||||
|
||||
return IMAGE_FORMAT_UNKNOWN;
|
||||
|
||||
case IMAGE_FORMAT_BGRA5551:
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA5551;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX5551;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_R5G6B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGR565;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA8888;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX8888;
|
||||
|
||||
return IMAGE_FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
return IMAGE_FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
#if defined( _X360 )
|
||||
const char *D3DFormatName( D3DFORMAT d3dFormat )
|
||||
{
|
||||
if ( IS_D3DFORMAT_SRGB( d3dFormat ) )
|
||||
{
|
||||
// sanitize the format from possible sRGB state for comparison purposes
|
||||
d3dFormat = MAKE_NON_SRGB_FMT( d3dFormat );
|
||||
}
|
||||
|
||||
switch ( d3dFormat )
|
||||
{
|
||||
case D3DFMT_A8R8G8B8:
|
||||
return "D3DFMT_A8R8G8B8";
|
||||
case D3DFMT_LIN_A8R8G8B8:
|
||||
return "D3DFMT_LIN_A8R8G8B8";
|
||||
case D3DFMT_X8R8G8B8:
|
||||
return "D3DFMT_X8R8G8B8";
|
||||
case D3DFMT_LIN_X8R8G8B8:
|
||||
return "D3DFMT_LIN_X8R8G8B8";
|
||||
case D3DFMT_R5G6B5:
|
||||
return "D3DFMT_R5G6B5";
|
||||
case D3DFMT_X1R5G5B5:
|
||||
return "D3DFMT_X1R5G5B5";
|
||||
case D3DFMT_A1R5G5B5:
|
||||
return "D3DFMT_A1R5G5B5";
|
||||
case D3DFMT_A4R4G4B4:
|
||||
return "D3DFMT_A4R4G4B4";
|
||||
case D3DFMT_L8:
|
||||
return "D3DFMT_L8";
|
||||
case D3DFMT_A8L8:
|
||||
return "D3DFMT_A8L8";
|
||||
case D3DFMT_A8:
|
||||
return "D3DFMT_A8";
|
||||
case D3DFMT_DXT1:
|
||||
return "D3DFMT_DXT1";
|
||||
case D3DFMT_DXT3:
|
||||
return "D3DFMT_DXT3";
|
||||
case D3DFMT_DXT5:
|
||||
return "D3DFMT_DXT5";
|
||||
case D3DFMT_V8U8:
|
||||
return "D3DFMT_V8U8";
|
||||
case D3DFMT_Q8W8V8U8:
|
||||
return "D3DFMT_Q8W8V8U8";
|
||||
case D3DFMT_D16:
|
||||
return "D3DFMT_D16";
|
||||
case D3DFMT_D24S8:
|
||||
return "D3DFMT_D24S8";
|
||||
case D3DFMT_D24FS8:
|
||||
return "D3DFMT_D24FS8";
|
||||
case D3DFMT_LIN_D24S8:
|
||||
return "D3DFMT_LIN_D24S8";
|
||||
case D3DFMT_A16B16G16R16:
|
||||
return "D3DFMT_A16B16G16R16";
|
||||
case D3DFMT_LIN_A16B16G16R16:
|
||||
return "D3DFMT_LIN_A16B16G16R16";
|
||||
}
|
||||
return "???";
|
||||
}
|
||||
#endif
|
||||
60
materialsystem/shaderapidx9/colorformatdx8.h
Normal file
60
materialsystem/shaderapidx9/colorformatdx8.h
Normal file
@@ -0,0 +1,60 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef COLORFORMATDX8_H
|
||||
#define COLORFORMATDX8_H
|
||||
|
||||
#include <pixelwriter.h>
|
||||
#include "togl/rendermechanism.h"
|
||||
|
||||
// FOURCC formats for ATI shadow depth textures
|
||||
#define ATIFMT_D16 ((D3DFORMAT)(MAKEFOURCC('D','F','1','6')))
|
||||
#define ATIFMT_D24S8 ((D3DFORMAT)(MAKEFOURCC('D','F','2','4')))
|
||||
|
||||
// FOURCC formats for ATI2N and ATI1N compressed textures (360 and DX10 parts also do these)
|
||||
#define ATIFMT_ATI2N ((D3DFORMAT) MAKEFOURCC('A', 'T', 'I', '2'))
|
||||
#define ATIFMT_ATI1N ((D3DFORMAT) MAKEFOURCC('A', 'T', 'I', '1'))
|
||||
|
||||
// FOURCC formats for nVidia shadow depth textures
|
||||
#define NVFMT_RAWZ ((D3DFORMAT)(MAKEFOURCC('R','A','W','Z')))
|
||||
#define NVFMT_INTZ ((D3DFORMAT)(MAKEFOURCC('I','N','T','Z')))
|
||||
|
||||
// FOURCC format for nVidia null texture format
|
||||
#define NVFMT_NULL ((D3DFORMAT)(MAKEFOURCC('N','U','L','L')))
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Finds the nearest supported frame buffer format
|
||||
//-----------------------------------------------------------------------------
|
||||
ImageFormat FindNearestSupportedBackBufferFormat( unsigned int displayAdapter, D3DDEVTYPE deviceType,
|
||||
ImageFormat displayFormat, ImageFormat backBufferFormat, bool bIsWindowed );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Initializes the color format informat; call it every time display mode changes
|
||||
//-----------------------------------------------------------------------------
|
||||
void InitializeColorInformation( unsigned int displayAdapter, D3DDEVTYPE deviceType,
|
||||
ImageFormat displayFormat );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns true if compressed textures are supported
|
||||
//-----------------------------------------------------------------------------
|
||||
bool D3DSupportsCompressedTextures();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns closest supported format
|
||||
//-----------------------------------------------------------------------------
|
||||
ImageFormat FindNearestSupportedFormat( ImageFormat format, bool bIsVertexTexture, bool bIsRenderTarget, bool bFilterableRequired );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Finds the nearest supported depth buffer format
|
||||
//-----------------------------------------------------------------------------
|
||||
D3DFORMAT FindNearestSupportedDepthFormat( int nAdapter, ImageFormat displayFormat, ImageFormat renderTargetFormat, D3DFORMAT depthFormat );
|
||||
|
||||
const char *D3DFormatName( D3DFORMAT d3dFormat );
|
||||
|
||||
#endif // COLORFORMATDX8_H
|
||||
764
materialsystem/shaderapidx9/cvballoctracker.cpp
Normal file
764
materialsystem/shaderapidx9/cvballoctracker.cpp
Normal file
@@ -0,0 +1,764 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: tracks VB allocations (and compressed/uncompressed vertex memory usage)
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "materialsystem/imaterial.h"
|
||||
#include "imeshdx8.h"
|
||||
#include "convar.h"
|
||||
#include "tier1/utlhash.h"
|
||||
#include "tier1/utlstack.h"
|
||||
|
||||
#include "materialsystem/ivballoctracker.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Types
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if ENABLE_VB_ALLOC_TRACKER
|
||||
|
||||
// FIXME: combine this into the lower bits of VertexFormat_t
|
||||
typedef uint64 VertexElementMap_t;
|
||||
|
||||
enum Saving_t
|
||||
{
|
||||
SAVING_COMPRESSION = 0,
|
||||
SAVING_REMOVAL = 1,
|
||||
SAVING_ALIGNMENT = 2
|
||||
};
|
||||
|
||||
struct ElementData
|
||||
{
|
||||
VertexElement_t element;
|
||||
int uncompressed; // uncompressed vertex size
|
||||
int currentCompressed; // current compressed vertex element size
|
||||
int idealCompressed; // ideal future compressed vertex element size
|
||||
const char *name;
|
||||
};
|
||||
|
||||
class CounterData
|
||||
{
|
||||
public:
|
||||
CounterData() : m_memCount( 0 ), m_vertCount( 0 ), m_paddingCount( 0 )
|
||||
{
|
||||
for ( int i = 0; i < VERTEX_ELEMENT_NUMELEMENTS; i++ )
|
||||
{
|
||||
m_elementsCompressed[ i ] = 0;
|
||||
m_elementsUncompressed[ i ] = 0;
|
||||
}
|
||||
m_AllocatorName[ 0 ] = 0;
|
||||
}
|
||||
|
||||
static const int MAX_NAME_SIZE = 128;
|
||||
int m_memCount;
|
||||
int m_vertCount;
|
||||
int m_paddingCount;
|
||||
int m_elementsCompressed[ VERTEX_ELEMENT_NUMELEMENTS ]; // Number of compressed verts using each element
|
||||
int m_elementsUncompressed[ VERTEX_ELEMENT_NUMELEMENTS ]; // Number of uncompressed verts using each element
|
||||
char m_AllocatorName[ MAX_NAME_SIZE ];
|
||||
};
|
||||
|
||||
class AllocData
|
||||
{
|
||||
public:
|
||||
AllocData( void * buffer, int bufferSize, VertexFormat_t fmt, int numVerts, int allocatorHash )
|
||||
: m_buffer( buffer ), m_bufferSize( bufferSize ), m_fmt( fmt ), m_numVerts( numVerts ), m_allocatorHash( allocatorHash ) {}
|
||||
AllocData() : m_buffer( NULL ), m_bufferSize( 0 ), m_fmt( 0 ), m_numVerts( 0 ), m_allocatorHash( 0 ) {}
|
||||
|
||||
VertexFormat_t m_fmt;
|
||||
void * m_buffer;
|
||||
int m_bufferSize;
|
||||
int m_numVerts;
|
||||
short m_allocatorHash;
|
||||
};
|
||||
|
||||
typedef CUtlHashFixed < CounterData, 64 > CCounterTable;
|
||||
typedef CUtlHashFixed < AllocData, 4096 > CAllocTable;
|
||||
typedef CUtlStack < short > CAllocNameHashes;
|
||||
|
||||
#endif // ENABLE_VB_ALLOC_TRACKER
|
||||
|
||||
|
||||
class CVBAllocTracker : public IVBAllocTracker
|
||||
{
|
||||
public:
|
||||
virtual void CountVB( void * buffer, bool isDynamic, int bufferSize, int vertexSize, VertexFormat_t fmt );
|
||||
virtual void UnCountVB( void * buffer );
|
||||
virtual bool TrackMeshAllocations( const char * allocatorName );
|
||||
|
||||
void DumpVBAllocs();
|
||||
|
||||
#if ENABLE_VB_ALLOC_TRACKER
|
||||
|
||||
public:
|
||||
CVBAllocTracker() : m_bSuperSpew( false ) { m_MeshAllocatorName[0] = 0; }
|
||||
|
||||
private:
|
||||
|
||||
UtlHashFixedHandle_t TrackAlloc( void * buffer, int bufferSize, VertexFormat_t fmt, int numVerts, short allocatorHash );
|
||||
bool KillAlloc( void * buffer, int & bufferSize, VertexFormat_t & fmt, int & numVerts, short & allocatorHash );
|
||||
|
||||
UtlHashFixedHandle_t GetCounterHandle( const char * allocatorName, short allocatorHash );
|
||||
|
||||
void SpewElements( const char * allocatorName, short nameHash );
|
||||
int ComputeVertexSize( VertexElementMap_t map, VertexFormat_t fmt, bool compressed );
|
||||
VertexElementMap_t ComputeElementMap( VertexFormat_t fmt, int vertexSize, bool isDynamic );
|
||||
void UpdateElements( CounterData & data, VertexFormat_t fmt, int numVerts, int vertexSize,
|
||||
bool isDynamic, bool isCompressed );
|
||||
|
||||
int ComputeAlignmentWastage( int bufferSize );
|
||||
void AddSaving( int & alreadySaved, int & yetToSave, const char *allocatorName, VertexElement_t element, Saving_t savingType );
|
||||
void SpewExpectedSavings( void );
|
||||
void UpdateData( const char * allocatorName, short allocatorKey, int bufferSize, VertexFormat_t fmt,
|
||||
int numVerts, int vertexSize, bool isDynamic, bool isCompressed );
|
||||
|
||||
const char * GetNameString( int allocatorKey );
|
||||
void SpewData( const char * allocatorName, short nameHash = 0 );
|
||||
void SpewDataSometimes( int inc );
|
||||
|
||||
|
||||
static const int SPEW_RATE = 64;
|
||||
static const int MAX_ALLOCATOR_NAME_SIZE = 128;
|
||||
char m_MeshAllocatorName[ MAX_ALLOCATOR_NAME_SIZE ];
|
||||
bool m_bSuperSpew;
|
||||
|
||||
CCounterTable m_VBCountTable;
|
||||
CAllocTable m_VBAllocTable;
|
||||
CAllocNameHashes m_VBTableNameHashes;
|
||||
|
||||
// We use a mutex since allocation tracking is accessed from multiple loading threads.
|
||||
// CThreadFastMutex is used as contention is expected to be low during loading.
|
||||
CThreadFastMutex m_VBAllocMutex;
|
||||
#endif // ENABLE_VB_ALLOC_TRACKER
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Global data
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if ENABLE_VB_ALLOC_TRACKER
|
||||
|
||||
// FIXME: do this in a better way:
|
||||
static const ElementData positionElement = { VERTEX_ELEMENT_POSITION, 12, 12, 8, "POSITION " }; // (UNDONE: need vertex shader to scale, may cause cracking w/ static props)
|
||||
static const ElementData normalElement = { VERTEX_ELEMENT_NORMAL, 12, 4, 4, "NORMAL " }; // (UNDONE: PC (2x16-byte Ravi method) or 360 (D3DDECLTYPE_HEND3N))
|
||||
static const ElementData colorElement = { VERTEX_ELEMENT_COLOR, 4, 4, 4, "COLOR " }; // (already minimal)
|
||||
static const ElementData specularElement = { VERTEX_ELEMENT_SPECULAR, 4, 4, 4, "SPECULAR " }; // (already minimal)
|
||||
static const ElementData tangentSElement = { VERTEX_ELEMENT_TANGENT_S, 12, 12, 4, "TANGENT_S " }; // (all-but-unused)
|
||||
static const ElementData tangentTElement = { VERTEX_ELEMENT_TANGENT_T, 12, 12, 4, "TANGENT_T " }; // (all-but-unused)
|
||||
static const ElementData wrinkleElement = { VERTEX_ELEMENT_WRINKLE, 4, 4, 0, "WRINKLE " }; // (UNDONE: compress it as a SHORTN in Position.w - is it [0,1]?)
|
||||
static const ElementData boneIndexElement = { VERTEX_ELEMENT_BONEINDEX, 4, 4, 4, "BONEINDEX " }; // (already minimal)
|
||||
static const ElementData boneWeight1Element = { VERTEX_ELEMENT_BONEWEIGHTS1, 4, 4, 4, "BONEWEIGHT1 " }; // (unused)
|
||||
static const ElementData boneWeight2Element = { VERTEX_ELEMENT_BONEWEIGHTS2, 8, 8, 4, "BONEWEIGHT2 " }; // (UNDONE: take care w.r.t cracking in flex regions)
|
||||
static const ElementData boneWeight3Element = { VERTEX_ELEMENT_BONEWEIGHTS3, 12, 12, 8, "BONEWEIGHT3 " }; // (unused)
|
||||
static const ElementData boneWeight4Element = { VERTEX_ELEMENT_BONEWEIGHTS4, 16, 16, 8, "BONEWEIGHT4 " }; // (unused)
|
||||
static const ElementData userData1Element = { VERTEX_ELEMENT_USERDATA1, 4, 4, 4, "USERDATA1 " }; // (unused)
|
||||
static const ElementData userData2Element = { VERTEX_ELEMENT_USERDATA2, 8, 8, 4, "USERDATA2 " }; // (unused)
|
||||
static const ElementData userData3Element = { VERTEX_ELEMENT_USERDATA3, 12, 12, 4, "USERDATA3 " }; // (unused)
|
||||
#if ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_SEPARATETANGENTS_SHORT2 )
|
||||
static const ElementData userData4Element = { VERTEX_ELEMENT_USERDATA4, 16, 4, 4, "USERDATA4 " }; // (UNDONE: PC (2x16-byte Ravi method) or 360 (D3DDECLTYPE_HEND3N))
|
||||
#else // ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 )
|
||||
static const ElementData userData4Element = { VERTEX_ELEMENT_USERDATA4, 16, 0, 0, "USERDATA4 " }; // (UNDONE: PC (2x16-byte Ravi method) or 360 (D3DDECLTYPE_HEND3N))
|
||||
#endif
|
||||
static const ElementData texCoord1D0Element = { VERTEX_ELEMENT_TEXCOORD1D_0, 4, 4, 4, "TEXCOORD1D_0" }; // (not worth compressing)
|
||||
static const ElementData texCoord1D1Element = { VERTEX_ELEMENT_TEXCOORD1D_1, 4, 4, 4, "TEXCOORD1D_1" }; // (not worth compressing)
|
||||
static const ElementData texCoord1D2Element = { VERTEX_ELEMENT_TEXCOORD1D_2, 4, 4, 4, "TEXCOORD1D_2" }; // (not worth compressing)
|
||||
static const ElementData texCoord1D3Element = { VERTEX_ELEMENT_TEXCOORD1D_3, 4, 4, 4, "TEXCOORD1D_3" }; // (not worth compressing)
|
||||
static const ElementData texCoord1D4Element = { VERTEX_ELEMENT_TEXCOORD1D_4, 4, 4, 4, "TEXCOORD1D_4" }; // (not worth compressing)
|
||||
static const ElementData texCoord1D5Element = { VERTEX_ELEMENT_TEXCOORD1D_5, 4, 4, 4, "TEXCOORD1D_5" }; // (not worth compressing)
|
||||
static const ElementData texCoord1D6Element = { VERTEX_ELEMENT_TEXCOORD1D_6, 4, 4, 4, "TEXCOORD1D_6" }; // (not worth compressing)
|
||||
static const ElementData texCoord1D7Element = { VERTEX_ELEMENT_TEXCOORD1D_7, 4, 4, 4, "TEXCOORD1D_7" }; // (not worth compressing)
|
||||
static const ElementData texCoord2D0Element = { VERTEX_ELEMENT_TEXCOORD2D_0, 8, 8, 4, "TEXCOORD2D_0" }; // (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord2D1Element = { VERTEX_ELEMENT_TEXCOORD2D_1, 8, 8, 4, "TEXCOORD2D_1" }; // (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord2D2Element = { VERTEX_ELEMENT_TEXCOORD2D_2, 8, 8, 4, "TEXCOORD2D_2" }; // (all-but-unused)
|
||||
static const ElementData texCoord2D3Element = { VERTEX_ELEMENT_TEXCOORD2D_3, 8, 8, 4, "TEXCOORD2D_3" }; // (unused)
|
||||
static const ElementData texCoord2D4Element = { VERTEX_ELEMENT_TEXCOORD2D_4, 8, 8, 4, "TEXCOORD2D_4" }; // (unused)
|
||||
static const ElementData texCoord2D5Element = { VERTEX_ELEMENT_TEXCOORD2D_5, 8, 8, 4, "TEXCOORD2D_5" }; // (unused)
|
||||
static const ElementData texCoord2D6Element = { VERTEX_ELEMENT_TEXCOORD2D_6, 8, 8, 4, "TEXCOORD2D_6" }; // (unused)
|
||||
static const ElementData texCoord2D7Element = { VERTEX_ELEMENT_TEXCOORD2D_7, 8, 8, 4, "TEXCOORD2D_7" }; // (unused)
|
||||
static const ElementData texCoord3D0Element = { VERTEX_ELEMENT_TEXCOORD3D_0, 12, 12, 8, "TEXCOORD3D_0" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord3D1Element = { VERTEX_ELEMENT_TEXCOORD3D_1, 12, 12, 8, "TEXCOORD3D_1" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord3D2Element = { VERTEX_ELEMENT_TEXCOORD3D_2, 12, 12, 8, "TEXCOORD3D_2" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord3D3Element = { VERTEX_ELEMENT_TEXCOORD3D_3, 12, 12, 8, "TEXCOORD3D_3" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord3D4Element = { VERTEX_ELEMENT_TEXCOORD3D_4, 12, 12, 8, "TEXCOORD3D_4" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord3D5Element = { VERTEX_ELEMENT_TEXCOORD3D_5, 12, 12, 8, "TEXCOORD3D_5" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord3D6Element = { VERTEX_ELEMENT_TEXCOORD3D_6, 12, 12, 8, "TEXCOORD3D_6" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord3D7Element = { VERTEX_ELEMENT_TEXCOORD3D_7, 12, 12, 8, "TEXCOORD3D_7" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord4D0Element = { VERTEX_ELEMENT_TEXCOORD4D_0, 16, 16, 8, "TEXCOORD4D_0" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord4D1Element = { VERTEX_ELEMENT_TEXCOORD4D_1, 16, 16, 8, "TEXCOORD4D_1" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord4D2Element = { VERTEX_ELEMENT_TEXCOORD4D_2, 16, 16, 8, "TEXCOORD4D_2" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord4D3Element = { VERTEX_ELEMENT_TEXCOORD4D_3, 16, 16, 8, "TEXCOORD4D_3" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord4D4Element = { VERTEX_ELEMENT_TEXCOORD4D_4, 16, 16, 8, "TEXCOORD4D_4" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord4D5Element = { VERTEX_ELEMENT_TEXCOORD4D_5, 16, 16, 8, "TEXCOORD4D_5" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord4D6Element = { VERTEX_ELEMENT_TEXCOORD4D_6, 16, 16, 8, "TEXCOORD4D_6" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord4D7Element = { VERTEX_ELEMENT_TEXCOORD4D_7, 16, 16, 8, "TEXCOORD4D_7" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData elementTable[ VERTEX_ELEMENT_NUMELEMENTS ] = { positionElement,
|
||||
normalElement,
|
||||
colorElement,
|
||||
specularElement,
|
||||
tangentSElement,
|
||||
tangentTElement,
|
||||
wrinkleElement,
|
||||
boneIndexElement,
|
||||
boneWeight1Element, boneWeight2Element, boneWeight3Element, boneWeight4Element,
|
||||
userData1Element, userData2Element, userData3Element, userData4Element,
|
||||
texCoord1D0Element, texCoord1D1Element, texCoord1D2Element, texCoord1D3Element, texCoord1D4Element, texCoord1D5Element, texCoord1D6Element, texCoord1D7Element,
|
||||
texCoord2D0Element, texCoord2D1Element, texCoord2D2Element, texCoord2D3Element, texCoord2D4Element, texCoord2D5Element, texCoord2D6Element, texCoord2D7Element,
|
||||
texCoord3D0Element, texCoord3D1Element, texCoord3D2Element, texCoord3D3Element, texCoord3D4Element, texCoord3D5Element, texCoord3D6Element, texCoord3D7Element,
|
||||
texCoord4D0Element, texCoord4D1Element, texCoord4D2Element, texCoord4D3Element, texCoord4D4Element, texCoord4D5Element, texCoord4D6Element, texCoord4D7Element,
|
||||
};
|
||||
|
||||
static ConVar mem_vballocspew( "mem_vballocspew", "0", FCVAR_CHEAT, "How often to spew vertex buffer allocation stats - 1: every alloc, 2+: every 2+ allocs, 0: off" );
|
||||
|
||||
#endif // ENABLE_VB_ALLOC_TRACKER
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton instance exposed to the engine
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
CVBAllocTracker g_VBAllocTrackerShaderAPI;
|
||||
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CVBAllocTracker, IVBAllocTracker,
|
||||
VB_ALLOC_TRACKER_INTERFACE_VERSION, g_VBAllocTrackerShaderAPI );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VB alloc-tracking code starts here
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if ENABLE_VB_ALLOC_TRACKER
|
||||
|
||||
UtlHashFixedHandle_t CVBAllocTracker::TrackAlloc( void * buffer, int bufferSize, VertexFormat_t fmt, int numVerts, short allocatorHash )
|
||||
{
|
||||
AllocData newData( buffer, bufferSize, fmt, numVerts, allocatorHash );
|
||||
UtlHashFixedHandle_t handle = m_VBAllocTable.Insert( (int)buffer, newData );
|
||||
if ( handle == m_VBAllocTable.InvalidHandle() )
|
||||
{
|
||||
Warning( "[VBMEM] VBMemAllocTable hash collision (grow table).\n" );
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
|
||||
bool CVBAllocTracker::KillAlloc( void * buffer, int & bufferSize, VertexFormat_t & fmt, int & numVerts, short & allocatorHash )
|
||||
{
|
||||
UtlHashFixedHandle_t handle = m_VBAllocTable.Find( (int)buffer );
|
||||
if ( handle != m_VBAllocTable.InvalidHandle() )
|
||||
{
|
||||
AllocData & data = m_VBAllocTable.Element( handle );
|
||||
bufferSize = data.m_bufferSize;
|
||||
fmt = data.m_fmt;
|
||||
numVerts = data.m_numVerts;
|
||||
allocatorHash = data.m_allocatorHash;
|
||||
m_VBAllocTable.Remove( handle );
|
||||
return true;
|
||||
}
|
||||
Warning( "[VBMEM] VBMemAllocTable failed to find alloc entry...\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
UtlHashFixedHandle_t CVBAllocTracker::GetCounterHandle( const char * allocatorName, short allocatorHash )
|
||||
{
|
||||
UtlHashFixedHandle_t handle = m_VBCountTable.Find( allocatorHash );
|
||||
if ( handle == m_VBCountTable.InvalidHandle() )
|
||||
{
|
||||
CounterData newData;
|
||||
Assert( ( allocatorName != NULL ) && ( allocatorName[0] != 0 ) );
|
||||
V_strncpy( newData.m_AllocatorName, allocatorName, CounterData::MAX_NAME_SIZE );
|
||||
handle = m_VBCountTable.Insert( allocatorHash, newData );
|
||||
m_VBTableNameHashes.Push( allocatorHash );
|
||||
}
|
||||
if ( handle == m_VBCountTable.InvalidHandle() )
|
||||
{
|
||||
Warning( "[VBMEM] CounterData hash collision (grow table).\n" );
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
|
||||
void CheckForElementTableUpdates( const ElementData & element )
|
||||
{
|
||||
// Ensure that 'elementTable' gets updated if VertexElement_t ever changes:
|
||||
int tableIndex = &element - &( elementTable[0] );
|
||||
Assert( tableIndex == element.element );
|
||||
if ( tableIndex != element.element )
|
||||
{
|
||||
static int timesToSpew = 20;
|
||||
if ( timesToSpew > 0 )
|
||||
{
|
||||
Warning( "VertexElement_t structure has changed, ElementData table in cvballoctracker needs updating!\n" );
|
||||
timesToSpew--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CVBAllocTracker::SpewElements( const char * allocatorName, short nameHash )
|
||||
{
|
||||
short allocatorHash = allocatorName ? HashString( allocatorName ) : nameHash;
|
||||
UtlHashFixedHandle_t handle = GetCounterHandle( allocatorName, allocatorHash );
|
||||
if ( handle != m_VBCountTable.InvalidHandle() )
|
||||
{
|
||||
CounterData & data = m_VBCountTable.Element( handle );
|
||||
int originalSum = 0, currentSum = 0, idealSum = 0;
|
||||
for (int i = 0;i < VERTEX_ELEMENT_NUMELEMENTS;i++)
|
||||
{
|
||||
CheckForElementTableUpdates( elementTable[ i ] );
|
||||
int numCompressed = data.m_elementsCompressed[ i ];
|
||||
int numUncompressed = data.m_elementsUncompressed[ i ];
|
||||
int numVerts = numCompressed + numUncompressed;
|
||||
originalSum += numVerts*elementTable[ i ].uncompressed;
|
||||
currentSum += numCompressed*elementTable[ i ].currentCompressed + numUncompressed*elementTable[ i ].uncompressed;
|
||||
idealSum += numVerts*elementTable[ i ].idealCompressed;
|
||||
}
|
||||
|
||||
if ( originalSum > 0 )
|
||||
{
|
||||
Msg( "[VBMEM] ----elements (%s)----:\n", data.m_AllocatorName);
|
||||
for (int i = 0;i < VERTEX_ELEMENT_NUMELEMENTS;i++)
|
||||
{
|
||||
// We count vertices (converted to bytes via elementTable)
|
||||
int numCompressed = data.m_elementsCompressed[ i ];
|
||||
int numUncompressed = data.m_elementsUncompressed[ i ];
|
||||
int numVerts = numCompressed + numUncompressed;
|
||||
const ElementData & elementData = elementTable[ i ];
|
||||
if ( numVerts > 0 )
|
||||
{
|
||||
Msg( " element: %5.2f MB 'U', %5.2f MB 'C', %5.2f MB 'I', %6.2f MB 'D', %s\n",
|
||||
numVerts*elementData.uncompressed / ( 1024.0f*1024.0f ),
|
||||
( numCompressed*elementData.currentCompressed + numUncompressed*elementData.uncompressed ) / ( 1024.0f*1024.0f ),
|
||||
numVerts*elementData.idealCompressed / ( 1024.0f*1024.0f ),
|
||||
-( numCompressed*elementData.currentCompressed + numUncompressed*elementData.uncompressed - numVerts*elementData.idealCompressed ) / ( 1024.0f*1024.0f ),
|
||||
elementData.name );
|
||||
}
|
||||
}
|
||||
Msg( "[VBMEM] total: %5.2f MB 'U', %5.2f MB 'C', %5.2f MB 'I', %6.2f MB 'D'\n",
|
||||
originalSum / ( 1024.0f*1024.0f ),
|
||||
currentSum / ( 1024.0f*1024.0f ),
|
||||
idealSum / ( 1024.0f*1024.0f ),
|
||||
-( currentSum - idealSum ) / ( 1024.0f*1024.0f ) );
|
||||
Msg( "[VBMEM] ----elements (%s)----:\n", data.m_AllocatorName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CVBAllocTracker::ComputeVertexSize( VertexElementMap_t map, VertexFormat_t fmt, bool compressed )
|
||||
{
|
||||
int vertexSize = 0;
|
||||
for ( int i = 0;i < VERTEX_ELEMENT_NUMELEMENTS;i++ )
|
||||
{
|
||||
const ElementData & element = elementTable[ i ];
|
||||
CheckForElementTableUpdates( element );
|
||||
VertexElementMap_t LSB = 1;
|
||||
if ( map & ( LSB << i ) )
|
||||
{
|
||||
vertexSize += compressed ? element.currentCompressed : element.uncompressed;
|
||||
}
|
||||
}
|
||||
|
||||
// On PC (see CVertexBufferBase::ComputeVertexDescription() in meshbase.cpp)
|
||||
// vertex strides are aligned to 16 bytes:
|
||||
bool bCacheAlign = ( fmt & VERTEX_FORMAT_USE_EXACT_FORMAT ) == 0;
|
||||
if ( bCacheAlign && ( vertexSize > 16 ) && IsPC() )
|
||||
{
|
||||
vertexSize = (vertexSize + 0xF) & (~0xF);
|
||||
}
|
||||
|
||||
return vertexSize;
|
||||
}
|
||||
|
||||
VertexElementMap_t CVBAllocTracker::ComputeElementMap( VertexFormat_t fmt, int vertexSize, bool isDynamic )
|
||||
{
|
||||
VertexElementMap_t map = 0, LSB = 1;
|
||||
if ( fmt & VERTEX_POSITION ) map |= LSB << VERTEX_ELEMENT_POSITION;
|
||||
if ( fmt & VERTEX_NORMAL ) map |= LSB << VERTEX_ELEMENT_NORMAL;
|
||||
if ( fmt & VERTEX_COLOR ) map |= LSB << VERTEX_ELEMENT_COLOR;
|
||||
if ( fmt & VERTEX_SPECULAR ) map |= LSB << VERTEX_ELEMENT_SPECULAR;
|
||||
if ( fmt & VERTEX_TANGENT_S ) map |= LSB << VERTEX_ELEMENT_TANGENT_S;
|
||||
if ( fmt & VERTEX_TANGENT_T ) map |= LSB << VERTEX_ELEMENT_TANGENT_T;
|
||||
if ( fmt & VERTEX_WRINKLE ) map |= LSB << VERTEX_ELEMENT_WRINKLE;
|
||||
if ( fmt & VERTEX_BONE_INDEX) map |= LSB << VERTEX_ELEMENT_BONEINDEX;
|
||||
int numBones = NumBoneWeights( fmt );
|
||||
if ( numBones > 0 ) map |= LSB << ( VERTEX_ELEMENT_BONEWEIGHTS1 + numBones - 1 );
|
||||
int userDataSize = UserDataSize( fmt );
|
||||
if ( userDataSize > 0 ) map |= LSB << ( VERTEX_ELEMENT_USERDATA1 + userDataSize - 1 );
|
||||
for ( int i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i )
|
||||
{
|
||||
VertexElement_t texCoordElements[4] = { VERTEX_ELEMENT_TEXCOORD1D_0, VERTEX_ELEMENT_TEXCOORD2D_0, VERTEX_ELEMENT_TEXCOORD3D_0, VERTEX_ELEMENT_TEXCOORD4D_0 };
|
||||
int nCoordSize = TexCoordSize( i, fmt );
|
||||
if ( nCoordSize > 0 )
|
||||
{
|
||||
Assert( i < 4 );
|
||||
if ( i < 4 )
|
||||
{
|
||||
map |= LSB << ( texCoordElements[ nCoordSize - 1 ] + i );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( map == 0 )
|
||||
{
|
||||
if ( !isDynamic )
|
||||
{
|
||||
// We expect all (non-dynamic) VB allocs to specify a vertex format
|
||||
// Warning("[VBMEM] unknown vertex format\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( vertexSize != 0 )
|
||||
{
|
||||
// Make sure elementTable above matches external computations of vertex size
|
||||
// FIXME: make this assert dependent on whether the current VB is compressed or not
|
||||
VertexCompressionType_t compressionType = CompressionType( fmt );
|
||||
bool isCompressedAlloc = ( compressionType == VERTEX_COMPRESSION_ON );
|
||||
// FIXME: once we've finalised which elements we're compressing for ship, update
|
||||
// elementTable to reflect that and re-enable this assert for compressed verts
|
||||
if ( !isCompressedAlloc )
|
||||
{
|
||||
Assert( vertexSize == ComputeVertexSize( map, fmt, isCompressedAlloc ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
void CVBAllocTracker::UpdateElements( CounterData & data, VertexFormat_t fmt, int numVerts, int vertexSize,
|
||||
bool isDynamic, bool isCompressed )
|
||||
{
|
||||
VertexElementMap_t map = ComputeElementMap( fmt, vertexSize, isDynamic );
|
||||
if ( map != 0 )
|
||||
{
|
||||
for (int i = 0;i < VERTEX_ELEMENT_NUMELEMENTS;i++)
|
||||
{
|
||||
// Count vertices (get bytes from our elements table)
|
||||
VertexElementMap_t LSB = 1;
|
||||
if ( map & ( LSB << i ) )
|
||||
{
|
||||
if ( isCompressed )
|
||||
data.m_elementsCompressed[ i ] += numVerts;
|
||||
else
|
||||
data.m_elementsUncompressed[ i ] += numVerts;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CVBAllocTracker::ComputeAlignmentWastage( int bufferSize )
|
||||
{
|
||||
if ( !IsX360() )
|
||||
return 0;
|
||||
|
||||
// VBs are 4KB-aligned on 360, so we waste thiiiiiis much:
|
||||
return ( ( 4096 - (bufferSize & 4095)) & 4095 );
|
||||
}
|
||||
|
||||
void CVBAllocTracker::AddSaving( int & alreadySaved, int & yetToSave, const char *allocatorName, VertexElement_t element, Saving_t savingType )
|
||||
{
|
||||
UtlHashFixedHandle_t handle = GetCounterHandle( allocatorName, HashString( allocatorName ) );
|
||||
if ( handle != m_VBCountTable.InvalidHandle() )
|
||||
{
|
||||
CheckForElementTableUpdates( elementTable[ element ] );
|
||||
CounterData & counterData = m_VBCountTable.Element( handle );
|
||||
const ElementData & elementData = elementTable[ element ];
|
||||
int numVerts = counterData.m_vertCount;
|
||||
int numCompressed = counterData.m_elementsCompressed[ element ];
|
||||
int numUncompressed = counterData.m_elementsUncompressed[ element ];
|
||||
switch( savingType )
|
||||
{
|
||||
case SAVING_COMPRESSION:
|
||||
alreadySaved += numCompressed*( elementData.uncompressed - elementData.currentCompressed );
|
||||
yetToSave += numUncompressed*( elementData.uncompressed - elementData.currentCompressed );
|
||||
break;
|
||||
case SAVING_REMOVAL:
|
||||
alreadySaved += elementData.uncompressed*( numVerts - ( numUncompressed + numCompressed ) );
|
||||
yetToSave += numUncompressed*elementData.uncompressed + numCompressed*elementData.uncompressed;
|
||||
break;
|
||||
case SAVING_ALIGNMENT:
|
||||
yetToSave += counterData.m_paddingCount;
|
||||
break;
|
||||
default:
|
||||
Assert(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CVBAllocTracker::SpewExpectedSavings( void )
|
||||
{
|
||||
int alreadySaved = 0, yetToSave = 0;
|
||||
|
||||
// We have removed bone weights+indices from static props
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_static)", VERTEX_ELEMENT_BONEWEIGHTS2, SAVING_REMOVAL );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_static)", VERTEX_ELEMENT_BONEINDEX, SAVING_REMOVAL );
|
||||
// We have removed vertex colors from all models (color should only ever be in stream1, for static vertex lighting)
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_dynamic)", VERTEX_ELEMENT_COLOR, SAVING_REMOVAL );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_static)", VERTEX_ELEMENT_COLOR, SAVING_REMOVAL );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (character)", VERTEX_ELEMENT_COLOR, SAVING_REMOVAL );
|
||||
|
||||
// We expect to compress texcoords (DONE: normals+tangents, boneweights) for all studiomdls
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_dynamic)", VERTEX_ELEMENT_NORMAL, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_static)", VERTEX_ELEMENT_NORMAL, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (character)", VERTEX_ELEMENT_NORMAL, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_dynamic)", VERTEX_ELEMENT_USERDATA4, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_static)", VERTEX_ELEMENT_USERDATA4, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (character)", VERTEX_ELEMENT_USERDATA4, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_dynamic)", VERTEX_ELEMENT_TEXCOORD2D_0, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_static)", VERTEX_ELEMENT_TEXCOORD2D_0, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (character)", VERTEX_ELEMENT_TEXCOORD2D_0, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (character)", VERTEX_ELEMENT_BONEWEIGHTS1, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (character)", VERTEX_ELEMENT_BONEWEIGHTS2, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_dynamic)", VERTEX_ELEMENT_BONEWEIGHTS1, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_dynamic)", VERTEX_ELEMENT_BONEWEIGHTS2, SAVING_COMPRESSION );
|
||||
|
||||
// UNDONE: compress bone weights for studiomdls? (issue: possible flex artifacts, but 2xSHORTN probably ok)
|
||||
// UNDONE: compress positions (+wrinkle) for studiomdls? (issue: possible flex artifacts)
|
||||
// UNDONE: disable tangents for non-bumped models (issue: forcedmaterialoverride support... don't think that needs tangents, though
|
||||
// however, if we use UBYTE4 normal+tangent encoding, removing tangents saves nothing)
|
||||
|
||||
if ( IsX360() )
|
||||
{
|
||||
// We expect to avoid 4-KB-alignment wastage for color meshes, by allocating them
|
||||
// out of a single, shared VB and adding per-mesh offsets in vertex shaders
|
||||
AddSaving( alreadySaved, yetToSave, "CColorMeshData::CreateResource", VERTEX_ELEMENT_USERDATA4, SAVING_ALIGNMENT );
|
||||
}
|
||||
|
||||
Msg("[VBMEM]\n");
|
||||
Msg("[VBMEM] Total expected memory saving by disabling/compressing vertex elements: %6.2f MB\n", yetToSave / ( 1024.0f*1024.0f ) );
|
||||
Msg("[VBMEM] ( total memory already saved: %6.2f MB)\n", alreadySaved / ( 1024.0f*1024.0f ) );
|
||||
Msg("[VBMEM] - compression of model texcoords, [DONE: normals+tangents, bone weights]\n" );
|
||||
Msg("[VBMEM] - avoidance of 4-KB alignment wastage for color meshes (on 360)\n" );
|
||||
Msg("[VBMEM] - [DONE: removal of unneeded bone weights+indices on models]\n" );
|
||||
Msg("[VBMEM]\n");
|
||||
}
|
||||
|
||||
void CVBAllocTracker::UpdateData( const char * allocatorName, short allocatorKey, int bufferSize, VertexFormat_t fmt,
|
||||
int numVerts, int vertexSize, bool isDynamic, bool isCompressed )
|
||||
{
|
||||
UtlHashFixedHandle_t handle = GetCounterHandle( allocatorName, allocatorKey );
|
||||
if ( handle != m_VBCountTable.InvalidHandle() )
|
||||
{
|
||||
CounterData & data = m_VBCountTable.Element( handle );
|
||||
data.m_memCount += bufferSize;
|
||||
Assert( data.m_memCount >= 0 );
|
||||
data.m_vertCount += numVerts;
|
||||
Assert( data.m_vertCount >= 0 );
|
||||
data.m_paddingCount += ( bufferSize < 0 ? -1 : +1 )*ComputeAlignmentWastage( abs( bufferSize ) );
|
||||
UpdateElements( data, fmt, numVerts, vertexSize, isDynamic, isCompressed );
|
||||
}
|
||||
}
|
||||
|
||||
const char * CVBAllocTracker::GetNameString( int allocatorKey )
|
||||
{
|
||||
UtlHashFixedHandle_t handle = GetCounterHandle( NULL, allocatorKey );
|
||||
if ( handle != m_VBCountTable.InvalidHandle() )
|
||||
{
|
||||
CounterData & data = m_VBCountTable.Element( handle );
|
||||
return data.m_AllocatorName;
|
||||
}
|
||||
return "null";
|
||||
}
|
||||
|
||||
void CVBAllocTracker::SpewData( const char * allocatorName, short nameHash )
|
||||
{
|
||||
short allocatorHash = allocatorName ? HashString( allocatorName ) : nameHash;
|
||||
UtlHashFixedHandle_t handle = GetCounterHandle( allocatorName, allocatorHash );
|
||||
if ( handle != m_VBCountTable.InvalidHandle() )
|
||||
{
|
||||
CounterData & data = m_VBCountTable.Element( handle );
|
||||
if ( data.m_memCount > 0 )
|
||||
{
|
||||
Msg("[VBMEM] running mem usage: (%5.2f M-verts) %6.2f MB | '%s'\n",
|
||||
data.m_vertCount / ( 1024.0f*1024.0f ),
|
||||
data.m_memCount / ( 1024.0f*1024.0f ),
|
||||
data.m_AllocatorName );
|
||||
}
|
||||
if ( data.m_paddingCount > 0 )
|
||||
{
|
||||
Msg("[VBMEM] 4KB VB alignment wastage: %6.2f MB | '%s'\n",
|
||||
data.m_paddingCount / ( 1024.0f*1024.0f ),
|
||||
data.m_AllocatorName );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CVBAllocTracker::SpewDataSometimes( int inc )
|
||||
{
|
||||
static int count = 0;
|
||||
|
||||
if ( inc < 0 ) count += inc;
|
||||
Assert( count >= 0 );
|
||||
|
||||
int period = mem_vballocspew.GetInt();
|
||||
if ( period >= 1 )
|
||||
{
|
||||
if ( ( count % period ) == 0 )
|
||||
{
|
||||
Msg( "[VBMEM] Status after %d VB allocs:\n", count );
|
||||
//#define ROUND_UP( _x_ ) ( ( ( _x_ ) + 31 ) & 31 )
|
||||
//Msg( "[VBMEM] Conservative estimate of mem used to track allocs: %d\n", 4096*ROUND_UP( 4 + sizeof( CUtlPtrLinkedList<AllocData> ) ) + count*ROUND_UP( sizeof( AllocData ) + 8 ) );
|
||||
SpewData( "total_static" );
|
||||
SpewData( "unknown" );
|
||||
}
|
||||
}
|
||||
|
||||
if ( inc > 0 ) count += inc;
|
||||
}
|
||||
|
||||
void CVBAllocTracker::DumpVBAllocs()
|
||||
{
|
||||
m_VBAllocMutex.Lock();
|
||||
|
||||
Msg("[VBMEM] ----running totals----\n" );
|
||||
for ( int i = ( m_VBTableNameHashes.Count() - 1 ); i >= 0; i-- )
|
||||
{
|
||||
short nameHash = m_VBTableNameHashes.Element( i );
|
||||
SpewElements( NULL, nameHash );
|
||||
}
|
||||
|
||||
Msg("[VBMEM]\n");
|
||||
Msg("[VBMEM] 'U' - original memory usage (all vertices uncompressed)\n" );
|
||||
Msg("[VBMEM] 'C' - current memory usage (some compression)\n" );
|
||||
Msg("[VBMEM] 'I' - ideal memory usage (all verts maximally compressed)\n" );
|
||||
Msg("[VBMEM] 'D' - difference between C and I (-> how much more compression could save)\n" );
|
||||
Msg("[VBMEM] 'W' - memory wasted due to 4-KB vertex buffer alignment\n" );
|
||||
Msg("[VBMEM]\n");
|
||||
for ( int i = ( m_VBTableNameHashes.Count() - 1 ); i >= 0; i-- )
|
||||
{
|
||||
short nameHash = m_VBTableNameHashes.Element( i );
|
||||
SpewData( NULL, nameHash );
|
||||
}
|
||||
SpewExpectedSavings();
|
||||
Msg("[VBMEM] ----running totals----\n" );
|
||||
|
||||
m_VBAllocMutex.Unlock();
|
||||
}
|
||||
|
||||
#endif // ENABLE_VB_ALLOC_TRACKER
|
||||
|
||||
void CVBAllocTracker::CountVB( void * buffer, bool isDynamic, int bufferSize, int vertexSize, VertexFormat_t fmt )
|
||||
{
|
||||
#if ENABLE_VB_ALLOC_TRACKER
|
||||
m_VBAllocMutex.Lock();
|
||||
|
||||
// Update VB memory counts for the relevant allocation type
|
||||
// (NOTE: we have 'unknown', 'dynamic' and 'total' counts)
|
||||
const char * allocatorName = ( m_MeshAllocatorName[0] == 0 ) ? "unknown" : m_MeshAllocatorName;
|
||||
if ( isDynamic ) allocatorName = "total_dynamic";
|
||||
int numVerts = ( vertexSize > 0 ) ? ( bufferSize / vertexSize ) : 0;
|
||||
short totalStaticKey = HashString( "total_static" );
|
||||
short key = HashString( allocatorName );
|
||||
bool isCompressed = ( VERTEX_COMPRESSION_NONE != CompressionType( fmt ) );
|
||||
|
||||
if ( m_MeshAllocatorName[0] == 0 )
|
||||
{
|
||||
Warning("[VBMEM] unknown allocation!\n");
|
||||
}
|
||||
|
||||
// Add to the VB memory counters
|
||||
TrackAlloc( buffer, bufferSize, fmt, numVerts, key );
|
||||
if ( !isDynamic )
|
||||
{
|
||||
// Keep dynamic allocs out of the total (dynamic VBs don't get compressed)
|
||||
UpdateData( "total_static", totalStaticKey, bufferSize, fmt, numVerts, vertexSize, isDynamic, isCompressed );
|
||||
}
|
||||
UpdateData( allocatorName, key, bufferSize, fmt, numVerts, vertexSize, isDynamic, isCompressed );
|
||||
|
||||
if ( m_bSuperSpew )
|
||||
{
|
||||
// Spew every alloc
|
||||
Msg( "[VBMEM] VB-alloc | %6.2f MB | %s | %s\n", bufferSize / ( 1024.0f*1024.0f ), ( isDynamic ? "DYNamic" : " STAtic" ), allocatorName );
|
||||
SpewData( allocatorName );
|
||||
}
|
||||
SpewDataSometimes( +1 );
|
||||
|
||||
m_VBAllocMutex.Unlock();
|
||||
#endif // ENABLE_VB_ALLOC_TRACKER
|
||||
}
|
||||
|
||||
void CVBAllocTracker::UnCountVB( void * buffer )
|
||||
{
|
||||
#if ENABLE_VB_ALLOC_TRACKER
|
||||
m_VBAllocMutex.Lock();
|
||||
|
||||
short totalKey = HashString( "total_static" );
|
||||
short dynamicKey = HashString( "total_dynamic" );
|
||||
int bufferSize;
|
||||
VertexFormat_t fmt;
|
||||
int numVerts;
|
||||
short key;
|
||||
|
||||
// We have to store allocation data because the caller often doesn't know what it alloc'd :o/
|
||||
if ( KillAlloc( buffer, bufferSize, fmt, numVerts, key ) )
|
||||
{
|
||||
bool isCompressed = ( VERTEX_COMPRESSION_NONE != CompressionType( fmt ) );
|
||||
bool isDynamic = ( key == dynamicKey );
|
||||
|
||||
// Subtract from the VB memory counters
|
||||
if ( !isDynamic )
|
||||
{
|
||||
UpdateData( NULL, totalKey, -bufferSize, fmt, -numVerts, 0, isDynamic, isCompressed );
|
||||
}
|
||||
UpdateData( NULL, key, -bufferSize, fmt, -numVerts, 0, isDynamic, isCompressed );
|
||||
|
||||
const char * nameString = GetNameString( key );
|
||||
|
||||
if ( m_bSuperSpew )
|
||||
{
|
||||
Msg( "[VBMEM] VB-free | %6.2f MB | %s | %s\n", bufferSize / ( 1024.0f*1024.0f ), ( isDynamic ? "DYNamic" : " STAtic" ), nameString );
|
||||
SpewData( nameString );
|
||||
}
|
||||
SpewDataSometimes( -1 );
|
||||
}
|
||||
|
||||
m_VBAllocMutex.Unlock();
|
||||
#endif // ENABLE_VB_ALLOC_TRACKER
|
||||
}
|
||||
|
||||
bool CVBAllocTracker::TrackMeshAllocations( const char * allocatorName )
|
||||
{
|
||||
#if ENABLE_VB_ALLOC_TRACKER
|
||||
// Tracks mesh allocations by name (set this before an alloc, clear it after)
|
||||
|
||||
if ( m_MeshAllocatorName[ 0 ] )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
m_VBAllocMutex.Lock();
|
||||
|
||||
if ( allocatorName )
|
||||
{
|
||||
Assert( m_MeshAllocatorName[0] == 0 );
|
||||
V_strncpy( m_MeshAllocatorName, allocatorName, MAX_ALLOCATOR_NAME_SIZE );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_MeshAllocatorName[0] = 0;
|
||||
}
|
||||
|
||||
m_VBAllocMutex.Unlock();
|
||||
#endif // ENABLE_VB_ALLOC_TRACKER
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifndef RETAIL
|
||||
|
||||
static void CC_DumpVBMemAllocs()
|
||||
{
|
||||
#if ( ENABLE_VB_ALLOC_TRACKER == 0 )
|
||||
Warning( "ENABLE_VB_ALLOC_TRACKER must be 1 to enable VB mem alloc tracking\n");
|
||||
#else
|
||||
g_VBAllocTrackerShaderAPI.DumpVBAllocs();
|
||||
#endif
|
||||
}
|
||||
|
||||
static ConCommand mem_dumpvballocs( "mem_dumpvballocs", CC_DumpVBMemAllocs, "Dump VB memory allocation stats.", FCVAR_CHEAT );
|
||||
|
||||
#endif // RETAIL
|
||||
825
materialsystem/shaderapidx9/d3d_async.cpp
Normal file
825
materialsystem/shaderapidx9/d3d_async.cpp
Normal file
@@ -0,0 +1,825 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// methods for muti-core dx9 threading
|
||||
//===========================================================================//
|
||||
|
||||
#ifdef D3D_ASYNC_SUPPORTED
|
||||
|
||||
#include "glmgr/dxabstract.h"
|
||||
#include "utlsymbol.h"
|
||||
#include "utlvector.h"
|
||||
#include "utldict.h"
|
||||
#include "utlbuffer.h"
|
||||
#include "UtlStringMap.h"
|
||||
#include "locald3dtypes.h"
|
||||
#include "shaderapidx8_global.h"
|
||||
#include "recording.h"
|
||||
#include "tier0/vprof.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "materialsystem/imaterialsystemhardwareconfig.h"
|
||||
#include "shaderapidx8.h"
|
||||
#include "materialsystem/IShader.h"
|
||||
#include "utllinkedlist.h"
|
||||
#include "IShaderSystem.h"
|
||||
#include "tier0/fasttimer.h"
|
||||
#include <stdlib.h>
|
||||
#include "convar.h"
|
||||
#include "materialsystem/shader_vcs_version.h"
|
||||
#include "datacache/idatacache.h"
|
||||
#include "winutils.h"
|
||||
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
#if SHADERAPI_USE_SMP
|
||||
|
||||
// Set this to 1 to get vprof nodes for playing back the command stream. This is good for counting calls in a frame, etc.
|
||||
#define SHADERAPI_VPROF_BUFFER_PLAYBACK 1
|
||||
|
||||
#if SHADERAPI_VPROF_BUFFER_PLAYBACK && SHADERAPI_BUFFER_D3DCALLS
|
||||
#define VPROF_BUFFER_PLAYBACK(name) VPROF(name)
|
||||
#else
|
||||
#define VPROF_BUFFER_PLAYBACK(name) ((void)0)
|
||||
#endif
|
||||
|
||||
template<class T, int QSIZE> class FixedWorkQueue
|
||||
{
|
||||
T Data[QSIZE];
|
||||
char pad0[256];
|
||||
volatile int n_added;
|
||||
int write_index;
|
||||
char pad1[256]; // make sure these don't share cache lines
|
||||
volatile int n_removed;
|
||||
int read_index;
|
||||
|
||||
public:
|
||||
FixedWorkQueue(void)
|
||||
{
|
||||
read_index=write_index=0;
|
||||
n_added=n_removed=0;
|
||||
}
|
||||
|
||||
int IsEmpty(void)
|
||||
{
|
||||
return (n_added==n_removed);
|
||||
}
|
||||
|
||||
int IsFull(void)
|
||||
{
|
||||
return (n_added-n_removed)>=QSIZE;
|
||||
}
|
||||
|
||||
T GetWorkUnit(void)
|
||||
{
|
||||
if (IsEmpty())
|
||||
return 0;
|
||||
return Data[read_index];
|
||||
}
|
||||
|
||||
void MarkUnitDone(void)
|
||||
{
|
||||
n_removed++;
|
||||
read_index=(read_index+1) % QSIZE;
|
||||
}
|
||||
|
||||
void AddWorkUnit(T unit)
|
||||
{
|
||||
#if SHADERAPI_BUFFER_D3DCALLS
|
||||
Assert( !IsFull() );
|
||||
#else
|
||||
while (IsFull())
|
||||
Sleep(0);
|
||||
#endif
|
||||
Data[write_index]=unit;
|
||||
n_added++;
|
||||
write_index=(write_index+1) % QSIZE;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#if SHADERAPI_BUFFER_D3DCALLS
|
||||
#define N_PUSH_BUFFERS 5000
|
||||
#else
|
||||
#define N_PUSH_BUFFERS 500
|
||||
#endif
|
||||
static volatile PushBuffer *PushBuffers[N_PUSH_BUFFERS];
|
||||
FixedWorkQueue<PushBuffer *, N_PUSH_BUFFERS> PBQueue;
|
||||
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
void __cdecl OurThreadInit( void * ourthis )
|
||||
#else
|
||||
unsigned int OurThreadInit( void * ourthis )
|
||||
#endif
|
||||
{
|
||||
(( D3DDeviceWrapper *) ourthis )->RunThread();
|
||||
#ifndef WIN32
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::RunThread( void )
|
||||
{
|
||||
SetThreadAffinityMask(GetCurrentThread(), 2);
|
||||
for(;;)
|
||||
{
|
||||
PushBuffer *Pbuf=PBQueue.GetWorkUnit();
|
||||
if (! Pbuf)
|
||||
{
|
||||
; //Sleep(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ExecutePushBuffer( Pbuf );
|
||||
PBQueue.MarkUnitDone();
|
||||
Pbuf->m_State = PUSHBUFFER_AVAILABLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if SHADERAPI_BUFFER_D3DCALLS
|
||||
void D3DDeviceWrapper::ExecuteAllWork( void )
|
||||
{
|
||||
if( !m_bBufferingD3DCalls )
|
||||
return;
|
||||
VPROF_BUDGET( "ExecuteAllWork", "ExecuteAllWork" );
|
||||
SubmitPushBufferAndGetANewOne();
|
||||
PushBuffer *Pbuf;
|
||||
while( ( Pbuf = PBQueue.GetWorkUnit() ) != NULL )
|
||||
{
|
||||
ExecutePushBuffer( Pbuf );
|
||||
PBQueue.MarkUnitDone();
|
||||
Pbuf->m_State = PUSHBUFFER_AVAILABLE;
|
||||
}
|
||||
m_bBufferingD3DCalls = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SHADERAPI_BUFFER_D3DCALLS
|
||||
#define MAXIMUM_NUMBER_OF_BUFFERS_LOCKED_AT_ONCE 1600
|
||||
#else
|
||||
#define MAXIMUM_NUMBER_OF_BUFFERS_LOCKED_AT_ONCE 16
|
||||
#endif
|
||||
|
||||
struct RememberedPointer
|
||||
{
|
||||
void *m_pKey;
|
||||
void *m_pRememberedPtr;
|
||||
} RememberedPointerHistory[MAXIMUM_NUMBER_OF_BUFFERS_LOCKED_AT_ONCE];
|
||||
|
||||
void D3DDeviceWrapper::SetASyncMode( bool onoff )
|
||||
{
|
||||
#if SHADERAPI_BUFFER_D3DCALLS
|
||||
if ( onoff )
|
||||
{
|
||||
m_bBufferingD3DCalls = true;
|
||||
// allocate push buffers if we need to
|
||||
if ( PushBuffers[0] == NULL )
|
||||
{
|
||||
for(int i=0; i<N_PUSH_BUFFERS; i++)
|
||||
PushBuffers[i]=new PushBuffer;
|
||||
}
|
||||
// create thread and init communications
|
||||
memset( RememberedPointerHistory,0,sizeof(RememberedPointerHistory) );
|
||||
}
|
||||
#else
|
||||
if ( onoff )
|
||||
{
|
||||
if (! m_pASyncThreadHandle )
|
||||
{
|
||||
// allocate push buffers if we need to
|
||||
if ( PushBuffers[0] == NULL )
|
||||
{
|
||||
for(int i=0; i<N_PUSH_BUFFERS; i++)
|
||||
PushBuffers[i]=new PushBuffer;
|
||||
}
|
||||
// create thread and init communications
|
||||
memset( RememberedPointerHistory,0,sizeof(RememberedPointerHistory) );
|
||||
SetThreadAffinityMask(GetCurrentThread(), 1);
|
||||
#ifdef WIN32
|
||||
m_pASyncThreadHandle = _beginthread( OurThreadInit, 128*1024, this );
|
||||
#else
|
||||
m_pASyncThreadHandle = (uintptr_t)CreateSimpleThread( OurThreadInit, this, 128*1024 );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Synchronize();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
PushBuffer *D3DDeviceWrapper::FindFreePushBuffer( PushBufferState newstate )
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::FindFreePushBuffer" );
|
||||
for(;;)
|
||||
{
|
||||
for(int i=0;i<N_PUSH_BUFFERS;i++)
|
||||
{
|
||||
if (PushBuffers[i]->m_State == PUSHBUFFER_AVAILABLE )
|
||||
{
|
||||
PushBuffers[i]->m_State = newstate;
|
||||
return (PushBuffer *) PushBuffers[i];
|
||||
}
|
||||
}
|
||||
// hmm, out of push buffers. better sleep and try again later
|
||||
SubmitPushBufferAndGetANewOne();
|
||||
Sleep(0);
|
||||
}
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::GetPushBuffer( void )
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::GetPushBuffer" );
|
||||
m_pCurPushBuffer = FindFreePushBuffer( PUSHBUFFER_BEING_FILLED );
|
||||
m_pOutputPtr = m_pCurPushBuffer->m_BufferData;
|
||||
m_PushBufferFreeSlots = PUSHBUFFER_NELEMS - 1; // leave room for end marker
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::SubmitPushBufferAndGetANewOne( void )
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::SubmitPushBufferAndGetANewOne" );
|
||||
|
||||
// submit the current push buffer
|
||||
if ( m_pCurPushBuffer )
|
||||
{
|
||||
if (m_pOutputPtr == m_pCurPushBuffer->m_BufferData) // haven't done anyting, don't bother
|
||||
return;
|
||||
*(m_pOutputPtr) = PBCMD_END; // mark end
|
||||
m_pCurPushBuffer->m_State = PUSHBUFFER_SUBMITTED;
|
||||
// here, enqueue for task
|
||||
PBQueue.AddWorkUnit( m_pCurPushBuffer );
|
||||
}
|
||||
GetPushBuffer();
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::SubmitIfNotBusy( void )
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::SubmitIfNotBusy" );
|
||||
if ( PBQueue.IsEmpty() )
|
||||
SubmitPushBufferAndGetANewOne();
|
||||
}
|
||||
|
||||
|
||||
void D3DDeviceWrapper::Synchronize( void )
|
||||
{
|
||||
#if SHADERAPI_BUFFER_D3DCALLS
|
||||
if( m_bBufferingD3DCalls )
|
||||
{
|
||||
Assert( 0 );
|
||||
Error( "Synchronize not supported with SHADERAPI_BUFFER_D3DCALLS" );
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
if ( ASyncMode())
|
||||
{
|
||||
SubmitPushBufferAndGetANewOne();
|
||||
// here, wait for queue to become empty
|
||||
while (! PBQueue.IsEmpty() )
|
||||
{
|
||||
// Sleep(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::AsynchronousLock( IDirect3DIndexBuffer9* ib,
|
||||
size_t offset, size_t size, void **ptr,
|
||||
DWORD flags,
|
||||
LockedBufferContext *lb)
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::AsynchronousLock index" );
|
||||
|
||||
if ( size <= sizeof( PushBuffers[0]->m_BufferData ))
|
||||
{
|
||||
// can use one of our pushbuffers for this
|
||||
lb->m_pPushBuffer = FindFreePushBuffer( PUSHBUFFER_BEING_USED_FOR_LOCKEDDATA );
|
||||
*(ptr) = lb->m_pPushBuffer->m_BufferData;
|
||||
Assert( *ptr );
|
||||
lb->m_pMallocedMemory = NULL;
|
||||
}
|
||||
else // out of buffer space or size too big
|
||||
{
|
||||
lb->m_pPushBuffer = NULL;
|
||||
lb->m_pMallocedMemory = new uint8 [ size ];
|
||||
*(ptr) = lb->m_pMallocedMemory;
|
||||
}
|
||||
// now, push lock commands
|
||||
AllocatePushBufferSpace( 1+N_DWORDS_IN_PTR+3 );
|
||||
*(m_pOutputPtr++)=PBCMD_ASYNC_LOCK_IB;
|
||||
*((LPDIRECT3DINDEXBUFFER *) m_pOutputPtr)=ib;
|
||||
m_pOutputPtr+=N_DWORDS_IN_PTR;
|
||||
*(m_pOutputPtr++)=offset;
|
||||
*(m_pOutputPtr++)=size;
|
||||
*(m_pOutputPtr++)=flags;
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::AsynchronousLock( IDirect3DVertexBuffer9* vb,
|
||||
size_t offset, size_t size, void **ptr,
|
||||
DWORD flags,
|
||||
LockedBufferContext *lb)
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::AsynchronousLock vertex" );
|
||||
// we have commands in flight. Need to use temporary memory for this lock.
|
||||
// if the size needed is < the amount of space in a push buffer, we can use
|
||||
// a push buffer for the buffer. Otherwise, we're going to malloc one.
|
||||
if ( size <= sizeof( PushBuffers[0]->m_BufferData ))
|
||||
{
|
||||
// can use one of our pushbuffers for this
|
||||
lb->m_pPushBuffer = FindFreePushBuffer( PUSHBUFFER_BEING_USED_FOR_LOCKEDDATA );
|
||||
*(ptr) = lb->m_pPushBuffer->m_BufferData;
|
||||
Assert( *ptr );
|
||||
lb->m_pMallocedMemory = NULL;
|
||||
}
|
||||
else // out of buffer space or size too big
|
||||
{
|
||||
lb->m_pPushBuffer = NULL;
|
||||
lb->m_pMallocedMemory = new uint8 [ size ];
|
||||
*(ptr) = lb->m_pMallocedMemory;
|
||||
}
|
||||
// now, push lock commands
|
||||
AllocatePushBufferSpace( 1+N_DWORDS_IN_PTR+3 );
|
||||
*(m_pOutputPtr++)=PBCMD_ASYNC_LOCK_VB;
|
||||
*((LPDIRECT3DVERTEXBUFFER *) m_pOutputPtr)=vb;
|
||||
m_pOutputPtr+=N_DWORDS_IN_PTR;
|
||||
*(m_pOutputPtr++)=offset;
|
||||
*(m_pOutputPtr++)=size;
|
||||
*(m_pOutputPtr++)=flags;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline void RememberLockedPointer( void *key, void *value )
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "RememberLockedPointer" );
|
||||
int repl=-1;
|
||||
int i;
|
||||
for(i=0;i<MAXIMUM_NUMBER_OF_BUFFERS_LOCKED_AT_ONCE;i++)
|
||||
{
|
||||
if ( RememberedPointerHistory[i].m_pKey==key )
|
||||
break;
|
||||
if ( (repl == -1 ) && (RememberedPointerHistory[i].m_pRememberedPtr == 0 ) )
|
||||
repl=i;
|
||||
}
|
||||
if (i != MAXIMUM_NUMBER_OF_BUFFERS_LOCKED_AT_ONCE )
|
||||
{
|
||||
RememberedPointerHistory[i].m_pRememberedPtr = value;
|
||||
if ( value==NULL )
|
||||
RememberedPointerHistory[i].m_pKey = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (repl == -1 )
|
||||
{
|
||||
Assert( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
RememberedPointerHistory[repl].m_pKey = key;
|
||||
RememberedPointerHistory[repl].m_pRememberedPtr = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void *RecallLockedPointer( void *key )
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "RecallLockedPointer" );
|
||||
|
||||
for(int i=0;i<MAXIMUM_NUMBER_OF_BUFFERS_LOCKED_AT_ONCE;i++)
|
||||
if ( RememberedPointerHistory[i].m_pKey == key )
|
||||
return RememberedPointerHistory[i].m_pRememberedPtr;
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::HandleAsynchronousLockVBCommand( uint32 const *dptr )
|
||||
{
|
||||
dptr++;
|
||||
LPDIRECT3DVERTEXBUFFER vb=*((LPDIRECT3DVERTEXBUFFER *) dptr);
|
||||
dptr+=N_DWORDS_IN_PTR;
|
||||
uint32 offset=*(dptr++);
|
||||
uint32 size=*(dptr++);
|
||||
uint32 flags=*(dptr++);
|
||||
void *locked_ptr=0;
|
||||
vb->Lock( offset, size, &locked_ptr, flags );
|
||||
RememberLockedPointer( vb, locked_ptr );
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::HandleAsynchronousUnLockVBCommand( uint32 const *dptr )
|
||||
{
|
||||
dptr++;
|
||||
LPDIRECT3DVERTEXBUFFER vb=*((LPDIRECT3DVERTEXBUFFER *) dptr);
|
||||
dptr+=N_DWORDS_IN_PTR;
|
||||
LockedBufferContext lb=*((LockedBufferContext *) dptr);
|
||||
dptr+=N_DWORDS( LockedBufferContext );
|
||||
size_t unlock_size=*( dptr++ );
|
||||
void *locked_data=RecallLockedPointer( vb );
|
||||
Assert( locked_data );
|
||||
if (lb.m_pPushBuffer)
|
||||
{
|
||||
Assert( ! lb.m_pMallocedMemory );
|
||||
if ( locked_data )
|
||||
memcpy( locked_data, lb.m_pPushBuffer->m_BufferData, unlock_size );
|
||||
lb.m_pPushBuffer->m_State = PUSHBUFFER_AVAILABLE;
|
||||
}
|
||||
else if ( lb.m_pMallocedMemory )
|
||||
{
|
||||
Assert( ! lb.m_pPushBuffer );
|
||||
if ( locked_data )
|
||||
memcpy( locked_data, lb.m_pMallocedMemory, unlock_size );
|
||||
delete[] ((uint8 *) lb.m_pMallocedMemory);
|
||||
}
|
||||
// now, actually unlock
|
||||
RememberLockedPointer( vb, NULL );
|
||||
vb->Unlock();
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::HandleAsynchronousLockIBCommand( uint32 const *dptr )
|
||||
{
|
||||
dptr++;
|
||||
LPDIRECT3DINDEXBUFFER ib=*((LPDIRECT3DINDEXBUFFER *) dptr);
|
||||
Assert( ib );
|
||||
dptr+=N_DWORDS_IN_PTR;
|
||||
uint32 offset=*(dptr++);
|
||||
uint32 size=*(dptr++);
|
||||
uint32 flags=*(dptr++);
|
||||
void *locked_ptr=0;
|
||||
ib->Lock( offset, size, &locked_ptr, flags );
|
||||
RememberLockedPointer( ib, locked_ptr );
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::HandleAsynchronousUnLockIBCommand( uint32 const *dptr )
|
||||
{
|
||||
dptr++;
|
||||
LPDIRECT3DINDEXBUFFER ib=*((LPDIRECT3DINDEXBUFFER *) dptr);
|
||||
dptr+=N_DWORDS_IN_PTR;
|
||||
LockedBufferContext lb=*((LockedBufferContext *) dptr);
|
||||
dptr+=N_DWORDS( LockedBufferContext );
|
||||
size_t unlock_size=*( dptr++ );
|
||||
void *locked_data=RecallLockedPointer( ib );
|
||||
Assert( locked_data );
|
||||
if (lb.m_pPushBuffer)
|
||||
{
|
||||
Assert( ! lb.m_pMallocedMemory );
|
||||
if ( locked_data )
|
||||
memcpy( locked_data, lb.m_pPushBuffer->m_BufferData, unlock_size );
|
||||
lb.m_pPushBuffer->m_State = PUSHBUFFER_AVAILABLE;
|
||||
}
|
||||
else if ( lb.m_pMallocedMemory )
|
||||
{
|
||||
Assert( ! lb.m_pPushBuffer );
|
||||
if ( locked_data )
|
||||
memcpy( locked_data, lb.m_pMallocedMemory, unlock_size );
|
||||
delete[] ((uint8 *) lb.m_pMallocedMemory);
|
||||
}
|
||||
// now, actually unlock
|
||||
RememberLockedPointer( ib, NULL );
|
||||
ib->Unlock();
|
||||
|
||||
}
|
||||
|
||||
|
||||
static inline void *FetchPtr( uint32 const *mem)
|
||||
{
|
||||
void **p=(void **) mem;
|
||||
return *p;
|
||||
}
|
||||
|
||||
#define CALC_STATS 1
|
||||
#if CALC_STATS
|
||||
int n_commands_executed=0;
|
||||
int n_pbs_executed=0;
|
||||
#endif
|
||||
|
||||
void D3DDeviceWrapper::ExecutePushBuffer( PushBuffer const* pb)
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::ExecutePushBuffer" );
|
||||
uint32 const *dptr=pb->m_BufferData;
|
||||
n_pbs_executed++;
|
||||
for(;;)
|
||||
{
|
||||
n_commands_executed++;
|
||||
switch( dptr[0] )
|
||||
{
|
||||
case PBCMD_END:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "END" );
|
||||
n_commands_executed--; // doesn't count
|
||||
return;
|
||||
}
|
||||
|
||||
case PBCMD_SET_RENDERSTATE:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_RENDERSTATE" );
|
||||
Dx9Device()->SetRenderState((D3DRENDERSTATETYPE) dptr[1],dptr[2]);
|
||||
dptr+=3;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_SAMPLER_STATE:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_SAMPLER_STATE" );
|
||||
Dx9Device()->SetSamplerState(dptr[1], (D3DSAMPLERSTATETYPE) dptr[2], dptr[3]);
|
||||
dptr+=4;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_DRAWPRIM:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "DRAWPRIM" );
|
||||
|
||||
tmZone( TELEMETRY_LEVEL2, TMZF_NONE, "Dx9Device()->DrawPrimitive" );
|
||||
|
||||
Dx9Device()->DrawPrimitive( (D3DPRIMITIVETYPE) dptr[1], dptr[2], dptr[3] );
|
||||
dptr+=4;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_DRAWINDEXEDPRIM:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "DRAWINDEXEDPRIM" );
|
||||
|
||||
tmZone( TELEMETRY_LEVEL2, TMZF_NONE, "Dx9Device()->DrawIndexedPrimitive" );
|
||||
|
||||
Dx9Device()->DrawIndexedPrimitive( (D3DPRIMITIVETYPE) dptr[1], dptr[2], dptr[3],
|
||||
dptr[4], dptr[5], dptr[6]);
|
||||
dptr+=7;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_STREAM_SOURCE:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_STREAM_SOURCE" );
|
||||
Dx9Device()->SetStreamSource( dptr[1],(IDirect3DVertexBuffer9 *) FetchPtr(dptr+2),
|
||||
dptr[3],dptr[4] );
|
||||
dptr += 4+N_DWORDS( IDirect3DVertexBuffer9 * );
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_TEXTURE:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_TEXTURE" );
|
||||
Dx9Device()->SetTexture( dptr[1],(IDirect3DBaseTexture *) FetchPtr(dptr+2));
|
||||
dptr += 2+N_DWORDS_IN_PTR;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_RENDER_TARGET:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_RENDER_TARGET" );
|
||||
Dx9Device()->SetRenderTarget( dptr[1],(IDirect3DSurface *) FetchPtr(dptr+2));
|
||||
dptr += 2+N_DWORDS_IN_PTR;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_PIXEL_SHADER:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_PIXEL_SHADER" );
|
||||
Dx9Device()->SetPixelShader( (IDirect3DPixelShader9 *) FetchPtr(dptr+1));
|
||||
dptr += 1+N_DWORDS_IN_PTR;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_INDICES:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_INDICES" );
|
||||
Dx9Device()->SetIndices( (IDirect3DIndexBuffer9*) FetchPtr(dptr+1));
|
||||
dptr += 1+N_DWORDS_IN_PTR;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_DEPTH_STENCIL_SURFACE:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_DEPTH_STENCIL_SURFACE" );
|
||||
Dx9Device()->SetDepthStencilSurface( (IDirect3DSurface9*) FetchPtr(dptr+1));
|
||||
dptr += 1+N_DWORDS_IN_PTR;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SETVIEWPORT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SETVIEWPORT" );
|
||||
Dx9Device()->SetViewport( (D3DVIEWPORT9 const *) (dptr+1) );
|
||||
dptr += 1+N_DWORDS(D3DVIEWPORT9);
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_VERTEX_SHADER:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_VERTEX_SHADER" );
|
||||
Dx9Device()->SetVertexShader( (IDirect3DVertexShader9 *) FetchPtr(dptr+1));
|
||||
dptr += 1+N_DWORDS_IN_PTR;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_ASYNC_LOCK_VB:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "ASYNC_LOCK_VB" );
|
||||
HandleAsynchronousLockVBCommand(dptr);
|
||||
dptr+=1+N_DWORDS_IN_PTR+3;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_ASYNC_UNLOCK_VB:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "ASYNC_UNLOCK_VB" );
|
||||
HandleAsynchronousUnLockVBCommand( dptr );
|
||||
dptr+=1+N_DWORDS_IN_PTR+N_DWORDS( LockedBufferContext )+1;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_ASYNC_LOCK_IB:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "ASYNC_LOCK_IB" );
|
||||
HandleAsynchronousLockIBCommand(dptr);
|
||||
dptr+=1+N_DWORDS_IN_PTR+3;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_ASYNC_UNLOCK_IB:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "ASYNC_UNLOCK_IB" );
|
||||
HandleAsynchronousUnLockIBCommand( dptr );
|
||||
dptr+=1+N_DWORDS_IN_PTR+N_DWORDS( LockedBufferContext )+1;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_UNLOCK_VB:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "UNLOCK_VB" );
|
||||
IDirect3DVertexBuffer9 *p=(IDirect3DVertexBuffer9 *) FetchPtr(dptr+1);
|
||||
p->Unlock();
|
||||
dptr += 1+N_DWORDS_IN_PTR;
|
||||
break;
|
||||
}
|
||||
case PBCMD_UNLOCK_IB:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "UNLOCK_IB" );
|
||||
IDirect3DIndexBuffer9 *p=(IDirect3DIndexBuffer9 *) FetchPtr(dptr+1);
|
||||
p->Unlock();
|
||||
dptr += 1+N_DWORDS_IN_PTR;
|
||||
break;
|
||||
}
|
||||
case PBCMD_SET_VERTEX_SHADER_CONSTANT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_VERTEX_SHADER_CONSTANT" );
|
||||
Dx9Device()->SetVertexShaderConstantF( dptr[1], (float const *) dptr+3, dptr[2]);
|
||||
dptr += 3+4*dptr[2];
|
||||
break;
|
||||
}
|
||||
case PBCMD_SET_BOOLEAN_VERTEX_SHADER_CONSTANT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_BOOLEAN_VERTEX_SHADER_CONSTANT" );
|
||||
Dx9Device()->SetVertexShaderConstantB( dptr[1], (int const *) dptr+3, dptr[2]);
|
||||
dptr += 3+dptr[2];
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_INTEGER_VERTEX_SHADER_CONSTANT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_INTEGER_VERTEX_SHADER_CONSTANT" );
|
||||
Dx9Device()->SetVertexShaderConstantI( dptr[1], (int const *) dptr+3, dptr[2]);
|
||||
dptr += 3+4*dptr[2];
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_PIXEL_SHADER_CONSTANT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_PIXEL_SHADER_CONSTANT" );
|
||||
Dx9Device()->SetPixelShaderConstantF( dptr[1], (float const *) dptr+3, dptr[2]);
|
||||
dptr += 3+4*dptr[2];
|
||||
break;
|
||||
}
|
||||
case PBCMD_SET_BOOLEAN_PIXEL_SHADER_CONSTANT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_BOOLEAN_PIXEL_SHADER_CONSTANT" );
|
||||
Dx9Device()->SetPixelShaderConstantB( dptr[1], (int const *) dptr+3, dptr[2]);
|
||||
dptr += 3+dptr[2];
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_INTEGER_PIXEL_SHADER_CONSTANT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_INTEGER_PIXEL_SHADER_CONSTANT" );
|
||||
Dx9Device()->SetPixelShaderConstantI( dptr[1], (int const *) dptr+3, dptr[2]);
|
||||
dptr += 3+4*dptr[2];
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_BEGIN_SCENE:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "BEGIN_SCENE" );
|
||||
Dx9Device()->BeginScene();
|
||||
dptr++;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_END_SCENE:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "END_SCENE" );
|
||||
Dx9Device()->EndScene();
|
||||
dptr++;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_CLEAR:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "CLEAR" );
|
||||
dptr++;
|
||||
int count=*(dptr++);
|
||||
D3DRECT const *pRects=0;
|
||||
if (count)
|
||||
{
|
||||
pRects=(D3DRECT const *) dptr;
|
||||
dptr+=count*N_DWORDS( D3DRECT );
|
||||
}
|
||||
int flags=*(dptr++);
|
||||
D3DCOLOR color=*((D3DCOLOR const *) (dptr++));
|
||||
float z=*((float const *) (dptr++));
|
||||
int stencil=*(dptr++);
|
||||
Dx9Device()->Clear( count, pRects, flags, color, z, stencil );
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_VERTEXDECLARATION:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_VERTEXDECLARATION" );
|
||||
Dx9Device()->SetVertexDeclaration( (IDirect3DVertexDeclaration9 *) FetchPtr(dptr+1));
|
||||
dptr += 1+N_DWORDS_IN_PTR;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SETCLIPPLANE:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SETCLIPPLANE" );
|
||||
Dx9Device()->SetClipPlane( dptr[1], (float const *) dptr+2 );
|
||||
dptr+=6;
|
||||
}
|
||||
break;
|
||||
|
||||
case PBCMD_STRETCHRECT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "STRETCHRECT" );
|
||||
dptr++;
|
||||
IDirect3DSurface9 *pSourceSurface=(IDirect3DSurface9 *) FetchPtr(dptr);
|
||||
dptr+=N_DWORDS_IN_PTR;
|
||||
RECT const *pSourceRect=0;
|
||||
if (*(dptr++))
|
||||
pSourceRect=(RECT const *) dptr;
|
||||
dptr += N_DWORDS( RECT );
|
||||
IDirect3DSurface9 *pDestSurface= (IDirect3DSurface9 *) FetchPtr( dptr );
|
||||
dptr += N_DWORDS_IN_PTR;
|
||||
RECT const *pDestRect=0;
|
||||
if (*(dptr++))
|
||||
pDestRect=(RECT const *) dptr;
|
||||
dptr += N_DWORDS( RECT );
|
||||
D3DTEXTUREFILTERTYPE Filter = (D3DTEXTUREFILTERTYPE) *(dptr++);
|
||||
Dx9Device()->StretchRect( pSourceSurface, pSourceRect,
|
||||
pDestSurface, pDestRect,
|
||||
Filter );
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case PBCMD_PRESENT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "PRESENT" );
|
||||
dptr++;
|
||||
RECT const *pSourceRect=0;
|
||||
if (* (dptr++) )
|
||||
pSourceRect=(RECT const *) dptr;
|
||||
dptr+=N_DWORDS( RECT );
|
||||
RECT const *pDestRect = 0;
|
||||
if (* (dptr++) )
|
||||
pDestRect=(RECT const *) dptr;
|
||||
dptr+=N_DWORDS( RECT );
|
||||
VD3DHWND hDestWindowOverride = (VD3DHWND) *(dptr++);
|
||||
RGNDATA const *pDirtyRegion=0;
|
||||
if ( *(dptr++) )
|
||||
pDirtyRegion= (RGNDATA const *) dptr;
|
||||
dptr+=N_DWORDS( RGNDATA );
|
||||
|
||||
tmZone( TELEMETRY_LEVEL1, TMZF_NONE, "!D3DPresent" );
|
||||
|
||||
Dx9Device()->Present( pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion );
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_SCISSOR_RECT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_SCISSOR_RECT" );
|
||||
dptr++;
|
||||
const RECT *pRect = ( RECT * )FetchPtr( dptr );
|
||||
dptr += sizeof( RECT );
|
||||
Dx9Device()->SetScissorRect( pRect );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // D3D_ASYNC_SUPPORTED
|
||||
1567
materialsystem/shaderapidx9/d3d_async.h
Normal file
1567
materialsystem/shaderapidx9/d3d_async.h
Normal file
File diff suppressed because it is too large
Load Diff
1289
materialsystem/shaderapidx9/dx9hook.h
Normal file
1289
materialsystem/shaderapidx9/dx9hook.h
Normal file
File diff suppressed because it is too large
Load Diff
1056
materialsystem/shaderapidx9/dynamicib.h
Normal file
1056
materialsystem/shaderapidx9/dynamicib.h
Normal file
File diff suppressed because it is too large
Load Diff
1098
materialsystem/shaderapidx9/dynamicvb.h
Normal file
1098
materialsystem/shaderapidx9/dynamicvb.h
Normal file
File diff suppressed because it is too large
Load Diff
480
materialsystem/shaderapidx9/gpubufferallocator.cpp
Normal file
480
materialsystem/shaderapidx9/gpubufferallocator.cpp
Normal file
@@ -0,0 +1,480 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: See gpubufferallocator.h
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "gpubufferallocator.h"
|
||||
#include "dynamicvb.h"
|
||||
#include "dynamicib.h"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
#if defined( _X360 )
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// globals
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "utlmap.h"
|
||||
MEMALLOC_DEFINE_EXTERNAL_TRACKING( XMem_CGPUBufferPool );
|
||||
|
||||
// Track non-pooled VB/IB physical allocations (used by CGPUBufferAllocator::SpewStats)
|
||||
CInterlockedInt g_NumIndividualVBPhysAllocs = 0;
|
||||
CInterlockedInt g_SizeIndividualVBPhysAllocs = 0;
|
||||
CInterlockedInt g_NumIndividualIBPhysAllocs = 0;
|
||||
CInterlockedInt g_SizeIndividualIBPhysAllocs = 0;
|
||||
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
// CGPUBufferAllocator
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
|
||||
CGPUBufferAllocator::CGPUBufferAllocator( void )
|
||||
: m_nBufferPools( 0 ),
|
||||
m_bEnabled( true )
|
||||
{
|
||||
memset( &( m_BufferPools[ 0 ] ), 0, sizeof( m_BufferPools ) );
|
||||
|
||||
m_bEnabled = USE_GPU_BUFFER_ALLOCATOR && !CommandLine()->FindParm( "-no_gpu_buffer_allocator" );
|
||||
if ( m_bEnabled )
|
||||
{
|
||||
// Start with one pool (the size should be the lowest-common-denominator for all maps)
|
||||
AllocatePool( INITIAL_POOL_SIZE );
|
||||
}
|
||||
}
|
||||
|
||||
CGPUBufferAllocator::~CGPUBufferAllocator( void )
|
||||
{
|
||||
for ( int i = 0; i < m_nBufferPools; i++ )
|
||||
{
|
||||
delete m_BufferPools[ i ];
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Allocate a new memory pool
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CGPUBufferAllocator::AllocatePool( int nPoolSize )
|
||||
{
|
||||
if ( m_nBufferPools == MAX_POOLS )
|
||||
return false;
|
||||
|
||||
m_BufferPools[ m_nBufferPools ] = new CGPUBufferPool( nPoolSize );
|
||||
if ( m_BufferPools[ m_nBufferPools ]->m_pMemory == NULL )
|
||||
{
|
||||
// Physical alloc failed! Continue without crashing, we *might* get away with it...
|
||||
ExecuteOnce( DebuggerBreakIfDebugging() );
|
||||
ExecuteNTimes( 15, Warning( "CGPUBufferAllocator::AllocatePool - physical allocation failed! Physical fragmentation is in bad shape... falling back to non-pooled VB/IB allocations. Brace for a crash :o/\n" ) );
|
||||
delete m_BufferPools[ m_nBufferPools ];
|
||||
m_BufferPools[ m_nBufferPools ] = NULL;
|
||||
return false;
|
||||
}
|
||||
m_nBufferPools++;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Make a new GPUBufferHandle_t to represent a given buffer allocation
|
||||
//-----------------------------------------------------------------------------
|
||||
inline GPUBufferHandle_t CGPUBufferAllocator::MakeGPUBufferHandle( int nPoolNum, int nPoolEntry )
|
||||
{
|
||||
GPUBufferHandle_t newHandle;
|
||||
newHandle.nPoolNum = nPoolNum;
|
||||
newHandle.nPoolEntry = nPoolEntry;
|
||||
newHandle.pMemory = m_BufferPools[ nPoolNum ]->m_pMemory + m_BufferPools[ nPoolNum ]->m_PoolEntries[ nPoolEntry ].nOffset;
|
||||
return newHandle;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Try to allocate a block of the given size from one of our pools
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CGPUBufferAllocator::AllocateBuffer( GPUBufferHandle_t *pHandle, int nBufferSize, void *pObject, bool bIsVertexBuffer )
|
||||
{
|
||||
if ( m_bEnabled && ( nBufferSize <= MAX_BUFFER_SIZE ) )
|
||||
{
|
||||
// Try to allocate at the end of one of our pools
|
||||
for ( int nPool = 0; nPool < m_nBufferPools; nPool++ )
|
||||
{
|
||||
int nPoolEntry = m_BufferPools[ nPool ]->Allocate( nBufferSize, bIsVertexBuffer, pObject );
|
||||
if ( nPoolEntry >= 0 )
|
||||
{
|
||||
// Tada.
|
||||
*pHandle = MakeGPUBufferHandle( nPool, nPoolEntry );
|
||||
return true;
|
||||
}
|
||||
if ( nPool == ( m_nBufferPools - 1 ) )
|
||||
{
|
||||
// Allocate a new pool (in which this buffer should DEFINITELY fit!)
|
||||
COMPILE_TIME_ASSERT( ADDITIONAL_POOL_SIZE >= MAX_BUFFER_SIZE );
|
||||
AllocatePool( ADDITIONAL_POOL_SIZE );
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Clear the given allocation from our pools (NOTE: the memory cannot be reused until Defrag() is called)
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGPUBufferAllocator::DeallocateBuffer( const GPUBufferHandle_t *pHandle )
|
||||
{
|
||||
Assert( pHandle );
|
||||
if ( pHandle )
|
||||
{
|
||||
Assert( ( pHandle->nPoolNum >= 0 ) && ( pHandle->nPoolNum < m_nBufferPools ) );
|
||||
if ( ( pHandle->nPoolNum >= 0 ) && ( pHandle->nPoolNum < m_nBufferPools ) )
|
||||
{
|
||||
m_BufferPools[ pHandle->nPoolNum ]->Deallocate( pHandle );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// If appropriate, allocate this VB's memory from one of our pools
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CGPUBufferAllocator::AllocateVertexBuffer( CVertexBuffer *pVertexBuffer, int nBufferSize )
|
||||
{
|
||||
AUTO_LOCK( m_mutex );
|
||||
|
||||
bool bIsVertexBuffer = true;
|
||||
GPUBufferHandle_t handle;
|
||||
if ( AllocateBuffer( &handle, nBufferSize, (void *)pVertexBuffer, bIsVertexBuffer ) )
|
||||
{
|
||||
// Success - give the VB the handle to this allocation
|
||||
pVertexBuffer->SetBufferAllocationHandle( handle );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Deallocate this VB's memory from our pools
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGPUBufferAllocator::DeallocateVertexBuffer( CVertexBuffer *pVertexBuffer )
|
||||
{
|
||||
AUTO_LOCK( m_mutex );
|
||||
|
||||
// Remove the allocation from the pool and clear the VB's handle
|
||||
DeallocateBuffer( pVertexBuffer->GetBufferAllocationHandle() );
|
||||
pVertexBuffer->SetBufferAllocationHandle( GPUBufferHandle_t() );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// If appropriate, allocate this IB's memory from one of our pools
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CGPUBufferAllocator::AllocateIndexBuffer( CIndexBuffer *pIndexBuffer, int nBufferSize )
|
||||
{
|
||||
AUTO_LOCK( m_mutex );
|
||||
|
||||
bool bIsNOTVertexBuffer = false;
|
||||
GPUBufferHandle_t handle;
|
||||
if ( AllocateBuffer( &handle, nBufferSize, (void *)pIndexBuffer, bIsNOTVertexBuffer ) )
|
||||
{
|
||||
// Success - give the IB the handle to this allocation
|
||||
pIndexBuffer->SetBufferAllocationHandle( handle );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Deallocate this IB's memory from our pools
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGPUBufferAllocator::DeallocateIndexBuffer( CIndexBuffer *pIndexBuffer )
|
||||
{
|
||||
AUTO_LOCK( m_mutex );
|
||||
|
||||
// Remove the allocation from the pool and clear the IB's handle
|
||||
DeallocateBuffer( pIndexBuffer->GetBufferAllocationHandle() );
|
||||
pIndexBuffer->SetBufferAllocationHandle( GPUBufferHandle_t() );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Move a buffer from one location to another (could be movement within the same pool)
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGPUBufferAllocator::MoveBufferMemory( int nDstPool, int *pnDstEntry, int *pnDstOffset, CGPUBufferPool &srcPool, GPUBufferPoolEntry_t &srcEntry )
|
||||
{
|
||||
// Move the data
|
||||
CGPUBufferPool &dstPool = *m_BufferPools[ nDstPool ];
|
||||
byte *pDest = dstPool.m_pMemory + *pnDstOffset;
|
||||
byte *pSource = srcPool.m_pMemory + srcEntry.nOffset;
|
||||
if ( pDest != pSource )
|
||||
V_memmove( pDest, pSource, srcEntry.nSize );
|
||||
|
||||
// Update the destination pool's allocation entry (NOTE: this could be srcEntry, so srcEntry.nOffset would change)
|
||||
dstPool.m_PoolEntries[ *pnDstEntry ] = srcEntry;
|
||||
dstPool.m_PoolEntries[ *pnDstEntry ].nOffset = *pnDstOffset;
|
||||
|
||||
// Tell the VB/IB about the updated allocation
|
||||
GPUBufferHandle_t newHandle = MakeGPUBufferHandle( nDstPool, *pnDstEntry );
|
||||
if ( srcEntry.bIsVertexBuffer )
|
||||
srcEntry.pVertexBuffer->SetBufferAllocationHandle( newHandle );
|
||||
else
|
||||
srcEntry.pIndexBuffer->SetBufferAllocationHandle( newHandle );
|
||||
|
||||
// Move the write address past this entry and increment the pool high water mark
|
||||
*pnDstOffset += srcEntry.nSize;
|
||||
*pnDstEntry += 1;
|
||||
dstPool.m_nBytesUsed += srcEntry.nSize;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Reclaim space freed by destroyed buffers and compact our pools ready for new allocations
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGPUBufferAllocator::Compact( void )
|
||||
{
|
||||
// NOTE: this must only be called during map transitions, no rendering must be in flight and everything must be single-threaded!
|
||||
AUTO_LOCK( m_mutex );
|
||||
|
||||
// SpewStats(); // pre-compact state
|
||||
|
||||
CFastTimer timer;
|
||||
timer.Start();
|
||||
|
||||
// Shuffle all pools to get rid of the empty space occupied by freed buffers.
|
||||
// We just walk the pools and entries in order, moving each buffer down within the same pool,
|
||||
// or to the end of a previous pool (if, after compaction, it now has free space).
|
||||
// Each pool should end up with contiguous, usable free space (may be zero bytes) at the end.
|
||||
int nDstPool = 0, nDstEntry = 0, nDstOffset = 0;
|
||||
for ( int nSrcPool = 0; nSrcPool < m_nBufferPools; nSrcPool++ )
|
||||
{
|
||||
CGPUBufferPool &srcPool = *m_BufferPools[ nSrcPool ];
|
||||
srcPool.m_nBytesUsed = 0; // Re-fill each pool from scratch
|
||||
int nEntriesRemainingInPool = 0;
|
||||
for ( int nSrcEntry = 0; nSrcEntry < srcPool.m_PoolEntries.Count(); nSrcEntry++ )
|
||||
{
|
||||
GPUBufferPoolEntry_t &srcEntry = srcPool.m_PoolEntries[ nSrcEntry ];
|
||||
if ( srcEntry.pVertexBuffer )
|
||||
{
|
||||
// First, try to move the buffer into one of the previous (already-compacted) pools
|
||||
bool bDone = false;
|
||||
while ( nDstPool < nSrcPool )
|
||||
{
|
||||
CGPUBufferPool &dstPool = *m_BufferPools[ nDstPool ];
|
||||
if ( ( nDstOffset + srcEntry.nSize ) <= dstPool.m_nSize )
|
||||
{
|
||||
// Add this buffer to the end of dstPool
|
||||
Assert( nDstEntry == dstPool.m_PoolEntries.Count() );
|
||||
dstPool.m_PoolEntries.AddToTail();
|
||||
MoveBufferMemory( nDstPool, &nDstEntry, &nDstOffset, srcPool, srcEntry );
|
||||
bDone = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// This pool is full, start writing into the next one
|
||||
nDstPool++;
|
||||
nDstEntry = 0;
|
||||
nDstOffset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// If that fails, just shuffle the entry down within srcPool
|
||||
if ( !bDone )
|
||||
{
|
||||
Assert( nSrcPool == nDstPool );
|
||||
MoveBufferMemory( nDstPool, &nDstEntry, &nDstOffset, srcPool, srcEntry );
|
||||
nEntriesRemainingInPool++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Discard unused entries from the end of the pool (freed buffers, or buffers moved to other pools)
|
||||
srcPool.m_PoolEntries.SetCountNonDestructively( nEntriesRemainingInPool );
|
||||
}
|
||||
|
||||
// Now free empty pools (keep the first (very large) one around, since fragmentation makes freeing+reallocing it a big risk)
|
||||
int nBytesFreed = 0;
|
||||
for ( int nPool = ( m_nBufferPools - 1 ); nPool > 0; nPool-- )
|
||||
{
|
||||
if ( m_BufferPools[ nPool ]->m_PoolEntries.Count() )
|
||||
break;
|
||||
|
||||
nBytesFreed += m_BufferPools[ nPool ]->m_nSize;
|
||||
Assert( m_BufferPools[ nPool ]->m_nBytesUsed == 0 );
|
||||
delete m_BufferPools[ nPool ];
|
||||
m_nBufferPools--;
|
||||
}
|
||||
|
||||
if ( m_nBufferPools > 1 )
|
||||
{
|
||||
// The above compaction algorithm could waste space due to large allocs causing nDstPool to increment before that pool
|
||||
// is actually full. With our current usage pattern (total in-use memory is less than INITIAL_POOL_SIZE, whenever Compact
|
||||
// is called), that doesn't matter. If that changes (i.e. the below warning fires), then the fix would be:
|
||||
// - for each pool, sort its entries by size (largest first) and try to allocate them on the end of prior (already-compacted) pools
|
||||
// - pack whatever remains in the pool down, and proceed to the next pool
|
||||
ExecuteOnce( Warning( "CGPUBufferAllocator::Compact may be wasting memory due to changed usage patterns (see code for suggested fix)." ) );
|
||||
}
|
||||
|
||||
#ifdef _X360
|
||||
// Invalidate the GPU caches for all pooled memory, since stuff has moved around
|
||||
for ( int nPool = 0; nPool < m_nBufferPools; nPool++ )
|
||||
{
|
||||
Dx9Device()->InvalidateGpuCache( m_BufferPools[ nPool ]->m_pMemory, m_BufferPools[ nPool ]->m_nSize, 0 );
|
||||
}
|
||||
#endif
|
||||
|
||||
timer.End();
|
||||
float compactTime = (float)timer.GetDuration().GetSeconds();
|
||||
Msg( "CGPUBufferAllocator::Compact took %.2f seconds, and freed %.1fkb\n", compactTime, ( nBytesFreed / 1024.0f ) );
|
||||
|
||||
// SpewStats(); // post-compact state
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Spew statistics about pool usage, so we can tune our constant values
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGPUBufferAllocator::SpewStats( bool bBrief )
|
||||
{
|
||||
AUTO_LOCK( m_mutex );
|
||||
|
||||
int nMemAllocated = 0;
|
||||
int nMemUsed = 0;
|
||||
int nOldMemWasted = 0;
|
||||
int nVBsInPools = 0;
|
||||
int nIBsInPools = 0;
|
||||
int nFreedBuffers = 0;
|
||||
int nFreedBufferMem = 0;
|
||||
for ( int i = 0; i < m_nBufferPools; i++ )
|
||||
{
|
||||
CGPUBufferPool *pool = m_BufferPools[ i ];
|
||||
nMemAllocated += pool->m_nSize;
|
||||
nMemUsed += pool->m_nBytesUsed;
|
||||
for ( int j = 0; j < pool->m_PoolEntries.Count(); j++ )
|
||||
{
|
||||
GPUBufferPoolEntry_t &poolEntry = pool->m_PoolEntries[ j ];
|
||||
if ( poolEntry.pVertexBuffer )
|
||||
{
|
||||
// Figure out how much memory we WOULD have allocated for this buffer, if we'd allocated it individually:
|
||||
nOldMemWasted += ALIGN_VALUE( poolEntry.nSize, 4096 ) - poolEntry.nSize;
|
||||
if ( poolEntry.bIsVertexBuffer ) nVBsInPools++;
|
||||
if ( !poolEntry.bIsVertexBuffer ) nIBsInPools++;
|
||||
}
|
||||
else
|
||||
{
|
||||
nFreedBuffers++;
|
||||
nFreedBufferMem += poolEntry.nSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: 'unused' memory doesn't count memory used by freed buffers, which should be zero during gameplay. The purpose is
|
||||
// to measure wastage at the END of a pool, to help determine ideal values for ADDITIONAL_POOL_SIZE and MAX_BUFFER_SIZE.
|
||||
int nMemUnused = nMemAllocated - nMemUsed;
|
||||
|
||||
const float KB = 1024.0f, MB = KB*KB;
|
||||
if ( bBrief )
|
||||
{
|
||||
ConMsg( "[GPUBUFLOG] Pools:%2d | Size:%5.1fMB | Unused:%5.1fMB | Freed:%5.1fMB | Unpooled:%5.1fMB\n",
|
||||
m_nBufferPools, nMemAllocated / MB, nMemUnused / MB, nFreedBufferMem / MB, ( g_SizeIndividualVBPhysAllocs + g_SizeIndividualIBPhysAllocs ) / MB );
|
||||
}
|
||||
else
|
||||
{
|
||||
Msg( "\nGPU Buffer Allocator stats:\n" );
|
||||
Msg( " -- %5d -- Num Pools allocated\n", m_nBufferPools );
|
||||
Msg( " -- %7.1fMB -- Memory allocated to pools\n", nMemAllocated / MB );
|
||||
Msg( " -- %7.1fkb -- Unused memory at tail-end of pools\n", nMemUnused / KB );
|
||||
Msg( " -- %7.1fkb -- Memory saved by allocating buffers from pools\n", nOldMemWasted / KB );
|
||||
Msg( " -- %5d -- Number of VBs allocated from pools\n", nVBsInPools );
|
||||
Msg( " -- %5d -- Number of IBs allocated from pools\n", nIBsInPools );
|
||||
Msg( " -- %5d -- Number of freed buffers in pools (should be zero during gameplay)\n", nFreedBuffers );
|
||||
Msg( " -- %7.1fkb -- Memory used by freed buffers in pools\n", nFreedBufferMem / KB );
|
||||
Msg( " -- %7.1fkb -- Mem allocated for NON-pooled VBs (%d VBs)\n", g_SizeIndividualVBPhysAllocs / KB, g_NumIndividualVBPhysAllocs );
|
||||
Msg( " -- %7.1fkb -- Mem allocated for NON-pooled IBs (%d IBs)\n", g_SizeIndividualIBPhysAllocs / KB, g_NumIndividualVBPhysAllocs );
|
||||
Msg( "\n" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
// CGPUBufferPool
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
|
||||
CGPUBufferPool::CGPUBufferPool( int nSize )
|
||||
: m_PoolEntries( POOL_ENTRIES_GROW_SIZE, POOL_ENTRIES_INIT_SIZE ),
|
||||
m_nSize( 0 ),
|
||||
m_nBytesUsed( 0 )
|
||||
{
|
||||
// NOTE: write-combining (PAGE_WRITECOMBINE) is deliberately not used, since it slows down 'Compact' hugely (and doesn't noticeably benefit load times)
|
||||
m_pMemory = (byte*)XPhysicalAlloc( nSize, MAXULONG_PTR, 0, PAGE_READWRITE );
|
||||
if ( m_pMemory )
|
||||
{
|
||||
MemAlloc_RegisterExternalAllocation( XMem_CGPUBufferPool, m_pMemory, XPhysicalSize( m_pMemory ) );
|
||||
m_nSize = nSize;
|
||||
}
|
||||
}
|
||||
|
||||
CGPUBufferPool::~CGPUBufferPool( void )
|
||||
{
|
||||
for ( int i = 0; i < m_PoolEntries.Count(); i++ )
|
||||
{
|
||||
if ( m_PoolEntries[ i ].pVertexBuffer )
|
||||
{
|
||||
// Buffers should be cleaned up before the CGPUBufferAllocator is shut down!
|
||||
Assert( 0 );
|
||||
Warning( "ERROR: Un-freed %s in CGPUBufferPool on shut down! (%6.1fKB\n",
|
||||
( m_PoolEntries[ i ].bIsVertexBuffer ? "VB" : "IB" ), ( m_PoolEntries[ i ].nSize / 1024.0f ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_pMemory )
|
||||
{
|
||||
MemAlloc_RegisterExternalDeallocation( XMem_CGPUBufferPool, m_pMemory, XPhysicalSize( m_pMemory ) );
|
||||
XPhysicalFree( m_pMemory );
|
||||
m_pMemory = 0;
|
||||
}
|
||||
|
||||
m_nSize = m_nBytesUsed = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Attempt to allocate a buffer of the given size in this pool
|
||||
//-----------------------------------------------------------------------------
|
||||
int CGPUBufferPool::Allocate( int nBufferSize, bool bIsVertexBuffer, void *pObject )
|
||||
{
|
||||
// Align the buffer size
|
||||
nBufferSize = ALIGN_VALUE( nBufferSize, POOL_ENTRY_ALIGNMENT );
|
||||
|
||||
// Check available space
|
||||
if ( ( m_nBytesUsed + nBufferSize ) > m_nSize )
|
||||
return -1;
|
||||
|
||||
int nPoolEntry = m_PoolEntries.AddToTail();
|
||||
GPUBufferPoolEntry_t &poolEntry = m_PoolEntries[ nPoolEntry ];
|
||||
poolEntry.nOffset = m_nBytesUsed;
|
||||
poolEntry.nSize = nBufferSize;
|
||||
poolEntry.bIsVertexBuffer = bIsVertexBuffer;
|
||||
poolEntry.pVertexBuffer = (CVertexBuffer *)pObject;
|
||||
|
||||
// Update 'used space' high watermark
|
||||
m_nBytesUsed += nBufferSize;
|
||||
|
||||
return nPoolEntry;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Deallocate the given entry from this pool
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGPUBufferPool::Deallocate( const GPUBufferHandle_t *pHandle )
|
||||
{
|
||||
Assert( m_PoolEntries.IsValidIndex( pHandle->nPoolEntry ) );
|
||||
if ( m_PoolEntries.IsValidIndex( pHandle->nPoolEntry ) )
|
||||
{
|
||||
Assert( m_PoolEntries[ pHandle->nPoolEntry ].pVertexBuffer );
|
||||
m_PoolEntries[ pHandle->nPoolEntry ].pVertexBuffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // _X360
|
||||
146
materialsystem/shaderapidx9/gpubufferallocator.h
Normal file
146
materialsystem/shaderapidx9/gpubufferallocator.h
Normal file
@@ -0,0 +1,146 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: CGPUBufferAllocator manages allocation of VBs/IBs from shared memory pools.
|
||||
// Avoids 4KB physical alloc alignment overhead per VB/IB.
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
|
||||
#ifndef GPUBUFFERALLOCATOR_H
|
||||
#define GPUBUFFERALLOCATOR_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#ifdef _X360
|
||||
|
||||
#include "tier1/utlvector.h"
|
||||
#include "tier1/convar.h"
|
||||
|
||||
class CVertexBuffer;
|
||||
class CIndexBuffer;
|
||||
|
||||
|
||||
// Only active on X360 atm
|
||||
#define USE_GPU_BUFFER_ALLOCATOR ( IsX360() )
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// A handle to a buffer pool allocation, held by the allocated VB/IB
|
||||
//-----------------------------------------------------------------------------
|
||||
struct GPUBufferHandle_t
|
||||
{
|
||||
GPUBufferHandle_t( void ) : nPoolNum( -1 ), pMemory( NULL ), nPoolEntry( -1 ) {}
|
||||
bool IsValid( void ) { return ( pMemory != NULL ); }
|
||||
byte * pMemory; // Physical address of the allocation
|
||||
int nPoolNum; // Identifies the pool
|
||||
int nPoolEntry; // Identifies this allocation within the pool
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Describes an entry in a CGPUBufferPool
|
||||
//-----------------------------------------------------------------------------
|
||||
struct GPUBufferPoolEntry_t
|
||||
{
|
||||
int nOffset;
|
||||
int nSize;
|
||||
bool bIsVertexBuffer;
|
||||
union
|
||||
{
|
||||
// These are set to NULL by CGPUBufferPool::Free() (called when the VB/IB is destroyed)
|
||||
CVertexBuffer *pVertexBuffer;
|
||||
CIndexBuffer *pIndexBuffer;
|
||||
};
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// A single memory block out of which individual VBs/IBs are allocated
|
||||
//-----------------------------------------------------------------------------
|
||||
class CGPUBufferPool
|
||||
{
|
||||
public:
|
||||
CGPUBufferPool( int nSize );
|
||||
virtual ~CGPUBufferPool( void );
|
||||
|
||||
// Returns the index (-1 on failure) of a new allocation in the pool, for a buffer of the given size.
|
||||
int Allocate( int nSize, bool bIsVertexBuffer, void *pObject );
|
||||
// Frees a given entry (just marks it as freed, the memory will not be reused by Allocate() until CGPUBufferAllocator::Defrag() is called )
|
||||
void Deallocate( const GPUBufferHandle_t *pHandle );
|
||||
|
||||
private:
|
||||
// NOTE: these values are specialized for X360 and should be #ifdef'd for other target platforms
|
||||
static const int POOL_ENTRIES_INIT_SIZE = 256;
|
||||
static const int POOL_ENTRIES_GROW_SIZE = 256;
|
||||
static const int POOL_ENTRY_ALIGNMENT = 4; // 4-byte alignment required for VB/IB data on XBox360
|
||||
|
||||
byte * m_pMemory; // Pointer to the (physical) address of the pool's memory
|
||||
int m_nSize; // Total size of the pool
|
||||
int m_nBytesUsed; // High watermark of used memory in the pool
|
||||
CUtlVector<GPUBufferPoolEntry_t>m_PoolEntries; // Memory-order array of items allocated in the pool
|
||||
|
||||
// CGPUBufferAllocator is a friend so that CGPUBufferAllocator::Defrag() can shuffle allocations around
|
||||
friend class CGPUBufferAllocator;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Manages a set of memory blocks out of which individual VBs/IBs are allocated
|
||||
//-----------------------------------------------------------------------------
|
||||
class CGPUBufferAllocator
|
||||
{
|
||||
public:
|
||||
CGPUBufferAllocator( void );
|
||||
virtual ~CGPUBufferAllocator( void );
|
||||
|
||||
// (De)Allocates memory for a vertex/index buffer:
|
||||
bool AllocateVertexBuffer( CVertexBuffer *pVertexBuffer, int nBufferSize );
|
||||
bool AllocateIndexBuffer( CIndexBuffer *pIndexBuffer, int nBufferSize );
|
||||
void DeallocateVertexBuffer( CVertexBuffer *pVertexBuffer );
|
||||
void DeallocateIndexBuffer( CIndexBuffer *pIndexBuffer );
|
||||
|
||||
// Compact memory to account for freed buffers
|
||||
// NOTE: this must only be called during map transitions, no rendering must be in flight and everything must be single-threaded!
|
||||
void Compact();
|
||||
|
||||
// Spew statistics about pooled buffer allocations
|
||||
void SpewStats( bool bBrief = false );
|
||||
|
||||
|
||||
private:
|
||||
// NOTE: these values are specialized for X360 and should be #ifdef'd for other target platforms
|
||||
static const int INITIAL_POOL_SIZE = 57*1024*1024 + 256*1024;
|
||||
static const int ADDITIONAL_POOL_SIZE = 2*1024*1024;
|
||||
static const int MAX_POOLS = 8;
|
||||
static const int MAX_BUFFER_SIZE = ADDITIONAL_POOL_SIZE; // 256*1024;
|
||||
|
||||
|
||||
// Allocate a new CGPUBufferPool
|
||||
bool AllocatePool( int nPoolSize );
|
||||
// Allocate/deallocate a buffer (type-agnostic)
|
||||
bool AllocateBuffer( GPUBufferHandle_t *pHandle, int nBufferSize, void *pObject, bool bIsVertexBuffer );
|
||||
void DeallocateBuffer( const GPUBufferHandle_t *pHandle );
|
||||
// Make a handle for a given allocation
|
||||
GPUBufferHandle_t MakeGPUBufferHandle( int nPoolNum, int nPoolEntry );
|
||||
// Helper for Compact
|
||||
void MoveBufferMemory( int nDstPool, int *pnDstEntry, int *pnDstOffset, CGPUBufferPool &srcPool, GPUBufferPoolEntry_t &srcEntry );
|
||||
|
||||
|
||||
CGPUBufferPool *m_BufferPools[ MAX_POOLS ];
|
||||
int m_nBufferPools;
|
||||
bool m_bEnabled;
|
||||
|
||||
CThreadFastMutex m_mutex;
|
||||
};
|
||||
|
||||
|
||||
// Track non-pooled physallocs, to help tune CGPUBufferAllocator usage:
|
||||
extern CInterlockedInt g_NumIndividualIBPhysAllocs;
|
||||
extern CInterlockedInt g_SizeIndividualIBPhysAllocs;
|
||||
extern CInterlockedInt g_NumIndividualVBPhysAllocs;
|
||||
extern CInterlockedInt g_SizeIndividualVBPhysAllocs;
|
||||
|
||||
#endif // _X360
|
||||
|
||||
#endif // GPUBUFFERALLOCATOR_H
|
||||
1323
materialsystem/shaderapidx9/hardwareconfig.cpp
Normal file
1323
materialsystem/shaderapidx9/hardwareconfig.cpp
Normal file
File diff suppressed because it is too large
Load Diff
288
materialsystem/shaderapidx9/hardwareconfig.h
Normal file
288
materialsystem/shaderapidx9/hardwareconfig.h
Normal file
@@ -0,0 +1,288 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef HARDWARECONFIG_H
|
||||
#define HARDWARECONFIG_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "materialsystem/imaterialsystemhardwareconfig.h"
|
||||
#include "IHardwareConfigInternal.h"
|
||||
#include "bitmap/imageformat.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ShaderDeviceInfo_t;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Vendor IDs sometimes needed for vendor-specific code
|
||||
//-----------------------------------------------------------------------------
|
||||
#define VENDORID_NVIDIA 0x10DE
|
||||
#define VENDORID_ATI 0x1002
|
||||
#define VENDORID_INTEL 0x8086
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ShaderAPI constants
|
||||
//-----------------------------------------------------------------------------
|
||||
enum
|
||||
{
|
||||
#if defined( DX_TO_GL_ABSTRACTION )
|
||||
MAXUSERCLIPPLANES = 2,
|
||||
#else
|
||||
MAXUSERCLIPPLANES = 6,
|
||||
#endif
|
||||
MAX_NUM_LIGHTS = 4,
|
||||
MAX_OUTPUTS = 3,
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Hardware caps structures
|
||||
//-----------------------------------------------------------------------------
|
||||
enum CompressedTextureState_t
|
||||
{
|
||||
COMPRESSED_TEXTURES_ON,
|
||||
COMPRESSED_TEXTURES_OFF,
|
||||
COMPRESSED_TEXTURES_NOT_INITIALIZED
|
||||
};
|
||||
|
||||
struct HardwareCaps_t : public MaterialAdapterInfo_t
|
||||
{
|
||||
// *****************************NOTE*********************************************
|
||||
// If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
|
||||
// If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
|
||||
// If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
|
||||
// If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
|
||||
// If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
|
||||
// *****************************NOTE*********************************************
|
||||
//
|
||||
// NOTE: Texture stages are an obsolete concept; used by fixed-function hardware
|
||||
// Samplers are dx9+, indicating how many textures we can simultaneously bind
|
||||
// In Dx8, samplers didn't exist and texture stages were used to indicate the
|
||||
// number of simultaneously bound textures; we'll emulate that by slamming
|
||||
// the number of samplers to == the number of texture stages.
|
||||
CompressedTextureState_t m_SupportsCompressedTextures;
|
||||
VertexCompressionType_t m_SupportsCompressedVertices;
|
||||
int m_NumSamplers;
|
||||
int m_NumTextureStages;
|
||||
int m_nMaxAnisotropy;
|
||||
int m_MaxTextureWidth;
|
||||
int m_MaxTextureHeight;
|
||||
int m_MaxTextureDepth;
|
||||
int m_MaxTextureAspectRatio;
|
||||
int m_MaxPrimitiveCount;
|
||||
int m_NumPixelShaderConstants;
|
||||
int m_NumBooleanPixelShaderConstants;
|
||||
int m_NumIntegerPixelShaderConstants;
|
||||
int m_NumVertexShaderConstants;
|
||||
int m_NumBooleanVertexShaderConstants;
|
||||
int m_NumIntegerVertexShaderConstants;
|
||||
int m_TextureMemorySize;
|
||||
int m_MaxNumLights;
|
||||
int m_MaxBlendMatrices;
|
||||
int m_MaxBlendMatrixIndices;
|
||||
int m_MaxVertexShaderBlendMatrices;
|
||||
int m_MaxUserClipPlanes;
|
||||
HDRType_t m_HDRType;
|
||||
char m_pShaderDLL[32];
|
||||
ImageFormat m_ShadowDepthTextureFormat;
|
||||
ImageFormat m_NullTextureFormat;
|
||||
int m_nVertexTextureCount;
|
||||
int m_nMaxVertexTextureDimension;
|
||||
unsigned long m_AlphaToCoverageState; // State to ping to toggle Alpha To Coverage (vendor-dependent)
|
||||
unsigned long m_AlphaToCoverageEnableValue; // Value to set above state to turn on Alpha To Coverage (vendor-dependent)
|
||||
unsigned long m_AlphaToCoverageDisableValue; // Value to set above state to turn off Alpha To Coverage (vendor-dependent)
|
||||
int m_nMaxViewports;
|
||||
float m_flMinGammaControlPoint;
|
||||
float m_flMaxGammaControlPoint;
|
||||
int m_nGammaControlPointCount;
|
||||
int m_MaxVertexShader30InstructionSlots;
|
||||
int m_MaxPixelShader30InstructionSlots;
|
||||
int m_MaxSimultaneousRenderTargets;
|
||||
|
||||
bool m_bDeviceOk : 1;
|
||||
bool m_HasSetDeviceGammaRamp : 1;
|
||||
bool m_SupportsVertexShaders : 1;
|
||||
bool m_SupportsVertexShaders_2_0 : 1;
|
||||
bool m_SupportsPixelShaders : 1;
|
||||
bool m_SupportsPixelShaders_1_4 : 1;
|
||||
bool m_SupportsPixelShaders_2_0 : 1;
|
||||
bool m_SupportsPixelShaders_2_b : 1;
|
||||
bool m_SupportsShaderModel_3_0 : 1;
|
||||
bool m_bSupportsAnisotropicFiltering : 1;
|
||||
bool m_bSupportsMagAnisotropicFiltering : 1;
|
||||
bool m_bSupportsVertexTextures : 1;
|
||||
bool m_ZBiasAndSlopeScaledDepthBiasSupported : 1;
|
||||
bool m_SupportsMipmapping : 1;
|
||||
bool m_SupportsOverbright : 1;
|
||||
bool m_SupportsCubeMaps : 1;
|
||||
bool m_SupportsHardwareLighting : 1;
|
||||
bool m_SupportsMipmappedCubemaps : 1;
|
||||
bool m_SupportsNonPow2Textures : 1;
|
||||
bool m_PreferDynamicTextures : 1;
|
||||
bool m_HasProjectedBumpEnv : 1;
|
||||
bool m_SupportsSRGB : 1; // Means both read and write
|
||||
bool m_bSupportsSpheremapping : 1;
|
||||
bool m_UseFastClipping : 1;
|
||||
bool m_bNeedsATICentroidHack : 1;
|
||||
bool m_bDisableShaderOptimizations : 1;
|
||||
bool m_bColorOnSecondStream : 1;
|
||||
bool m_bSupportsStreamOffset : 1;
|
||||
bool m_bFogColorSpecifiedInLinearSpace : 1;
|
||||
bool m_bFogColorAlwaysLinearSpace : 1;
|
||||
bool m_bSupportsAlphaToCoverage : 1;
|
||||
bool m_bSupportsShadowDepthTextures : 1;
|
||||
bool m_bSupportsFetch4 : 1;
|
||||
bool m_bSoftwareVertexProcessing : 1;
|
||||
bool m_bScissorSupported : 1;
|
||||
bool m_bSupportsFloat32RenderTargets : 1;
|
||||
bool m_bSupportsNormalMapCompression : 1;
|
||||
bool m_bSupportsBorderColor : 1;
|
||||
bool m_bDX10Card : 1; // Indicates DX10 part with performant vertex textures running DX9 path
|
||||
bool m_bDX10Blending : 1; // Indicates DX10 part that does DX10 blending (but may not have performant vertex textures, such as Intel parts)
|
||||
bool m_bSupportsStaticControlFlow : 1; // Useful on OpenGL, where we have a mix of support...
|
||||
bool m_FakeSRGBWrite : 1; // Gotta do this on OpenGL. Mostly hidden, but some high level code needs to know
|
||||
bool m_CanDoSRGBReadFromRTs : 1; // Gotta do this on OpenGL. Mostly hidden, but some high level code needs to know
|
||||
bool m_bSupportsGLMixedSizeTargets : 1; // on OpenGL, are mixed size depth buffers supported - aka ARB_framebuffer_object
|
||||
bool m_bCanStretchRectFromTextures : 1; // Does the device expose D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES (or is it >DX9?)
|
||||
|
||||
HDRType_t m_MaxHDRType;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Contains the hardware configuration for the current device
|
||||
//-----------------------------------------------------------------------------
|
||||
class CHardwareConfig : public IHardwareConfigInternal
|
||||
{
|
||||
public:
|
||||
CHardwareConfig();
|
||||
|
||||
// Sets up the hardware caps given the specified DX level
|
||||
void SetupHardwareCaps( const ShaderDeviceInfo_t& mode, const HardwareCaps_t &actualCaps );
|
||||
|
||||
// FIXME: This is for backward compat only.. don't use these
|
||||
void SetupHardwareCaps( int nDXLevel, const HardwareCaps_t &actualCaps );
|
||||
HardwareCaps_t& ActualCapsForEdit() { return m_ActualCaps; }
|
||||
HardwareCaps_t& CapsForEdit() { return m_Caps; }
|
||||
|
||||
// Members of IMaterialSystemHardwareConfig
|
||||
virtual bool HasDestAlphaBuffer() const;
|
||||
virtual bool HasStencilBuffer() const;
|
||||
virtual int GetFrameBufferColorDepth() const;
|
||||
virtual int GetSamplerCount() const;
|
||||
virtual bool HasSetDeviceGammaRamp() const;
|
||||
virtual bool SupportsCompressedTextures() const;
|
||||
virtual VertexCompressionType_t SupportsCompressedVertices() const;
|
||||
virtual bool SupportsNormalMapCompression() const;
|
||||
virtual bool SupportsBorderColor() const;
|
||||
virtual bool SupportsFetch4() const;
|
||||
virtual bool CanStretchRectFromTextures() const;
|
||||
virtual bool SupportsVertexAndPixelShaders() const;
|
||||
virtual bool SupportsPixelShaders_1_4() const;
|
||||
virtual bool SupportsPixelShaders_2_0() const;
|
||||
virtual bool SupportsStaticControlFlow() const;
|
||||
virtual bool SupportsVertexShaders_2_0() const;
|
||||
virtual int MaximumAnisotropicLevel() const;
|
||||
virtual int MaxTextureWidth() const;
|
||||
virtual int MaxTextureHeight() const;
|
||||
virtual int TextureMemorySize() const;
|
||||
virtual bool SupportsOverbright() const;
|
||||
virtual bool SupportsCubeMaps() const;
|
||||
virtual bool SupportsMipmappedCubemaps() const;
|
||||
virtual bool SupportsNonPow2Textures() const;
|
||||
virtual int GetTextureStageCount() const;
|
||||
virtual int NumVertexShaderConstants() const;
|
||||
virtual int NumBooleanVertexShaderConstants() const;
|
||||
virtual int NumIntegerVertexShaderConstants() const;
|
||||
virtual int NumPixelShaderConstants() const;
|
||||
virtual int NumBooleanPixelShaderConstants() const;
|
||||
virtual int NumIntegerPixelShaderConstants() const;
|
||||
virtual int MaxNumLights() const;
|
||||
virtual bool SupportsHardwareLighting() const;
|
||||
virtual int MaxBlendMatrices() const;
|
||||
virtual int MaxBlendMatrixIndices() const;
|
||||
virtual int MaxTextureAspectRatio() const;
|
||||
virtual int MaxVertexShaderBlendMatrices() const;
|
||||
virtual int MaxUserClipPlanes() const;
|
||||
virtual bool UseFastClipping() const;
|
||||
virtual int GetDXSupportLevel() const;
|
||||
virtual const char *GetShaderDLLName() const;
|
||||
virtual bool ReadPixelsFromFrontBuffer() const;
|
||||
virtual bool PreferDynamicTextures() const;
|
||||
virtual bool SupportsHDR() const;
|
||||
virtual bool HasProjectedBumpEnv() const;
|
||||
virtual bool SupportsSpheremapping() const;
|
||||
virtual bool NeedsAAClamp() const;
|
||||
virtual bool NeedsATICentroidHack() const;
|
||||
virtual bool SupportsColorOnSecondStream() const;
|
||||
virtual bool SupportsStaticPlusDynamicLighting() const;
|
||||
virtual bool PreferReducedFillrate() const;
|
||||
virtual int GetMaxDXSupportLevel() const;
|
||||
virtual bool SpecifiesFogColorInLinearSpace() const;
|
||||
virtual bool SupportsSRGB() const;
|
||||
virtual bool FakeSRGBWrite() const;
|
||||
virtual bool CanDoSRGBReadFromRTs() const;
|
||||
virtual bool SupportsGLMixedSizeTargets() const;
|
||||
virtual bool IsAAEnabled() const;
|
||||
virtual int GetVertexTextureCount() const;
|
||||
virtual int GetMaxVertexTextureDimension() const;
|
||||
virtual int MaxTextureDepth() const;
|
||||
virtual HDRType_t GetHDRType() const;
|
||||
virtual HDRType_t GetHardwareHDRType() const;
|
||||
virtual bool SupportsPixelShaders_2_b() const;
|
||||
virtual bool SupportsShaderModel_3_0() const;
|
||||
virtual bool SupportsStreamOffset() const;
|
||||
virtual int StencilBufferBits() const;
|
||||
virtual int MaxViewports() const;
|
||||
virtual void OverrideStreamOffsetSupport( bool bOverrideEnabled, bool bEnableSupport );
|
||||
virtual int GetShadowFilterMode() const;
|
||||
virtual int NeedsShaderSRGBConversion() const;
|
||||
virtual bool UsesSRGBCorrectBlending() const;
|
||||
virtual bool HasFastVertexTextures() const;
|
||||
virtual int MaxHWMorphBatchCount() const;
|
||||
|
||||
const char *GetHWSpecificShaderDLLName() const;
|
||||
int GetActualSamplerCount() const;
|
||||
int GetActualTextureStageCount() const;
|
||||
bool SupportsMipmapping() const;
|
||||
virtual bool ActuallySupportsPixelShaders_2_b() const;
|
||||
|
||||
virtual bool SupportsHDRMode( HDRType_t nHDRMode ) const;
|
||||
|
||||
const HardwareCaps_t& ActualCaps() const { return m_ActualCaps; }
|
||||
const HardwareCaps_t& Caps() const { return m_Caps; }
|
||||
virtual bool GetHDREnabled( void ) const;
|
||||
virtual void SetHDREnabled( bool bEnable );
|
||||
|
||||
protected:
|
||||
// Gets the recommended configuration associated with a particular dx level
|
||||
void ForceCapsToDXLevel( HardwareCaps_t *pCaps, int nDxLevel, const HardwareCaps_t &actualCaps );
|
||||
|
||||
// Members related to capabilities
|
||||
HardwareCaps_t m_ActualCaps;
|
||||
HardwareCaps_t m_Caps;
|
||||
HardwareCaps_t m_UnOverriddenCaps;
|
||||
bool m_bHDREnabled;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton hardware config
|
||||
//-----------------------------------------------------------------------------
|
||||
extern CHardwareConfig *g_pHardwareConfig;
|
||||
|
||||
|
||||
#endif // HARDWARECONFIG_H
|
||||
98
materialsystem/shaderapidx9/imeshdx8.h
Normal file
98
materialsystem/shaderapidx9/imeshdx8.h
Normal file
@@ -0,0 +1,98 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef IMESHDX8_H
|
||||
#define IMESHDX8_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "meshbase.h"
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
|
||||
|
||||
abstract_class IMeshMgr
|
||||
{
|
||||
public:
|
||||
// Initialize, shutdown
|
||||
virtual void Init() = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
|
||||
// Task switch...
|
||||
virtual void ReleaseBuffers() = 0;
|
||||
virtual void RestoreBuffers() = 0;
|
||||
|
||||
// Releases all dynamic vertex buffers
|
||||
virtual void DestroyVertexBuffers() = 0;
|
||||
|
||||
// Flushes the dynamic mesh. Should be called when state changes
|
||||
virtual void Flush() = 0;
|
||||
|
||||
// Discards the dynamic vertex and index buffer
|
||||
virtual void DiscardVertexBuffers() = 0;
|
||||
|
||||
// Creates, destroys static meshes
|
||||
virtual IMesh* CreateStaticMesh( VertexFormat_t vertexFormat, const char *pTextureBudgetGroup, IMaterial *pMaterial = NULL ) = 0;
|
||||
virtual void DestroyStaticMesh( IMesh* pMesh ) = 0;
|
||||
|
||||
// Gets at the dynamic mesh
|
||||
virtual IMesh* GetDynamicMesh( IMaterial* pMaterial, VertexFormat_t vertexFormat, int nHWSkinBoneCount, bool buffered = true,
|
||||
IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0) = 0;
|
||||
|
||||
// ------------ New Vertex/Index Buffer interface ----------------------------
|
||||
// Do we need support for bForceTempMesh and bSoftwareVertexShader?
|
||||
// I don't think we use bSoftwareVertexShader anymore. .need to look into bForceTempMesh.
|
||||
virtual IVertexBuffer *CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroup ) = 0;
|
||||
virtual IIndexBuffer *CreateIndexBuffer( ShaderBufferType_t indexBufferType, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroup ) = 0;
|
||||
virtual void DestroyVertexBuffer( IVertexBuffer * ) = 0;
|
||||
virtual void DestroyIndexBuffer( IIndexBuffer * ) = 0;
|
||||
// Do we need to specify the stream here in the case of locking multiple dynamic VBs on different streams?
|
||||
virtual IVertexBuffer *GetDynamicVertexBuffer( int streamID, VertexFormat_t vertexFormat, bool bBuffered = true ) = 0;
|
||||
virtual IIndexBuffer *GetDynamicIndexBuffer( MaterialIndexFormat_t fmt, bool bBuffered = true ) = 0;
|
||||
virtual void BindVertexBuffer( int streamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions = 1 ) = 0;
|
||||
virtual void BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes ) = 0;
|
||||
virtual void Draw( MaterialPrimitiveType_t primitiveType, int nFirstIndex, int nIndexCount ) = 0;
|
||||
// ------------ End ----------------------------
|
||||
virtual VertexFormat_t GetCurrentVertexFormat( void ) const = 0;
|
||||
virtual void RenderPassWithVertexAndIndexBuffers( void ) = 0;
|
||||
|
||||
// Computes the vertex format
|
||||
virtual VertexFormat_t ComputeVertexFormat( unsigned int flags,
|
||||
int numTexCoords, int* pTexCoordDimensions, int numBoneWeights,
|
||||
int userDataSize ) const = 0;
|
||||
|
||||
// Returns the number of buffers...
|
||||
virtual int BufferCount() const = 0;
|
||||
|
||||
// Use fat vertices (for tools)
|
||||
virtual void UseFatVertices( bool bUseFat ) = 0;
|
||||
|
||||
// Returns the number of vertices + indices we can render using the dynamic mesh
|
||||
// Passing true in the second parameter will return the max # of vertices + indices
|
||||
// we can use before a flush is provoked and may return different values
|
||||
// if called multiple times in succession.
|
||||
// Passing false into the second parameter will return
|
||||
// the maximum possible vertices + indices that can be rendered in a single batch
|
||||
virtual void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices ) = 0;
|
||||
|
||||
// Returns the max number of vertices we can render for a given material
|
||||
virtual int GetMaxVerticesToRender( IMaterial *pMaterial ) = 0;
|
||||
virtual int GetMaxIndicesToRender( ) = 0;
|
||||
virtual IMesh *GetFlexMesh() = 0;
|
||||
|
||||
virtual void ComputeVertexDescription( unsigned char* pBuffer, VertexFormat_t vertexFormat, MeshDesc_t& desc ) const = 0;
|
||||
|
||||
virtual IVertexBuffer *GetDynamicVertexBuffer( IMaterial *pMaterial, bool buffered = true ) = 0;
|
||||
virtual IIndexBuffer *GetDynamicIndexBuffer( IMaterial *pMaterial, bool buffered = true ) = 0;
|
||||
|
||||
virtual void MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords ) = 0;
|
||||
};
|
||||
|
||||
#endif // IMESHDX8_H
|
||||
214
materialsystem/shaderapidx9/inputlayoutdx10.cpp
Normal file
214
materialsystem/shaderapidx9/inputlayoutdx10.cpp
Normal file
@@ -0,0 +1,214 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include <d3d10.h>
|
||||
#undef GetCommandLine
|
||||
|
||||
#include "inputlayoutdx10.h"
|
||||
#include "materialsystem/imesh.h"
|
||||
#include "shaderdevicedx10.h"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Standard input layouts
|
||||
//-----------------------------------------------------------------------------
|
||||
static const DXGI_FORMAT s_pSizeLookup[] =
|
||||
{
|
||||
DXGI_FORMAT_UNKNOWN, // Should be unused...
|
||||
DXGI_FORMAT_R32_FLOAT, // D3DDECLTYPE_FLOAT1
|
||||
DXGI_FORMAT_R32G32_FLOAT, // D3DDECLTYPE_FLOAT2,
|
||||
DXGI_FORMAT_R32G32B32_FLOAT, // D3DDECLTYPE_FLOAT3,
|
||||
DXGI_FORMAT_R32G32B32A32_FLOAT, // D3DDECLTYPE_FLOAT4
|
||||
};
|
||||
|
||||
struct FieldInfo_t
|
||||
{
|
||||
const char *m_pSemanticString;
|
||||
unsigned int m_nSemanticIndex;
|
||||
uint64 m_nFormatMask;
|
||||
int m_nFieldSize;
|
||||
};
|
||||
|
||||
static FieldInfo_t s_pFieldInfo[] =
|
||||
{
|
||||
{ "POSITION", 0, VERTEX_POSITION, sizeof( float ) * 3 },
|
||||
{ "BLENDWEIGHT", 0, VERTEX_BONE_WEIGHT_MASK, 0 },
|
||||
{ "BLENDINDICES", 0, VERTEX_BONE_INDEX, 4 },
|
||||
{ "NORMAL", 0, VERTEX_NORMAL, sizeof( float ) * 3 },
|
||||
{ "COLOR", 0, VERTEX_COLOR, 4 },
|
||||
{ "SPECULAR", 0, VERTEX_SPECULAR, 4 },
|
||||
{ "TEXCOORD", 0, VERTEX_TEXCOORD_MASK(0), 0 },
|
||||
{ "TEXCOORD", 1, VERTEX_TEXCOORD_MASK(1), 0 },
|
||||
{ "TEXCOORD", 2, VERTEX_TEXCOORD_MASK(2), 0 },
|
||||
{ "TEXCOORD", 3, VERTEX_TEXCOORD_MASK(3), 0 },
|
||||
{ "TEXCOORD", 4, VERTEX_TEXCOORD_MASK(4), 0 },
|
||||
{ "TEXCOORD", 5, VERTEX_TEXCOORD_MASK(5), 0 },
|
||||
{ "TEXCOORD", 6, VERTEX_TEXCOORD_MASK(6), 0 },
|
||||
{ "TEXCOORD", 7, VERTEX_TEXCOORD_MASK(7), 0 },
|
||||
{ "TANGENT", 0, VERTEX_TANGENT_S, sizeof( float ) * 3 },
|
||||
{ "BINORMAL", 0, VERTEX_TANGENT_T, sizeof( float ) * 3 },
|
||||
{ "USERDATA", 0, USER_DATA_SIZE_MASK, 0 },
|
||||
{ NULL, 0, 0 },
|
||||
};
|
||||
|
||||
static D3D10_INPUT_ELEMENT_DESC s_pVertexDesc[] =
|
||||
{
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "BLENDWEIGHT", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "BLENDINDICES", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "SPECULAR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 1, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 2, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 3, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 4, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 5, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 6, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 7, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "BINORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "USERDATA", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
};
|
||||
|
||||
static D3D10_INPUT_ELEMENT_DESC s_pFallbackVertexDesc[] =
|
||||
{
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 15, 0, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "BLENDWEIGHT", 0, DXGI_FORMAT_R32G32_FLOAT, 15, 12, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "BLENDINDICES", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 15, 20, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 15, 24, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 15, 36, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "SPECULAR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 15, 40, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 15, 44, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "TEXCOORD", 1, DXGI_FORMAT_R32G32_FLOAT, 15, 52, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "TEXCOORD", 2, DXGI_FORMAT_R32G32_FLOAT, 15, 60, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "TEXCOORD", 3, DXGI_FORMAT_R32G32_FLOAT, 15, 68, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "TEXCOORD", 4, DXGI_FORMAT_R32G32_FLOAT, 15, 76, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "TEXCOORD", 5, DXGI_FORMAT_R32G32_FLOAT, 15, 84, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "TEXCOORD", 6, DXGI_FORMAT_R32G32_FLOAT, 15, 92, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "TEXCOORD", 7, DXGI_FORMAT_R32G32_FLOAT, 15, 100, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 15, 108, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "BINORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 15, 120, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "USERDATA", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 15, 132, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Computes the required input desc based on the vertex format
|
||||
//-----------------------------------------------------------------------------
|
||||
static void PrintInputDesc( int nCount, const D3D10_INPUT_ELEMENT_DESC *pDecl )
|
||||
{
|
||||
for ( int i = 0; i < nCount; i++ )
|
||||
{
|
||||
Msg( "%s (%d): Stream: %d, Offset: %d, Instanced? %c\n",
|
||||
pDecl[i].SemanticName,
|
||||
pDecl[i].SemanticIndex,
|
||||
( int )pDecl[i].InputSlot,
|
||||
( int )pDecl[i].AlignedByteOffset,
|
||||
pDecl[i].InputSlotClass == D3D10_INPUT_PER_VERTEX_DATA ? 'n' : 'y'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Checks to see if a shader requires a particular field
|
||||
//-----------------------------------------------------------------------------
|
||||
static bool CheckShaderSignatureExpectations( ID3D10ShaderReflection* pReflection, const char* pSemantic, unsigned int nSemanticIndex )
|
||||
{
|
||||
D3D10_SHADER_DESC shaderDesc;
|
||||
D3D10_SIGNATURE_PARAMETER_DESC paramDesc;
|
||||
|
||||
Assert( pSemantic );
|
||||
Assert( pReflection );
|
||||
|
||||
pReflection->GetDesc( &shaderDesc );
|
||||
|
||||
for ( unsigned int k=0; k < shaderDesc.InputParameters; k++ )
|
||||
{
|
||||
pReflection->GetInputParameterDesc( k, ¶mDesc );
|
||||
if ( ( nSemanticIndex == paramDesc.SemanticIndex ) && !Q_stricmp( pSemantic, paramDesc.SemanticName ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Computes the required input desc based on the vertex format
|
||||
//-----------------------------------------------------------------------------
|
||||
static unsigned int ComputeInputDesc( VertexFormat_t fmt, D3D10_INPUT_ELEMENT_DESC *pDecl, ID3D10ShaderReflection* pReflection )
|
||||
{
|
||||
unsigned int nCount = 0;
|
||||
int nOffset = 0;
|
||||
|
||||
// Fix up the global table so we don't need special-case code
|
||||
int nBoneCount = NumBoneWeights( fmt );
|
||||
s_pFieldInfo[1].m_nFieldSize = sizeof( float ) * nBoneCount;
|
||||
s_pVertexDesc[1].Format = s_pSizeLookup[ nBoneCount ];
|
||||
|
||||
int nUserDataSize = UserDataSize( fmt );
|
||||
s_pFieldInfo[16].m_nFieldSize = sizeof( float ) * nUserDataSize;
|
||||
s_pVertexDesc[16].Format = s_pSizeLookup[ nUserDataSize ];
|
||||
|
||||
// NOTE: Fix s_pFieldInfo, s_pVertexDesc, s_pFallbackVertexDesc if you add more fields
|
||||
// As well as the fallback stream (stream #15)
|
||||
COMPILE_TIME_ASSERT( VERTEX_MAX_TEXTURE_COORDINATES == 8 );
|
||||
for ( int i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i )
|
||||
{
|
||||
int nTexCoordCount = TexCoordSize( i, fmt );
|
||||
s_pFieldInfo[6+i].m_nFieldSize = sizeof( float ) * nTexCoordCount;
|
||||
s_pVertexDesc[6+i].Format = s_pSizeLookup[ nTexCoordCount ];
|
||||
}
|
||||
|
||||
// FIXME: Change this loop so CheckShaderSignatureExpectations is called once!
|
||||
for ( int i = 0; s_pFieldInfo[i].m_pSemanticString; ++i )
|
||||
{
|
||||
if ( fmt & s_pFieldInfo[i].m_nFormatMask )
|
||||
{
|
||||
memcpy( &pDecl[nCount], &s_pVertexDesc[i], sizeof(D3D10_INPUT_ELEMENT_DESC) );
|
||||
pDecl[nCount].AlignedByteOffset = nOffset;
|
||||
nOffset += s_pFieldInfo[i].m_nFieldSize;
|
||||
++nCount;
|
||||
}
|
||||
else if ( CheckShaderSignatureExpectations( pReflection, s_pFieldInfo[i].m_pSemanticString, s_pFieldInfo[i].m_nSemanticIndex ) )
|
||||
{
|
||||
memcpy( &pDecl[nCount], &s_pFallbackVertexDesc[i], sizeof(D3D10_INPUT_ELEMENT_DESC) );
|
||||
++nCount;
|
||||
}
|
||||
}
|
||||
|
||||
// For debugging only...
|
||||
// PrintInputDesc( nCount, pDecl );
|
||||
|
||||
return nCount;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the input layout associated with a vertex format
|
||||
//-----------------------------------------------------------------------------
|
||||
ID3D10InputLayout *CreateInputLayout( VertexFormat_t fmt, ID3D10ShaderReflection* pReflection, const void *pByteCode, size_t nByteCodeLen )
|
||||
{
|
||||
D3D10_INPUT_ELEMENT_DESC pDecl[32];
|
||||
unsigned int nDeclCount = ComputeInputDesc( fmt, pDecl, pReflection );
|
||||
|
||||
ID3D10InputLayout *pInputLayout;
|
||||
HRESULT hr = D3D10Device()->CreateInputLayout( pDecl, nDeclCount, pByteCode, nByteCodeLen, &pInputLayout );
|
||||
if ( FAILED( hr ) )
|
||||
{
|
||||
Warning( "CreateInputLayout::Unable to create input layout for format %llX!\n", fmt );
|
||||
return NULL;
|
||||
}
|
||||
return pInputLayout;
|
||||
}
|
||||
35
materialsystem/shaderapidx9/inputlayoutdx10.h
Normal file
35
materialsystem/shaderapidx9/inputlayoutdx10.h
Normal file
@@ -0,0 +1,35 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef INPUTLAYOUTDX10_H
|
||||
#define INPUTLAYOUTDX10_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "materialsystem/imaterial.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declaration
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ID3D10InputLayout;
|
||||
struct ID3D10ShaderReflection;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the input layout associated with a vertex format
|
||||
// FIXME: Note that we'll need to change this from a VertexFormat_t
|
||||
//-----------------------------------------------------------------------------
|
||||
ID3D10InputLayout *CreateInputLayout( VertexFormat_t fmt,
|
||||
ID3D10ShaderReflection* pReflection, const void *pByteCode, size_t nByteCodeLen );
|
||||
|
||||
|
||||
#endif // INPUTLAYOUTDX10_H
|
||||
|
||||
34
materialsystem/shaderapidx9/ivertexbufferdx8.h
Normal file
34
materialsystem/shaderapidx9/ivertexbufferdx8.h
Normal file
@@ -0,0 +1,34 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef IVERTEXBUFFERDX8_H
|
||||
#define IVERTEXBUFFERDX8_H
|
||||
#pragma once
|
||||
|
||||
#include "IVertexBuffer.h"
|
||||
|
||||
abstract_class IVertexBufferDX8 : public IVertexBuffer
|
||||
{
|
||||
public:
|
||||
// TEMPORARY!
|
||||
virtual int Begin( int flags, int numVerts ) = 0;
|
||||
|
||||
// Sets up the renderstate
|
||||
virtual void SetRenderState( int stream ) = 0;
|
||||
|
||||
// Gets FVF info
|
||||
virtual void ComputeFVFInfo( int flags, int& fvf, int& size ) const = 0;
|
||||
|
||||
// Cleans up the vertex buffers
|
||||
virtual void CleanUp() = 0;
|
||||
|
||||
// Flushes the vertex buffers
|
||||
virtual void Flush() = 0;
|
||||
};
|
||||
|
||||
#endif // IVERTEXBUFFERDX8_H
|
||||
419
materialsystem/shaderapidx9/meshbase.cpp
Normal file
419
materialsystem/shaderapidx9/meshbase.cpp
Normal file
@@ -0,0 +1,419 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "meshbase.h"
|
||||
#include "shaderapi_global.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helpers with VertexDesc_t...
|
||||
//-----------------------------------------------------------------------------
|
||||
// FIXME: add compression-agnostic read-accessors (which decompress and return by value, checking desc.m_CompressionType)
|
||||
inline Vector &Position( VertexDesc_t const &desc, int vert )
|
||||
{
|
||||
return *(Vector*)((unsigned char*)desc.m_pPosition + vert * desc.m_VertexSize_Position );
|
||||
}
|
||||
|
||||
inline float Wrinkle( VertexDesc_t const &desc, int vert )
|
||||
{
|
||||
return *(float*)((unsigned char*)desc.m_pWrinkle + vert * desc.m_VertexSize_Wrinkle );
|
||||
}
|
||||
|
||||
inline float *BoneWeight( VertexDesc_t const &desc, int vert )
|
||||
{
|
||||
Assert( desc.m_CompressionType == VERTEX_COMPRESSION_NONE );
|
||||
return (float*)((unsigned char*)desc.m_pBoneWeight + vert * desc.m_VertexSize_BoneWeight );
|
||||
}
|
||||
|
||||
inline unsigned char *BoneIndex( VertexDesc_t const &desc, int vert )
|
||||
{
|
||||
return desc.m_pBoneMatrixIndex + vert * desc.m_VertexSize_BoneMatrixIndex;
|
||||
}
|
||||
|
||||
inline Vector &Normal( VertexDesc_t const &desc, int vert )
|
||||
{
|
||||
Assert( desc.m_CompressionType == VERTEX_COMPRESSION_NONE );
|
||||
return *(Vector*)((unsigned char*)desc.m_pNormal + vert * desc.m_VertexSize_Normal );
|
||||
}
|
||||
|
||||
inline unsigned char *Color( VertexDesc_t const &desc, int vert )
|
||||
{
|
||||
return desc.m_pColor + vert * desc.m_VertexSize_Color;
|
||||
}
|
||||
|
||||
inline Vector2D &TexCoord( VertexDesc_t const &desc, int vert, int stage )
|
||||
{
|
||||
return *(Vector2D*)((unsigned char*)desc.m_pTexCoord[stage] + vert * desc.m_VertexSize_TexCoord[stage] );
|
||||
}
|
||||
|
||||
inline Vector &TangentS( VertexDesc_t const &desc, int vert )
|
||||
{
|
||||
return *(Vector*)((unsigned char*)desc.m_pTangentS + vert * desc.m_VertexSize_TangentS );
|
||||
}
|
||||
|
||||
inline Vector &TangentT( VertexDesc_t const &desc, int vert )
|
||||
{
|
||||
return *(Vector*)((unsigned char*)desc.m_pTangentT + vert * desc.m_VertexSize_TangentT );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Vertex Buffer implementations begin here
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CVertexBufferBase::CVertexBufferBase( const char *pBudgetGroupName )
|
||||
{
|
||||
m_pBudgetGroupName = pBudgetGroupName;
|
||||
}
|
||||
|
||||
CVertexBufferBase::~CVertexBufferBase()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Displays the vertex format
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVertexBufferBase::PrintVertexFormat( VertexFormat_t vertexFormat )
|
||||
{
|
||||
VertexCompressionType_t compression = CompressionType( vertexFormat );
|
||||
if( vertexFormat & VERTEX_POSITION )
|
||||
{
|
||||
Msg( "VERTEX_POSITION|" );
|
||||
}
|
||||
if( vertexFormat & VERTEX_NORMAL )
|
||||
{
|
||||
// FIXME: genericise this stuff using VertexElement_t data tables (so funcs like 'just work' if we make compression changes)
|
||||
if ( compression == VERTEX_COMPRESSION_ON )
|
||||
Msg( "VERTEX_NORMAL|" );
|
||||
else
|
||||
Msg( "VERTEX_NORMAL[COMPRESSED]|" );
|
||||
}
|
||||
if( vertexFormat & VERTEX_COLOR )
|
||||
{
|
||||
Msg( "VERTEX_COLOR|" );
|
||||
}
|
||||
if( vertexFormat & VERTEX_SPECULAR )
|
||||
{
|
||||
Msg( "VERTEX_SPECULAR|" );
|
||||
}
|
||||
if( vertexFormat & VERTEX_TANGENT_S )
|
||||
{
|
||||
Msg( "VERTEX_TANGENT_S|" );
|
||||
}
|
||||
if( vertexFormat & VERTEX_TANGENT_T )
|
||||
{
|
||||
Msg( "VERTEX_TANGENT_T|" );
|
||||
}
|
||||
if( vertexFormat & VERTEX_BONE_INDEX )
|
||||
{
|
||||
Msg( "VERTEX_BONE_INDEX|" );
|
||||
}
|
||||
if( vertexFormat & VERTEX_FORMAT_VERTEX_SHADER )
|
||||
{
|
||||
Msg( "VERTEX_FORMAT_VERTEX_SHADER|" );
|
||||
}
|
||||
if( NumBoneWeights( vertexFormat ) > 0 )
|
||||
{
|
||||
Msg( "VERTEX_BONEWEIGHT(%d)%s|",
|
||||
NumBoneWeights( vertexFormat ), ( compression ? "[COMPRESSED]" : "" ) );
|
||||
}
|
||||
if( UserDataSize( vertexFormat ) > 0 )
|
||||
{
|
||||
Msg( "VERTEX_USERDATA_SIZE(%d)|", UserDataSize( vertexFormat ) );
|
||||
}
|
||||
int i;
|
||||
for( i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ )
|
||||
{
|
||||
int nDim = TexCoordSize( i, vertexFormat );
|
||||
if ( nDim == 0 )
|
||||
continue;
|
||||
|
||||
Msg( "VERTEX_TEXCOORD_SIZE(%d,%d)", i, nDim );
|
||||
}
|
||||
Msg( "\n" );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to construct vertex data
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVertexBufferBase::ComputeVertexDescription( unsigned char *pBuffer,
|
||||
VertexFormat_t vertexFormat, VertexDesc_t &desc )
|
||||
{
|
||||
ComputeVertexDesc( pBuffer, vertexFormat, desc );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the vertex format size
|
||||
//-----------------------------------------------------------------------------
|
||||
int CVertexBufferBase::VertexFormatSize( VertexFormat_t vertexFormat )
|
||||
{
|
||||
// FIXME: We could make this much faster
|
||||
MeshDesc_t temp;
|
||||
ComputeVertexDescription( 0, vertexFormat, temp );
|
||||
return temp.m_ActualVertexSize;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Spews the mesh data
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVertexBufferBase::Spew( int nVertexCount, const VertexDesc_t &desc )
|
||||
{
|
||||
LOCK_SHADERAPI();
|
||||
|
||||
char pTempBuf[1024];
|
||||
Q_snprintf( pTempBuf, sizeof(pTempBuf), "\nVerts %d (First %d, Offset %d) :\n", nVertexCount, desc.m_nFirstVertex, desc.m_nOffset );
|
||||
Warning( "%s", pTempBuf );
|
||||
|
||||
Assert( ( desc.m_NumBoneWeights == 2 ) || ( desc.m_NumBoneWeights == 0 ) );
|
||||
|
||||
int nLen = 0;
|
||||
int nBoneWeightCount = desc.m_NumBoneWeights;
|
||||
for ( int i = 0; i < nVertexCount; ++i )
|
||||
{
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "[%4d] ", i + desc.m_nFirstVertex );
|
||||
if ( desc.m_VertexSize_Position )
|
||||
{
|
||||
Vector &pos = Position( desc, i );
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "P %8.2f %8.2f %8.2f ",
|
||||
pos[0], pos[1], pos[2]);
|
||||
}
|
||||
|
||||
if ( desc.m_VertexSize_Wrinkle )
|
||||
{
|
||||
float flWrinkle = Wrinkle( desc, i );
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "Wr %8.2f ",flWrinkle );
|
||||
}
|
||||
|
||||
if ( nBoneWeightCount )
|
||||
{
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "BW ");
|
||||
float* pWeight = BoneWeight( desc, i );
|
||||
for ( int j = 0; j < nBoneWeightCount; ++j )
|
||||
{
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "%1.2f ", pWeight[j] );
|
||||
}
|
||||
}
|
||||
if ( desc.m_VertexSize_BoneMatrixIndex )
|
||||
{
|
||||
unsigned char *pIndex = BoneIndex( desc, i );
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "BI %d %d %d %d ", ( int )pIndex[0], ( int )pIndex[1], ( int )pIndex[2], ( int )pIndex[3] );
|
||||
Assert( pIndex[0] >= 0 && pIndex[0] < 16 );
|
||||
Assert( pIndex[1] >= 0 && pIndex[1] < 16 );
|
||||
Assert( pIndex[2] >= 0 && pIndex[2] < 16 );
|
||||
Assert( pIndex[3] >= 0 && pIndex[3] < 16 );
|
||||
}
|
||||
|
||||
if ( desc.m_VertexSize_Normal )
|
||||
{
|
||||
Vector & normal = Normal( desc, i );
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "N %1.2f %1.2f %1.2f ",
|
||||
normal[0], normal[1], normal[2]);
|
||||
}
|
||||
|
||||
if ( desc.m_VertexSize_Color )
|
||||
{
|
||||
unsigned char* pColor = Color( desc, i );
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "C b %3d g %3d r %3d a %3d ",
|
||||
pColor[0], pColor[1], pColor[2], pColor[3]);
|
||||
}
|
||||
|
||||
for ( int j = 0; j < VERTEX_MAX_TEXTURE_COORDINATES; ++j )
|
||||
{
|
||||
if ( desc.m_VertexSize_TexCoord[j] )
|
||||
{
|
||||
Vector2D& texcoord = TexCoord( desc, i, j );
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "T%d %.2f %.2f ", j,texcoord[0], texcoord[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if ( desc.m_VertexSize_TangentS )
|
||||
{
|
||||
Vector& tangentS = TangentS( desc, i );
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "S %1.2f %1.2f %1.2f ",
|
||||
tangentS[0], tangentS[1], tangentS[2]);
|
||||
}
|
||||
|
||||
if ( desc.m_VertexSize_TangentT )
|
||||
{
|
||||
Vector& tangentT = TangentT( desc, i );
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "T %1.2f %1.2f %1.2f ",
|
||||
tangentT[0], tangentT[1], tangentT[2]);
|
||||
}
|
||||
|
||||
Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "\n" );
|
||||
Warning( "%s", pTempBuf );
|
||||
nLen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Validates vertex buffer data
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVertexBufferBase::ValidateData( int nVertexCount, const VertexDesc_t &spewDesc )
|
||||
{
|
||||
LOCK_SHADERAPI();
|
||||
#ifdef VALIDATE_DEBUG
|
||||
int i;
|
||||
|
||||
// This is needed so buffering can just use this
|
||||
VertexFormat_t fmt = m_pMaterial->GetVertexUsage();
|
||||
|
||||
// Set up the vertex descriptor
|
||||
VertexDesc_t desc = spewDesc;
|
||||
|
||||
int numBoneWeights = NumBoneWeights( fmt );
|
||||
for ( i = 0; i < nVertexCount; ++i )
|
||||
{
|
||||
if( fmt & VERTEX_POSITION )
|
||||
{
|
||||
D3DXVECTOR3& pos = Position( desc, i );
|
||||
Assert( IsFinite( pos[0] ) && IsFinite( pos[1] ) && IsFinite( pos[2] ) );
|
||||
}
|
||||
if( fmt & VERTEX_WRINKLE )
|
||||
{
|
||||
float flWrinkle = Wrinkle( desc, i );
|
||||
Assert( IsFinite( flWrinkle ) );
|
||||
}
|
||||
if (numBoneWeights > 0)
|
||||
{
|
||||
float* pWeight = BoneWeight( desc, i );
|
||||
for (int j = 0; j < numBoneWeights; ++j)
|
||||
{
|
||||
Assert( pWeight[j] >= 0.0f && pWeight[j] <= 1.0f );
|
||||
}
|
||||
}
|
||||
if( fmt & VERTEX_BONE_INDEX )
|
||||
{
|
||||
unsigned char *pIndex = BoneIndex( desc, i );
|
||||
Assert( pIndex[0] >= 0 && pIndex[0] < 16 );
|
||||
Assert( pIndex[1] >= 0 && pIndex[1] < 16 );
|
||||
Assert( pIndex[2] >= 0 && pIndex[2] < 16 );
|
||||
Assert( pIndex[3] >= 0 && pIndex[3] < 16 );
|
||||
}
|
||||
if( fmt & VERTEX_NORMAL )
|
||||
{
|
||||
D3DXVECTOR3& normal = Normal( desc, i );
|
||||
Assert( normal[0] >= -1.05f && normal[0] <= 1.05f );
|
||||
Assert( normal[1] >= -1.05f && normal[1] <= 1.05f );
|
||||
Assert( normal[2] >= -1.05f && normal[2] <= 1.05f );
|
||||
}
|
||||
|
||||
if (fmt & VERTEX_COLOR)
|
||||
{
|
||||
int* pColor = (int*)Color( desc, i );
|
||||
Assert( *pColor != FLOAT32_NAN_BITS );
|
||||
}
|
||||
|
||||
for (int j = 0; j < VERTEX_MAX_TEXTURE_COORDINATES; ++j)
|
||||
{
|
||||
if( TexCoordSize( j, fmt ) > 0)
|
||||
{
|
||||
D3DXVECTOR2& texcoord = TexCoord( desc, i, j );
|
||||
Assert( IsFinite( texcoord[0] ) && IsFinite( texcoord[1] ) );
|
||||
}
|
||||
}
|
||||
|
||||
if (fmt & VERTEX_TANGENT_S)
|
||||
{
|
||||
D3DXVECTOR3& tangentS = TangentS( desc, i );
|
||||
Assert( IsFinite( tangentS[0] ) && IsFinite( tangentS[1] ) && IsFinite( tangentS[2] ) );
|
||||
}
|
||||
|
||||
if (fmt & VERTEX_TANGENT_T)
|
||||
{
|
||||
D3DXVECTOR3& tangentT = TangentT( desc, i );
|
||||
Assert( IsFinite( tangentT[0] ) && IsFinite( tangentT[1] ) && IsFinite( tangentT[2] ) );
|
||||
}
|
||||
}
|
||||
#endif // _DEBUG
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Index Buffer implementations begin here
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CIndexBufferBase::CIndexBufferBase( const char *pBudgetGroupName ) : m_pBudgetGroupName( pBudgetGroupName )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Spews the mesh data
|
||||
//-----------------------------------------------------------------------------
|
||||
void CIndexBufferBase::Spew( int nIndexCount, const IndexDesc_t &indexDesc )
|
||||
{
|
||||
LOCK_SHADERAPI();
|
||||
|
||||
char pTempBuf[512];
|
||||
int nLen = 0;
|
||||
pTempBuf[0] = '\0';
|
||||
char *pTemp = pTempBuf;
|
||||
Q_snprintf( pTempBuf, sizeof(pTempBuf), "\nIndices: %d (First %d, Offset %d)\n", nIndexCount, indexDesc.m_nFirstIndex, indexDesc.m_nOffset );
|
||||
Warning( "%s", pTempBuf );
|
||||
for ( int i = 0; i < nIndexCount; ++i )
|
||||
{
|
||||
nLen += Q_snprintf( pTemp, sizeof(pTempBuf) - nLen - 1, "%d ", ( int )indexDesc.m_pIndices[i] );
|
||||
pTemp = pTempBuf + nLen;
|
||||
if ( (i & 0x0F) == 0x0F )
|
||||
{
|
||||
Q_snprintf( pTemp, sizeof(pTempBuf) - nLen - 1, "\n" );
|
||||
Warning( "%s", pTempBuf );
|
||||
pTempBuf[0] = '\0';
|
||||
nLen = 0;
|
||||
pTemp = pTempBuf;
|
||||
}
|
||||
}
|
||||
Q_snprintf( pTemp, sizeof(pTempBuf) - nLen - 1, "\n" );
|
||||
Warning( "%s", pTempBuf );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Call this in debug mode to make sure our data is good.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CIndexBufferBase::ValidateData( int nIndexCount, const IndexDesc_t& desc )
|
||||
{
|
||||
/* FIXME */
|
||||
// NOTE: Is there anything reasonable to do here at all?
|
||||
// Or is this a bogus method altogether?
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Base mesh
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CMeshBase::CMeshBase()
|
||||
{
|
||||
}
|
||||
|
||||
CMeshBase::~CMeshBase()
|
||||
{
|
||||
}
|
||||
309
materialsystem/shaderapidx9/meshbase.h
Normal file
309
materialsystem/shaderapidx9/meshbase.h
Normal file
@@ -0,0 +1,309 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef MESHBASE_H
|
||||
#define MESHBASE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "materialsystem/imesh.h"
|
||||
#include "materialsystem/imaterial.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Base vertex buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class CVertexBufferBase : public IVertexBuffer
|
||||
{
|
||||
// Methods of IVertexBuffer
|
||||
public:
|
||||
virtual void Spew( int nVertexCount, const VertexDesc_t &desc );
|
||||
virtual void ValidateData( int nVertexCount, const VertexDesc_t& desc );
|
||||
|
||||
public:
|
||||
// constructor, destructor
|
||||
CVertexBufferBase( const char *pBudgetGroupName );
|
||||
virtual ~CVertexBufferBase();
|
||||
|
||||
// Displays the vertex format
|
||||
static void PrintVertexFormat( VertexFormat_t vertexFormat );
|
||||
|
||||
// Used to construct vertex data
|
||||
static void ComputeVertexDescription( unsigned char *pBuffer, VertexFormat_t vertexFormat, VertexDesc_t &desc );
|
||||
|
||||
// Returns the vertex format size
|
||||
static int VertexFormatSize( VertexFormat_t vertexFormat );
|
||||
|
||||
protected:
|
||||
const char *m_pBudgetGroupName;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Base index buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class CIndexBufferBase : public IIndexBuffer
|
||||
{
|
||||
// Methods of IIndexBuffer
|
||||
public:
|
||||
virtual void Spew( int nIndexCount, const IndexDesc_t &desc );
|
||||
virtual void ValidateData( int nIndexCount, const IndexDesc_t& desc );
|
||||
|
||||
// Other public methods
|
||||
public:
|
||||
// constructor, destructor
|
||||
CIndexBufferBase( const char *pBudgetGroupName );
|
||||
virtual ~CIndexBufferBase() {}
|
||||
|
||||
protected:
|
||||
const char *m_pBudgetGroupName;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Base mesh
|
||||
//-----------------------------------------------------------------------------
|
||||
class CMeshBase : public IMesh
|
||||
{
|
||||
// Methods of IMesh
|
||||
public:
|
||||
|
||||
// Other public methods that need to be overridden
|
||||
public:
|
||||
// Begins a pass
|
||||
virtual void BeginPass( ) = 0;
|
||||
|
||||
// Draws a single pass of the mesh
|
||||
virtual void RenderPass() = 0;
|
||||
|
||||
// Does it have a color mesh?
|
||||
virtual bool HasColorMesh() const = 0;
|
||||
|
||||
// Am I using morph data?
|
||||
virtual bool IsUsingMorphData() const = 0;
|
||||
|
||||
virtual bool HasFlexMesh() const = 0;
|
||||
|
||||
virtual IMesh *GetMesh() { return this; }
|
||||
|
||||
public:
|
||||
// constructor, destructor
|
||||
CMeshBase();
|
||||
virtual ~CMeshBase();
|
||||
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Utility method for VertexDesc_t (don't want to expose it in public, in imesh.h)
|
||||
//-----------------------------------------------------------------------------
|
||||
inline void ComputeVertexDesc( unsigned char * pBuffer, VertexFormat_t vertexFormat, VertexDesc_t & desc )
|
||||
{
|
||||
int i;
|
||||
int *pVertexSizesToSet[64];
|
||||
int nVertexSizesToSet = 0;
|
||||
static ALIGN32 ModelVertexDX8_t temp[4];
|
||||
float *dummyData = (float*)&temp; // should be larger than any CMeshBuilder command can set.
|
||||
|
||||
// Determine which vertex compression type this format specifies (affects element sizes/decls):
|
||||
VertexCompressionType_t compression = CompressionType( vertexFormat );
|
||||
desc.m_CompressionType = compression;
|
||||
|
||||
// We use fvf instead of flags here because we may pad out the fvf
|
||||
// vertex structure to optimize performance
|
||||
int offset = 0;
|
||||
// NOTE: At the moment, we assume that if you specify wrinkle, you also specify position
|
||||
Assert( ( ( vertexFormat & VERTEX_WRINKLE ) == 0 ) || ( ( vertexFormat & VERTEX_POSITION ) != 0 ) );
|
||||
if ( vertexFormat & VERTEX_POSITION )
|
||||
{
|
||||
// UNDONE: compress position+wrinkle to SHORT4N, and roll the scale into the transform matrices
|
||||
desc.m_pPosition = reinterpret_cast<float*>(pBuffer);
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_POSITION, compression );
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_Position;
|
||||
|
||||
if ( vertexFormat & VERTEX_WRINKLE )
|
||||
{
|
||||
desc.m_pWrinkle = reinterpret_cast<float*>( pBuffer + offset );
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_WRINKLE, compression );
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_Wrinkle;
|
||||
}
|
||||
else
|
||||
{
|
||||
desc.m_pWrinkle = dummyData;
|
||||
desc.m_VertexSize_Wrinkle = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
desc.m_pPosition = dummyData;
|
||||
desc.m_VertexSize_Position = 0;
|
||||
desc.m_pWrinkle = dummyData;
|
||||
desc.m_VertexSize_Wrinkle = 0;
|
||||
}
|
||||
|
||||
// Bone weights/matrix indices
|
||||
desc.m_NumBoneWeights = NumBoneWeights( vertexFormat );
|
||||
|
||||
Assert( ( desc.m_NumBoneWeights == 2 ) || ( desc.m_NumBoneWeights == 0 ) );
|
||||
|
||||
// We assume that if you have any indices/weights, you have exactly two of them
|
||||
Assert( ( ( desc.m_NumBoneWeights == 2 ) && ( ( vertexFormat & VERTEX_BONE_INDEX ) != 0 ) ) ||
|
||||
( ( desc.m_NumBoneWeights == 0 ) && ( ( vertexFormat & VERTEX_BONE_INDEX ) == 0 ) ) );
|
||||
|
||||
if ( ( vertexFormat & VERTEX_BONE_INDEX ) != 0 )
|
||||
{
|
||||
if ( desc.m_NumBoneWeights > 0 )
|
||||
{
|
||||
Assert( desc.m_NumBoneWeights == 2 );
|
||||
|
||||
// Always exactly two weights
|
||||
desc.m_pBoneWeight = reinterpret_cast<float*>(pBuffer + offset);
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_BONEWEIGHTS2, compression );
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_BoneWeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
desc.m_pBoneWeight = dummyData;
|
||||
desc.m_VertexSize_BoneWeight = 0;
|
||||
}
|
||||
|
||||
desc.m_pBoneMatrixIndex = pBuffer + offset;
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_BONEINDEX, compression );
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_BoneMatrixIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
desc.m_pBoneWeight = dummyData;
|
||||
desc.m_VertexSize_BoneWeight = 0;
|
||||
|
||||
desc.m_pBoneMatrixIndex = (unsigned char*)dummyData;
|
||||
desc.m_VertexSize_BoneMatrixIndex = 0;
|
||||
}
|
||||
|
||||
if ( vertexFormat & VERTEX_NORMAL )
|
||||
{
|
||||
desc.m_pNormal = reinterpret_cast<float*>(pBuffer + offset);
|
||||
// See PackNormal_[SHORT2|UBYTE4|HEND3N] in mathlib.h for the compression algorithm
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_NORMAL, compression );
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_Normal;
|
||||
}
|
||||
else
|
||||
{
|
||||
desc.m_pNormal = dummyData;
|
||||
desc.m_VertexSize_Normal = 0;
|
||||
}
|
||||
|
||||
if ( vertexFormat & VERTEX_COLOR )
|
||||
{
|
||||
desc.m_pColor = pBuffer + offset;
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_COLOR, compression );
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_Color;
|
||||
}
|
||||
else
|
||||
{
|
||||
desc.m_pColor = (unsigned char*)dummyData;
|
||||
desc.m_VertexSize_Color = 0;
|
||||
}
|
||||
|
||||
if ( vertexFormat & VERTEX_SPECULAR )
|
||||
{
|
||||
desc.m_pSpecular = pBuffer + offset;
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_SPECULAR, compression );
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_Specular;
|
||||
}
|
||||
else
|
||||
{
|
||||
desc.m_pSpecular = (unsigned char*)dummyData;
|
||||
desc.m_VertexSize_Specular = 0;
|
||||
}
|
||||
|
||||
// Set up texture coordinates
|
||||
for ( i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i )
|
||||
{
|
||||
// FIXME: compress texcoords to SHORT2N/SHORT4N, with a scale rolled into the texture transform
|
||||
VertexElement_t texCoordElements[4] = { VERTEX_ELEMENT_TEXCOORD1D_0, VERTEX_ELEMENT_TEXCOORD2D_0, VERTEX_ELEMENT_TEXCOORD3D_0, VERTEX_ELEMENT_TEXCOORD4D_0 };
|
||||
int nSize = TexCoordSize( i, vertexFormat );
|
||||
if ( nSize != 0 )
|
||||
{
|
||||
desc.m_pTexCoord[i] = reinterpret_cast<float*>(pBuffer + offset);
|
||||
VertexElement_t texCoordElement = (VertexElement_t)( texCoordElements[ nSize - 1 ] + i );
|
||||
offset += GetVertexElementSize( texCoordElement, compression );
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_TexCoord[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
desc.m_pTexCoord[i] = dummyData;
|
||||
desc.m_VertexSize_TexCoord[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Binormal + tangent...
|
||||
// Note we have to put these at the end so the vertex is FVF + stuff at end
|
||||
if ( vertexFormat & VERTEX_TANGENT_S )
|
||||
{
|
||||
// UNDONE: use normal compression here (use mem_dumpvballocs to see if this uses much memory)
|
||||
desc.m_pTangentS = reinterpret_cast<float*>(pBuffer + offset);
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_TANGENT_S, compression );
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_TangentS;
|
||||
}
|
||||
else
|
||||
{
|
||||
desc.m_pTangentS = dummyData;
|
||||
desc.m_VertexSize_TangentS = 0;
|
||||
}
|
||||
|
||||
if ( vertexFormat & VERTEX_TANGENT_T )
|
||||
{
|
||||
// UNDONE: use normal compression here (use mem_dumpvballocs to see if this uses much memory)
|
||||
desc.m_pTangentT = reinterpret_cast<float*>(pBuffer + offset);
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_TANGENT_T, compression );
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_TangentT;
|
||||
}
|
||||
else
|
||||
{
|
||||
desc.m_pTangentT = dummyData;
|
||||
desc.m_VertexSize_TangentT = 0;
|
||||
}
|
||||
|
||||
// User data..
|
||||
int userDataSize = UserDataSize( vertexFormat );
|
||||
if ( userDataSize > 0 )
|
||||
{
|
||||
desc.m_pUserData = reinterpret_cast<float*>(pBuffer + offset);
|
||||
VertexElement_t userDataElement = (VertexElement_t)( VERTEX_ELEMENT_USERDATA1 + ( userDataSize - 1 ) );
|
||||
// See PackNormal_[SHORT2|UBYTE4|HEND3N] in mathlib.h for the compression algorithm
|
||||
offset += GetVertexElementSize( userDataElement, compression );
|
||||
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_UserData;
|
||||
}
|
||||
else
|
||||
{
|
||||
desc.m_pUserData = dummyData;
|
||||
desc.m_VertexSize_UserData = 0;
|
||||
}
|
||||
|
||||
// We always use vertex sizes which are half-cache aligned (16 bytes)
|
||||
// x360 compressed vertexes are not compatible with forced alignments
|
||||
bool bCacheAlign = ( vertexFormat & VERTEX_FORMAT_USE_EXACT_FORMAT ) == 0;
|
||||
if ( bCacheAlign && ( offset > 16 ) && IsPC() )
|
||||
{
|
||||
offset = (offset + 0xF) & (~0xF);
|
||||
}
|
||||
desc.m_ActualVertexSize = offset;
|
||||
|
||||
// Now set the m_VertexSize for all the members that were actually valid.
|
||||
Assert( nVertexSizesToSet < sizeof(pVertexSizesToSet)/sizeof(pVertexSizesToSet[0]) );
|
||||
for ( int iElement=0; iElement < nVertexSizesToSet; iElement++ )
|
||||
{
|
||||
*pVertexSizesToSet[iElement] = offset;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MESHBASE_H
|
||||
775
materialsystem/shaderapidx9/meshdx10.cpp
Normal file
775
materialsystem/shaderapidx9/meshdx10.cpp
Normal file
@@ -0,0 +1,775 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include <d3d10.h>
|
||||
#undef GetCommandLine
|
||||
|
||||
#include "meshdx10.h"
|
||||
#include "utlvector.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "IHardwareConfigInternal.h"
|
||||
#include "shaderapi_global.h"
|
||||
#include "shaderapi/ishaderutil.h"
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
#include "shaderdevicedx10.h"
|
||||
#include "materialsystem/imesh.h"
|
||||
#include "tier0/vprof.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "materialsystem/idebugtextureinfo.h"
|
||||
#include "materialsystem/ivballoctracker.h"
|
||||
#include "tier2/tier2.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Dx10 implementation of a vertex buffer
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// globals
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef _DEBUG
|
||||
int CVertexBufferDx10::s_nBufferCount = 0;
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CVertexBufferDx10::CVertexBufferDx10( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroupName ) :
|
||||
BaseClass( pBudgetGroupName )
|
||||
{
|
||||
Assert( nVertexCount != 0 );
|
||||
|
||||
m_pVertexBuffer = NULL;
|
||||
m_VertexFormat = fmt;
|
||||
m_nVertexCount = ( fmt == VERTEX_FORMAT_UNKNOWN ) ? 0 : nVertexCount;
|
||||
m_nBufferSize = ( fmt == VERTEX_FORMAT_UNKNOWN ) ? nVertexCount : nVertexCount * VertexSize();
|
||||
m_nFirstUnwrittenOffset = 0;
|
||||
m_bIsLocked = false;
|
||||
m_bIsDynamic = ( type == SHADER_BUFFER_TYPE_DYNAMIC ) || ( type == SHADER_BUFFER_TYPE_DYNAMIC_TEMP );
|
||||
m_bFlush = false;
|
||||
}
|
||||
|
||||
CVertexBufferDx10::~CVertexBufferDx10()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Creates, destroys the vertex buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CVertexBufferDx10::Allocate( )
|
||||
{
|
||||
Assert( !m_pVertexBuffer );
|
||||
|
||||
m_nFirstUnwrittenOffset = 0;
|
||||
|
||||
D3D10_BUFFER_DESC bd;
|
||||
bd.Usage = D3D10_USAGE_DYNAMIC;
|
||||
bd.ByteWidth = m_nBufferSize;
|
||||
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
||||
bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
||||
bd.MiscFlags = 0;
|
||||
|
||||
HRESULT hr = D3D10Device()->CreateBuffer( &bd, NULL, &m_pVertexBuffer );
|
||||
bool bOk = !FAILED( hr ) && ( m_pVertexBuffer != 0 );
|
||||
|
||||
if ( bOk )
|
||||
{
|
||||
// Track VB allocations
|
||||
g_VBAllocTracker->CountVB( m_pVertexBuffer, m_bIsDynamic, m_nBufferSize, VertexSize(), GetVertexFormat() );
|
||||
|
||||
if ( !m_bIsDynamic )
|
||||
{
|
||||
VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER,
|
||||
COUNTER_GROUP_TEXTURE_GLOBAL, m_nBufferSize );
|
||||
}
|
||||
else
|
||||
{
|
||||
VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER,
|
||||
COUNTER_GROUP_TEXTURE_GLOBAL, m_nBufferSize );
|
||||
// Dynamic meshes should never be compressed (slows down writing to them)
|
||||
Assert( CompressionType( GetVertexFormat() ) == VERTEX_COMPRESSION_NONE );
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
++s_nBufferCount;
|
||||
#endif
|
||||
}
|
||||
|
||||
return bOk;
|
||||
}
|
||||
|
||||
void CVertexBufferDx10::Free()
|
||||
{
|
||||
if ( m_pVertexBuffer )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
--s_nBufferCount;
|
||||
#endif
|
||||
|
||||
// Track VB allocations
|
||||
g_VBAllocTracker->UnCountVB( m_pVertexBuffer );
|
||||
|
||||
m_pVertexBuffer->Release();
|
||||
m_pVertexBuffer = NULL;
|
||||
|
||||
if ( !m_bIsDynamic )
|
||||
{
|
||||
VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER,
|
||||
COUNTER_GROUP_TEXTURE_GLOBAL, - m_nBufferSize );
|
||||
}
|
||||
else
|
||||
{
|
||||
VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER,
|
||||
COUNTER_GROUP_TEXTURE_GLOBAL, - m_nBufferSize );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Vertex Buffer info
|
||||
//-----------------------------------------------------------------------------
|
||||
int CVertexBufferDx10::VertexCount() const
|
||||
{
|
||||
Assert( !m_bIsDynamic );
|
||||
return m_nVertexCount;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the buffer format (only valid for static index buffers)
|
||||
//-----------------------------------------------------------------------------
|
||||
VertexFormat_t CVertexBufferDx10::GetVertexFormat() const
|
||||
{
|
||||
Assert( !m_bIsDynamic );
|
||||
return m_VertexFormat;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns true if the buffer is dynamic
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CVertexBufferDx10::IsDynamic() const
|
||||
{
|
||||
return m_bIsDynamic;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Only used by dynamic buffers, indicates the next lock should perform a discard.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVertexBufferDx10::Flush()
|
||||
{
|
||||
// This strange-looking line makes a flush only occur if the buffer is dynamic.
|
||||
m_bFlush = m_bIsDynamic;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Casts a dynamic buffer to be a particular vertex type
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVertexBufferDx10::BeginCastBuffer( VertexFormat_t format )
|
||||
{
|
||||
Assert( format != MATERIAL_INDEX_FORMAT_UNKNOWN );
|
||||
Assert( m_bIsDynamic && ( m_VertexFormat == 0 || m_VertexFormat == format ) );
|
||||
if ( !m_bIsDynamic )
|
||||
return;
|
||||
|
||||
m_VertexFormat = format;
|
||||
m_nVertexCount = m_nBufferSize / VertexSize();
|
||||
}
|
||||
|
||||
void CVertexBufferDx10::EndCastBuffer( )
|
||||
{
|
||||
Assert( m_bIsDynamic && m_VertexFormat != 0 );
|
||||
if ( !m_bIsDynamic )
|
||||
return;
|
||||
m_VertexFormat = 0;
|
||||
m_nVertexCount = 0;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the number of indices that can be written into the buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
int CVertexBufferDx10::GetRoomRemaining() const
|
||||
{
|
||||
return ( m_nBufferSize - m_nFirstUnwrittenOffset ) / VertexSize();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Lock, unlock
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CVertexBufferDx10::Lock( int nMaxVertexCount, bool bAppend, VertexDesc_t &desc )
|
||||
{
|
||||
Assert( !m_bIsLocked && ( nMaxVertexCount != 0 ) && ( nMaxVertexCount <= m_nVertexCount ) );
|
||||
Assert( m_VertexFormat != 0 );
|
||||
|
||||
// FIXME: Why do we need to sync matrices now?
|
||||
ShaderUtil()->SyncMatrices();
|
||||
g_ShaderMutex.Lock();
|
||||
|
||||
void *pLockedData = NULL;
|
||||
HRESULT hr;
|
||||
|
||||
// This can happen if the buffer was locked but a type wasn't bound
|
||||
if ( m_VertexFormat == 0 )
|
||||
goto vertexBufferLockFailed;
|
||||
|
||||
// Just give the app crap buffers to fill up while we're suppressed...
|
||||
if ( g_pShaderDevice->IsDeactivated() || ( nMaxVertexCount == 0 ) )
|
||||
goto vertexBufferLockFailed;
|
||||
|
||||
// Did we ask for something too large?
|
||||
if ( nMaxVertexCount > m_nVertexCount )
|
||||
{
|
||||
Warning( "Too many vertices for vertex buffer. . tell a programmer (%d>%d)\n", nMaxVertexCount, m_nVertexCount );
|
||||
goto vertexBufferLockFailed;
|
||||
}
|
||||
|
||||
// We might not have a buffer owing to alt-tab type stuff
|
||||
if ( !m_pVertexBuffer )
|
||||
{
|
||||
if ( !Allocate() )
|
||||
goto vertexBufferLockFailed;
|
||||
}
|
||||
|
||||
// Check to see if we have enough memory
|
||||
int nMemoryRequired = nMaxVertexCount * VertexSize();
|
||||
bool bHasEnoughMemory = ( m_nFirstUnwrittenOffset + nMemoryRequired <= m_nBufferSize );
|
||||
|
||||
D3D10_MAP map;
|
||||
if ( bAppend )
|
||||
{
|
||||
// Can't have the first lock after a flush be an appending lock
|
||||
Assert( !m_bFlush );
|
||||
|
||||
// If we're appending and we don't have enough room, then puke!
|
||||
if ( !bHasEnoughMemory || m_bFlush )
|
||||
goto vertexBufferLockFailed;
|
||||
map = ( m_nFirstUnwrittenOffset == 0 ) ? D3D10_MAP_WRITE_DISCARD : D3D10_MAP_WRITE_NO_OVERWRITE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we're not appending, no overwrite unless we don't have enough room
|
||||
// If we're a static buffer, always discard if we're not appending
|
||||
if ( !m_bFlush && bHasEnoughMemory && m_bIsDynamic )
|
||||
{
|
||||
map = ( m_nFirstUnwrittenOffset == 0 ) ? D3D10_MAP_WRITE_DISCARD : D3D10_MAP_WRITE_NO_OVERWRITE;
|
||||
}
|
||||
else
|
||||
{
|
||||
map = D3D10_MAP_WRITE_DISCARD;
|
||||
m_nFirstUnwrittenOffset = 0;
|
||||
m_bFlush = false;
|
||||
}
|
||||
}
|
||||
|
||||
hr = m_pVertexBuffer->Map( map, 0, &pLockedData );
|
||||
if ( FAILED( hr ) )
|
||||
{
|
||||
Warning( "Failed to lock vertex buffer in CVertexBufferDx10::Lock\n" );
|
||||
goto vertexBufferLockFailed;
|
||||
}
|
||||
|
||||
ComputeVertexDescription( (unsigned char*)pLockedData + m_nFirstUnwrittenOffset, m_VertexFormat, desc );
|
||||
desc.m_nFirstVertex = 0;
|
||||
desc.m_nOffset = m_nFirstUnwrittenOffset;
|
||||
m_bIsLocked = true;
|
||||
return true;
|
||||
|
||||
vertexBufferLockFailed:
|
||||
g_ShaderMutex.Unlock();
|
||||
|
||||
// Set up a bogus index descriptor
|
||||
ComputeVertexDescription( 0, 0, desc );
|
||||
desc.m_nFirstVertex = 0;
|
||||
desc.m_nOffset = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
void CVertexBufferDx10::Unlock( int nWrittenVertexCount, VertexDesc_t &desc )
|
||||
{
|
||||
Assert( nWrittenVertexCount <= m_nVertexCount );
|
||||
|
||||
// NOTE: This can happen if the lock occurs during alt-tab
|
||||
// or if another application is initializing
|
||||
if ( !m_bIsLocked )
|
||||
return;
|
||||
|
||||
if ( m_pVertexBuffer )
|
||||
{
|
||||
m_pVertexBuffer->Unmap();
|
||||
}
|
||||
|
||||
m_nFirstUnwrittenOffset += nWrittenVertexCount * VertexSize();
|
||||
m_bIsLocked = false;
|
||||
g_ShaderMutex.Unlock();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Dx10 implementation of an index buffer
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// globals
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// shove indices into this if you don't actually want indices
|
||||
static unsigned int s_nScratchIndexBuffer = 0;
|
||||
|
||||
#ifdef _DEBUG
|
||||
int CIndexBufferDx10::s_nBufferCount = 0;
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CIndexBufferDx10::CIndexBufferDx10( ShaderBufferType_t type, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroupName ) :
|
||||
BaseClass( pBudgetGroupName )
|
||||
{
|
||||
Assert( nIndexCount != 0 );
|
||||
Assert( IsDynamicBufferType( type ) || ( fmt != MATERIAL_INDEX_FORMAT_UNKNOWN ) );
|
||||
|
||||
m_pIndexBuffer = NULL;
|
||||
m_IndexFormat = fmt;
|
||||
m_nIndexCount = ( fmt == MATERIAL_INDEX_FORMAT_UNKNOWN ) ? 0 : nIndexCount;
|
||||
m_nBufferSize = ( fmt == MATERIAL_INDEX_FORMAT_UNKNOWN ) ? nIndexCount : nIndexCount * IndexSize();
|
||||
m_nFirstUnwrittenOffset = 0;
|
||||
m_bIsLocked = false;
|
||||
m_bIsDynamic = IsDynamicBufferType( type );
|
||||
m_bFlush = false;
|
||||
|
||||
// NOTE: This has to happen at the end since m_IndexFormat must be valid for IndexSize() to work
|
||||
if ( m_bIsDynamic )
|
||||
{
|
||||
m_IndexFormat = MATERIAL_INDEX_FORMAT_UNKNOWN;
|
||||
m_nIndexCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
CIndexBufferDx10::~CIndexBufferDx10()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Creates, destroys the index buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CIndexBufferDx10::Allocate( )
|
||||
{
|
||||
Assert( !m_pIndexBuffer );
|
||||
|
||||
m_nFirstUnwrittenOffset = 0;
|
||||
|
||||
D3D10_BUFFER_DESC bd;
|
||||
bd.Usage = D3D10_USAGE_DYNAMIC;
|
||||
bd.ByteWidth = m_nBufferSize;
|
||||
bd.BindFlags = D3D10_BIND_INDEX_BUFFER;
|
||||
bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
||||
bd.MiscFlags = 0;
|
||||
|
||||
HRESULT hr = D3D10Device()->CreateBuffer( &bd, NULL, &m_pIndexBuffer );
|
||||
bool bOk = !FAILED( hr ) && ( m_pIndexBuffer != NULL );
|
||||
|
||||
if ( bOk )
|
||||
{
|
||||
if ( !m_bIsDynamic )
|
||||
{
|
||||
VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER,
|
||||
COUNTER_GROUP_TEXTURE_GLOBAL, m_nBufferSize );
|
||||
}
|
||||
else
|
||||
{
|
||||
VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER,
|
||||
COUNTER_GROUP_TEXTURE_GLOBAL, m_nBufferSize );
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
++s_nBufferCount;
|
||||
#endif
|
||||
}
|
||||
|
||||
return bOk;
|
||||
}
|
||||
|
||||
void CIndexBufferDx10::Free()
|
||||
{
|
||||
if ( m_pIndexBuffer )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
--s_nBufferCount;
|
||||
#endif
|
||||
|
||||
m_pIndexBuffer->Release();
|
||||
m_pIndexBuffer = NULL;
|
||||
|
||||
if ( !m_bIsDynamic )
|
||||
{
|
||||
VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER,
|
||||
COUNTER_GROUP_TEXTURE_GLOBAL, - m_nBufferSize );
|
||||
}
|
||||
else
|
||||
{
|
||||
VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER,
|
||||
COUNTER_GROUP_TEXTURE_GLOBAL, - m_nBufferSize );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the buffer size (only valid for static index buffers)
|
||||
//-----------------------------------------------------------------------------
|
||||
int CIndexBufferDx10::IndexCount() const
|
||||
{
|
||||
Assert( !m_bIsDynamic );
|
||||
return m_nIndexCount;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the buffer format (only valid for static index buffers)
|
||||
//-----------------------------------------------------------------------------
|
||||
MaterialIndexFormat_t CIndexBufferDx10::IndexFormat() const
|
||||
{
|
||||
Assert( !m_bIsDynamic );
|
||||
return m_IndexFormat;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns true if the buffer is dynamic
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CIndexBufferDx10::IsDynamic() const
|
||||
{
|
||||
return m_bIsDynamic;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Only used by dynamic buffers, indicates the next lock should perform a discard.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CIndexBufferDx10::Flush()
|
||||
{
|
||||
// This strange-looking line makes a flush only occur if the buffer is dynamic.
|
||||
m_bFlush = m_bIsDynamic;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Casts a dynamic buffer to be a particular index type
|
||||
//-----------------------------------------------------------------------------
|
||||
void CIndexBufferDx10::BeginCastBuffer( MaterialIndexFormat_t format )
|
||||
{
|
||||
Assert( format != MATERIAL_INDEX_FORMAT_UNKNOWN );
|
||||
Assert( m_bIsDynamic && ( m_IndexFormat == MATERIAL_INDEX_FORMAT_UNKNOWN || m_IndexFormat == format ) );
|
||||
if ( !m_bIsDynamic )
|
||||
return;
|
||||
|
||||
m_IndexFormat = format;
|
||||
m_nIndexCount = m_nBufferSize / IndexSize();
|
||||
}
|
||||
|
||||
void CIndexBufferDx10::EndCastBuffer( )
|
||||
{
|
||||
Assert( m_bIsDynamic && m_IndexFormat != MATERIAL_INDEX_FORMAT_UNKNOWN );
|
||||
if ( !m_bIsDynamic )
|
||||
return;
|
||||
m_IndexFormat = MATERIAL_INDEX_FORMAT_UNKNOWN;
|
||||
m_nIndexCount = 0;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the number of indices that can be written into the buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
int CIndexBufferDx10::GetRoomRemaining() const
|
||||
{
|
||||
return ( m_nBufferSize - m_nFirstUnwrittenOffset ) / IndexSize();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Locks, unlocks the mesh
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CIndexBufferDx10::Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t &desc )
|
||||
{
|
||||
Assert( !m_bIsLocked && ( nMaxIndexCount != 0 ) && ( nMaxIndexCount <= m_nIndexCount ) );
|
||||
Assert( m_IndexFormat != MATERIAL_INDEX_FORMAT_UNKNOWN );
|
||||
|
||||
// FIXME: Why do we need to sync matrices now?
|
||||
ShaderUtil()->SyncMatrices();
|
||||
g_ShaderMutex.Lock();
|
||||
|
||||
void *pLockedData = NULL;
|
||||
HRESULT hr;
|
||||
|
||||
// This can happen if the buffer was locked but a type wasn't bound
|
||||
if ( m_IndexFormat == MATERIAL_INDEX_FORMAT_UNKNOWN )
|
||||
goto indexBufferLockFailed;
|
||||
|
||||
// Just give the app crap buffers to fill up while we're suppressed...
|
||||
if ( g_pShaderDevice->IsDeactivated() || ( nMaxIndexCount == 0 ) )
|
||||
goto indexBufferLockFailed;
|
||||
|
||||
// Did we ask for something too large?
|
||||
if ( nMaxIndexCount > m_nIndexCount )
|
||||
{
|
||||
Warning( "Too many indices for index buffer. . tell a programmer (%d>%d)\n", nMaxIndexCount, m_nIndexCount );
|
||||
goto indexBufferLockFailed;
|
||||
}
|
||||
|
||||
// We might not have a buffer owing to alt-tab type stuff
|
||||
if ( !m_pIndexBuffer )
|
||||
{
|
||||
if ( !Allocate() )
|
||||
goto indexBufferLockFailed;
|
||||
}
|
||||
|
||||
// Check to see if we have enough memory
|
||||
int nMemoryRequired = nMaxIndexCount * IndexSize();
|
||||
bool bHasEnoughMemory = ( m_nFirstUnwrittenOffset + nMemoryRequired <= m_nBufferSize );
|
||||
|
||||
D3D10_MAP map;
|
||||
if ( bAppend )
|
||||
{
|
||||
// Can't have the first lock after a flush be an appending lock
|
||||
Assert( !m_bFlush );
|
||||
|
||||
// If we're appending and we don't have enough room, then puke!
|
||||
if ( !bHasEnoughMemory || m_bFlush )
|
||||
goto indexBufferLockFailed;
|
||||
map = ( m_nFirstUnwrittenOffset == 0 ) ? D3D10_MAP_WRITE_DISCARD : D3D10_MAP_WRITE_NO_OVERWRITE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we're not appending, no overwrite unless we don't have enough room
|
||||
if ( !m_bFlush && bHasEnoughMemory && m_bIsDynamic )
|
||||
{
|
||||
map = ( m_nFirstUnwrittenOffset == 0 ) ? D3D10_MAP_WRITE_DISCARD : D3D10_MAP_WRITE_NO_OVERWRITE;
|
||||
}
|
||||
else
|
||||
{
|
||||
map = D3D10_MAP_WRITE_DISCARD;
|
||||
m_nFirstUnwrittenOffset = 0;
|
||||
m_bFlush = false;
|
||||
}
|
||||
}
|
||||
|
||||
hr = m_pIndexBuffer->Map( map, 0, &pLockedData );
|
||||
if ( FAILED( hr ) )
|
||||
{
|
||||
Warning( "Failed to lock index buffer in CIndexBufferDx10::Lock\n" );
|
||||
goto indexBufferLockFailed;
|
||||
}
|
||||
|
||||
desc.m_pIndices = (unsigned short*)( (unsigned char*)pLockedData + m_nFirstUnwrittenOffset );
|
||||
desc.m_nIndexSize = IndexSize() >> 1;
|
||||
desc.m_nFirstIndex = 0;
|
||||
desc.m_nOffset = m_nFirstUnwrittenOffset;
|
||||
m_bIsLocked = true;
|
||||
return true;
|
||||
|
||||
indexBufferLockFailed:
|
||||
g_ShaderMutex.Unlock();
|
||||
|
||||
// Set up a bogus index descriptor
|
||||
desc.m_pIndices = (unsigned short*)( &s_nScratchIndexBuffer );
|
||||
desc.m_nFirstIndex = 0;
|
||||
desc.m_nIndexSize = 0;
|
||||
desc.m_nOffset = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
void CIndexBufferDx10::Unlock( int nWrittenIndexCount, IndexDesc_t &desc )
|
||||
{
|
||||
Assert( nWrittenIndexCount <= m_nIndexCount );
|
||||
|
||||
// NOTE: This can happen if the lock occurs during alt-tab
|
||||
// or if another application is initializing
|
||||
if ( !m_bIsLocked )
|
||||
return;
|
||||
|
||||
if ( m_pIndexBuffer )
|
||||
{
|
||||
m_pIndexBuffer->Unmap();
|
||||
}
|
||||
|
||||
m_nFirstUnwrittenOffset += nWrittenIndexCount * IndexSize();
|
||||
m_bIsLocked = false;
|
||||
g_ShaderMutex.Unlock();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Locks, unlocks an existing mesh
|
||||
//-----------------------------------------------------------------------------
|
||||
void CIndexBufferDx10::ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc )
|
||||
{
|
||||
Assert( 0 );
|
||||
}
|
||||
|
||||
void CIndexBufferDx10::ModifyEnd( IndexDesc_t& desc )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// The empty mesh...
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CMeshDx10::CMeshDx10()
|
||||
{
|
||||
m_pVertexMemory = new unsigned char[VERTEX_BUFFER_SIZE];
|
||||
}
|
||||
|
||||
CMeshDx10::~CMeshDx10()
|
||||
{
|
||||
delete[] m_pVertexMemory;
|
||||
}
|
||||
|
||||
void CMeshDx10::LockMesh( int numVerts, int numIndices, MeshDesc_t& desc )
|
||||
{
|
||||
// Who cares about the data?
|
||||
desc.m_pPosition = (float*)m_pVertexMemory;
|
||||
desc.m_pNormal = (float*)m_pVertexMemory;
|
||||
desc.m_pColor = m_pVertexMemory;
|
||||
int i;
|
||||
for ( i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i)
|
||||
desc.m_pTexCoord[i] = (float*)m_pVertexMemory;
|
||||
desc.m_pIndices = (unsigned short*)m_pVertexMemory;
|
||||
|
||||
desc.m_pBoneWeight = (float*)m_pVertexMemory;
|
||||
desc.m_pBoneMatrixIndex = (unsigned char*)m_pVertexMemory;
|
||||
desc.m_pTangentS = (float*)m_pVertexMemory;
|
||||
desc.m_pTangentT = (float*)m_pVertexMemory;
|
||||
desc.m_pUserData = (float*)m_pVertexMemory;
|
||||
desc.m_NumBoneWeights = 2;
|
||||
|
||||
desc.m_VertexSize_Position = 0;
|
||||
desc.m_VertexSize_BoneWeight = 0;
|
||||
desc.m_VertexSize_BoneMatrixIndex = 0;
|
||||
desc.m_VertexSize_Normal = 0;
|
||||
desc.m_VertexSize_Color = 0;
|
||||
for( i=0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ )
|
||||
desc.m_VertexSize_TexCoord[i] = 0;
|
||||
desc.m_VertexSize_TangentS = 0;
|
||||
desc.m_VertexSize_TangentT = 0;
|
||||
desc.m_VertexSize_UserData = 0;
|
||||
desc.m_ActualVertexSize = 0; // Size of the vertices.. Some of the m_VertexSize_ elements above
|
||||
|
||||
desc.m_nFirstVertex = 0;
|
||||
desc.m_nIndexSize = 0;
|
||||
}
|
||||
|
||||
void CMeshDx10::UnlockMesh( int numVerts, int numIndices, MeshDesc_t& desc )
|
||||
{
|
||||
}
|
||||
|
||||
void CMeshDx10::ModifyBeginEx( bool bReadOnly, int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc )
|
||||
{
|
||||
// Who cares about the data?
|
||||
desc.m_pPosition = (float*)m_pVertexMemory;
|
||||
desc.m_pNormal = (float*)m_pVertexMemory;
|
||||
desc.m_pColor = m_pVertexMemory;
|
||||
int i;
|
||||
for ( i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i)
|
||||
desc.m_pTexCoord[i] = (float*)m_pVertexMemory;
|
||||
desc.m_pIndices = (unsigned short*)m_pVertexMemory;
|
||||
|
||||
desc.m_pBoneWeight = (float*)m_pVertexMemory;
|
||||
desc.m_pBoneMatrixIndex = (unsigned char*)m_pVertexMemory;
|
||||
desc.m_pTangentS = (float*)m_pVertexMemory;
|
||||
desc.m_pTangentT = (float*)m_pVertexMemory;
|
||||
desc.m_pUserData = (float*)m_pVertexMemory;
|
||||
desc.m_NumBoneWeights = 2;
|
||||
|
||||
desc.m_VertexSize_Position = 0;
|
||||
desc.m_VertexSize_BoneWeight = 0;
|
||||
desc.m_VertexSize_BoneMatrixIndex = 0;
|
||||
desc.m_VertexSize_Normal = 0;
|
||||
desc.m_VertexSize_Color = 0;
|
||||
for( i=0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ )
|
||||
desc.m_VertexSize_TexCoord[i] = 0;
|
||||
desc.m_VertexSize_TangentS = 0;
|
||||
desc.m_VertexSize_TangentT = 0;
|
||||
desc.m_VertexSize_UserData = 0;
|
||||
desc.m_ActualVertexSize = 0; // Size of the vertices.. Some of the m_VertexSize_ elements above
|
||||
|
||||
desc.m_nFirstVertex = 0;
|
||||
desc.m_nIndexSize = 0;
|
||||
}
|
||||
|
||||
void CMeshDx10::ModifyBegin( int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc )
|
||||
{
|
||||
ModifyBeginEx( false, firstVertex, numVerts, firstIndex, numIndices, desc );
|
||||
}
|
||||
|
||||
void CMeshDx10::ModifyEnd( MeshDesc_t& desc )
|
||||
{
|
||||
}
|
||||
|
||||
// returns the # of vertices (static meshes only)
|
||||
int CMeshDx10::VertexCount() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Sets the primitive type
|
||||
void CMeshDx10::SetPrimitiveType( MaterialPrimitiveType_t type )
|
||||
{
|
||||
}
|
||||
|
||||
// Draws the entire mesh
|
||||
void CMeshDx10::Draw( int firstIndex, int numIndices )
|
||||
{
|
||||
}
|
||||
|
||||
void CMeshDx10::Draw(CPrimList *pPrims, int nPrims)
|
||||
{
|
||||
}
|
||||
|
||||
// Copy verts and/or indices to a mesh builder. This only works for temp meshes!
|
||||
void CMeshDx10::CopyToMeshBuilder(
|
||||
int iStartVert, // Which vertices to copy.
|
||||
int nVerts,
|
||||
int iStartIndex, // Which indices to copy.
|
||||
int nIndices,
|
||||
int indexOffset, // This is added to each index.
|
||||
CMeshBuilder &builder )
|
||||
{
|
||||
}
|
||||
|
||||
// Spews the mesh data
|
||||
void CMeshDx10::Spew( int numVerts, int numIndices, const MeshDesc_t & desc )
|
||||
{
|
||||
}
|
||||
|
||||
void CMeshDx10::ValidateData( int numVerts, int numIndices, const MeshDesc_t & desc )
|
||||
{
|
||||
}
|
||||
|
||||
// gets the associated material
|
||||
IMaterial* CMeshDx10::GetMaterial()
|
||||
{
|
||||
// umm. this don't work none
|
||||
Assert(0);
|
||||
return 0;
|
||||
}
|
||||
282
materialsystem/shaderapidx9/meshdx10.h
Normal file
282
materialsystem/shaderapidx9/meshdx10.h
Normal file
@@ -0,0 +1,282 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
|
||||
#ifndef MESHDX10_H
|
||||
#define MESHDX10_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "meshbase.h"
|
||||
#include "shaderapi/ishaderdevice.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declaration
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ID3D10Buffer;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Dx10 implementation of a vertex buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
class CVertexBufferDx10 : public CVertexBufferBase
|
||||
{
|
||||
typedef CVertexBufferBase BaseClass;
|
||||
|
||||
// Methods of IVertexBuffer
|
||||
public:
|
||||
virtual int VertexCount() const;
|
||||
virtual VertexFormat_t GetVertexFormat() const;
|
||||
virtual bool Lock( int nMaxVertexCount, bool bAppend, VertexDesc_t &desc );
|
||||
virtual void Unlock( int nWrittenVertexCount, VertexDesc_t &desc );
|
||||
virtual bool IsDynamic() const;
|
||||
virtual void BeginCastBuffer( VertexFormat_t format );
|
||||
virtual void EndCastBuffer( );
|
||||
virtual int GetRoomRemaining() const;
|
||||
|
||||
// Other public methods
|
||||
public:
|
||||
// constructor, destructor
|
||||
CVertexBufferDx10( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroupName );
|
||||
virtual ~CVertexBufferDx10();
|
||||
|
||||
ID3D10Buffer* GetDx10Buffer() const;
|
||||
int VertexSize() const;
|
||||
|
||||
// Only used by dynamic buffers, indicates the next lock should perform a discard.
|
||||
void Flush();
|
||||
|
||||
protected:
|
||||
// Creates, destroys the index buffer
|
||||
bool Allocate( );
|
||||
void Free();
|
||||
|
||||
ID3D10Buffer *m_pVertexBuffer;
|
||||
VertexFormat_t m_VertexFormat;
|
||||
int m_nVertexCount;
|
||||
int m_nBufferSize;
|
||||
int m_nFirstUnwrittenOffset;
|
||||
bool m_bIsLocked : 1;
|
||||
bool m_bIsDynamic : 1;
|
||||
bool m_bFlush : 1; // Used only for dynamic buffers, indicates to discard the next time
|
||||
|
||||
#ifdef _DEBUG
|
||||
static int s_nBufferCount;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// inline methods for CVertexBufferDx10
|
||||
//-----------------------------------------------------------------------------
|
||||
inline ID3D10Buffer* CVertexBufferDx10::GetDx10Buffer() const
|
||||
{
|
||||
return m_pVertexBuffer;
|
||||
}
|
||||
|
||||
inline int CVertexBufferDx10::VertexSize() const
|
||||
{
|
||||
return VertexFormatSize( m_VertexFormat );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Dx10 implementation of an index buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
class CIndexBufferDx10 : public CIndexBufferBase
|
||||
{
|
||||
typedef CIndexBufferBase BaseClass;
|
||||
|
||||
// Methods of IIndexBuffer
|
||||
public:
|
||||
virtual int IndexCount() const;
|
||||
virtual MaterialIndexFormat_t IndexFormat() const;
|
||||
virtual int GetRoomRemaining() const;
|
||||
virtual bool Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t &desc );
|
||||
virtual void Unlock( int nWrittenIndexCount, IndexDesc_t &desc );
|
||||
virtual void ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc );
|
||||
virtual void ModifyEnd( IndexDesc_t& desc );
|
||||
virtual bool IsDynamic() const;
|
||||
virtual void BeginCastBuffer( MaterialIndexFormat_t format );
|
||||
virtual void EndCastBuffer( );
|
||||
|
||||
// Other public methods
|
||||
public:
|
||||
// constructor, destructor
|
||||
CIndexBufferDx10( ShaderBufferType_t type, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroupName );
|
||||
virtual ~CIndexBufferDx10();
|
||||
|
||||
ID3D10Buffer* GetDx10Buffer() const;
|
||||
MaterialIndexFormat_t GetIndexFormat() const;
|
||||
|
||||
// Only used by dynamic buffers, indicates the next lock should perform a discard.
|
||||
void Flush();
|
||||
|
||||
protected:
|
||||
// Creates, destroys the index buffer
|
||||
bool Allocate( );
|
||||
void Free();
|
||||
|
||||
// Returns the size of the index in bytes
|
||||
int IndexSize() const;
|
||||
|
||||
ID3D10Buffer *m_pIndexBuffer;
|
||||
MaterialIndexFormat_t m_IndexFormat;
|
||||
int m_nIndexCount;
|
||||
int m_nBufferSize;
|
||||
int m_nFirstUnwrittenOffset; // Used only for dynamic buffers, indicates where it's safe to write (nooverwrite)
|
||||
bool m_bIsLocked : 1;
|
||||
bool m_bIsDynamic : 1;
|
||||
bool m_bFlush : 1; // Used only for dynamic buffers, indicates to discard the next time
|
||||
|
||||
#ifdef _DEBUG
|
||||
static int s_nBufferCount;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the size of the index in bytes
|
||||
//-----------------------------------------------------------------------------
|
||||
inline int CIndexBufferDx10::IndexSize() const
|
||||
{
|
||||
switch( m_IndexFormat )
|
||||
{
|
||||
default:
|
||||
case MATERIAL_INDEX_FORMAT_UNKNOWN:
|
||||
return 0;
|
||||
case MATERIAL_INDEX_FORMAT_16BIT:
|
||||
return 2;
|
||||
case MATERIAL_INDEX_FORMAT_32BIT:
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
inline ID3D10Buffer* CIndexBufferDx10::GetDx10Buffer() const
|
||||
{
|
||||
return m_pIndexBuffer;
|
||||
}
|
||||
|
||||
inline MaterialIndexFormat_t CIndexBufferDx10::GetIndexFormat() const
|
||||
{
|
||||
return m_IndexFormat;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Dx10 implementation of a mesh
|
||||
//-----------------------------------------------------------------------------
|
||||
class CMeshDx10 : public CMeshBase
|
||||
{
|
||||
public:
|
||||
CMeshDx10();
|
||||
virtual ~CMeshDx10();
|
||||
|
||||
// FIXME: Make this work! Unsupported methods of IIndexBuffer
|
||||
virtual bool Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t& desc ) { Assert(0); return false; }
|
||||
virtual void Unlock( int nWrittenIndexCount, IndexDesc_t& desc ) { Assert(0); }
|
||||
virtual int GetRoomRemaining() const { Assert(0); return 0; }
|
||||
virtual void ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc ) { Assert(0); }
|
||||
virtual void ModifyEnd( IndexDesc_t& desc ) { Assert(0); }
|
||||
virtual void Spew( int nIndexCount, const IndexDesc_t & desc ) { Assert(0); }
|
||||
virtual void ValidateData( int nIndexCount, const IndexDesc_t &desc ) { Assert(0); }
|
||||
virtual bool Lock( int nVertexCount, bool bAppend, VertexDesc_t &desc ) { Assert(0); return false; }
|
||||
virtual void Unlock( int nVertexCount, VertexDesc_t &desc ) { Assert(0); }
|
||||
virtual void Spew( int nVertexCount, const VertexDesc_t &desc ) { Assert(0); }
|
||||
virtual void ValidateData( int nVertexCount, const VertexDesc_t & desc ) { Assert(0); }
|
||||
virtual bool IsDynamic() const { Assert(0); return false; }
|
||||
virtual void BeginCastBuffer( MaterialIndexFormat_t format ) { Assert(0); }
|
||||
virtual void BeginCastBuffer( VertexFormat_t format ) { Assert(0); }
|
||||
virtual void EndCastBuffer( ) { Assert(0); }
|
||||
|
||||
void LockMesh( int numVerts, int numIndices, MeshDesc_t& desc );
|
||||
void UnlockMesh( int numVerts, int numIndices, MeshDesc_t& desc );
|
||||
|
||||
void ModifyBeginEx( bool bReadOnly, int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc );
|
||||
void ModifyBegin( int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc );
|
||||
void ModifyEnd( MeshDesc_t& desc );
|
||||
|
||||
// returns the # of vertices (static meshes only)
|
||||
int VertexCount() const;
|
||||
|
||||
virtual void BeginPass( ) {}
|
||||
virtual void RenderPass() {}
|
||||
virtual bool HasColorMesh() const { return false; }
|
||||
virtual bool IsUsingMorphData() const { return false; }
|
||||
virtual bool HasFlexMesh() const { return false; }
|
||||
|
||||
// Sets the primitive type
|
||||
void SetPrimitiveType( MaterialPrimitiveType_t type );
|
||||
|
||||
// Draws the entire mesh
|
||||
void Draw(int firstIndex, int numIndices);
|
||||
|
||||
void Draw(CPrimList *pPrims, int nPrims);
|
||||
|
||||
// Copy verts and/or indices to a mesh builder. This only works for temp meshes!
|
||||
virtual void CopyToMeshBuilder(
|
||||
int iStartVert, // Which vertices to copy.
|
||||
int nVerts,
|
||||
int iStartIndex, // Which indices to copy.
|
||||
int nIndices,
|
||||
int indexOffset, // This is added to each index.
|
||||
CMeshBuilder &builder );
|
||||
|
||||
// Spews the mesh data
|
||||
void Spew( int numVerts, int numIndices, const MeshDesc_t & desc );
|
||||
|
||||
void ValidateData( int numVerts, int numIndices, const MeshDesc_t & desc );
|
||||
|
||||
// gets the associated material
|
||||
IMaterial* GetMaterial();
|
||||
|
||||
void SetColorMesh( IMesh *pColorMesh, int nVertexOffset )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual int IndexCount() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual MaterialIndexFormat_t IndexFormat() const
|
||||
{
|
||||
Assert( 0 );
|
||||
return MATERIAL_INDEX_FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
virtual void SetFlexMesh( IMesh *pMesh, int nVertexOffset ) {}
|
||||
|
||||
virtual void DisableFlexMesh() {}
|
||||
|
||||
virtual void MarkAsDrawn() {}
|
||||
|
||||
virtual unsigned ComputeMemoryUsed() { return 0; }
|
||||
|
||||
virtual VertexFormat_t GetVertexFormat() const { return VERTEX_POSITION; }
|
||||
|
||||
virtual IMesh *GetMesh()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
VERTEX_BUFFER_SIZE = 1024 * 1024
|
||||
};
|
||||
|
||||
unsigned char* m_pVertexMemory;
|
||||
};
|
||||
|
||||
#endif // MESHDX10_H
|
||||
|
||||
5982
materialsystem/shaderapidx9/meshdx8.cpp
Normal file
5982
materialsystem/shaderapidx9/meshdx8.cpp
Normal file
File diff suppressed because it is too large
Load Diff
157
materialsystem/shaderapidx9/recording.cpp
Normal file
157
materialsystem/shaderapidx9/recording.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include "togl/rendermechanism.h"
|
||||
#include "recording.h"
|
||||
#include "shaderapi/ishaderutil.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "shaderapidx8_global.h"
|
||||
#include "utlvector.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
#ifdef RECORDING
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Globals
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static CUtlVector<unsigned char> g_pRecordingBuffer;
|
||||
static int g_ArgsRemaining = 0;
|
||||
static int g_CommandStartIdx = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Opens the recording file
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static FILE* OpenRecordingFile()
|
||||
{
|
||||
#ifdef CRASH_RECORDING
|
||||
static FILE *fp = 0;
|
||||
#else
|
||||
FILE* fp = 0;
|
||||
#endif
|
||||
static bool g_CantOpenFile = false;
|
||||
static bool g_NeverOpened = true;
|
||||
if (!g_CantOpenFile)
|
||||
{
|
||||
#ifdef CRASH_RECORDING
|
||||
if( g_NeverOpened )
|
||||
{
|
||||
fp = fopen( "shaderdx8.rec", "wbc" );
|
||||
}
|
||||
#else
|
||||
fp = fopen( "shaderdx8.rec", g_NeverOpened ? "wb" : "ab" );
|
||||
#endif
|
||||
if (!fp)
|
||||
{
|
||||
Warning("Unable to open recording file shaderdx8.rec!\n");
|
||||
g_CantOpenFile = true;
|
||||
}
|
||||
g_NeverOpened = false;
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Writes to the recording file
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define COMMAND_BUFFER_SIZE 32768
|
||||
|
||||
static void WriteRecordingFile()
|
||||
{
|
||||
// Store the command size
|
||||
*(int*)&g_pRecordingBuffer[g_CommandStartIdx] =
|
||||
g_pRecordingBuffer.Size() - g_CommandStartIdx;
|
||||
|
||||
#ifndef CRASH_RECORDING
|
||||
// When not crash recording, flush when buffer gets too big,
|
||||
// or when Present() is called
|
||||
if ((g_pRecordingBuffer.Size() < COMMAND_BUFFER_SIZE) &&
|
||||
(g_pRecordingBuffer[g_CommandStartIdx+4] != DX8_PRESENT))
|
||||
return;
|
||||
#endif
|
||||
|
||||
FILE* fp = OpenRecordingFile();
|
||||
if (fp)
|
||||
{
|
||||
// store the command size
|
||||
fwrite( g_pRecordingBuffer.Base(), 1, g_pRecordingBuffer.Size(), fp );
|
||||
fflush( fp );
|
||||
#ifndef CRASH_RECORDING
|
||||
fclose( fp );
|
||||
#endif
|
||||
}
|
||||
|
||||
g_pRecordingBuffer.RemoveAll();
|
||||
}
|
||||
|
||||
// Write the buffered crap out on shutdown.
|
||||
void FinishRecording()
|
||||
{
|
||||
#ifndef CRASH_RECORDING
|
||||
FILE* fp = OpenRecordingFile();
|
||||
if (fp)
|
||||
{
|
||||
// store the command size
|
||||
fwrite( g_pRecordingBuffer.Base(), 1, g_pRecordingBuffer.Size(), fp );
|
||||
fflush( fp );
|
||||
}
|
||||
|
||||
g_pRecordingBuffer.RemoveAll();
|
||||
#endif
|
||||
}
|
||||
|
||||
// set this to true in the debugger to actually record commands.
|
||||
static bool g_bDoRecord = true;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Records a command
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void RecordCommand( RecordingCommands_t cmd, int numargs )
|
||||
{
|
||||
if( !g_bDoRecord )
|
||||
{
|
||||
return;
|
||||
}
|
||||
Assert( g_ArgsRemaining == 0 );
|
||||
|
||||
g_CommandStartIdx = g_pRecordingBuffer.AddMultipleToTail( 6 );
|
||||
|
||||
// save space for the total command size
|
||||
g_pRecordingBuffer[g_CommandStartIdx+4] = cmd;
|
||||
g_pRecordingBuffer[g_CommandStartIdx+5] = numargs;
|
||||
g_ArgsRemaining = numargs;
|
||||
if (g_ArgsRemaining == 0)
|
||||
WriteRecordingFile();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Records an argument for a command, flushes when the command is done
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void RecordArgument( void const* pMemory, int size )
|
||||
{
|
||||
if( !g_bDoRecord )
|
||||
{
|
||||
return;
|
||||
}
|
||||
Assert( g_ArgsRemaining > 0 );
|
||||
int tail = g_pRecordingBuffer.Size();
|
||||
g_pRecordingBuffer.AddMultipleToTail( size );
|
||||
memcpy( &g_pRecordingBuffer[tail], pMemory, size );
|
||||
if (--g_ArgsRemaining == 0)
|
||||
WriteRecordingFile();
|
||||
}
|
||||
|
||||
|
||||
#endif // RECORDING
|
||||
198
materialsystem/shaderapidx9/recording.h
Normal file
198
materialsystem/shaderapidx9/recording.h
Normal file
@@ -0,0 +1,198 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef RECORDING_H
|
||||
#define RECORDING_H
|
||||
#pragma once
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Use this to put us into a 'recording' mode
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//#define RECORDING
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Uncomment these to record special frames in the recording
|
||||
// that reset the entire render state.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//#define RECORD_KEYFRAMES 1
|
||||
#define KEYFRAME_INTERVAL 100 // number of actual frames between each keyframe
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Use this to allow us to record crashes (write every command immediately)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//#define CRASH_RECORDING
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Use this to record textures (checkboards are used for textures otherwise)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define RECORD_TEXTURES
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Use this to record debug strings . .these are only useful if you are doing "playback -list"
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define RECORD_DEBUG_STRINGS
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Recording state, if you change this, change the table in playback/playback.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
enum RecordingCommands_t
|
||||
{
|
||||
DX8_CREATE_DEVICE = 0,
|
||||
DX8_DESTROY_DEVICE,
|
||||
DX8_RESET,
|
||||
DX8_SHOW_CURSOR,
|
||||
DX8_BEGIN_SCENE,
|
||||
DX8_END_SCENE,
|
||||
DX8_PRESENT,
|
||||
DX8_CREATE_TEXTURE,
|
||||
DX8_DESTROY_TEXTURE,
|
||||
DX8_SET_TEXTURE,
|
||||
DX8_SET_TRANSFORM,
|
||||
DX8_CREATE_VERTEX_SHADER,
|
||||
DX8_CREATE_PIXEL_SHADER,
|
||||
DX8_DESTROY_VERTEX_SHADER,
|
||||
DX8_DESTROY_PIXEL_SHADER,
|
||||
DX8_SET_VERTEX_SHADER,
|
||||
DX8_SET_PIXEL_SHADER,
|
||||
DX8_SET_VERTEX_SHADER_CONSTANT,
|
||||
DX8_SET_PIXEL_SHADER_CONSTANT,
|
||||
DX8_SET_MATERIAL,
|
||||
DX8_LIGHT_ENABLE,
|
||||
DX8_SET_LIGHT,
|
||||
DX8_SET_VIEWPORT,
|
||||
DX8_CLEAR,
|
||||
DX8_VALIDATE_DEVICE,
|
||||
DX8_SET_RENDER_STATE,
|
||||
DX8_SET_TEXTURE_STAGE_STATE,
|
||||
|
||||
DX8_CREATE_VERTEX_BUFFER,
|
||||
DX8_DESTROY_VERTEX_BUFFER,
|
||||
DX8_LOCK_VERTEX_BUFFER,
|
||||
DX8_VERTEX_DATA,
|
||||
DX8_UNLOCK_VERTEX_BUFFER,
|
||||
|
||||
DX8_CREATE_INDEX_BUFFER,
|
||||
DX8_DESTROY_INDEX_BUFFER,
|
||||
DX8_LOCK_INDEX_BUFFER,
|
||||
DX8_INDEX_DATA,
|
||||
DX8_UNLOCK_INDEX_BUFFER,
|
||||
|
||||
DX8_SET_STREAM_SOURCE,
|
||||
DX8_SET_INDICES,
|
||||
DX8_DRAW_PRIMITIVE,
|
||||
DX8_DRAW_INDEXED_PRIMITIVE,
|
||||
|
||||
DX8_LOCK_TEXTURE,
|
||||
DX8_UNLOCK_TEXTURE,
|
||||
|
||||
DX8_KEYFRAME, // isn't actually a dx8 command, used to help find particular frames
|
||||
|
||||
DX8_SET_TEXTURE_DATA,
|
||||
DX8_BLIT_TEXTURE_BITS,
|
||||
|
||||
DX8_GET_DEVICE_CAPS,
|
||||
DX8_GET_ADAPTER_IDENTIFIER,
|
||||
|
||||
DX8_HARDWARE_SYNC,
|
||||
|
||||
DX8_COPY_FRAMEBUFFER_TO_TEXTURE,
|
||||
DX8_DEBUG_STRING,
|
||||
DX8_CREATE_DEPTH_TEXTURE,
|
||||
DX8_DESTROY_DEPTH_TEXTURE,
|
||||
DX8_SET_RENDER_TARGET,
|
||||
|
||||
DX8_TEST_COOPERATIVE_LEVEL,
|
||||
|
||||
DX8_SET_VERTEX_BUFFER_FORMAT, // isn't actually a dx8 command. . let's playback know what format a buffer is for listing info
|
||||
|
||||
DX8_SET_SAMPLER_STATE,
|
||||
DX8_SET_VERTEX_DECLARATION,
|
||||
DX8_CREATE_VERTEX_DECLARATION,
|
||||
DX8_SET_FVF,
|
||||
DX8_SET_CLIP_PLANE,
|
||||
|
||||
DX8_SYNC_TOKEN,
|
||||
|
||||
DX8_LOCK_VERTEX_TEXTURE,
|
||||
DX8_UNLOCK_VERTEX_TEXTURE,
|
||||
|
||||
DX8_SET_SCISSOR_RECT,
|
||||
|
||||
DX8_NUM_RECORDING_COMMANDS
|
||||
};
|
||||
|
||||
#ifdef RECORDING
|
||||
|
||||
void RecordCommand( RecordingCommands_t cmd, int numargs );
|
||||
void RecordArgument( void const* pMemory, int size );
|
||||
void FinishRecording( void );
|
||||
|
||||
inline void RecordInt( int i )
|
||||
{
|
||||
RecordArgument( &i, sizeof(int) );
|
||||
}
|
||||
|
||||
inline void RecordFloat( float f )
|
||||
{
|
||||
RecordArgument( &f, sizeof(float) );
|
||||
}
|
||||
|
||||
# define RECORD_COMMAND( _cmd, _numargs ) RecordCommand( _cmd, _numargs )
|
||||
# define RECORD_INT( _int ) RecordInt( _int )
|
||||
# define RECORD_FLOAT( _float ) RecordFloat( _float )
|
||||
# define RECORD_STRING( _string ) RecordArgument( _string, strlen(_string) + 1 )
|
||||
# define RECORD_STRUCT( _struct, _size ) RecordArgument( _struct, _size )
|
||||
|
||||
# define RECORD_RENDER_STATE( _state, _val ) \
|
||||
RECORD_COMMAND( DX8_SET_RENDER_STATE, 2 ); \
|
||||
RECORD_INT( _state ); \
|
||||
RECORD_INT( _val )
|
||||
|
||||
# define RECORD_TEXTURE_STAGE_STATE( _stage, _state, _val ) \
|
||||
RECORD_COMMAND( DX8_SET_TEXTURE_STAGE_STATE, 3 ); \
|
||||
RECORD_INT( _stage ); \
|
||||
RECORD_INT( _state ); \
|
||||
RECORD_INT( _val )
|
||||
|
||||
# define RECORD_SAMPLER_STATE( _stage, _state, _val ) \
|
||||
RECORD_COMMAND( DX8_SET_SAMPLER_STATE, 3 ); \
|
||||
RECORD_INT( _stage ); \
|
||||
RECORD_INT( _state ); \
|
||||
RECORD_INT( _val )
|
||||
|
||||
# ifdef RECORD_DEBUG_STRINGS
|
||||
# define RECORD_DEBUG_STRING( _str ) \
|
||||
RECORD_COMMAND( DX8_DEBUG_STRING, 1 ); \
|
||||
RECORD_STRING( _str )
|
||||
# else
|
||||
# define RECORD_DEBUG_STRING( _str ) 0
|
||||
# endif
|
||||
|
||||
#else // not RECORDING
|
||||
|
||||
# undef RECORD_TEXTURES
|
||||
|
||||
# define RECORD_COMMAND( _cmd, _numargs ) 0
|
||||
# define RECORD_INT( _int ) 0
|
||||
# define RECORD_FLOAT( _float ) 0
|
||||
# define RECORD_STRING( _string ) 0
|
||||
# define RECORD_STRUCT( _struct, _size ) 0
|
||||
# define RECORD_RENDER_STATE( _state, _val ) 0
|
||||
# define RECORD_TEXTURE_STAGE_STATE( _stage, _state, _val ) 0
|
||||
# define RECORD_SAMPLER_STATE( _stage, _state, _val ) 0
|
||||
# define RECORD_DEBUG_STRING( _str ) 0
|
||||
|
||||
#endif // RECORDING
|
||||
|
||||
#endif // RECORDING_H
|
||||
105
materialsystem/shaderapidx9/shaderapi_global.h
Normal file
105
materialsystem/shaderapidx9/shaderapi_global.h
Normal file
@@ -0,0 +1,105 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERAPI_GLOBAL_H
|
||||
#define SHADERAPI_GLOBAL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "tier0/threadtools.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Use this to fill in structures with the current board state
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef _DEBUG
|
||||
#define DEBUG_BOARD_STATE 0
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class IShaderUtil;
|
||||
class CShaderDeviceBase;
|
||||
class CShaderDeviceMgrBase;
|
||||
class CShaderAPIBase;
|
||||
class IShaderShadow;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global interfaces
|
||||
//-----------------------------------------------------------------------------
|
||||
extern IShaderUtil* g_pShaderUtil;
|
||||
inline IShaderUtil* ShaderUtil()
|
||||
{
|
||||
return g_pShaderUtil;
|
||||
}
|
||||
|
||||
extern CShaderDeviceBase *g_pShaderDevice;
|
||||
extern CShaderDeviceMgrBase *g_pShaderDeviceMgr;
|
||||
extern CShaderAPIBase *g_pShaderAPI;
|
||||
extern IShaderShadow *g_pShaderShadow;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Memory debugging
|
||||
//-----------------------------------------------------------------------------
|
||||
#define MEM_ALLOC_D3D_CREDIT() MEM_ALLOC_CREDIT_("D3D:" __FILE__)
|
||||
#define BEGIN_D3D_ALLOCATION() MemAlloc_PushAllocDbgInfo("D3D:" __FILE__, __LINE__)
|
||||
#define END_D3D_ALLOCATION() MemAlloc_PopAllocDbgInfo()
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Threading
|
||||
//-----------------------------------------------------------------------------
|
||||
extern bool g_bUseShaderMutex;
|
||||
|
||||
//#define USE_SHADER_DISALLOW 1
|
||||
//#define STRICT_MT_SHADERAPI 1
|
||||
|
||||
#if defined(_DEBUG)
|
||||
#if !defined(STRICT_MT_SHADERAPI)
|
||||
#define UNCONDITIONAL_MT_SHADERAPI 1
|
||||
#endif
|
||||
#else
|
||||
#if !defined(STRICT_MT_SHADERAPI) && !defined(UNCONDITIONAL_MT_SHADERAPI)
|
||||
#define ST_SHADERAPI 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(ST_SHADERAPI)
|
||||
typedef CThreadNullMutex CShaderMutex;
|
||||
#elif defined(STRICT_MT_SHADERAPI)
|
||||
typedef CThreadConditionalMutex<CThreadTerminalMutex<CThreadFastMutex>, &g_bUseShaderMutex> CShaderMutex;
|
||||
#elif defined(UNCONDITIONAL_MT_SHADERAPI)
|
||||
typedef CThreadFastMutex CShaderMutex;
|
||||
#else
|
||||
typedef CThreadConditionalMutex<CThreadFastMutex, &g_bUseShaderMutex> CShaderMutex;
|
||||
#endif
|
||||
|
||||
extern CShaderMutex g_ShaderMutex;
|
||||
|
||||
extern bool g_bShaderAccessDisallowed;
|
||||
|
||||
#ifdef USE_SHADER_DISALLOW
|
||||
#define TestShaderPermission() do { if ( (!g_bUseShaderMutex || g_ShaderMutex.GetDepth() == 0) && g_bShaderAccessDisallowed ) { ExecuteOnce( DebuggerBreakIfDebugging() ); } } while (0)
|
||||
#define LOCK_SHADERAPI() TestShaderPermission(); AUTO_LOCK_( CShaderMutex, g_ShaderMutex )
|
||||
#define LockShaderMutex() TestShaderPermission(); g_ShaderMutex.Lock();
|
||||
#define UnlockShaderMutex() TestShaderPermission(); g_ShaderMutex.Unlock();
|
||||
#else
|
||||
#define TestShaderPermission() ((void)0)
|
||||
#define LOCK_SHADERAPI() ((void)0)
|
||||
#define LockShaderMutex() ((void)0)
|
||||
#define UnlockShaderMutex() ((void)0)
|
||||
#endif
|
||||
|
||||
|
||||
#endif // SHADERAPI_GLOBAL_H
|
||||
42
materialsystem/shaderapidx9/shaderapibase.cpp
Normal file
42
materialsystem/shaderapidx9/shaderapibase.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#undef PROTECTED_THINGS_ENABLE // prevent warnings when windows.h gets included
|
||||
|
||||
#include "shaderapibase.h"
|
||||
#include "shaderapi/ishaderutil.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// The Base implementation of the shader render class
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CShaderAPIBase::CShaderAPIBase()
|
||||
{
|
||||
}
|
||||
|
||||
CShaderAPIBase::~CShaderAPIBase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Methods of IShaderDynamicAPI
|
||||
//-----------------------------------------------------------------------------
|
||||
void CShaderAPIBase::GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo )
|
||||
{
|
||||
g_pShaderUtil->GetCurrentColorCorrection( pInfo );
|
||||
}
|
||||
|
||||
|
||||
86
materialsystem/shaderapidx9/shaderapibase.h
Normal file
86
materialsystem/shaderapidx9/shaderapibase.h
Normal file
@@ -0,0 +1,86 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERRENDERBASE_H
|
||||
#define SHADERRENDERBASE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "togl/rendermechanism.h"
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
#include "shaderapi_global.h"
|
||||
#include "locald3dtypes.h"
|
||||
|
||||
// Colors for PIX graphs
|
||||
#define PIX_VALVE_ORANGE 0xFFF5940F
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Base implementation of the shader rendering interface
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderAPIBase : public IShaderAPI
|
||||
{
|
||||
public:
|
||||
// constructor, destructor
|
||||
CShaderAPIBase();
|
||||
virtual ~CShaderAPIBase();
|
||||
|
||||
// Called when the device is initializing or shutting down
|
||||
virtual bool OnDeviceInit() = 0;
|
||||
virtual void OnDeviceShutdown() = 0;
|
||||
|
||||
// Pix events
|
||||
virtual void BeginPIXEvent( unsigned long color, const char *szName ) = 0;
|
||||
virtual void EndPIXEvent() = 0;
|
||||
virtual void AdvancePIXFrame() = 0;
|
||||
|
||||
// Release, reacquire objects
|
||||
virtual void ReleaseShaderObjects() = 0;
|
||||
virtual void RestoreShaderObjects() = 0;
|
||||
|
||||
// Resets the render state to its well defined initial value
|
||||
virtual void ResetRenderState( bool bFullReset = true ) = 0;
|
||||
|
||||
// Returns a d3d texture associated with a texture handle
|
||||
virtual IDirect3DBaseTexture* GetD3DTexture( ShaderAPITextureHandle_t hTexture ) = 0;
|
||||
|
||||
// Queues a non-full reset of render state next BeginFrame.
|
||||
virtual void QueueResetRenderState() = 0;
|
||||
|
||||
// Methods of IShaderDynamicAPI
|
||||
public:
|
||||
virtual void GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo );
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Pix measurement class
|
||||
//-----------------------------------------------------------------------------
|
||||
class CPixEvent
|
||||
{
|
||||
public:
|
||||
CPixEvent( unsigned long color, const char *szName )
|
||||
{
|
||||
if ( g_pShaderAPI )
|
||||
g_pShaderAPI->BeginPIXEvent( color, szName );
|
||||
}
|
||||
|
||||
~CPixEvent()
|
||||
{
|
||||
if ( g_pShaderAPI )
|
||||
g_pShaderAPI->EndPIXEvent();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // SHADERRENDERBASE_H
|
||||
1461
materialsystem/shaderapidx9/shaderapidx10.cpp
Normal file
1461
materialsystem/shaderapidx9/shaderapidx10.cpp
Normal file
File diff suppressed because it is too large
Load Diff
940
materialsystem/shaderapidx9/shaderapidx10.h
Normal file
940
materialsystem/shaderapidx9/shaderapidx10.h
Normal file
@@ -0,0 +1,940 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERAPIDX10_H
|
||||
#define SHADERAPIDX10_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <d3d10.h>
|
||||
|
||||
#include "shaderapibase.h"
|
||||
#include "materialsystem/idebugtextureinfo.h"
|
||||
#include "meshdx10.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
struct MaterialSystemHardwareIdentifier_t;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// DX10 enumerations that don't appear to exist
|
||||
//-----------------------------------------------------------------------------
|
||||
#define MAX_DX10_VIEWPORTS 16
|
||||
#define MAX_DX10_STREAMS 16
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// A record describing the state on the board
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ShaderIndexBufferStateDx10_t
|
||||
{
|
||||
ID3D10Buffer *m_pBuffer;
|
||||
DXGI_FORMAT m_Format;
|
||||
UINT m_nOffset;
|
||||
|
||||
bool operator!=( const ShaderIndexBufferStateDx10_t& src ) const
|
||||
{
|
||||
return memcmp( this, &src, sizeof(ShaderIndexBufferStateDx10_t) ) != 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct ShaderVertexBufferStateDx10_t
|
||||
{
|
||||
ID3D10Buffer *m_pBuffer;
|
||||
UINT m_nStride;
|
||||
UINT m_nOffset;
|
||||
};
|
||||
|
||||
struct ShaderInputLayoutStateDx10_t
|
||||
{
|
||||
VertexShaderHandle_t m_hVertexShader;
|
||||
VertexFormat_t m_pVertexDecl[ MAX_DX10_STREAMS ];
|
||||
};
|
||||
|
||||
struct ShaderStateDx10_t
|
||||
{
|
||||
int m_nViewportCount;
|
||||
D3D10_VIEWPORT m_pViewports[ MAX_DX10_VIEWPORTS ];
|
||||
FLOAT m_ClearColor[4];
|
||||
ShaderRasterState_t m_RasterState;
|
||||
ID3D10RasterizerState *m_pRasterState;
|
||||
ID3D10VertexShader *m_pVertexShader;
|
||||
ID3D10GeometryShader *m_pGeometryShader;
|
||||
ID3D10PixelShader *m_pPixelShader;
|
||||
ShaderVertexBufferStateDx10_t m_pVertexBuffer[ MAX_DX10_STREAMS ];
|
||||
ShaderIndexBufferStateDx10_t m_IndexBuffer;
|
||||
ShaderInputLayoutStateDx10_t m_InputLayout;
|
||||
D3D10_PRIMITIVE_TOPOLOGY m_Topology;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Commit function helper class
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef void (*StateCommitFunc_t)( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t ¤tState, bool bForce );
|
||||
|
||||
class CFunctionCommit
|
||||
{
|
||||
public:
|
||||
CFunctionCommit();
|
||||
~CFunctionCommit();
|
||||
|
||||
void Init( int nFunctionCount );
|
||||
|
||||
// Methods related to queuing functions to be called per-(pMesh->Draw call) or per-pass
|
||||
void ClearAllCommitFuncs( );
|
||||
void CallCommitFuncs( bool bForce );
|
||||
bool IsCommitFuncInUse( int nFunc ) const;
|
||||
void MarkCommitFuncInUse( int nFunc );
|
||||
void AddCommitFunc( StateCommitFunc_t f );
|
||||
void CallCommitFuncs( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t ¤tState, bool bForce = false );
|
||||
|
||||
private:
|
||||
// A list of state commit functions to run as per-draw call commit time
|
||||
unsigned char* m_pCommitFlags;
|
||||
int m_nCommitBufferSize;
|
||||
CUtlVector< StateCommitFunc_t > m_CommitFuncs;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Dx10 implementation of the shader API
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderAPIDx10 : public CShaderAPIBase, public IDebugTextureInfo
|
||||
{
|
||||
typedef CShaderAPIBase BaseClass;
|
||||
|
||||
public:
|
||||
// constructor, destructor
|
||||
CShaderAPIDx10( );
|
||||
virtual ~CShaderAPIDx10();
|
||||
|
||||
// Methods of IShaderAPI
|
||||
// NOTE: These methods have been ported over
|
||||
public:
|
||||
virtual void SetViewports( int nCount, const ShaderViewport_t* pViewports );
|
||||
virtual int GetViewports( ShaderViewport_t* pViewports, int nMax ) const;
|
||||
virtual void ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil, int renderTargetWidth, int renderTargetHeight );
|
||||
virtual void ClearColor3ub( unsigned char r, unsigned char g, unsigned char b );
|
||||
virtual void ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a );
|
||||
virtual void SetRasterState( const ShaderRasterState_t& state );
|
||||
virtual void BindVertexShader( VertexShaderHandle_t hVertexShader );
|
||||
virtual void BindGeometryShader( GeometryShaderHandle_t hGeometryShader );
|
||||
virtual void BindPixelShader( PixelShaderHandle_t hPixelShader );
|
||||
virtual void BindVertexBuffer( int nStreamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions = 1 );
|
||||
virtual void BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes );
|
||||
virtual void Draw( MaterialPrimitiveType_t primitiveType, int nFirstIndex, int nIndexCount );
|
||||
|
||||
// Methods of IShaderDynamicAPI
|
||||
public:
|
||||
virtual void GetBackBufferDimensions( int& nWidth, int& nHeight ) const;
|
||||
|
||||
public:
|
||||
// Methods of CShaderAPIBase
|
||||
virtual bool OnDeviceInit() { ResetRenderState(); return true; }
|
||||
virtual void OnDeviceShutdown() {}
|
||||
virtual void ReleaseShaderObjects();
|
||||
virtual void RestoreShaderObjects();
|
||||
virtual void BeginPIXEvent( unsigned long color, const char *szName ) {}
|
||||
virtual void EndPIXEvent() {}
|
||||
virtual void AdvancePIXFrame() {}
|
||||
|
||||
// NOTE: These methods have not been ported over.
|
||||
// IDebugTextureInfo implementation.
|
||||
public:
|
||||
|
||||
virtual bool IsDebugTextureListFresh( int numFramesAllowed = 1 ) { return false; }
|
||||
virtual void EnableDebugTextureList( bool bEnable ) {}
|
||||
virtual void EnableGetAllTextures( bool bEnable ) {}
|
||||
virtual KeyValues* GetDebugTextureList() { return NULL; }
|
||||
virtual int GetTextureMemoryUsed( TextureMemoryType eTextureMemory ) { return 0; }
|
||||
virtual bool SetDebugTextureRendering( bool bEnable ) { return false; }
|
||||
|
||||
public:
|
||||
// Other public methods
|
||||
void Unbind( VertexShaderHandle_t hShader );
|
||||
void Unbind( GeometryShaderHandle_t hShader );
|
||||
void Unbind( PixelShaderHandle_t hShader );
|
||||
void UnbindVertexBuffer( ID3D10Buffer *pBuffer );
|
||||
void UnbindIndexBuffer( ID3D10Buffer *pBuffer );
|
||||
|
||||
void PrintfVA( char *fmt, va_list vargs ) {}
|
||||
void Printf( PRINTF_FORMAT_STRING const char *fmt, ... ) {}
|
||||
float Knob( char *knobname, float *setvalue = NULL ) { return 0.0f;}
|
||||
|
||||
private:
|
||||
|
||||
// Returns a d3d texture associated with a texture handle
|
||||
virtual IDirect3DBaseTexture* GetD3DTexture( ShaderAPITextureHandle_t hTexture ) { Assert(0); return NULL; }
|
||||
virtual void QueueResetRenderState() {}
|
||||
|
||||
void SetTopology( MaterialPrimitiveType_t topology );
|
||||
|
||||
virtual bool DoRenderTargetsNeedSeparateDepthBuffer() const;
|
||||
|
||||
void SetHardwareGammaRamp( float fGamma )
|
||||
{
|
||||
}
|
||||
|
||||
// Used to clear the transition table when we know it's become invalid.
|
||||
void ClearSnapshots();
|
||||
|
||||
// Sets the mode...
|
||||
bool SetMode( void* hwnd, int nAdapter, const ShaderDeviceInfo_t &info )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void ChangeVideoMode( const ShaderDeviceInfo_t &info )
|
||||
{
|
||||
}
|
||||
|
||||
// Called when the dx support level has changed
|
||||
virtual void DXSupportLevelChanged() {}
|
||||
|
||||
virtual void EnableUserClipTransformOverride( bool bEnable ) {}
|
||||
virtual void UserClipTransform( const VMatrix &worldToView ) {}
|
||||
virtual bool GetUserClipTransform( VMatrix &worldToView ) { return false; }
|
||||
|
||||
// Sets the default *dynamic* state
|
||||
void SetDefaultState( );
|
||||
|
||||
// Returns the snapshot id for the shader state
|
||||
StateSnapshot_t TakeSnapshot( );
|
||||
|
||||
// Returns true if the state snapshot is transparent
|
||||
bool IsTranslucent( StateSnapshot_t id ) const;
|
||||
bool IsAlphaTested( StateSnapshot_t id ) const;
|
||||
bool UsesVertexAndPixelShaders( StateSnapshot_t id ) const;
|
||||
virtual bool IsDepthWriteEnabled( StateSnapshot_t id ) const;
|
||||
|
||||
// Gets the vertex format for a set of snapshot ids
|
||||
VertexFormat_t ComputeVertexFormat( int numSnapshots, StateSnapshot_t* pIds ) const;
|
||||
|
||||
// Gets the vertex format for a set of snapshot ids
|
||||
VertexFormat_t ComputeVertexUsage( int numSnapshots, StateSnapshot_t* pIds ) const;
|
||||
|
||||
// Begins a rendering pass that uses a state snapshot
|
||||
void BeginPass( StateSnapshot_t snapshot );
|
||||
|
||||
// Uses a state snapshot
|
||||
void UseSnapshot( StateSnapshot_t snapshot );
|
||||
|
||||
// Use this to get the mesh builder that allows us to modify vertex data
|
||||
CMeshBuilder* GetVertexModifyBuilder();
|
||||
|
||||
// Sets the color to modulate by
|
||||
void Color3f( float r, float g, float b );
|
||||
void Color3fv( float const* pColor );
|
||||
void Color4f( float r, float g, float b, float a );
|
||||
void Color4fv( float const* pColor );
|
||||
|
||||
// Faster versions of color
|
||||
void Color3ub( unsigned char r, unsigned char g, unsigned char b );
|
||||
void Color3ubv( unsigned char const* rgb );
|
||||
void Color4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a );
|
||||
void Color4ubv( unsigned char const* rgba );
|
||||
|
||||
// Sets the lights
|
||||
void SetLight( int lightNum, const LightDesc_t& desc );
|
||||
void SetAmbientLight( float r, float g, float b );
|
||||
void SetAmbientLightCube( Vector4D cube[6] );
|
||||
virtual void SetLightingOrigin( Vector vLightingOrigin ) {}
|
||||
|
||||
// Get the lights
|
||||
int GetMaxLights( void ) const;
|
||||
const LightDesc_t& GetLight( int lightNum ) const;
|
||||
|
||||
// Render state for the ambient light cube (vertex shaders)
|
||||
void SetVertexShaderStateAmbientLightCube();
|
||||
virtual void SetPixelShaderStateAmbientLightCube( int pshReg, bool bForceToBlack = false ) {}
|
||||
void SetPixelShaderStateAmbientLightCube( int pshReg )
|
||||
{
|
||||
}
|
||||
virtual void GetDX9LightState( LightState_t *state ) const {}
|
||||
|
||||
float GetAmbientLightCubeLuminance(void)
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
void SetSkinningMatrices();
|
||||
|
||||
// Lightmap texture binding
|
||||
void BindLightmap( TextureStage_t stage );
|
||||
void BindLightmapAlpha( TextureStage_t stage )
|
||||
{
|
||||
}
|
||||
void BindBumpLightmap( TextureStage_t stage );
|
||||
void BindFullbrightLightmap( TextureStage_t stage );
|
||||
void BindWhite( TextureStage_t stage );
|
||||
void BindBlack( TextureStage_t stage );
|
||||
void BindGrey( TextureStage_t stage );
|
||||
void BindFBTexture( TextureStage_t stage, int textureIdex );
|
||||
void CopyRenderTargetToTexture( ShaderAPITextureHandle_t texID )
|
||||
{
|
||||
}
|
||||
|
||||
void CopyRenderTargetToTextureEx( ShaderAPITextureHandle_t texID, int nRenderTargetID, Rect_t *pSrcRect, Rect_t *pDstRect )
|
||||
{
|
||||
}
|
||||
|
||||
void CopyTextureToRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t textureHandle, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL )
|
||||
{
|
||||
}
|
||||
|
||||
// Special system flat normal map binding.
|
||||
void BindFlatNormalMap( TextureStage_t stage );
|
||||
void BindNormalizationCubeMap( TextureStage_t stage );
|
||||
void BindSignedNormalizationCubeMap( TextureStage_t stage );
|
||||
|
||||
// Set the number of bone weights
|
||||
void SetNumBoneWeights( int numBones );
|
||||
|
||||
// Flushes any primitives that are buffered
|
||||
void FlushBufferedPrimitives();
|
||||
|
||||
// Creates/destroys Mesh
|
||||
IMesh* CreateStaticMesh( VertexFormat_t fmt, const char *pTextureBudgetGroup, IMaterial * pMaterial = NULL );
|
||||
void DestroyStaticMesh( IMesh* mesh );
|
||||
|
||||
// Gets the dynamic mesh; note that you've got to render the mesh
|
||||
// before calling this function a second time. Clients should *not*
|
||||
// call DestroyStaticMesh on the mesh returned by this call.
|
||||
IMesh* GetDynamicMesh( IMaterial* pMaterial, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride );
|
||||
IMesh* GetDynamicMeshEx( IMaterial* pMaterial, VertexFormat_t fmt, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride );
|
||||
IVertexBuffer *GetDynamicVertexBuffer( IMaterial* pMaterial, bool buffered )
|
||||
{
|
||||
Assert( 0 );
|
||||
return NULL;
|
||||
}
|
||||
IIndexBuffer *GetDynamicIndexBuffer( IMaterial* pMaterial, bool buffered )
|
||||
{
|
||||
Assert( 0 );
|
||||
return NULL;
|
||||
}
|
||||
IMesh* GetFlexMesh();
|
||||
|
||||
// Renders a single pass of a material
|
||||
void RenderPass( int nPass, int nPassCount );
|
||||
|
||||
// stuff related to matrix stacks
|
||||
void MatrixMode( MaterialMatrixMode_t matrixMode );
|
||||
void PushMatrix();
|
||||
void PopMatrix();
|
||||
void LoadMatrix( float *m );
|
||||
void LoadBoneMatrix( int boneIndex, const float *m ) {}
|
||||
void MultMatrix( float *m );
|
||||
void MultMatrixLocal( float *m );
|
||||
void GetMatrix( MaterialMatrixMode_t matrixMode, float *dst );
|
||||
void LoadIdentity( void );
|
||||
void LoadCameraToWorld( void );
|
||||
void Ortho( double left, double top, double right, double bottom, double zNear, double zFar );
|
||||
void PerspectiveX( double fovx, double aspect, double zNear, double zFar );
|
||||
void PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right );
|
||||
void PickMatrix( int x, int y, int width, int height );
|
||||
void Rotate( float angle, float x, float y, float z );
|
||||
void Translate( float x, float y, float z );
|
||||
void Scale( float x, float y, float z );
|
||||
void ScaleXY( float x, float y );
|
||||
|
||||
void Viewport( int x, int y, int width, int height );
|
||||
void GetViewport( int& x, int& y, int& width, int& height ) const;
|
||||
|
||||
// Fog methods...
|
||||
void FogMode( MaterialFogMode_t fogMode );
|
||||
void FogStart( float fStart );
|
||||
void FogEnd( float fEnd );
|
||||
void SetFogZ( float fogZ );
|
||||
void FogMaxDensity( float flMaxDensity );
|
||||
void GetFogDistances( float *fStart, float *fEnd, float *fFogZ );
|
||||
void FogColor3f( float r, float g, float b );
|
||||
void FogColor3fv( float const* rgb );
|
||||
void FogColor3ub( unsigned char r, unsigned char g, unsigned char b );
|
||||
void FogColor3ubv( unsigned char const* rgb );
|
||||
|
||||
virtual void SceneFogColor3ub( unsigned char r, unsigned char g, unsigned char b );
|
||||
virtual void SceneFogMode( MaterialFogMode_t fogMode );
|
||||
virtual void GetSceneFogColor( unsigned char *rgb );
|
||||
virtual MaterialFogMode_t GetSceneFogMode( );
|
||||
virtual int GetPixelFogCombo( );
|
||||
|
||||
void SetHeightClipZ( float z );
|
||||
void SetHeightClipMode( enum MaterialHeightClipMode_t heightClipMode );
|
||||
|
||||
void SetClipPlane( int index, const float *pPlane );
|
||||
void EnableClipPlane( int index, bool bEnable );
|
||||
|
||||
void SetFastClipPlane( const float *pPlane );
|
||||
void EnableFastClip( bool bEnable );
|
||||
|
||||
// We use smaller dynamic VBs during level transitions, to free up memory
|
||||
virtual int GetCurrentDynamicVBSize( void );
|
||||
virtual void DestroyVertexBuffers( bool bExitingLevel = false );
|
||||
|
||||
// Sets the vertex and pixel shaders
|
||||
void SetVertexShaderIndex( int vshIndex );
|
||||
void SetPixelShaderIndex( int pshIndex );
|
||||
|
||||
// Sets the constant register for vertex and pixel shaders
|
||||
void SetVertexShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false );
|
||||
void SetPixelShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false );
|
||||
|
||||
void SetBooleanVertexShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false )
|
||||
{
|
||||
Assert(0);
|
||||
}
|
||||
|
||||
|
||||
void SetIntegerVertexShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false )
|
||||
{
|
||||
Assert(0);
|
||||
}
|
||||
|
||||
|
||||
void SetBooleanPixelShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false )
|
||||
{
|
||||
Assert(0);
|
||||
}
|
||||
|
||||
void SetIntegerPixelShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false )
|
||||
{
|
||||
Assert(0);
|
||||
}
|
||||
|
||||
bool ShouldWriteDepthToDestAlpha( void ) const
|
||||
{
|
||||
Assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void InvalidateDelayedShaderConstants( void );
|
||||
|
||||
// Gamma<->Linear conversions according to the video hardware we're running on
|
||||
float GammaToLinear_HardwareSpecific( float fGamma ) const
|
||||
{
|
||||
return 0.;
|
||||
}
|
||||
|
||||
float LinearToGamma_HardwareSpecific( float fLinear ) const
|
||||
{
|
||||
return 0.;
|
||||
}
|
||||
|
||||
//Set's the linear->gamma conversion textures to use for this hardware for both srgb writes enabled and disabled(identity)
|
||||
void SetLinearToGammaConversionTextures( ShaderAPITextureHandle_t hSRGBWriteEnabledTexture, ShaderAPITextureHandle_t hIdentityTexture );
|
||||
|
||||
// Cull mode
|
||||
void CullMode( MaterialCullMode_t cullMode );
|
||||
|
||||
// Force writes only when z matches. . . useful for stenciling things out
|
||||
// by rendering the desired Z values ahead of time.
|
||||
void ForceDepthFuncEquals( bool bEnable );
|
||||
|
||||
// Forces Z buffering on or off
|
||||
void OverrideDepthEnable( bool bEnable, bool bDepthEnable );
|
||||
// Forces alpha writes on or off
|
||||
void OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable );
|
||||
//forces color writes on or off
|
||||
void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable );
|
||||
|
||||
// Sets the shade mode
|
||||
void ShadeMode( ShaderShadeMode_t mode );
|
||||
|
||||
// Binds a particular material to render with
|
||||
void Bind( IMaterial* pMaterial );
|
||||
|
||||
// Returns the nearest supported format
|
||||
ImageFormat GetNearestSupportedFormat( ImageFormat fmt, bool bFilteringRequired = true ) const;
|
||||
ImageFormat GetNearestRenderTargetFormat( ImageFormat fmt ) const;
|
||||
|
||||
// Sets the texture state
|
||||
void BindTexture( Sampler_t stage, ShaderAPITextureHandle_t textureHandle );
|
||||
|
||||
void SetRenderTarget( ShaderAPITextureHandle_t colorTextureHandle, ShaderAPITextureHandle_t depthTextureHandle )
|
||||
{
|
||||
}
|
||||
|
||||
void SetRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t colorTextureHandle, ShaderAPITextureHandle_t depthTextureHandle )
|
||||
{
|
||||
}
|
||||
|
||||
// Indicates we're going to be modifying this texture
|
||||
// TexImage2D, TexSubImage2D, TexWrap, TexMinFilter, and TexMagFilter
|
||||
// all use the texture specified by this function.
|
||||
void ModifyTexture( ShaderAPITextureHandle_t textureHandle );
|
||||
|
||||
// Texture management methods
|
||||
void TexImage2D( int level, int cubeFace, ImageFormat dstFormat, int zOffset, int width, int height,
|
||||
ImageFormat srcFormat, bool bSrcIsTiled, void *imageData );
|
||||
void TexSubImage2D( int level, int cubeFace, int xOffset, int yOffset, int zOffset, int width, int height,
|
||||
ImageFormat srcFormat, int srcStride, bool bSrcIsTiled, void *imageData );
|
||||
void TexImageFromVTF( IVTFTexture *pVTF, int iVTFFrame );
|
||||
|
||||
bool TexLock( int level, int cubeFaceID, int xOffset, int yOffset,
|
||||
int width, int height, CPixelWriter& writer );
|
||||
void TexUnlock( );
|
||||
|
||||
// These are bound to the texture, not the texture environment
|
||||
void TexMinFilter( ShaderTexFilterMode_t texFilterMode );
|
||||
void TexMagFilter( ShaderTexFilterMode_t texFilterMode );
|
||||
void TexWrap( ShaderTexCoordComponent_t coord, ShaderTexWrapMode_t wrapMode );
|
||||
void TexSetPriority( int priority );
|
||||
|
||||
ShaderAPITextureHandle_t CreateTexture(
|
||||
int width,
|
||||
int height,
|
||||
int depth,
|
||||
ImageFormat dstImageFormat,
|
||||
int numMipLevels,
|
||||
int numCopies,
|
||||
int flags,
|
||||
const char *pDebugName,
|
||||
const char *pTextureGroupName );
|
||||
void CreateTextures(
|
||||
ShaderAPITextureHandle_t *pHandles,
|
||||
int count,
|
||||
int width,
|
||||
int height,
|
||||
int depth,
|
||||
ImageFormat dstImageFormat,
|
||||
int numMipLevels,
|
||||
int numCopies,
|
||||
int flags,
|
||||
const char *pDebugName,
|
||||
const char *pTextureGroupName );
|
||||
ShaderAPITextureHandle_t CreateDepthTexture( ImageFormat renderFormat, int width, int height, const char *pDebugName, bool bTexture );
|
||||
void DeleteTexture( ShaderAPITextureHandle_t textureHandle );
|
||||
bool IsTexture( ShaderAPITextureHandle_t textureHandle );
|
||||
bool IsTextureResident( ShaderAPITextureHandle_t textureHandle );
|
||||
|
||||
// stuff that isn't to be used from within a shader
|
||||
void ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth );
|
||||
void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth );
|
||||
void PerformFullScreenStencilOperation( void );
|
||||
void ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat );
|
||||
virtual void ReadPixels( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *data, ImageFormat dstFormat, int nDstStride );
|
||||
|
||||
// Selection mode methods
|
||||
int SelectionMode( bool selectionMode );
|
||||
void SelectionBuffer( unsigned int* pBuffer, int size );
|
||||
void ClearSelectionNames( );
|
||||
void LoadSelectionName( int name );
|
||||
void PushSelectionName( int name );
|
||||
void PopSelectionName();
|
||||
|
||||
void FlushHardware();
|
||||
void ResetRenderState( bool bFullReset = true );
|
||||
|
||||
// Can we download textures?
|
||||
virtual bool CanDownloadTextures() const;
|
||||
|
||||
// Board-independent calls, here to unify how shaders set state
|
||||
// Implementations should chain back to IShaderUtil->BindTexture(), etc.
|
||||
|
||||
// Use this to begin and end the frame
|
||||
void BeginFrame();
|
||||
void EndFrame();
|
||||
|
||||
// returns current time
|
||||
double CurrentTime() const;
|
||||
|
||||
// Get the current camera position in world space.
|
||||
void GetWorldSpaceCameraPosition( float * pPos ) const;
|
||||
|
||||
void ForceHardwareSync( void );
|
||||
|
||||
int GetCurrentNumBones( void ) const;
|
||||
bool IsHWMorphingEnabled( ) const;
|
||||
int GetCurrentLightCombo( void ) const;
|
||||
int MapLightComboToPSLightCombo( int nLightCombo ) const;
|
||||
MaterialFogMode_t GetCurrentFogType( void ) const;
|
||||
|
||||
void RecordString( const char *pStr );
|
||||
|
||||
void EvictManagedResources();
|
||||
|
||||
void SetTextureTransformDimension( TextureStage_t textureStage, int dimension, bool projected );
|
||||
void DisableTextureTransform( TextureStage_t textureStage )
|
||||
{
|
||||
}
|
||||
void SetBumpEnvMatrix( TextureStage_t textureStage, float m00, float m01, float m10, float m11 );
|
||||
|
||||
// Gets the lightmap dimensions
|
||||
virtual void GetLightmapDimensions( int *w, int *h );
|
||||
|
||||
virtual void SyncToken( const char *pToken );
|
||||
|
||||
// Setup standard vertex shader constants (that don't change)
|
||||
// This needs to be called anytime that overbright changes.
|
||||
virtual void SetStandardVertexShaderConstants( float fOverbright )
|
||||
{
|
||||
}
|
||||
|
||||
// Scissor Rect
|
||||
virtual void SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor ) {}
|
||||
|
||||
// Reports support for a given CSAA mode
|
||||
bool SupportsCSAAMode( int nNumSamples, int nQualityLevel ) { return false; }
|
||||
|
||||
// Level of anisotropic filtering
|
||||
virtual void SetAnisotropicLevel( int nAnisotropyLevel )
|
||||
{
|
||||
}
|
||||
|
||||
void SetDefaultDynamicState()
|
||||
{
|
||||
}
|
||||
virtual void CommitPixelShaderLighting( int pshReg )
|
||||
{
|
||||
}
|
||||
|
||||
virtual void MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords )
|
||||
{
|
||||
}
|
||||
|
||||
ShaderAPIOcclusionQuery_t CreateOcclusionQueryObject( void )
|
||||
{
|
||||
return INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE;
|
||||
}
|
||||
|
||||
void DestroyOcclusionQueryObject( ShaderAPIOcclusionQuery_t handle )
|
||||
{
|
||||
}
|
||||
|
||||
void BeginOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t handle )
|
||||
{
|
||||
}
|
||||
|
||||
void EndOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t handle )
|
||||
{
|
||||
}
|
||||
|
||||
int OcclusionQuery_GetNumPixelsRendered( ShaderAPIOcclusionQuery_t handle, bool bFlush )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual void AcquireThreadOwnership() {}
|
||||
virtual void ReleaseThreadOwnership() {}
|
||||
|
||||
virtual bool SupportsBorderColor() const { return false; }
|
||||
virtual bool SupportsFetch4() const { return false; }
|
||||
virtual void EnableBuffer2FramesAhead( bool bEnable ) {}
|
||||
|
||||
virtual void SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale ) {}
|
||||
|
||||
void SetPixelShaderFogParams( int reg )
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool InFlashlightMode() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool InEditorMode() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// What fields in the morph do we actually use?
|
||||
virtual MorphFormat_t ComputeMorphFormat( int numSnapshots, StateSnapshot_t* pIds ) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Gets the bound morph's vertex format; returns 0 if no morph is bound
|
||||
virtual MorphFormat_t GetBoundMorphFormat()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id );
|
||||
|
||||
// Binds a standard texture
|
||||
virtual void BindStandardTexture( Sampler_t stage, StandardTextureId_t id )
|
||||
{
|
||||
}
|
||||
|
||||
virtual void BindStandardVertexTexture( VertexTextureSampler_t stage, StandardTextureId_t id )
|
||||
{
|
||||
}
|
||||
|
||||
virtual void SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture )
|
||||
{
|
||||
}
|
||||
|
||||
virtual void SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture )
|
||||
{
|
||||
}
|
||||
|
||||
virtual const FlashlightState_t &GetFlashlightState( VMatrix &worldToTexture ) const
|
||||
{
|
||||
static FlashlightState_t blah;
|
||||
return blah;
|
||||
}
|
||||
|
||||
virtual const FlashlightState_t &GetFlashlightStateEx( VMatrix &worldToTexture, ITexture **pFlashlightDepthTexture ) const
|
||||
{
|
||||
static FlashlightState_t blah;
|
||||
return blah;
|
||||
}
|
||||
|
||||
virtual void SetModeChangeCallback( ModeChangeCallbackFunc_t func )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual void ClearVertexAndPixelShaderRefCounts()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void PurgeUnusedVertexAndPixelShaders()
|
||||
{
|
||||
}
|
||||
|
||||
// Binds a vertex texture to a particular texture stage in the vertex pipe
|
||||
virtual void BindVertexTexture( VertexTextureSampler_t nStage, ShaderAPITextureHandle_t hTexture )
|
||||
{
|
||||
}
|
||||
|
||||
// Sets morph target factors
|
||||
virtual void SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights )
|
||||
{
|
||||
}
|
||||
|
||||
// NOTE: Stuff after this is added after shipping HL2.
|
||||
ITexture *GetRenderTargetEx( int nRenderTargetID )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SetToneMappingScaleLinear( const Vector &scale )
|
||||
{
|
||||
}
|
||||
|
||||
const Vector &GetToneMappingScaleLinear( void ) const
|
||||
{
|
||||
static Vector dummy;
|
||||
return dummy;
|
||||
}
|
||||
|
||||
virtual float GetLightMapScaleFactor( void ) const
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
// For dealing with device lost in cases where SwapBuffers isn't called all the time (Hammer)
|
||||
virtual void HandleDeviceLost()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void EnableLinearColorSpaceFrameBuffer( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
// Lets the shader know about the full-screen texture so it can
|
||||
virtual void SetFullScreenTextureHandle( ShaderAPITextureHandle_t h )
|
||||
{
|
||||
}
|
||||
|
||||
void SetFloatRenderingParameter(int parm_number, float value)
|
||||
{
|
||||
}
|
||||
|
||||
void SetIntRenderingParameter(int parm_number, int value)
|
||||
{
|
||||
}
|
||||
void SetVectorRenderingParameter(int parm_number, Vector const &value)
|
||||
{
|
||||
}
|
||||
|
||||
float GetFloatRenderingParameter(int parm_number) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GetIntRenderingParameter(int parm_number) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Vector GetVectorRenderingParameter(int parm_number) const
|
||||
{
|
||||
return Vector(0,0,0);
|
||||
}
|
||||
|
||||
// Methods related to stencil
|
||||
void SetStencilEnable(bool onoff)
|
||||
{
|
||||
}
|
||||
|
||||
void SetStencilFailOperation(StencilOperation_t op)
|
||||
{
|
||||
}
|
||||
|
||||
void SetStencilZFailOperation(StencilOperation_t op)
|
||||
{
|
||||
}
|
||||
|
||||
void SetStencilPassOperation(StencilOperation_t op)
|
||||
{
|
||||
}
|
||||
|
||||
void SetStencilCompareFunction(StencilComparisonFunction_t cmpfn)
|
||||
{
|
||||
}
|
||||
|
||||
void SetStencilReferenceValue(int ref)
|
||||
{
|
||||
}
|
||||
|
||||
void SetStencilTestMask(uint32 msk)
|
||||
{
|
||||
}
|
||||
|
||||
void SetStencilWriteMask(uint32 msk)
|
||||
{
|
||||
}
|
||||
|
||||
void ClearStencilBufferRectangle( int xmin, int ymin, int xmax, int ymax,int value)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void GetDXLevelDefaults(uint &max_dxlevel,uint &recommended_dxlevel)
|
||||
{
|
||||
max_dxlevel=recommended_dxlevel=90;
|
||||
}
|
||||
|
||||
virtual void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices )
|
||||
{
|
||||
*pMaxVerts = 32768;
|
||||
*pMaxIndices = 32768;
|
||||
}
|
||||
|
||||
// Returns the max possible vertices + indices to render in a single draw call
|
||||
virtual int GetMaxVerticesToRender( IMaterial *pMaterial )
|
||||
{
|
||||
return 32768;
|
||||
}
|
||||
|
||||
virtual int GetMaxIndicesToRender( )
|
||||
{
|
||||
return 32768;
|
||||
}
|
||||
virtual int CompareSnapshots( StateSnapshot_t snapshot0, StateSnapshot_t snapshot1 ) { return 0; }
|
||||
|
||||
virtual void DisableAllLocalLights() {}
|
||||
|
||||
virtual bool SupportsMSAAMode( int nMSAAMode ) { return false; }
|
||||
|
||||
// Hooks for firing PIX events from outside the Material System...
|
||||
virtual void SetPIXMarker( unsigned long color, const char *szName ) {}
|
||||
|
||||
virtual void ComputeVertexDescription( unsigned char* pBuffer, VertexFormat_t vertexFormat, MeshDesc_t& desc ) const {}
|
||||
|
||||
virtual bool SupportsShadowDepthTextures() { return false; }
|
||||
|
||||
virtual int NeedsShaderSRGBConversion(void) const { return 1; }
|
||||
|
||||
virtual bool SupportsFetch4() { return false; }
|
||||
|
||||
virtual void SetShadowDepthBiasFactors( float fShadowSlopeScaleDepthBias, float fShadowDepthBias ) {}
|
||||
|
||||
virtual void SetDisallowAccess( bool ) {}
|
||||
virtual void EnableShaderShaderMutex( bool ) {}
|
||||
virtual void ShaderLock() {}
|
||||
virtual void ShaderUnlock() {}
|
||||
virtual void EnableHWMorphing( bool bEnable ) {}
|
||||
ImageFormat GetNullTextureFormat( void ) { return IMAGE_FORMAT_ABGR8888; } // stub
|
||||
virtual void PushDeformation( DeformationBase_t const *Deformation )
|
||||
{
|
||||
}
|
||||
|
||||
virtual void PopDeformation( )
|
||||
{
|
||||
}
|
||||
|
||||
virtual int GetNumActiveDeformations() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
virtual void ExecuteCommandBuffer( uint8 *pBuf )
|
||||
{
|
||||
}
|
||||
|
||||
void SetStandardTextureHandle(StandardTextureId_t,ShaderAPITextureHandle_t)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void SetPSNearAndFarZ( int pshReg )
|
||||
{
|
||||
}
|
||||
|
||||
int GetPackedDeformationInformation( int nMaskOfUnderstoodDeformations,
|
||||
float *pConstantValuesOut,
|
||||
int nBufferSize,
|
||||
int nMaximumDeformations,
|
||||
int *pNumDefsOut ) const
|
||||
{
|
||||
*pNumDefsOut = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual bool OwnGPUResources( bool bEnable )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
TRANSLUCENT = 0x1,
|
||||
ALPHATESTED = 0x2,
|
||||
VERTEX_AND_PIXEL_SHADERS = 0x4,
|
||||
DEPTHWRITE = 0x8,
|
||||
};
|
||||
void EnableAlphaToCoverage() {} ;
|
||||
void DisableAlphaToCoverage() {} ;
|
||||
|
||||
ImageFormat GetShadowDepthTextureFormat() { return IMAGE_FORMAT_UNKNOWN; };
|
||||
|
||||
//
|
||||
// NOTE: Under here are real methods being used by dx10 implementation
|
||||
// above is stuff I still have to port over.
|
||||
//
|
||||
private:
|
||||
void ClearShaderState( ShaderStateDx10_t* pState );
|
||||
void CommitStateChanges( bool bForce = false );
|
||||
|
||||
private:
|
||||
CMeshDx10 m_Mesh;
|
||||
|
||||
bool m_bResettingRenderState : 1;
|
||||
CFunctionCommit m_Commit;
|
||||
ShaderStateDx10_t m_DesiredState;
|
||||
ShaderStateDx10_t m_CurrentState;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton global
|
||||
//-----------------------------------------------------------------------------
|
||||
extern CShaderAPIDx10* g_pShaderAPIDx10;
|
||||
|
||||
#endif // SHADERAPIDX10_H
|
||||
|
||||
19
materialsystem/shaderapidx9/shaderapidx10_global.h
Normal file
19
materialsystem/shaderapidx9/shaderapidx10_global.h
Normal file
@@ -0,0 +1,19 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERAPIDX10_GLOBAL_H
|
||||
#define SHADERAPIDX10_GLOBAL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "shaderapi_global.h"
|
||||
|
||||
|
||||
#endif // SHADERAPIDX10_GLOBAL_H
|
||||
14356
materialsystem/shaderapidx9/shaderapidx8.cpp
Normal file
14356
materialsystem/shaderapidx9/shaderapidx8.cpp
Normal file
File diff suppressed because it is too large
Load Diff
118
materialsystem/shaderapidx9/shaderapidx8.h
Normal file
118
materialsystem/shaderapidx9/shaderapidx8.h
Normal file
@@ -0,0 +1,118 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERAPIDX8_H
|
||||
#define SHADERAPIDX8_H
|
||||
|
||||
#include "shaderapibase.h"
|
||||
#include "shaderapi/ishadershadow.h"
|
||||
#include "locald3dtypes.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Vendor-specific defines
|
||||
//-----------------------------------------------------------------------------
|
||||
#define ATI_FETCH4_ENABLE MAKEFOURCC('G','E','T','4')
|
||||
#define ATI_FETCH4_DISABLE MAKEFOURCC('G','E','T','1')
|
||||
#define ATISAMP_FETCH4 D3DSAMP_MIPMAPLODBIAS
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class CMeshBase;
|
||||
class CMeshBuilder;
|
||||
struct ShadowState_t;
|
||||
class IMaterialInternal;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// State that matters to buffered meshes... (for debugging only)
|
||||
//-----------------------------------------------------------------------------
|
||||
struct BufferedState_t
|
||||
{
|
||||
D3DXMATRIX m_Transform[3];
|
||||
D3DVIEWPORT9 m_Viewport;
|
||||
int m_BoundTexture[16];
|
||||
void *m_VertexShader;
|
||||
void *m_PixelShader;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The DX8 shader API
|
||||
//-----------------------------------------------------------------------------
|
||||
// FIXME: Remove this! Either move them into CShaderAPIBase or CShaderAPIDx8
|
||||
class IShaderAPIDX8 : public CShaderAPIBase
|
||||
{
|
||||
public:
|
||||
// Draws the mesh
|
||||
virtual void DrawMesh( CMeshBase *pMesh ) = 0;
|
||||
|
||||
// Draw the mesh with the currently bound vertex and index buffers.
|
||||
virtual void DrawWithVertexAndIndexBuffers( void ) = 0;
|
||||
|
||||
// modifies the vertex data when necessary
|
||||
virtual void ModifyVertexData( ) = 0;
|
||||
|
||||
// Gets the current buffered state... (debug only)
|
||||
virtual void GetBufferedState( BufferedState_t &state ) = 0;
|
||||
|
||||
// Gets the current backface cull state....
|
||||
virtual D3DCULL GetCullMode() const = 0;
|
||||
|
||||
// Measures fill rate
|
||||
virtual void ComputeFillRate() = 0;
|
||||
|
||||
// Selection mode methods
|
||||
virtual bool IsInSelectionMode() const = 0;
|
||||
|
||||
// We hit somefin in selection mode
|
||||
virtual void RegisterSelectionHit( float minz, float maxz ) = 0;
|
||||
|
||||
// Get the currently bound material
|
||||
virtual IMaterialInternal* GetBoundMaterial() = 0;
|
||||
|
||||
// These methods are called by the transition table
|
||||
// They depend on dynamic state so can't exist inside the transition table
|
||||
virtual void ApplyZBias( const ShadowState_t &shaderState ) = 0;
|
||||
virtual void ApplyTextureEnable( const ShadowState_t &state, int stage ) = 0;
|
||||
virtual void ApplyCullEnable( bool bEnable ) = 0;
|
||||
virtual void SetVertexBlendState( int numBones ) = 0;
|
||||
virtual void ApplyFogMode( ShaderFogMode_t fogMode, bool bSRGBWritesEnabled, bool bDisableGammaCorrection ) = 0;
|
||||
|
||||
virtual int GetActualTextureStageCount() const = 0;
|
||||
virtual int GetActualSamplerCount() const = 0;
|
||||
|
||||
virtual bool IsRenderingMesh() const = 0;
|
||||
|
||||
// Fog methods...
|
||||
virtual void FogMode( MaterialFogMode_t fogMode ) = 0;
|
||||
|
||||
virtual int GetCurrentFrameCounter( void ) const = 0;
|
||||
|
||||
// Workaround hack for visualization of selection mode
|
||||
virtual void SetupSelectionModeVisualizationState() = 0;
|
||||
|
||||
virtual bool UsingSoftwareVertexProcessing() const = 0;
|
||||
|
||||
//notification that the SRGB write state is being changed
|
||||
virtual void EnabledSRGBWrite( bool bEnabled ) = 0;
|
||||
|
||||
// Alpha to coverage
|
||||
virtual void ApplyAlphaToCoverage( bool bEnable ) = 0;
|
||||
|
||||
#if defined( _X360 )
|
||||
virtual void ApplySRGBReadState( int iTextureStage, bool bSRGBReadEnabled ) = 0; //360 needs to rebind the texture over again instead of setting a sampler state
|
||||
#endif
|
||||
|
||||
virtual void PrintfVA( char *fmt, va_list vargs ) = 0;
|
||||
virtual void Printf( PRINTF_FORMAT_STRING const char *fmt, ... ) = 0;
|
||||
virtual float Knob( char *knobname, float *setvalue = NULL ) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif // SHADERAPIDX8_H
|
||||
100
materialsystem/shaderapidx9/shaderapidx8_global.h
Normal file
100
materialsystem/shaderapidx9/shaderapidx8_global.h
Normal file
@@ -0,0 +1,100 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERAPIDX8_GLOBAL_H
|
||||
#define SHADERAPIDX8_GLOBAL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "tier0/dbg.h"
|
||||
#include "tier0/memalloc.h"
|
||||
#include "shaderapi_global.h"
|
||||
#include "tier2/tier2.h"
|
||||
#include "shaderdevicedx8.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Use this to fill in structures with the current board state
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define DEBUG_BOARD_STATE 0
|
||||
#endif
|
||||
|
||||
#if !defined( _X360 )
|
||||
IDirect3DDevice9 *Dx9Device();
|
||||
IDirect3D9 *D3D();
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Measures driver allocations
|
||||
//-----------------------------------------------------------------------------
|
||||
//#define MEASURE_DRIVER_ALLOCATIONS 1
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class IShaderUtil;
|
||||
class IVertexBufferDX8;
|
||||
class IShaderShadowDX8;
|
||||
class IMeshMgr;
|
||||
class IShaderAPIDX8;
|
||||
class IFileSystem;
|
||||
class IShaderManager;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// A new shader draw flag we need to workaround dx8
|
||||
//-----------------------------------------------------------------------------
|
||||
enum
|
||||
{
|
||||
SHADER_HAS_CONSTANT_COLOR = 0x80000000
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The main shader API
|
||||
//-----------------------------------------------------------------------------
|
||||
extern IShaderAPIDX8 *g_pShaderAPIDX8;
|
||||
inline IShaderAPIDX8* ShaderAPI()
|
||||
{
|
||||
return g_pShaderAPIDX8;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The shader shadow
|
||||
//-----------------------------------------------------------------------------
|
||||
IShaderShadowDX8* ShaderShadow();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Manager of all vertex + pixel shaders
|
||||
//-----------------------------------------------------------------------------
|
||||
inline IShaderManager *ShaderManager()
|
||||
{
|
||||
extern IShaderManager *g_pShaderManager;
|
||||
return g_pShaderManager;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The mesh manager
|
||||
//-----------------------------------------------------------------------------
|
||||
IMeshMgr* MeshMgr();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The main hardware config interface
|
||||
//-----------------------------------------------------------------------------
|
||||
inline IMaterialSystemHardwareConfig* HardwareConfig()
|
||||
{
|
||||
return g_pMaterialSystemHardwareConfig;
|
||||
}
|
||||
|
||||
|
||||
#endif // SHADERAPIDX8_GLOBAL_H
|
||||
146
materialsystem/shaderapidx9/shaderapidx9.vpc
Normal file
146
materialsystem/shaderapidx9/shaderapidx9.vpc
Normal file
@@ -0,0 +1,146 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// SHADERDX8.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR "..\.."
|
||||
$Macro OUTBINDIR "$SRCDIR\..\game\bin"
|
||||
$Macro OUTBINNAME "shaderapidx9"
|
||||
|
||||
$include "$SRCDIR\vpc_scripts\source_dll_base.vpc"
|
||||
|
||||
|
||||
// Common Configuration
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE;$SRCDIR\dx9sdk\include" [$WIN32 && !$GL]
|
||||
$AdditionalIncludeDirectories "$BASE;$SRCDIR\x360xdk\include\xbox" [$X360]
|
||||
$AdditionalIncludeDirectories "$BASE;..\"
|
||||
$PreprocessorDefinitions "$BASE;SHADERAPIDX9;SHADER_DLL_EXPORT;PROTECTED_THINGS_ENABLE;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead"
|
||||
$PreprocessorDefinitions "$BASE;USE_ACTUAL_DX" [($WIN32||$X360) && !$GL]
|
||||
$PreprocessorDefinitions "$BASE;GL_GLEXT_PROTOTYPES;DX_TO_GL_ABSTRACTION" [$GL]
|
||||
// $AdditionalOptions "/FC"
|
||||
}
|
||||
|
||||
$Linker
|
||||
{
|
||||
$SystemLibraries "iconv" [$OSXALL]
|
||||
$GCC_ExtraLinkerFlags "-L/usr/lib32" [$LINUXALL]
|
||||
$SystemFrameworks "Carbon;OpenGL;Quartz;Cocoa;IOKit" [$OSXALL]
|
||||
$AdditionalDependencies "$BASE ws2_32.lib" [$WIN32]
|
||||
}
|
||||
}
|
||||
|
||||
$Configuration "Debug"
|
||||
{
|
||||
$Linker [$X360]
|
||||
{
|
||||
$AdditionalDependencies "$BASE d3dx9d.lib xuirund.lib xuirenderd.lib xaudiod2.lib xmcored.lib"
|
||||
}
|
||||
}
|
||||
|
||||
$Configuration "Release"
|
||||
{
|
||||
$Linker [$X360]
|
||||
{
|
||||
$AdditionalDependencies "$BASE d3dx9.lib xuirun.lib xuirender.lib xaudio2.lib xmcore.lib"
|
||||
}
|
||||
}
|
||||
|
||||
$Project "shaderapidx9"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "colorformatdx8.cpp"
|
||||
$File "$SRCDIR\public\filesystem_helpers.cpp"
|
||||
$File "hardwareconfig.cpp"
|
||||
$File "meshbase.cpp"
|
||||
$File "meshdx8.cpp"
|
||||
$File "recording.cpp" [$WIN32 && !$GL]
|
||||
$File "shaderapidx8.cpp"
|
||||
$File "shaderdevicebase.cpp"
|
||||
$File "shaderapibase.cpp"
|
||||
$File "shaderdevicedx8.cpp"
|
||||
$File "shadershadowdx8.cpp"
|
||||
$File "texturedx8.cpp"
|
||||
$File "TransitionTable.cpp"
|
||||
$File "cvballoctracker.cpp"
|
||||
$File "vertexdecl.cpp"
|
||||
$File "vertexshaderdx8.cpp"
|
||||
$File "wmi.cpp" [$WIN32 && !$GL]
|
||||
$File "textureheap.cpp" [$X360]
|
||||
$File "winutils.cpp" [!$WIN32]
|
||||
}
|
||||
|
||||
$Folder "DirectX Header Files" [$WIN32 && !$GL]
|
||||
{
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9.h"
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9anim.h"
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9core.h"
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9effect.h"
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9math.h"
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9math.inl"
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9mesh.h"
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9shader.h"
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9shape.h"
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9tex.h"
|
||||
}
|
||||
|
||||
$Folder "Public Header Files"
|
||||
{
|
||||
$File "$SRCDIR\public\shaderapi\IShaderDevice.h"
|
||||
$File "$SRCDIR\public\shaderapi\ishaderutil.h"
|
||||
$File "$SRCDIR\public\shaderapi\ishaderapi.h"
|
||||
$File "$SRCDIR\public\shaderapi\ishaderdynamic.h"
|
||||
$File "$SRCDIR\public\shaderapi\ishadershadow.h"
|
||||
$File "$SRCDIR\public\materialsystem\idebugtextureinfo.h"
|
||||
$File "$SRCDIR\public\materialsystem\ivballoctracker.h"
|
||||
$File "$SRCDIR\public\materialsystem\shader_vcs_version.h"
|
||||
}
|
||||
|
||||
$Folder "Header Files"
|
||||
{
|
||||
$File "TransitionTable.h"
|
||||
$File "vertexdecl.h"
|
||||
$File "colorformatdx8.h"
|
||||
$File "dynamicib.h"
|
||||
$File "dynamicvb.h"
|
||||
$File "hardwareconfig.h"
|
||||
$File "meshbase.h"
|
||||
$File "imeshdx8.h"
|
||||
$File "locald3dtypes.h"
|
||||
$File "recording.h"
|
||||
$File "shaderapidx8.h"
|
||||
$File "shaderdevicebase.h"
|
||||
$File "shaderapibase.h"
|
||||
$File "shaderdevicedx8.h"
|
||||
$File "shaderapidx8_global.h"
|
||||
$File "shadershadowdx8.h"
|
||||
$File "stubd3ddevice.h"
|
||||
$File "texturedx8.h"
|
||||
$File "vertexshaderdx8.h"
|
||||
$File "wmi.h" [$WIN32 && !$GL]
|
||||
$File "textureheap.h" [$X360]
|
||||
$File "winutils.h" [!$WIN32]
|
||||
}
|
||||
|
||||
$Folder "Link Libraries" [$WIN32]
|
||||
{
|
||||
|
||||
$File "$SRCDIR\dx9sdk\lib\d3d9.lib" [$WIN32 && !$GL]
|
||||
$File "$SRCDIR\dx9sdk\lib\d3dx9.lib" [$WIN32 && !$GL&&!$VS2015]
|
||||
$File "$LIBCOMMON\d3dx9.lib" [$WIN32 && !$GL &&$VS2015]
|
||||
}
|
||||
|
||||
$Folder "Link Libraries"
|
||||
{
|
||||
$Lib bitmap
|
||||
$Lib mathlib
|
||||
$Lib tier2
|
||||
//$Lib "$LIBCOMMON/bzip2"
|
||||
$ImpLib togl [!$IS_LIB_PROJECT && $GL]
|
||||
}
|
||||
}
|
||||
1256
materialsystem/shaderapidx9/shaderdevicebase.cpp
Normal file
1256
materialsystem/shaderapidx9/shaderdevicebase.cpp
Normal file
File diff suppressed because it is too large
Load Diff
234
materialsystem/shaderapidx9/shaderdevicebase.h
Normal file
234
materialsystem/shaderapidx9/shaderdevicebase.h
Normal file
@@ -0,0 +1,234 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERDEVICEBASE_H
|
||||
#define SHADERDEVICEBASE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "togl/rendermechanism.h"
|
||||
#include "shaderapi/IShaderDevice.h"
|
||||
#include "IHardwareConfigInternal.h"
|
||||
#include "bitmap/imageformat.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "hardwareconfig.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class KeyValues;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// define this if you want to run with NVPERFHUD
|
||||
//-----------------------------------------------------------------------------
|
||||
//#define NVPERFHUD 1
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Uncomment this to activate the reference rasterizer
|
||||
//-----------------------------------------------------------------------------
|
||||
//#define USE_REFERENCE_RASTERIZER 1
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Uncomment to check for -nulldevice on command line and use D3DDEVTYPE_NULLREF.
|
||||
//-----------------------------------------------------------------------------
|
||||
#define ENABLE_NULLREF_DEVICE_SUPPORT
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Base implementation of the shader device
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderDeviceMgrBase : public IShaderDeviceMgr
|
||||
{
|
||||
public:
|
||||
// constructor, destructor
|
||||
CShaderDeviceMgrBase();
|
||||
virtual ~CShaderDeviceMgrBase();
|
||||
|
||||
// Methods of IAppSystem
|
||||
virtual bool Connect( CreateInterfaceFn factory );
|
||||
virtual void Disconnect();
|
||||
virtual void *QueryInterface( const char *pInterfaceName );
|
||||
|
||||
// Methods of IShaderDeviceMgr
|
||||
virtual bool GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, KeyValues *pCongifuration );
|
||||
virtual void AddModeChangeCallback( ShaderModeChangeCallbackFunc_t func );
|
||||
virtual void RemoveModeChangeCallback( ShaderModeChangeCallbackFunc_t func );
|
||||
|
||||
// Reads in the hardware caps from the dxsupport.cfg file
|
||||
void ReadHardwareCaps( HardwareCaps_t &caps, int nDxLevel );
|
||||
|
||||
// Reads in the max + preferred DX support level
|
||||
void ReadDXSupportLevels( HardwareCaps_t &caps );
|
||||
|
||||
// Returns the hardware caps for a particular adapter
|
||||
const HardwareCaps_t& GetHardwareCaps( int nAdapter ) const;
|
||||
|
||||
// Invokes mode change callbacks
|
||||
void InvokeModeChangeCallbacks();
|
||||
|
||||
// Factory to return from SetMode
|
||||
static void* ShaderInterfaceFactory( const char *pInterfaceName, int *pReturnCode );
|
||||
|
||||
// Returns only valid dx levels
|
||||
int GetClosestActualDXLevel( int nDxLevel ) const;
|
||||
|
||||
protected:
|
||||
struct AdapterInfo_t
|
||||
{
|
||||
HardwareCaps_t m_ActualCaps;
|
||||
};
|
||||
|
||||
private:
|
||||
// Reads in the dxsupport.cfg keyvalues
|
||||
KeyValues *ReadDXSupportKeyValues();
|
||||
|
||||
// Reads in ConVars + config variables
|
||||
void LoadConfig( KeyValues *pKeyValues, KeyValues *pConfiguration );
|
||||
|
||||
// Loads the hardware caps, for cases in which the D3D caps lie or where we need to augment the caps
|
||||
void LoadHardwareCaps( KeyValues *pGroup, HardwareCaps_t &caps );
|
||||
|
||||
// Gets the recommended configuration associated with a particular dx level
|
||||
bool GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, int nVendorID, int nDeviceID, KeyValues *pConfiguration );
|
||||
|
||||
// Returns the amount of video memory in bytes for a particular adapter
|
||||
virtual int GetVidMemBytes( int nAdapter ) const = 0;
|
||||
|
||||
// Looks for override keyvalues in the dxsupport cfg keyvalues
|
||||
KeyValues *FindDXLevelSpecificConfig( KeyValues *pKeyValues, int nDxLevel );
|
||||
KeyValues *FindDXLevelAndVendorSpecificConfig( KeyValues *pKeyValues, int nDxLevel, int nVendorID );
|
||||
KeyValues *FindCPUSpecificConfig( KeyValues *pKeyValues, int nCPUMhz, bool bAMD );
|
||||
KeyValues *FindMemorySpecificConfig( KeyValues *pKeyValues, int nSystemRamMB );
|
||||
KeyValues *FindVidMemSpecificConfig( KeyValues *pKeyValues, int nVideoRamMB );
|
||||
KeyValues *FindCardSpecificConfig( KeyValues *pKeyValues, int nVendorID, int nDeviceID );
|
||||
|
||||
protected:
|
||||
// Stores adapter info for all adapters
|
||||
CUtlVector<AdapterInfo_t> m_Adapters;
|
||||
|
||||
// Installed mode change callbacks
|
||||
CUtlVector< ShaderModeChangeCallbackFunc_t > m_ModeChangeCallbacks;
|
||||
|
||||
KeyValues *m_pDXSupport;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Base implementation of the shader device
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderDeviceBase : public IShaderDevice
|
||||
{
|
||||
public:
|
||||
enum IPCMessage_t
|
||||
{
|
||||
RELEASE_MESSAGE = 0x5E740DE0,
|
||||
REACQUIRE_MESSAGE = 0x5E740DE1,
|
||||
EVICT_MESSAGE = 0x5E740DE2,
|
||||
};
|
||||
|
||||
// Methods of IShaderDevice
|
||||
public:
|
||||
virtual ImageFormat GetBackBufferFormat() const;
|
||||
virtual int StencilBufferBits() const;
|
||||
virtual bool IsAAEnabled() const;
|
||||
virtual bool AddView( void* hWnd );
|
||||
virtual void RemoveView( void* hWnd );
|
||||
virtual void SetView( void* hWnd );
|
||||
virtual void GetWindowSize( int& nWidth, int& nHeight ) const;
|
||||
|
||||
// Methods exposed to the rest of shader api
|
||||
virtual bool InitDevice( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode ) = 0;
|
||||
virtual void ShutdownDevice() = 0;
|
||||
virtual bool IsDeactivated() const = 0;
|
||||
|
||||
public:
|
||||
// constructor, destructor
|
||||
CShaderDeviceBase();
|
||||
virtual ~CShaderDeviceBase();
|
||||
|
||||
virtual void OtherAppInitializing( bool initializing ) {}
|
||||
virtual void EvictManagedResourcesInternal() {}
|
||||
|
||||
void* GetIPCHWnd();
|
||||
void SendIPCMessage( IPCMessage_t message );
|
||||
|
||||
protected:
|
||||
// IPC communication for multiple shaderapi apps
|
||||
void InstallWindowHook( void *hWnd );
|
||||
void RemoveWindowHook( void *hWnd );
|
||||
void SetCurrentThreadAsOwner();
|
||||
void RemoveThreadOwner();
|
||||
bool ThreadOwnsDevice();
|
||||
|
||||
// Finds a child window
|
||||
int FindView( void* hWnd ) const;
|
||||
|
||||
int m_nAdapter;
|
||||
void *m_hWnd;
|
||||
void* m_hWndCookie;
|
||||
bool m_bInitialized : 1;
|
||||
bool m_bIsMinimized : 1;
|
||||
|
||||
// The current view hwnd
|
||||
void* m_ViewHWnd;
|
||||
|
||||
int m_nWindowWidth;
|
||||
int m_nWindowHeight;
|
||||
uint32 m_dwThreadId;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inline methods
|
||||
//-----------------------------------------------------------------------------
|
||||
inline void* CShaderDeviceBase::GetIPCHWnd()
|
||||
{
|
||||
return m_hWndCookie;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helper class to reduce code related to shader buffers
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
class CShaderBuffer : public IShaderBuffer
|
||||
{
|
||||
public:
|
||||
CShaderBuffer( T *pBlob ) : m_pBlob( pBlob ) {}
|
||||
|
||||
virtual size_t GetSize() const
|
||||
{
|
||||
return m_pBlob ? m_pBlob->GetBufferSize() : 0;
|
||||
}
|
||||
|
||||
virtual const void* GetBits() const
|
||||
{
|
||||
return m_pBlob ? m_pBlob->GetBufferPointer() : NULL;
|
||||
}
|
||||
|
||||
virtual void Release()
|
||||
{
|
||||
if ( m_pBlob )
|
||||
{
|
||||
m_pBlob->Release();
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
|
||||
private:
|
||||
T *m_pBlob;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // SHADERDEVICEBASE_H
|
||||
1002
materialsystem/shaderapidx9/shaderdevicedx10.cpp
Normal file
1002
materialsystem/shaderapidx9/shaderdevicedx10.cpp
Normal file
File diff suppressed because it is too large
Load Diff
254
materialsystem/shaderapidx9/shaderdevicedx10.h
Normal file
254
materialsystem/shaderapidx9/shaderdevicedx10.h
Normal file
@@ -0,0 +1,254 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERDEVICEDX10_H
|
||||
#define SHADERDEVICEDX10_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "shaderdevicebase.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "tier1/utlrbtree.h"
|
||||
#include "tier1/utllinkedlist.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declaration
|
||||
//-----------------------------------------------------------------------------
|
||||
struct IDXGIFactory;
|
||||
struct IDXGIAdapter;
|
||||
struct IDXGIOutput;
|
||||
struct IDXGISwapChain;
|
||||
struct ID3D10Device;
|
||||
struct ID3D10RenderTargetView;
|
||||
struct ID3D10VertexShader;
|
||||
struct ID3D10PixelShader;
|
||||
struct ID3D10GeometryShader;
|
||||
struct ID3D10InputLayout;
|
||||
struct ID3D10ShaderReflection;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Base implementation of the shader device
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderDeviceMgrDx10 : public CShaderDeviceMgrBase
|
||||
{
|
||||
typedef CShaderDeviceMgrBase BaseClass;
|
||||
|
||||
public:
|
||||
// constructor, destructor
|
||||
CShaderDeviceMgrDx10();
|
||||
virtual ~CShaderDeviceMgrDx10();
|
||||
|
||||
// Methods of IAppSystem
|
||||
virtual bool Connect( CreateInterfaceFn factory );
|
||||
virtual void Disconnect();
|
||||
virtual InitReturnVal_t Init();
|
||||
virtual void Shutdown();
|
||||
|
||||
// Methods of IShaderDeviceMgr
|
||||
virtual int GetAdapterCount() const;
|
||||
virtual void GetAdapterInfo( int adapter, MaterialAdapterInfo_t& info ) const;
|
||||
virtual int GetModeCount( int nAdapter ) const;
|
||||
virtual void GetModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter, int mode ) const;
|
||||
virtual void GetCurrentModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter ) const;
|
||||
virtual bool SetAdapter( int nAdapter, int nFlags );
|
||||
virtual CreateInterfaceFn SetMode( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode );
|
||||
|
||||
private:
|
||||
// Initialize adapter information
|
||||
void InitAdapterInfo();
|
||||
|
||||
// Determines hardware caps from D3D
|
||||
bool ComputeCapsFromD3D( HardwareCaps_t *pCaps, IDXGIAdapter *pAdapter, IDXGIOutput *pOutput );
|
||||
|
||||
// Returns the amount of video memory in bytes for a particular adapter
|
||||
virtual int GetVidMemBytes( int nAdapter ) const;
|
||||
|
||||
// Returns the appropriate adapter output to use
|
||||
IDXGIOutput* GetAdapterOutput( int nAdapter ) const;
|
||||
|
||||
// Returns the adapter interface for a particular adapter
|
||||
IDXGIAdapter* GetAdapter( int nAdapter ) const;
|
||||
|
||||
// Used to enumerate adapters, attach to windows
|
||||
IDXGIFactory *m_pDXGIFactory;
|
||||
|
||||
bool m_bObeyDxCommandlineOverride: 1;
|
||||
|
||||
friend class CShaderDeviceDx10;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Dx10 implementation of the shader device
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderDeviceDx10 : public CShaderDeviceBase
|
||||
{
|
||||
public:
|
||||
// constructor, destructor
|
||||
CShaderDeviceDx10();
|
||||
virtual ~CShaderDeviceDx10();
|
||||
|
||||
public:
|
||||
// Methods of IShaderDevice
|
||||
virtual bool IsUsingGraphics() const;
|
||||
virtual int GetCurrentAdapter() const;
|
||||
virtual ImageFormat GetBackBufferFormat() const;
|
||||
virtual void GetBackBufferDimensions( int& width, int& height ) const;
|
||||
virtual void SpewDriverInfo() const;
|
||||
virtual void Present();
|
||||
virtual IShaderBuffer* CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion );
|
||||
virtual VertexShaderHandle_t CreateVertexShader( IShaderBuffer *pShader );
|
||||
virtual void DestroyVertexShader( VertexShaderHandle_t hShader );
|
||||
virtual GeometryShaderHandle_t CreateGeometryShader( IShaderBuffer* pShaderBuffer );
|
||||
virtual void DestroyGeometryShader( GeometryShaderHandle_t hShader );
|
||||
virtual PixelShaderHandle_t CreatePixelShader( IShaderBuffer* pShaderBuffer );
|
||||
virtual void DestroyPixelShader( PixelShaderHandle_t hShader );
|
||||
virtual void ReleaseResources() {}
|
||||
virtual void ReacquireResources() {}
|
||||
virtual IMesh* CreateStaticMesh( VertexFormat_t format, const char *pTextureBudgetGroup, IMaterial * pMaterial );
|
||||
virtual void DestroyStaticMesh( IMesh* mesh );
|
||||
virtual IVertexBuffer *CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pTextureBudgetGroup );
|
||||
virtual void DestroyVertexBuffer( IVertexBuffer *pVertexBuffer );
|
||||
virtual IIndexBuffer *CreateIndexBuffer( ShaderBufferType_t type, MaterialIndexFormat_t fmt, int nIndexCount, const char *pTextureBudgetGroup );
|
||||
virtual void DestroyIndexBuffer( IIndexBuffer *pIndexBuffer );
|
||||
virtual IVertexBuffer *GetDynamicVertexBuffer( int nStreamID, VertexFormat_t vertexFormat, bool bBuffered = true );
|
||||
virtual IIndexBuffer *GetDynamicIndexBuffer( MaterialIndexFormat_t fmt, bool bBuffered = true );
|
||||
virtual void SetHardwareGammaRamp( float fGamma, float fGammaTVRangeMin, float fGammaTVRangeMax, float fGammaTVExponent, bool bTVEnabled );
|
||||
|
||||
// A special path used to tick the front buffer while loading on the 360
|
||||
virtual void EnableNonInteractiveMode( MaterialNonInteractiveMode_t mode, ShaderNonInteractiveInfo_t *pInfo ) {}
|
||||
virtual void RefreshFrontBufferNonInteractive( ) {}
|
||||
virtual void HandleThreadEvent( uint32 threadEvent ) {}
|
||||
|
||||
public:
|
||||
// Methods of CShaderDeviceBase
|
||||
virtual bool InitDevice( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode );
|
||||
virtual void ShutdownDevice();
|
||||
virtual bool IsDeactivated() const { return false; }
|
||||
|
||||
// Other public methods
|
||||
ID3D10VertexShader* GetVertexShader( VertexShaderHandle_t hShader ) const;
|
||||
ID3D10GeometryShader* GetGeometryShader( GeometryShaderHandle_t hShader ) const;
|
||||
ID3D10PixelShader* GetPixelShader( PixelShaderHandle_t hShader ) const;
|
||||
ID3D10InputLayout* GetInputLayout( VertexShaderHandle_t hShader, VertexFormat_t format );
|
||||
|
||||
private:
|
||||
struct InputLayout_t
|
||||
{
|
||||
ID3D10InputLayout *m_pInputLayout;
|
||||
VertexFormat_t m_VertexFormat;
|
||||
};
|
||||
|
||||
typedef CUtlRBTree< InputLayout_t, unsigned short > InputLayoutDict_t;
|
||||
|
||||
static bool InputLayoutLessFunc( const InputLayout_t &lhs, const InputLayout_t &rhs )
|
||||
{
|
||||
return ( lhs.m_VertexFormat < rhs.m_VertexFormat );
|
||||
}
|
||||
|
||||
struct VertexShader_t
|
||||
{
|
||||
ID3D10VertexShader *m_pShader;
|
||||
ID3D10ShaderReflection *m_pInfo;
|
||||
void *m_pByteCode;
|
||||
size_t m_nByteCodeLen;
|
||||
InputLayoutDict_t m_InputLayouts;
|
||||
|
||||
VertexShader_t() : m_InputLayouts( 0, 0, InputLayoutLessFunc ) {}
|
||||
};
|
||||
|
||||
struct GeometryShader_t
|
||||
{
|
||||
ID3D10GeometryShader *m_pShader;
|
||||
ID3D10ShaderReflection *m_pInfo;
|
||||
};
|
||||
|
||||
struct PixelShader_t
|
||||
{
|
||||
ID3D10PixelShader *m_pShader;
|
||||
ID3D10ShaderReflection *m_pInfo;
|
||||
};
|
||||
|
||||
typedef CUtlFixedLinkedList< VertexShader_t >::IndexType_t VertexShaderIndex_t;
|
||||
typedef CUtlFixedLinkedList< GeometryShader_t >::IndexType_t GeometryShaderIndex_t;
|
||||
typedef CUtlFixedLinkedList< PixelShader_t >::IndexType_t PixelShaderIndex_t;
|
||||
|
||||
void SetupHardwareCaps();
|
||||
void ReleaseInputLayouts( VertexShaderIndex_t nIndex );
|
||||
|
||||
IDXGIOutput *m_pOutput;
|
||||
ID3D10Device *m_pDevice;
|
||||
IDXGISwapChain *m_pSwapChain;
|
||||
ID3D10RenderTargetView *m_pRenderTargetView;
|
||||
|
||||
CUtlFixedLinkedList< VertexShader_t > m_VertexShaderDict;
|
||||
CUtlFixedLinkedList< GeometryShader_t > m_GeometryShaderDict;
|
||||
CUtlFixedLinkedList< PixelShader_t > m_PixelShaderDict;
|
||||
|
||||
friend ID3D10Device *D3D10Device();
|
||||
friend IDXGISwapChain *D3D10SwapChain();
|
||||
friend ID3D10RenderTargetView *D3D10RenderTargetView();
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inline methods of CShaderDeviceDx10
|
||||
//-----------------------------------------------------------------------------
|
||||
inline ID3D10VertexShader* CShaderDeviceDx10::GetVertexShader( VertexShaderHandle_t hShader ) const
|
||||
{
|
||||
if ( hShader != VERTEX_SHADER_HANDLE_INVALID )
|
||||
return m_VertexShaderDict[ (VertexShaderIndex_t)hShader ].m_pShader;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline ID3D10GeometryShader* CShaderDeviceDx10::GetGeometryShader( GeometryShaderHandle_t hShader ) const
|
||||
{
|
||||
if ( hShader != GEOMETRY_SHADER_HANDLE_INVALID )
|
||||
return m_GeometryShaderDict[ (GeometryShaderIndex_t)hShader ].m_pShader;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline ID3D10PixelShader* CShaderDeviceDx10::GetPixelShader( PixelShaderHandle_t hShader ) const
|
||||
{
|
||||
if ( hShader != PIXEL_SHADER_HANDLE_INVALID )
|
||||
return m_PixelShaderDict[ (PixelShaderIndex_t)hShader ].m_pShader;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton
|
||||
//-----------------------------------------------------------------------------
|
||||
extern CShaderDeviceDx10* g_pShaderDeviceDx10;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Utility methods
|
||||
//-----------------------------------------------------------------------------
|
||||
inline ID3D10Device *D3D10Device()
|
||||
{
|
||||
return g_pShaderDeviceDx10->m_pDevice;
|
||||
}
|
||||
|
||||
inline IDXGISwapChain *D3D10SwapChain()
|
||||
{
|
||||
return g_pShaderDeviceDx10->m_pSwapChain;
|
||||
}
|
||||
|
||||
inline ID3D10RenderTargetView *D3D10RenderTargetView()
|
||||
{
|
||||
return g_pShaderDeviceDx10->m_pRenderTargetView;
|
||||
}
|
||||
|
||||
|
||||
#endif // SHADERDEVICEDX10_H
|
||||
3707
materialsystem/shaderapidx9/shaderdevicedx8.cpp
Normal file
3707
materialsystem/shaderapidx9/shaderdevicedx8.cpp
Normal file
File diff suppressed because it is too large
Load Diff
382
materialsystem/shaderapidx9/shaderdevicedx8.h
Normal file
382
materialsystem/shaderapidx9/shaderdevicedx8.h
Normal file
@@ -0,0 +1,382 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERDEVICEDX8_H
|
||||
#define SHADERDEVICEDX8_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "shaderdevicebase.h"
|
||||
#include "shaderapidx8_global.h"
|
||||
#include "tier1/utlvector.h"
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Describes which D3DDEVTYPE to use
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef USE_REFERENCE_RASTERIZER
|
||||
#define DX8_DEVTYPE D3DDEVTYPE_HAL
|
||||
#else
|
||||
#define DX8_DEVTYPE D3DDEVTYPE_REF
|
||||
#endif
|
||||
|
||||
|
||||
// PC: By default, PIX profiling is explicitly disallowed using the D3DPERF_SetOptions(1) API on PC
|
||||
// X360: PIX_INSTRUMENTATION will only generate PIX events in RELEASE builds on 360
|
||||
// Uncomment to use PIX instrumentation:
|
||||
#if PIX_ENABLE
|
||||
#define PIX_INSTRUMENTATION
|
||||
#endif
|
||||
|
||||
#define MAX_PIX_ERRORS 3
|
||||
|
||||
#if defined( PIX_INSTRUMENTATION ) && defined ( DX_TO_GL_ABSTRACTION ) && defined( _WIN32 )
|
||||
typedef int (WINAPI *D3DPERF_BeginEvent_FuncPtr)( D3DCOLOR col, LPCWSTR wszName );
|
||||
typedef int (WINAPI *D3DPERF_EndEvent_FuncPtr)( void );
|
||||
typedef void (WINAPI *D3DPERF_SetMarker_FuncPtr)( D3DCOLOR col, LPCWSTR wszName );
|
||||
typedef void (WINAPI *D3DPERF_SetOptions_FuncPtr)( DWORD dwOptions );
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Base implementation of the shader device
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderDeviceMgrDx8 : public CShaderDeviceMgrBase
|
||||
{
|
||||
typedef CShaderDeviceMgrBase BaseClass;
|
||||
|
||||
public:
|
||||
// constructor, destructor
|
||||
CShaderDeviceMgrDx8();
|
||||
virtual ~CShaderDeviceMgrDx8();
|
||||
|
||||
// Methods of IAppSystem
|
||||
virtual bool Connect( CreateInterfaceFn factory );
|
||||
virtual void Disconnect();
|
||||
virtual InitReturnVal_t Init();
|
||||
virtual void Shutdown();
|
||||
|
||||
// Methods of IShaderDevice
|
||||
virtual int GetAdapterCount() const;
|
||||
virtual void GetAdapterInfo( int adapter, MaterialAdapterInfo_t& info ) const;
|
||||
virtual int GetModeCount( int nAdapter ) const;
|
||||
virtual void GetModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter, int mode ) const;
|
||||
virtual void GetCurrentModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter ) const;
|
||||
virtual bool SetAdapter( int nAdapter, int nFlags );
|
||||
virtual CreateInterfaceFn SetMode( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode );
|
||||
|
||||
// Determines hardware caps from D3D
|
||||
bool ComputeCapsFromD3D( HardwareCaps_t *pCaps, int nAdapter );
|
||||
|
||||
// Forces caps to a specific dx level
|
||||
void ForceCapsToDXLevel( HardwareCaps_t *pCaps, int nDxLevel, const HardwareCaps_t &actualCaps );
|
||||
|
||||
// Validates the mode...
|
||||
bool ValidateMode( int nAdapter, const ShaderDeviceInfo_t &info ) const;
|
||||
|
||||
// Returns the amount of video memory in bytes for a particular adapter
|
||||
virtual int GetVidMemBytes( int nAdapter ) const;
|
||||
|
||||
#if !defined( _X360 )
|
||||
FORCEINLINE IDirect3D9 *D3D() const
|
||||
{
|
||||
return m_pD3D;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined( PIX_INSTRUMENTATION ) && defined ( DX_TO_GL_ABSTRACTION ) && defined( _WIN32 )
|
||||
HMODULE m_hD3D9;
|
||||
D3DPERF_BeginEvent_FuncPtr m_pBeginEvent;
|
||||
D3DPERF_EndEvent_FuncPtr m_pEndEvent;
|
||||
D3DPERF_SetMarker_FuncPtr m_pSetMarker;
|
||||
D3DPERF_SetOptions_FuncPtr m_pSetOptions;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
// Determine capabilities
|
||||
bool DetermineHardwareCaps( );
|
||||
|
||||
private:
|
||||
// Initialize adapter information
|
||||
void InitAdapterInfo();
|
||||
|
||||
// Code to detect support for texture border mode (not a simple caps check)
|
||||
void CheckBorderColorSupport( HardwareCaps_t *pCaps, int nAdapter );
|
||||
|
||||
// Vendor-dependent code to detect support for various flavors of shadow mapping
|
||||
void CheckVendorDependentShadowMappingSupport( HardwareCaps_t *pCaps, int nAdapter );
|
||||
|
||||
// Vendor-dependent code to detect Alpha To Coverage Backdoors
|
||||
void CheckVendorDependentAlphaToCoverage( HardwareCaps_t *pCaps, int nAdapter );
|
||||
|
||||
// Compute the effective DX support level based on all the other caps
|
||||
void ComputeDXSupportLevel( HardwareCaps_t &caps );
|
||||
|
||||
// Used to enumerate adapters, attach to windows
|
||||
#if !defined( _X360 )
|
||||
IDirect3D9 *m_pD3D;
|
||||
#endif
|
||||
|
||||
bool m_bObeyDxCommandlineOverride : 1;
|
||||
bool m_bAdapterInfoIntialized : 1;
|
||||
};
|
||||
|
||||
extern CShaderDeviceMgrDx8* g_pShaderDeviceMgrDx8;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// IDirect3D accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
#if defined( _X360 )
|
||||
|
||||
extern IDirect3D9 *m_pD3D;
|
||||
inline IDirect3D9* D3D()
|
||||
{
|
||||
return m_pD3D;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
inline IDirect3D9* D3D()
|
||||
{
|
||||
return g_pShaderDeviceMgrDx8->D3D();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#define NUM_FRAME_SYNC_QUERIES 2
|
||||
#define NUM_FRAME_SYNC_FRAMES_LATENCY 0
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Dx8implementation of the shader device
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderDeviceDx8 : public CShaderDeviceBase
|
||||
{
|
||||
// Methods of IShaderDevice
|
||||
public:
|
||||
virtual bool IsUsingGraphics() const;
|
||||
virtual ImageFormat GetBackBufferFormat() const;
|
||||
virtual void GetBackBufferDimensions( int& width, int& height ) const;
|
||||
virtual void Present();
|
||||
virtual IShaderBuffer* CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion );
|
||||
virtual VertexShaderHandle_t CreateVertexShader( IShaderBuffer *pBuffer );
|
||||
virtual void DestroyVertexShader( VertexShaderHandle_t hShader );
|
||||
virtual GeometryShaderHandle_t CreateGeometryShader( IShaderBuffer* pShaderBuffer );
|
||||
virtual void DestroyGeometryShader( GeometryShaderHandle_t hShader );
|
||||
virtual PixelShaderHandle_t CreatePixelShader( IShaderBuffer* pShaderBuffer );
|
||||
virtual void DestroyPixelShader( PixelShaderHandle_t hShader );
|
||||
virtual void ReleaseResources();
|
||||
virtual void ReacquireResources();
|
||||
virtual IMesh* CreateStaticMesh( VertexFormat_t format, const char *pBudgetGroup, IMaterial * pMaterial = NULL );
|
||||
virtual void DestroyStaticMesh( IMesh* mesh );
|
||||
virtual IVertexBuffer *CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroup );
|
||||
virtual void DestroyVertexBuffer( IVertexBuffer *pVertexBuffer );
|
||||
virtual IIndexBuffer *CreateIndexBuffer( ShaderBufferType_t bufferType, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroup );
|
||||
virtual void DestroyIndexBuffer( IIndexBuffer *pIndexBuffer );
|
||||
virtual IVertexBuffer *GetDynamicVertexBuffer( int nStreamID, VertexFormat_t vertexFormat, bool bBuffered = true );
|
||||
virtual IIndexBuffer *GetDynamicIndexBuffer( MaterialIndexFormat_t fmt, bool bBuffered = true );
|
||||
virtual void SetHardwareGammaRamp( float fGamma, float fGammaTVRangeMin, float fGammaTVRangeMax, float fGammaTVExponent, bool bTVEnabled );
|
||||
virtual void SpewDriverInfo() const;
|
||||
virtual int GetCurrentAdapter() const;
|
||||
virtual void EnableNonInteractiveMode( MaterialNonInteractiveMode_t mode, ShaderNonInteractiveInfo_t *pInfo = NULL );
|
||||
virtual void RefreshFrontBufferNonInteractive();
|
||||
virtual char *GetDisplayDeviceName() OVERRIDE;
|
||||
|
||||
// Alternative method for ib/vs
|
||||
// NOTE: If this works, remove GetDynamicVertexBuffer/IndexBuffer
|
||||
|
||||
// Methods of CShaderDeviceBase
|
||||
public:
|
||||
virtual bool InitDevice( void* hWnd, int nAdapter, const ShaderDeviceInfo_t &info );
|
||||
virtual void ShutdownDevice();
|
||||
virtual bool IsDeactivated() const;
|
||||
|
||||
// Other public methods
|
||||
public:
|
||||
// constructor, destructor
|
||||
CShaderDeviceDx8();
|
||||
virtual ~CShaderDeviceDx8();
|
||||
|
||||
// Call this when another app is initializing or finished initializing
|
||||
virtual void OtherAppInitializing( bool initializing );
|
||||
|
||||
// This handles any events queued because they were called outside of the owning thread
|
||||
virtual void HandleThreadEvent( uint32 threadEvent );
|
||||
|
||||
// FIXME: Make private
|
||||
// Which device are we using?
|
||||
UINT m_DisplayAdapter;
|
||||
D3DDEVTYPE m_DeviceType;
|
||||
|
||||
protected:
|
||||
enum DeviceState_t
|
||||
{
|
||||
DEVICE_STATE_OK = 0,
|
||||
DEVICE_STATE_OTHER_APP_INIT,
|
||||
DEVICE_STATE_LOST_DEVICE,
|
||||
DEVICE_STATE_NEEDS_RESET,
|
||||
};
|
||||
|
||||
struct NonInteractiveRefreshState_t
|
||||
{
|
||||
IDirect3DVertexShader9 *m_pVertexShader;
|
||||
IDirect3DPixelShader9 *m_pPixelShader;
|
||||
IDirect3DPixelShader9 *m_pPixelShaderStartup;
|
||||
IDirect3DPixelShader9 *m_pPixelShaderStartupPass2;
|
||||
IDirect3DVertexDeclaration9 *m_pVertexDecl;
|
||||
ShaderNonInteractiveInfo_t m_Info;
|
||||
MaterialNonInteractiveMode_t m_Mode;
|
||||
float m_flLastPacifierTime;
|
||||
int m_nPacifierFrame;
|
||||
|
||||
float m_flStartTime;
|
||||
float m_flLastPresentTime;
|
||||
float m_flPeakDt;
|
||||
float m_flTotalDt;
|
||||
int m_nSamples;
|
||||
int m_nCountAbove66;
|
||||
};
|
||||
|
||||
protected:
|
||||
// Creates the D3D Device
|
||||
bool CreateD3DDevice( void* pHWnd, int nAdapter, const ShaderDeviceInfo_t &info );
|
||||
|
||||
// Actually creates the D3D Device once the present parameters are set up
|
||||
IDirect3DDevice9* InvokeCreateDevice( void* hWnd, int nAdapter, DWORD deviceCreationFlags );
|
||||
|
||||
// Checks for CreateQuery support
|
||||
void DetectQuerySupport( IDirect3DDevice9* pD3DDevice );
|
||||
|
||||
// Computes the presentation parameters
|
||||
void SetPresentParameters( void* hWnd, int nAdapter, const ShaderDeviceInfo_t &info );
|
||||
|
||||
// Computes the supersample flags
|
||||
D3DMULTISAMPLE_TYPE ComputeMultisampleType( int nSampleCount );
|
||||
|
||||
// Is the device active?
|
||||
bool IsActive() const;
|
||||
|
||||
// Try to reset the device, returned true if it succeeded
|
||||
bool TryDeviceReset();
|
||||
|
||||
// Queue up the fact that the device was lost
|
||||
void MarkDeviceLost();
|
||||
|
||||
// Deals with lost devices
|
||||
void CheckDeviceLost( bool bOtherAppInitializing );
|
||||
|
||||
// Changes the window size
|
||||
bool ResizeWindow( const ShaderDeviceInfo_t &info );
|
||||
|
||||
// Deals with the frame synching object
|
||||
void AllocFrameSyncObjects( void );
|
||||
void FreeFrameSyncObjects( void );
|
||||
|
||||
// Alloc and free objects that are necessary for frame syncing
|
||||
void AllocFrameSyncTextureObject();
|
||||
void FreeFrameSyncTextureObject();
|
||||
|
||||
// Alloc and free objects necessary for noninteractive frame refresh on the x360
|
||||
bool AllocNonInteractiveRefreshObjects();
|
||||
void FreeNonInteractiveRefreshObjects();
|
||||
|
||||
// FIXME: This is for backward compat; I still haven't solved a way of decoupling this
|
||||
virtual bool OnAdapterSet() = 0;
|
||||
virtual void ResetRenderState( bool bFullReset = true ) = 0;
|
||||
|
||||
// For measuring if we meed TCR 022 on the XBox (refreshing often enough)
|
||||
void UpdatePresentStats();
|
||||
|
||||
bool InNonInteractiveMode() const;
|
||||
|
||||
void ReacquireResourcesInternal( bool bResetState = false, bool bForceReacquire = false, char const *pszForceReason = NULL );
|
||||
|
||||
#ifdef DX_TO_GL_ABSTRACTION
|
||||
public:
|
||||
virtual void DoStartupShaderPreloading( void );
|
||||
protected:
|
||||
#endif
|
||||
|
||||
D3DPRESENT_PARAMETERS m_PresentParameters;
|
||||
ImageFormat m_AdapterFormat;
|
||||
|
||||
// Mode info
|
||||
int m_DeviceSupportsCreateQuery;
|
||||
|
||||
ShaderDeviceInfo_t m_PendingVideoModeChangeConfig;
|
||||
DeviceState_t m_DeviceState;
|
||||
|
||||
bool m_bOtherAppInitializing : 1;
|
||||
bool m_bQueuedDeviceLost : 1;
|
||||
bool m_IsResizing : 1;
|
||||
bool m_bPendingVideoModeChange : 1;
|
||||
bool m_bUsingStencil : 1;
|
||||
bool m_bResourcesReleased : 1;
|
||||
|
||||
// amount of stencil variation we have available
|
||||
int m_iStencilBufferBits;
|
||||
|
||||
#ifdef _X360
|
||||
CON_COMMAND_MEMBER_F( CShaderDeviceDx8, "360vidinfo", SpewVideoInfo360, "Get information on the video mode on the 360", 0 );
|
||||
#endif
|
||||
|
||||
// Frame sync objects
|
||||
IDirect3DQuery9 *m_pFrameSyncQueryObject[NUM_FRAME_SYNC_QUERIES];
|
||||
bool m_bQueryIssued[NUM_FRAME_SYNC_QUERIES];
|
||||
int m_currentSyncQuery;
|
||||
IDirect3DTexture9 *m_pFrameSyncTexture;
|
||||
|
||||
#if defined( _X360 )
|
||||
HXUIDC m_hDC;
|
||||
#endif
|
||||
|
||||
CUtlString m_sDisplayDeviceName;
|
||||
|
||||
// Used for x360 only
|
||||
NonInteractiveRefreshState_t m_NonInteractiveRefresh;
|
||||
CThreadFastMutex m_nonInteractiveModeMutex;
|
||||
friend class CShaderDeviceMgrDx8;
|
||||
|
||||
int m_numReleaseResourcesRefCount; // This is holding the number of ReleaseResources calls queued up,
|
||||
// for every ReleaseResources call there should be a matching call to
|
||||
// ReacquireResources, only the last top-level ReacquireResources will
|
||||
// have effect. Nested ReleaseResources calls are bugs.
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Globals
|
||||
//-----------------------------------------------------------------------------
|
||||
extern IDirect3DDevice9 *g_pD3DDevice;
|
||||
FORCEINLINE IDirect3DDevice9 *Dx9Device()
|
||||
{
|
||||
return g_pD3DDevice;
|
||||
}
|
||||
|
||||
extern CShaderDeviceDx8* g_pShaderDeviceDx8;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inline methods
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE bool CShaderDeviceDx8::IsActive() const
|
||||
{
|
||||
return ( g_pD3DDevice != NULL );
|
||||
}
|
||||
|
||||
// used to determine if we're deactivated
|
||||
FORCEINLINE bool CShaderDeviceDx8::IsDeactivated() const
|
||||
{
|
||||
return ( IsPC() && ( ( m_DeviceState != DEVICE_STATE_OK ) || m_bQueuedDeviceLost || m_numReleaseResourcesRefCount ) );
|
||||
}
|
||||
|
||||
|
||||
#endif // SHADERDEVICEDX8_H
|
||||
227
materialsystem/shaderapidx9/shadershadowdx10.cpp
Normal file
227
materialsystem/shaderapidx9/shadershadowdx10.cpp
Normal file
@@ -0,0 +1,227 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "shadershadowdx10.h"
|
||||
#include "utlvector.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "IHardwareConfigInternal.h"
|
||||
#include "shadersystem.h"
|
||||
#include "shaderapi/ishaderutil.h"
|
||||
#include "materialsystem/imesh.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "materialsystem/idebugtextureinfo.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Class Factory
|
||||
//-----------------------------------------------------------------------------
|
||||
static CShaderShadowDx10 s_ShaderShadow;
|
||||
CShaderShadowDx10 *g_pShaderShadowDx10 = &s_ShaderShadow;
|
||||
|
||||
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderShadowDx10, IShaderShadow,
|
||||
SHADERSHADOW_INTERFACE_VERSION, s_ShaderShadow )
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The shader shadow interface
|
||||
//-----------------------------------------------------------------------------
|
||||
CShaderShadowDx10::CShaderShadowDx10()
|
||||
{
|
||||
m_IsTranslucent = false;
|
||||
m_IsAlphaTested = false;
|
||||
m_bIsDepthWriteEnabled = true;
|
||||
m_bUsesVertexAndPixelShaders = false;
|
||||
}
|
||||
|
||||
CShaderShadowDx10::~CShaderShadowDx10()
|
||||
{
|
||||
}
|
||||
|
||||
// Sets the default *shadow* state
|
||||
void CShaderShadowDx10::SetDefaultState()
|
||||
{
|
||||
m_IsTranslucent = false;
|
||||
m_IsAlphaTested = false;
|
||||
m_bIsDepthWriteEnabled = true;
|
||||
m_bUsesVertexAndPixelShaders = false;
|
||||
}
|
||||
|
||||
// Methods related to depth buffering
|
||||
void CShaderShadowDx10::DepthFunc( ShaderDepthFunc_t depthFunc )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::EnableDepthWrites( bool bEnable )
|
||||
{
|
||||
m_bIsDepthWriteEnabled = bEnable;
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::EnableDepthTest( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::EnablePolyOffset( PolygonOffsetMode_t nOffsetMode )
|
||||
{
|
||||
}
|
||||
|
||||
// Suppresses/activates color writing
|
||||
void CShaderShadowDx10::EnableColorWrites( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
// Suppresses/activates alpha writing
|
||||
void CShaderShadowDx10::EnableAlphaWrites( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
// Methods related to alpha blending
|
||||
void CShaderShadowDx10::EnableBlending( bool bEnable )
|
||||
{
|
||||
m_IsTranslucent = bEnable;
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::BlendFunc( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::BlendOp( ShaderBlendOp_t blendOp )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::BlendOpSeparateAlpha( ShaderBlendOp_t blendOp )
|
||||
{
|
||||
}
|
||||
|
||||
// A simpler method of dealing with alpha modulation
|
||||
void CShaderShadowDx10::EnableAlphaPipe( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::EnableConstantAlpha( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::EnableVertexAlpha( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::EnableTextureAlpha( TextureStage_t stage, bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::SetShadowDepthFiltering( Sampler_t stage )
|
||||
{
|
||||
}
|
||||
|
||||
// Alpha testing
|
||||
void CShaderShadowDx10::EnableAlphaTest( bool bEnable )
|
||||
{
|
||||
m_IsAlphaTested = bEnable;
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::AlphaFunc( ShaderAlphaFunc_t alphaFunc, float alphaRef /* [0-1] */ )
|
||||
{
|
||||
}
|
||||
|
||||
// Wireframe/filled polygons
|
||||
void CShaderShadowDx10::PolyMode( ShaderPolyModeFace_t face, ShaderPolyMode_t polyMode )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Back face culling
|
||||
void CShaderShadowDx10::EnableCulling( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
// Alpha to coverage
|
||||
void CShaderShadowDx10::EnableAlphaToCoverage( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
// constant color + transparency
|
||||
void CShaderShadowDx10::EnableConstantColor( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Indicates the vertex format for use with a vertex shader
|
||||
// The flags to pass in here come from the VertexFormatFlags_t enum
|
||||
// If pTexCoordDimensions is *not* specified, we assume all coordinates
|
||||
// are 2-dimensional
|
||||
void CShaderShadowDx10::VertexShaderVertexFormat( unsigned int flags,
|
||||
int numTexCoords, int* pTexCoordDimensions,
|
||||
int userDataSize )
|
||||
{
|
||||
}
|
||||
|
||||
// Indicates we're going to light the model
|
||||
void CShaderShadowDx10::EnableLighting( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::EnableSpecular( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
// Activate/deactivate skinning
|
||||
void CShaderShadowDx10::EnableVertexBlend( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
// per texture unit stuff
|
||||
void CShaderShadowDx10::OverbrightValue( TextureStage_t stage, float value )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::EnableTexture( Sampler_t stage, bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::EnableCustomPixelPipe( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::CustomTextureStages( int stageCount )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::CustomTextureOperation( TextureStage_t stage, ShaderTexChannel_t channel,
|
||||
ShaderTexOp_t op, ShaderTexArg_t arg1, ShaderTexArg_t arg2 )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::EnableTexGen( TextureStage_t stage, bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::TexGen( TextureStage_t stage, ShaderTexGenParam_t param )
|
||||
{
|
||||
}
|
||||
|
||||
// Sets the vertex and pixel shaders
|
||||
void CShaderShadowDx10::SetVertexShader( const char *pShaderName, int vshIndex )
|
||||
{
|
||||
m_bUsesVertexAndPixelShaders = ( pShaderName != NULL );
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::EnableBlendingSeparateAlpha( bool bEnable )
|
||||
{
|
||||
}
|
||||
void CShaderShadowDx10::SetPixelShader( const char *pShaderName, int pshIndex )
|
||||
{
|
||||
m_bUsesVertexAndPixelShaders = ( pShaderName != NULL );
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::BlendFuncSeparateAlpha( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor )
|
||||
{
|
||||
}
|
||||
// indicates what per-vertex data we're providing
|
||||
void CShaderShadowDx10::DrawFlags( unsigned int drawFlags )
|
||||
{
|
||||
}
|
||||
|
||||
1826
materialsystem/shaderapidx9/shadershadowdx8.cpp
Normal file
1826
materialsystem/shaderapidx9/shadershadowdx8.cpp
Normal file
File diff suppressed because it is too large
Load Diff
176
materialsystem/shaderapidx9/shadershadowdx8.h
Normal file
176
materialsystem/shaderapidx9/shadershadowdx8.h
Normal file
@@ -0,0 +1,176 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERSHADOWDX8_H
|
||||
#define SHADERSHADOWDX8_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "togl/rendermechanism.h"
|
||||
#include "locald3dtypes.h"
|
||||
#include "shaderapi/ishadershadow.h"
|
||||
|
||||
class IShaderAPIDX8;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Important enumerations
|
||||
//-----------------------------------------------------------------------------
|
||||
enum
|
||||
{
|
||||
MAX_SAMPLERS = 16,
|
||||
MAX_TEXTURE_STAGES = 16,
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// A structure maintaining the shadowed board state
|
||||
//-----------------------------------------------------------------------------
|
||||
struct TextureStageShadowState_t
|
||||
{
|
||||
// State shadowing affects these
|
||||
D3DTEXTUREOP m_ColorOp;
|
||||
int m_ColorArg1;
|
||||
int m_ColorArg2;
|
||||
D3DTEXTUREOP m_AlphaOp;
|
||||
int m_AlphaArg1;
|
||||
int m_AlphaArg2;
|
||||
int m_TexCoordIndex;
|
||||
};
|
||||
|
||||
struct SamplerShadowState_t
|
||||
{
|
||||
bool m_TextureEnable : 1;
|
||||
bool m_SRGBReadEnable : 1;
|
||||
bool m_Fetch4Enable : 1;
|
||||
bool m_ShadowFilterEnable : 1;
|
||||
};
|
||||
|
||||
struct ShadowState_t
|
||||
{
|
||||
// Depth buffering state
|
||||
D3DCMPFUNC m_ZFunc;
|
||||
D3DZBUFFERTYPE m_ZEnable;
|
||||
|
||||
// Write enable
|
||||
DWORD m_ColorWriteEnable;
|
||||
|
||||
// Fill mode
|
||||
D3DFILLMODE m_FillMode;
|
||||
|
||||
// Alpha state
|
||||
D3DBLEND m_SrcBlend;
|
||||
D3DBLEND m_DestBlend;
|
||||
D3DBLENDOP m_BlendOp;
|
||||
|
||||
// Separate alpha blend state
|
||||
D3DBLEND m_SrcBlendAlpha;
|
||||
D3DBLEND m_DestBlendAlpha;
|
||||
D3DBLENDOP m_BlendOpAlpha;
|
||||
|
||||
D3DCMPFUNC m_AlphaFunc;
|
||||
int m_AlphaRef;
|
||||
|
||||
// Texture stage state
|
||||
TextureStageShadowState_t m_TextureStage[MAX_TEXTURE_STAGES];
|
||||
|
||||
// Sampler state
|
||||
SamplerShadowState_t m_SamplerState[MAX_SAMPLERS];
|
||||
|
||||
ShaderFogMode_t m_FogMode;
|
||||
|
||||
D3DMATERIALCOLORSOURCE m_DiffuseMaterialSource;
|
||||
|
||||
unsigned char m_ZWriteEnable:1;
|
||||
unsigned char m_ZBias:2;
|
||||
// Cull State?
|
||||
unsigned char m_CullEnable:1;
|
||||
// Lighting in hardware?
|
||||
unsigned char m_Lighting:1;
|
||||
unsigned char m_SpecularEnable:1;
|
||||
unsigned char m_AlphaBlendEnable:1;
|
||||
unsigned char m_AlphaTestEnable:1;
|
||||
|
||||
// Fixed function?
|
||||
unsigned char m_UsingFixedFunction:1;
|
||||
// Vertex blending?
|
||||
unsigned char m_VertexBlendEnable:1;
|
||||
// Auto-convert from linear to gamma upon writing to the frame buffer?
|
||||
unsigned char m_SRGBWriteEnable:1;
|
||||
// Seperate Alpha Blend?
|
||||
unsigned char m_SeparateAlphaBlendEnable:1;
|
||||
// Stencil?
|
||||
unsigned char m_StencilEnable:1;
|
||||
|
||||
unsigned char m_bDisableFogGammaCorrection:1;
|
||||
|
||||
unsigned char m_EnableAlphaToCoverage:1;
|
||||
|
||||
unsigned char m_Reserved : 1;
|
||||
unsigned short m_nReserved2;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// These are part of the "shadow" since they describe the shading algorithm
|
||||
// but aren't actually captured in the state transition table
|
||||
// because it would produce too many transitions
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ShadowShaderState_t
|
||||
{
|
||||
// The vertex + pixel shader group to use...
|
||||
VertexShader_t m_VertexShader;
|
||||
PixelShader_t m_PixelShader;
|
||||
|
||||
// The static vertex + pixel shader indices
|
||||
int m_nStaticVshIndex;
|
||||
int m_nStaticPshIndex;
|
||||
|
||||
// Vertex data used by this snapshot
|
||||
// Note that the vertex format actually used will be the
|
||||
// aggregate of the vertex formats used by all snapshots in a material
|
||||
VertexFormat_t m_VertexUsage;
|
||||
|
||||
// Morph data used by this snapshot
|
||||
// Note that the morph format actually used will be the
|
||||
// aggregate of the morph formats used by all snapshots in a material
|
||||
MorphFormat_t m_MorphUsage;
|
||||
|
||||
// Modulate constant color into the vertex color
|
||||
bool m_ModulateConstantColor;
|
||||
|
||||
bool m_nReserved[3];
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The shader setup API
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class IShaderShadowDX8 : public IShaderShadow
|
||||
{
|
||||
public:
|
||||
// Initializes it
|
||||
virtual void Init() = 0;
|
||||
|
||||
// Gets at the shadow state
|
||||
virtual ShadowState_t const& GetShadowState() = 0;
|
||||
virtual ShadowShaderState_t const& GetShadowShaderState() = 0;
|
||||
|
||||
// This must be called right before taking a snapshot
|
||||
virtual void ComputeAggregateShadowState( ) = 0;
|
||||
|
||||
// Class factory methods
|
||||
static IShaderShadowDX8* Create( IShaderAPIDX8* pShaderAPIDX8 );
|
||||
static void Destroy( IShaderShadowDX8* pShaderShadow );
|
||||
};
|
||||
|
||||
extern IShaderShadowDX8 *g_pShaderShadowDx8;
|
||||
|
||||
#endif // SHADERSHADOWDX8_H
|
||||
809
materialsystem/shaderapidx9/stubd3ddevice.h
Normal file
809
materialsystem/shaderapidx9/stubd3ddevice.h
Normal file
@@ -0,0 +1,809 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef STUBD3DDEVICE_H
|
||||
#define STUBD3DDEVICE_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#ifdef STUBD3D
|
||||
|
||||
#include "locald3dtypes.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
#ifdef USE_FOPEN
|
||||
#include <stdio.h>
|
||||
#define FPRINTF fprintf
|
||||
#else
|
||||
#define FPRINTF s_pFileSystem->FPrintf
|
||||
#endif
|
||||
|
||||
#ifdef USE_FOPEN
|
||||
|
||||
static FILE *s_FileHandle;
|
||||
|
||||
#else
|
||||
|
||||
static IFileSystem *s_pFileSystem;
|
||||
static FileHandle_t s_FileHandle;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
class CStubD3DTexture : public IDirect3DTexture8
|
||||
{
|
||||
private:
|
||||
IDirect3DTexture8 *m_pTexture;
|
||||
IDirect3DDevice8 *m_pDevice;
|
||||
|
||||
public:
|
||||
CStubD3DTexture( IDirect3DTexture8 *pTexture, IDirect3DDevice8 *pDevice )
|
||||
{
|
||||
m_pTexture = pTexture;
|
||||
m_pDevice = pDevice;
|
||||
}
|
||||
|
||||
/*** IUnknown methods ***/
|
||||
HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObj)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::QueryInterface\n" );
|
||||
return m_pTexture->QueryInterface( riid, ppvObj );
|
||||
}
|
||||
|
||||
ULONG __stdcall AddRef()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::AddRef\n" );
|
||||
return m_pTexture->AddRef();
|
||||
}
|
||||
|
||||
ULONG __stdcall Release()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::Release\n" );
|
||||
return m_pTexture->Release();
|
||||
}
|
||||
|
||||
/*** IDirect3DBaseTexture8 methods ***/
|
||||
HRESULT __stdcall GetDevice( IDirect3DDevice8** ppDevice )
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::GetDevice\n" );
|
||||
#if 0
|
||||
*ppDevice = m_pDevice;
|
||||
return D3D_OK;
|
||||
#else
|
||||
return m_pTexture->GetDevice( ppDevice );
|
||||
#endif
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetPrivateData( REFGUID refguid,CONST void* pData,DWORD SizeOfData,DWORD Flags)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::SetPrivateData\n" );
|
||||
return m_pTexture->SetPrivateData( refguid, pData, SizeOfData, Flags );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetPrivateData( REFGUID refguid,void* pData,DWORD* pSizeOfData )
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::GetPrivateData\n" );
|
||||
return m_pTexture->GetPrivateData( refguid, pData, pSizeOfData );
|
||||
}
|
||||
|
||||
HRESULT __stdcall FreePrivateData( REFGUID refguid )
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::GetPrivateData\n" );
|
||||
return m_pTexture->FreePrivateData( refguid );
|
||||
}
|
||||
|
||||
DWORD __stdcall SetPriority( DWORD PriorityNew )
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::SetPriority\n" );
|
||||
return m_pTexture->SetPriority( PriorityNew );
|
||||
}
|
||||
|
||||
DWORD __stdcall GetPriority()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::GetPriority\n" );
|
||||
return m_pTexture->GetPriority();
|
||||
}
|
||||
|
||||
void __stdcall PreLoad()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::PreLoad\n" );
|
||||
m_pTexture->PreLoad();
|
||||
}
|
||||
|
||||
D3DRESOURCETYPE __stdcall GetType()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::GetType\n" );
|
||||
return m_pTexture->GetType();
|
||||
}
|
||||
|
||||
DWORD __stdcall SetLOD( DWORD LODNew )
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::SetLOD\n" );
|
||||
return m_pTexture->SetLOD( LODNew );
|
||||
}
|
||||
|
||||
DWORD __stdcall GetLOD()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::GetLOD\n" );
|
||||
return m_pTexture->GetLOD();
|
||||
}
|
||||
|
||||
DWORD __stdcall GetLevelCount()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::GetLevelCount\n" );
|
||||
return m_pTexture->GetLevelCount();
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetLevelDesc(UINT Level,D3DSURFACE_DESC *pDesc)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::GetLevelCount\n" );
|
||||
return m_pTexture->GetLevelDesc( Level, pDesc );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetSurfaceLevel(UINT Level,IDirect3DSurface8** ppSurfaceLevel)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::GetSurfaceLevel\n" );
|
||||
return m_pTexture->GetSurfaceLevel( Level, ppSurfaceLevel );
|
||||
}
|
||||
|
||||
HRESULT __stdcall LockRect(UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::LockRect\n" );
|
||||
return m_pTexture->LockRect( Level, pLockedRect, pRect, Flags );
|
||||
}
|
||||
|
||||
HRESULT __stdcall UnlockRect(UINT Level)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::UnlockRect\n" );
|
||||
return m_pTexture->UnlockRect( Level );
|
||||
}
|
||||
|
||||
HRESULT __stdcall AddDirtyRect( CONST RECT* pDirtyRect )
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::AddDirtyRect\n" );
|
||||
return m_pTexture->AddDirtyRect( pDirtyRect );
|
||||
}
|
||||
};
|
||||
|
||||
class CStubD3DDevice : public IDirect3DDevice8
|
||||
{
|
||||
public:
|
||||
CStubD3DDevice( IDirect3DDevice8 *pD3DDevice, IFileSystem *pFileSystem )
|
||||
{
|
||||
Assert( pD3DDevice );
|
||||
m_pD3DDevice = pD3DDevice;
|
||||
#ifdef USE_FOPEN
|
||||
s_FileHandle = fopen( "stubd3d.txt", "w" );
|
||||
#else
|
||||
Assert( pFileSystem );
|
||||
s_pFileSystem = pFileSystem;
|
||||
s_FileHandle = pFileSystem->Open( "stubd3d.txt", "w" );
|
||||
#endif
|
||||
}
|
||||
|
||||
~CStubD3DDevice()
|
||||
{
|
||||
#ifdef USE_FOPEN
|
||||
fclose( s_FileHandle );
|
||||
#else
|
||||
s_pFileSystem->Close( s_FileHandle );
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
IDirect3DDevice8 *m_pD3DDevice;
|
||||
|
||||
public:
|
||||
/*** IUnknown methods ***/
|
||||
HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObj)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "QueryInterface\n" );
|
||||
return m_pD3DDevice->QueryInterface( riid, ppvObj );
|
||||
}
|
||||
|
||||
ULONG __stdcall AddRef()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "AddRef\n" );
|
||||
return m_pD3DDevice->AddRef();
|
||||
}
|
||||
|
||||
ULONG __stdcall Release()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "Release\n" );
|
||||
return m_pD3DDevice->Release();
|
||||
delete this;
|
||||
}
|
||||
|
||||
/*** IDirect3DDevice8 methods ***/
|
||||
HRESULT __stdcall TestCooperativeLevel()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "TestCooperativeLevel\n" );
|
||||
return m_pD3DDevice->TestCooperativeLevel();
|
||||
}
|
||||
|
||||
UINT __stdcall GetAvailableTextureMem()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetAvailableTextureMem\n" );
|
||||
return m_pD3DDevice->GetAvailableTextureMem();
|
||||
}
|
||||
|
||||
HRESULT __stdcall ResourceManagerDiscardBytes(DWORD Bytes)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "ResourceManagerDiscardBytes\n" );
|
||||
return m_pD3DDevice->ResourceManagerDiscardBytes( Bytes );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetDirect3D(IDirect3D8** ppD3D8)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetDirect3D\n" );
|
||||
return m_pD3DDevice->GetDirect3D( ppD3D8 );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetDeviceCaps(D3DCAPS8* pCaps)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetDeviceCaps\n" );
|
||||
return m_pD3DDevice->GetDeviceCaps( pCaps );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetDisplayMode(D3DDISPLAYMODE* pMode)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetDisplayMode\n" );
|
||||
return m_pD3DDevice->GetDisplayMode( pMode );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS *pParameters)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetCreationParameters\n" );
|
||||
return m_pD3DDevice->GetCreationParameters( pParameters );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetCursorProperties(UINT XHotSpot,UINT YHotSpot,IDirect3DSurface8* pCursorBitmap)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetCursorProperties\n" );
|
||||
return m_pD3DDevice->SetCursorProperties( XHotSpot, YHotSpot, pCursorBitmap );
|
||||
}
|
||||
|
||||
void __stdcall SetCursorPosition(UINT XScreenSpace,UINT YScreenSpace,DWORD Flags)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetCursorPosition\n" );
|
||||
m_pD3DDevice->SetCursorPosition( XScreenSpace, YScreenSpace, Flags );
|
||||
}
|
||||
|
||||
BOOL __stdcall ShowCursor(BOOL bShow)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "ShowCursor\n" );
|
||||
return m_pD3DDevice->ShowCursor( bShow );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DSwapChain8** pSwapChain)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateAdditionalSwapChain\n" );
|
||||
return m_pD3DDevice->CreateAdditionalSwapChain( pPresentationParameters, pSwapChain );
|
||||
}
|
||||
|
||||
HRESULT __stdcall Reset(D3DPRESENT_PARAMETERS* pPresentationParameters)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "Reset\n" );
|
||||
return m_pD3DDevice->Reset( pPresentationParameters );
|
||||
}
|
||||
|
||||
HRESULT __stdcall Present(CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "Present\n" );
|
||||
return m_pD3DDevice->Present( pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetBackBuffer(UINT BackBuffer,D3DBACKBUFFER_TYPE Type,IDirect3DSurface8** ppBackBuffer)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetBackBuffer\n" );
|
||||
return m_pD3DDevice->GetBackBuffer( BackBuffer, Type, ppBackBuffer );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetRasterStatus(D3DRASTER_STATUS* pRasterStatus)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetRasterStatus\n" );
|
||||
return m_pD3DDevice->GetRasterStatus( pRasterStatus );
|
||||
}
|
||||
|
||||
void __stdcall SetGammaRamp(DWORD Flags,CONST D3DGAMMARAMP* pRamp)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetGammaRamp\n" );
|
||||
m_pD3DDevice->SetGammaRamp( Flags, pRamp );
|
||||
}
|
||||
|
||||
void __stdcall GetGammaRamp(D3DGAMMARAMP* pRamp)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetGammaRamp\n" );
|
||||
m_pD3DDevice->GetGammaRamp( pRamp );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateTexture(UINT Width,UINT Height,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DTexture8** ppTexture)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateTexture\n" );
|
||||
#if 0
|
||||
HRESULT ret = m_pD3DDevice->CreateTexture( Width, Height, Levels, Usage, Format, Pool, ppTexture );
|
||||
if( ret == D3D_OK )
|
||||
{
|
||||
*ppTexture = new CStubD3DTexture( *ppTexture, this );
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
return m_pD3DDevice->CreateTexture( Width, Height, Levels, Usage, Format, Pool, ppTexture );
|
||||
#endif
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateVolumeTexture(UINT Width,UINT Height,UINT Depth,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DVolumeTexture8** ppVolumeTexture)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateVolumeTexture\n" );
|
||||
return m_pD3DDevice->CreateVolumeTexture( Width, Height, Depth, Levels, Usage, Format, Pool, ppVolumeTexture );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateCubeTexture(UINT EdgeLength,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DCubeTexture8** ppCubeTexture)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateCubeTexture\n" );
|
||||
return m_pD3DDevice->CreateCubeTexture( EdgeLength, Levels, Usage, Format, Pool, ppCubeTexture );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateVertexBuffer(UINT Length,DWORD Usage,DWORD FVF,D3DPOOL Pool,IDirect3DVertexBuffer8** ppVertexBuffer)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateVertexBuffer\n" );
|
||||
return m_pD3DDevice->CreateVertexBuffer( Length, Usage, FVF, Pool, ppVertexBuffer );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateIndexBuffer(UINT Length,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DIndexBuffer8** ppIndexBuffer)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateIndexBuffer\n" );
|
||||
return m_pD3DDevice->CreateIndexBuffer( Length, Usage, Format, Pool, ppIndexBuffer );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateRenderTarget(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,BOOL Lockable,IDirect3DSurface8** ppSurface)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateRenderTarget\n" );
|
||||
return m_pD3DDevice->CreateRenderTarget( Width, Height, Format, MultiSample, Lockable, ppSurface );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateDepthStencilSurface(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,IDirect3DSurface8** ppSurface)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateDepthStencilSurface\n" );
|
||||
return m_pD3DDevice->CreateDepthStencilSurface( Width, Height, Format, MultiSample, ppSurface );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateImageSurface(UINT Width,UINT Height,D3DFORMAT Format,IDirect3DSurface8** ppSurface)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateImageSurface\n" );
|
||||
return m_pD3DDevice->CreateImageSurface( Width, Height, Format, ppSurface );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CopyRects(IDirect3DSurface8* pSourceSurface,CONST RECT* pSourceRectsArray,UINT cRects,IDirect3DSurface8* pDestinationSurface,CONST POINT* pDestPointsArray)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CopyRects\n" );
|
||||
return m_pD3DDevice->CopyRects( pSourceSurface, pSourceRectsArray, cRects, pDestinationSurface, pDestPointsArray );
|
||||
}
|
||||
|
||||
HRESULT __stdcall UpdateTexture(IDirect3DBaseTexture8* pSourceTexture,IDirect3DBaseTexture8* pDestinationTexture)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "UpdateTexture\n" );
|
||||
return m_pD3DDevice->UpdateTexture( pSourceTexture, pDestinationTexture );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetFrontBuffer(IDirect3DSurface8* pDestSurface)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetFrontBuffer\n" );
|
||||
return m_pD3DDevice->GetFrontBuffer( pDestSurface );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetRenderTarget(IDirect3DSurface8* pRenderTarget,IDirect3DSurface8* pNewZStencil)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetRenderTarget\n" );
|
||||
return m_pD3DDevice->SetRenderTarget( pRenderTarget, pNewZStencil );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetRenderTarget(IDirect3DSurface8** ppRenderTarget)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetRenderTarget\n" );
|
||||
return m_pD3DDevice->GetRenderTarget( ppRenderTarget );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetDepthStencilSurface(IDirect3DSurface8** ppZStencilSurface)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetDepthStencilSurface\n" );
|
||||
return m_pD3DDevice->GetDepthStencilSurface( ppZStencilSurface );
|
||||
}
|
||||
|
||||
HRESULT __stdcall BeginScene( void )
|
||||
{
|
||||
FPRINTF( s_FileHandle, "BeginScene\n" );
|
||||
return m_pD3DDevice->BeginScene();
|
||||
}
|
||||
|
||||
HRESULT __stdcall EndScene()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "EndScene\n" );
|
||||
return m_pD3DDevice->EndScene();
|
||||
}
|
||||
|
||||
HRESULT __stdcall Clear(DWORD Count,CONST D3DRECT* pRects,DWORD Flags,D3DCOLOR Color,float Z,DWORD Stencil)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "Clear\n" );
|
||||
return m_pD3DDevice->Clear( Count, pRects, Flags, Color, Z, Stencil );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetTransform\n" );
|
||||
return m_pD3DDevice->SetTransform( State, pMatrix );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetTransform(D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetTransform\n" );
|
||||
return m_pD3DDevice->GetTransform( State, pMatrix );
|
||||
}
|
||||
|
||||
HRESULT __stdcall MultiplyTransform(D3DTRANSFORMSTATETYPE transformState,CONST D3DMATRIX* pMatrix)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "MultiplyTransform\n" );
|
||||
return m_pD3DDevice->MultiplyTransform( transformState, pMatrix );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetViewport(CONST D3DVIEWPORT8* pViewport)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetViewport\n" );
|
||||
return m_pD3DDevice->SetViewport( pViewport );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetViewport(D3DVIEWPORT8* pViewport)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetViewport\n" );
|
||||
return m_pD3DDevice->GetViewport( pViewport );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetMaterial(CONST D3DMATERIAL8* pMaterial)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetMaterial\n" );
|
||||
return m_pD3DDevice->SetMaterial( pMaterial );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetMaterial(D3DMATERIAL8* pMaterial)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetMaterial\n" );
|
||||
return m_pD3DDevice->GetMaterial( pMaterial );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetLight(DWORD Index,CONST D3DLIGHT8* pLight)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetLight\n" );
|
||||
return m_pD3DDevice->SetLight( Index, pLight );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetLight(DWORD Index,D3DLIGHT8* pLight)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetLight\n" );
|
||||
return m_pD3DDevice->GetLight( Index, pLight );
|
||||
}
|
||||
|
||||
HRESULT __stdcall LightEnable(DWORD Index,BOOL Enable)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "LightEnable\n" );
|
||||
return m_pD3DDevice->LightEnable( Index, Enable );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetLightEnable(DWORD Index,BOOL* pEnable)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetLightEnable\n" );
|
||||
return m_pD3DDevice->GetLightEnable( Index, pEnable );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetClipPlane(DWORD Index,CONST float* pPlane)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetClipPlane\n" );
|
||||
return m_pD3DDevice->SetClipPlane( Index, pPlane );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetClipPlane(DWORD Index,float* pPlane)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetClipPlane\n" );
|
||||
return m_pD3DDevice->GetClipPlane( Index, pPlane );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetRenderState(D3DRENDERSTATETYPE State,DWORD Value)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetRenderState\n" );
|
||||
return m_pD3DDevice->SetRenderState( State, Value );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetRenderState(D3DRENDERSTATETYPE State,DWORD* pValue)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetRenderState\n" );
|
||||
return m_pD3DDevice->GetRenderState( State, pValue );
|
||||
}
|
||||
|
||||
HRESULT __stdcall BeginStateBlock(void)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "BeginStateBlock\n" );
|
||||
return m_pD3DDevice->BeginStateBlock();
|
||||
}
|
||||
|
||||
HRESULT __stdcall EndStateBlock(DWORD* pToken)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "EndStateBlock\n" );
|
||||
return m_pD3DDevice->EndStateBlock( pToken );
|
||||
}
|
||||
|
||||
HRESULT __stdcall ApplyStateBlock(DWORD Token)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "ApplyStateBlock\n" );
|
||||
return m_pD3DDevice->ApplyStateBlock( Token );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CaptureStateBlock(DWORD Token)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CaptureStateBlock\n" );
|
||||
return m_pD3DDevice->CaptureStateBlock( Token );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DeleteStateBlock(DWORD Token)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DeleteStateBlock\n" );
|
||||
return m_pD3DDevice->DeleteStateBlock( Token );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateStateBlock(D3DSTATEBLOCKTYPE Type,DWORD* pToken)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateStateBlock\n" );
|
||||
return m_pD3DDevice->CreateStateBlock( Type, pToken );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetClipStatus(CONST D3DCLIPSTATUS8* pClipStatus)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetClipStatus\n" );
|
||||
return m_pD3DDevice->SetClipStatus( pClipStatus );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetClipStatus(D3DCLIPSTATUS8* pClipStatus)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetClipStatus\n" );
|
||||
return m_pD3DDevice->GetClipStatus( pClipStatus );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetTexture(DWORD Stage,IDirect3DBaseTexture8** ppTexture)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetTexture\n" );
|
||||
return m_pD3DDevice->GetTexture( Stage, ppTexture );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetTexture(DWORD Stage,IDirect3DBaseTexture8* pTexture)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetTexture\n" );
|
||||
return m_pD3DDevice->SetTexture( Stage, pTexture );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetTextureStageState(DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetTextureStageState\n" );
|
||||
return m_pD3DDevice->GetTextureStageState( Stage, Type, pValue );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetTextureStageState(DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD Value)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetTextureStageState\n" );
|
||||
return m_pD3DDevice->SetTextureStageState( Stage, Type, Value );
|
||||
}
|
||||
|
||||
HRESULT __stdcall ValidateDevice(DWORD* pNumPasses)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "ValidateDevice\n" );
|
||||
#if 0
|
||||
return m_pD3DDevice->ValidateDevice( pNumPasses );
|
||||
#else
|
||||
return D3D_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetInfo(DWORD DevInfoID,void* pDevInfoStruct,DWORD DevInfoStructSize)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetInfo\n" );
|
||||
return m_pD3DDevice->GetInfo( DevInfoID, pDevInfoStruct, DevInfoStructSize );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetPaletteEntries(UINT PaletteNumber,CONST PALETTEENTRY* pEntries)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetPaletteEntries\n" );
|
||||
return m_pD3DDevice->SetPaletteEntries( PaletteNumber, pEntries );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetPaletteEntries(UINT PaletteNumber,PALETTEENTRY* pEntries)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetPaletteEntries\n" );
|
||||
return m_pD3DDevice->GetPaletteEntries( PaletteNumber, pEntries );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetCurrentTexturePalette(UINT PaletteNumber)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetCurrentTexturePalette\n" );
|
||||
return m_pD3DDevice->SetCurrentTexturePalette( PaletteNumber );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetCurrentTexturePalette(UINT *PaletteNumber)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetCurrentTexturePalette\n" );
|
||||
return m_pD3DDevice->GetCurrentTexturePalette( PaletteNumber );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType,UINT StartVertex,UINT PrimitiveCount)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DrawPrimitive\n" );
|
||||
return m_pD3DDevice->DrawPrimitive( PrimitiveType, StartVertex, PrimitiveCount );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DrawIndexedPrimitive(D3DPRIMITIVETYPE primitiveType,UINT minIndex,UINT NumVertices,UINT startIndex,UINT primCount)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DrawIndexedPrimitive\n" );
|
||||
return m_pD3DDevice->DrawIndexedPrimitive( primitiveType,minIndex,NumVertices,startIndex,primCount );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DrawPrimitiveUP\n" );
|
||||
return m_pD3DDevice->DrawPrimitiveUP( PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DrawIndexedPrimitiveUP\n" );
|
||||
return m_pD3DDevice->DrawIndexedPrimitiveUP( PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount, pIndexData, IndexDataFormat,pVertexStreamZeroData, VertexStreamZeroStride );
|
||||
}
|
||||
|
||||
HRESULT __stdcall ProcessVertices(UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "ProcessVertices\n" );
|
||||
return m_pD3DDevice->ProcessVertices( SrcStartIndex, DestIndex, VertexCount, pDestBuffer, Flags );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateVertexShader(CONST DWORD* pDeclaration,CONST DWORD* pFunction,DWORD* pHandle,DWORD Usage)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateVertexShader\n" );
|
||||
return m_pD3DDevice->CreateVertexShader( pDeclaration, pFunction, pHandle, Usage );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetVertexShader(DWORD Handle)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetVertexShader\n" );
|
||||
return m_pD3DDevice->SetVertexShader( Handle );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetVertexShader(DWORD* pHandle)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetVertexShader\n" );
|
||||
return m_pD3DDevice->GetVertexShader( pHandle );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DeleteVertexShader(DWORD Handle)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DeleteVertexShader\n" );
|
||||
return m_pD3DDevice->DeleteVertexShader( Handle );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetVertexShaderConstant(DWORD Register,CONST void* pConstantData,DWORD ConstantCount)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetVertexShaderConstant\n" );
|
||||
return m_pD3DDevice->SetVertexShaderConstant( Register, pConstantData, ConstantCount );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetVertexShaderConstant(DWORD Register,void* pConstantData,DWORD ConstantCount)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetVertexShaderConstant\n" );
|
||||
return m_pD3DDevice->GetVertexShaderConstant( Register, pConstantData, ConstantCount );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetVertexShaderDeclaration(DWORD Handle,void* pData,DWORD* pSizeOfData)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetVertexShaderDeclaration\n" );
|
||||
return m_pD3DDevice->GetVertexShaderDeclaration( Handle, pData, pSizeOfData );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetVertexShaderFunction(DWORD Handle,void* pData,DWORD* pSizeOfData)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetVertexShaderFunction\n" );
|
||||
return m_pD3DDevice->GetVertexShaderFunction( Handle, pData, pSizeOfData );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer8* pStreamData,UINT Stride)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetStreamSource\n" );
|
||||
return m_pD3DDevice->SetStreamSource( StreamNumber, pStreamData, Stride );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer8** ppStreamData,UINT* pStride)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetStreamSource\n" );
|
||||
return m_pD3DDevice->GetStreamSource( StreamNumber, ppStreamData, pStride );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetIndices(IDirect3DIndexBuffer8* pIndexData,UINT BaseVertexIndex)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetIndices\n" );
|
||||
return m_pD3DDevice->SetIndices( pIndexData, BaseVertexIndex );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetIndices(IDirect3DIndexBuffer8** ppIndexData,UINT* pBaseVertexIndex)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetIndices\n" );
|
||||
return m_pD3DDevice->GetIndices( ppIndexData, pBaseVertexIndex );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreatePixelShader(CONST DWORD* pFunction,DWORD* pHandle)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreatePixelShader\n" );
|
||||
return m_pD3DDevice->CreatePixelShader( pFunction, pHandle );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetPixelShader(DWORD Handle)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetPixelShader\n" );
|
||||
return m_pD3DDevice->SetPixelShader( Handle );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetPixelShader(DWORD* pHandle)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetPixelShader\n" );
|
||||
return m_pD3DDevice->GetPixelShader( pHandle );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DeletePixelShader(DWORD Handle)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DeletePixelShader\n" );
|
||||
return m_pD3DDevice->DeletePixelShader( Handle );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetPixelShaderConstant(DWORD Register,CONST void* pConstantData,DWORD ConstantCount)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetPixelShaderConstant\n" );
|
||||
return m_pD3DDevice->SetPixelShaderConstant( Register, pConstantData, ConstantCount );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetPixelShaderConstant(DWORD Register,void* pConstantData,DWORD ConstantCount)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetPixelShaderConstant\n" );
|
||||
return m_pD3DDevice->GetPixelShaderConstant( Register, pConstantData, ConstantCount );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetPixelShaderFunction(DWORD Handle,void* pData,DWORD* pSizeOfData)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetPixelShaderFunction\n" );
|
||||
return m_pD3DDevice->GetPixelShaderFunction( Handle, pData, pSizeOfData );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DrawRectPatch(UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DrawRectPatch\n" );
|
||||
return m_pD3DDevice->DrawRectPatch( Handle, pNumSegs, pRectPatchInfo );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DrawTriPatch(UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DrawTriPatch\n" );
|
||||
return m_pD3DDevice->DrawTriPatch( Handle, pNumSegs, pTriPatchInfo );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DeletePatch(UINT Handle)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DeletePatch\n" );
|
||||
return m_pD3DDevice->DeletePatch( Handle );
|
||||
}
|
||||
};
|
||||
|
||||
#endif // STUBD3D
|
||||
|
||||
#endif // STUBD3DDEVICE_H
|
||||
|
||||
1545
materialsystem/shaderapidx9/texturedx8.cpp
Normal file
1545
materialsystem/shaderapidx9/texturedx8.cpp
Normal file
File diff suppressed because it is too large
Load Diff
110
materialsystem/shaderapidx9/texturedx8.h
Normal file
110
materialsystem/shaderapidx9/texturedx8.h
Normal file
@@ -0,0 +1,110 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef TEXTUREDX8_H
|
||||
#define TEXTUREDX8_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "togl/rendermechanism.h"
|
||||
#include "bitmap/imageformat.h"
|
||||
#include "locald3dtypes.h"
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class CPixelWriter;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the size of texture memory
|
||||
//-----------------------------------------------------------------------------
|
||||
int ComputeTextureMemorySize( const GUID &nDeviceId, D3DDEVTYPE deviceType );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Texture creation
|
||||
//-----------------------------------------------------------------------------
|
||||
IDirect3DBaseTexture *CreateD3DTexture( int width, int height, int depth,
|
||||
ImageFormat dstFormat, int numLevels, int creationFlags, char *debugLabel=NULL ); // OK to not-supply the last param
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Texture destruction
|
||||
//-----------------------------------------------------------------------------
|
||||
void DestroyD3DTexture( IDirect3DBaseTexture *pTex );
|
||||
|
||||
int GetD3DTextureRefCount( IDirect3DBaseTexture *pTex );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Texture heap methods
|
||||
//-----------------------------------------------------------------------------
|
||||
#if defined( _X360 )
|
||||
void SetD3DTextureImmobile( IDirect3DBaseTexture *pTex, bool bImmobile );
|
||||
void CompactTextureHeap();
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Stats...
|
||||
//-----------------------------------------------------------------------------
|
||||
int TextureCount();
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Info for texture loading
|
||||
//-----------------------------------------------------------------------------
|
||||
struct TextureLoadInfo_t
|
||||
{
|
||||
ShaderAPITextureHandle_t m_TextureHandle;
|
||||
int m_nCopy;
|
||||
IDirect3DBaseTexture *m_pTexture;
|
||||
int m_nLevel;
|
||||
D3DCUBEMAP_FACES m_CubeFaceID;
|
||||
int m_nWidth;
|
||||
int m_nHeight;
|
||||
int16 m_nZOffset; // What z-slice of the volume texture are we loading?
|
||||
#if defined( _X360 )
|
||||
bool m_bSrcIsTiled; // format may not be, but data could be
|
||||
bool m_bCanConvertFormat; // allow format conversion
|
||||
#else
|
||||
bool m_bTextureIsLockable;
|
||||
#endif
|
||||
ImageFormat m_SrcFormat;
|
||||
unsigned char *m_pSrcData;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Texture image upload
|
||||
//-----------------------------------------------------------------------------
|
||||
void LoadTexture( TextureLoadInfo_t &info );
|
||||
void LoadTextureFromVTF( TextureLoadInfo_t &info, IVTFTexture* pVTF, int iVTFFrame );
|
||||
void LoadCubeTextureFromVTF( TextureLoadInfo_t &info, IVTFTexture* pVTF, int iVTFFrame );
|
||||
void LoadVolumeTextureFromVTF( TextureLoadInfo_t &info, IVTFTexture* pVTF, int iVTFFrame );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Upload to a sub-piece of a texture
|
||||
//-----------------------------------------------------------------------------
|
||||
void LoadSubTexture( TextureLoadInfo_t &info, int xOffset, int yOffset, int srcStride );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Lock, unlock a texture...
|
||||
//-----------------------------------------------------------------------------
|
||||
bool LockTexture( ShaderAPITextureHandle_t textureHandle, int copy, IDirect3DBaseTexture* pTexture, int level,
|
||||
D3DCUBEMAP_FACES cubeFaceID, int xOffset, int yOffset, int width, int height, bool bDiscard,
|
||||
CPixelWriter& writer );
|
||||
|
||||
void UnlockTexture( ShaderAPITextureHandle_t textureHandle, int copy, IDirect3DBaseTexture* pTexture, int level,
|
||||
D3DCUBEMAP_FACES cubeFaceID );
|
||||
|
||||
#endif // TEXTUREDX8_H
|
||||
1258
materialsystem/shaderapidx9/textureheap.cpp
Normal file
1258
materialsystem/shaderapidx9/textureheap.cpp
Normal file
File diff suppressed because it is too large
Load Diff
42
materialsystem/shaderapidx9/textureheap.h
Normal file
42
materialsystem/shaderapidx9/textureheap.h
Normal file
@@ -0,0 +1,42 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef TEXTUREHEAP_H
|
||||
#define TEXTUREHEAP_H
|
||||
|
||||
#if defined( _X360 )
|
||||
|
||||
#include "locald3dtypes.h"
|
||||
|
||||
class CTextureHeap
|
||||
{
|
||||
public:
|
||||
IDirect3DTexture *AllocTexture( int width, int height, int levels, DWORD usage, D3DFORMAT format, bool bFallback, bool bNoD3DMemory );
|
||||
IDirect3DCubeTexture *AllocCubeTexture( int width, int levels, DWORD usage, D3DFORMAT format, bool bFallback, bool bNoD3DMemory );
|
||||
IDirect3DVolumeTexture *AllocVolumeTexture( int width, int height, int depth, int levels, DWORD usage, D3DFORMAT format );
|
||||
IDirect3DSurface *AllocRenderTargetSurface( int width, int height, D3DFORMAT format, bool bMultiSample = false , int base = -1);
|
||||
|
||||
// Perform the real d3d allocation, returns true if succesful, false otherwise.
|
||||
// Only valid for a texture created with no d3d bits, otherwise no-op.
|
||||
bool AllocD3DMemory( IDirect3DBaseTexture *pTexture );
|
||||
|
||||
// Release header and d3d bits.
|
||||
void FreeTexture( IDirect3DBaseTexture *pTexture );
|
||||
|
||||
// Returns the amount of memory needed or allocated for the texture.
|
||||
int GetSize( IDirect3DBaseTexture *pTexture );
|
||||
|
||||
// Crunch the heap.
|
||||
void Compact();
|
||||
|
||||
// Get current backbuffer multisample type
|
||||
D3DMULTISAMPLE_TYPE GetBackBufferMultiSampleType();
|
||||
};
|
||||
|
||||
extern CTextureHeap g_TextureHeap;
|
||||
|
||||
#endif
|
||||
#endif // TEXTUREHEAP_H
|
||||
576
materialsystem/shaderapidx9/vertexdecl.cpp
Normal file
576
materialsystem/shaderapidx9/vertexdecl.cpp
Normal file
@@ -0,0 +1,576 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#undef PROTECTED_THINGS_ENABLE
|
||||
#include "vertexdecl.h" // this includes <windows.h> inside the dx headers
|
||||
#define PROTECTED_THINGS_ENABLE
|
||||
#include "materialsystem/imaterialsystemhardwareconfig.h"
|
||||
#include "shaderapidx8_global.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "utlrbtree.h"
|
||||
#include "recording.h"
|
||||
#include "tier1/strtools.h"
|
||||
#include "tier0/vprof.h"
|
||||
#include "materialsystem/imesh.h"
|
||||
#include "shaderdevicedx8.h"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Computes the DX8 vertex specification
|
||||
//-----------------------------------------------------------------------------
|
||||
static const char *DeclTypeToString( BYTE type )
|
||||
{
|
||||
switch( type )
|
||||
{
|
||||
case D3DDECLTYPE_FLOAT1:
|
||||
return "D3DDECLTYPE_FLOAT1";
|
||||
case D3DDECLTYPE_FLOAT2:
|
||||
return "D3DDECLTYPE_FLOAT2";
|
||||
case D3DDECLTYPE_FLOAT3:
|
||||
return "D3DDECLTYPE_FLOAT3";
|
||||
case D3DDECLTYPE_FLOAT4:
|
||||
return "D3DDECLTYPE_FLOAT4";
|
||||
case D3DDECLTYPE_D3DCOLOR:
|
||||
return "D3DDECLTYPE_D3DCOLOR";
|
||||
case D3DDECLTYPE_UBYTE4:
|
||||
return "D3DDECLTYPE_UBYTE4";
|
||||
case D3DDECLTYPE_SHORT2:
|
||||
return "D3DDECLTYPE_SHORT2";
|
||||
case D3DDECLTYPE_SHORT4:
|
||||
return "D3DDECLTYPE_SHORT4";
|
||||
case D3DDECLTYPE_UBYTE4N:
|
||||
return "D3DDECLTYPE_UBYTE4N";
|
||||
case D3DDECLTYPE_SHORT2N:
|
||||
return "D3DDECLTYPE_SHORT2N";
|
||||
case D3DDECLTYPE_SHORT4N:
|
||||
return "D3DDECLTYPE_SHORT4N";
|
||||
case D3DDECLTYPE_USHORT2N:
|
||||
return "D3DDECLTYPE_USHORT2N";
|
||||
case D3DDECLTYPE_USHORT4N:
|
||||
return "D3DDECLTYPE_USHORT4N";
|
||||
case D3DDECLTYPE_UDEC3:
|
||||
return "D3DDECLTYPE_UDEC3";
|
||||
case D3DDECLTYPE_DEC3N:
|
||||
return "D3DDECLTYPE_DEC3N";
|
||||
case D3DDECLTYPE_FLOAT16_2:
|
||||
return "D3DDECLTYPE_FLOAT16_2";
|
||||
case D3DDECLTYPE_FLOAT16_4:
|
||||
return "D3DDECLTYPE_FLOAT16_4";
|
||||
default:
|
||||
Assert( 0 );
|
||||
return "ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
static const char *DeclMethodToString( BYTE method )
|
||||
{
|
||||
switch( method )
|
||||
{
|
||||
case D3DDECLMETHOD_DEFAULT:
|
||||
return "D3DDECLMETHOD_DEFAULT";
|
||||
case D3DDECLMETHOD_PARTIALU:
|
||||
return "D3DDECLMETHOD_PARTIALU";
|
||||
case D3DDECLMETHOD_PARTIALV:
|
||||
return "D3DDECLMETHOD_PARTIALV";
|
||||
case D3DDECLMETHOD_CROSSUV:
|
||||
return "D3DDECLMETHOD_CROSSUV";
|
||||
case D3DDECLMETHOD_UV:
|
||||
return "D3DDECLMETHOD_UV";
|
||||
case D3DDECLMETHOD_LOOKUP:
|
||||
return "D3DDECLMETHOD_LOOKUP";
|
||||
case D3DDECLMETHOD_LOOKUPPRESAMPLED:
|
||||
return "D3DDECLMETHOD_LOOKUPPRESAMPLED";
|
||||
default:
|
||||
Assert( 0 );
|
||||
return "ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
static const char *DeclUsageToString( BYTE usage )
|
||||
{
|
||||
switch( usage )
|
||||
{
|
||||
case D3DDECLUSAGE_POSITION:
|
||||
return "D3DDECLUSAGE_POSITION";
|
||||
case D3DDECLUSAGE_BLENDWEIGHT:
|
||||
return "D3DDECLUSAGE_BLENDWEIGHT";
|
||||
case D3DDECLUSAGE_BLENDINDICES:
|
||||
return "D3DDECLUSAGE_BLENDINDICES";
|
||||
case D3DDECLUSAGE_NORMAL:
|
||||
return "D3DDECLUSAGE_NORMAL";
|
||||
case D3DDECLUSAGE_PSIZE:
|
||||
return "D3DDECLUSAGE_PSIZE";
|
||||
case D3DDECLUSAGE_COLOR:
|
||||
return "D3DDECLUSAGE_COLOR";
|
||||
case D3DDECLUSAGE_TEXCOORD:
|
||||
return "D3DDECLUSAGE_TEXCOORD";
|
||||
case D3DDECLUSAGE_TANGENT:
|
||||
return "D3DDECLUSAGE_TANGENT";
|
||||
case D3DDECLUSAGE_BINORMAL:
|
||||
return "D3DDECLUSAGE_BINORMAL";
|
||||
case D3DDECLUSAGE_TESSFACTOR:
|
||||
return "D3DDECLUSAGE_TESSFACTOR";
|
||||
// case D3DDECLUSAGE_POSITIONTL:
|
||||
// return "D3DDECLUSAGE_POSITIONTL";
|
||||
default:
|
||||
Assert( 0 );
|
||||
return "ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
static D3DDECLTYPE VertexElementToDeclType( VertexElement_t element, VertexCompressionType_t compressionType )
|
||||
{
|
||||
Detect_VertexElement_t_Changes( element );
|
||||
|
||||
if ( compressionType == VERTEX_COMPRESSION_ON )
|
||||
{
|
||||
// Compressed-vertex element sizes
|
||||
switch ( element )
|
||||
{
|
||||
#if ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_SEPARATETANGENTS_SHORT2 )
|
||||
case VERTEX_ELEMENT_NORMAL: return D3DDECLTYPE_SHORT2;
|
||||
case VERTEX_ELEMENT_USERDATA4: return D3DDECLTYPE_SHORT2;
|
||||
#else //( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 )
|
||||
case VERTEX_ELEMENT_NORMAL: return D3DDECLTYPE_UBYTE4;
|
||||
case VERTEX_ELEMENT_USERDATA4: return D3DDECLTYPE_UBYTE4;
|
||||
#endif
|
||||
case VERTEX_ELEMENT_BONEWEIGHTS1: return D3DDECLTYPE_SHORT2;
|
||||
case VERTEX_ELEMENT_BONEWEIGHTS2: return D3DDECLTYPE_SHORT2;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Uncompressed-vertex element sizes
|
||||
switch ( element )
|
||||
{
|
||||
case VERTEX_ELEMENT_POSITION: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_NORMAL: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_COLOR: return D3DDECLTYPE_D3DCOLOR;
|
||||
case VERTEX_ELEMENT_SPECULAR: return D3DDECLTYPE_D3DCOLOR;
|
||||
case VERTEX_ELEMENT_TANGENT_S: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_TANGENT_T: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_WRINKLE:
|
||||
// Wrinkle is packed into Position.W, it is not specified as a separate vertex element
|
||||
Assert( 0 );
|
||||
return D3DDECLTYPE_UNUSED;
|
||||
#if !defined( _X360 )
|
||||
case VERTEX_ELEMENT_BONEINDEX: return D3DDECLTYPE_D3DCOLOR;
|
||||
#else
|
||||
// UBYTE4 comes in as [0,255] in the shader, which is ideal for bone indices
|
||||
// (unfortunately, UBYTE4 is not universally supported on PC DX8 GPUs)
|
||||
case VERTEX_ELEMENT_BONEINDEX: return D3DDECLTYPE_UBYTE4;
|
||||
#endif
|
||||
case VERTEX_ELEMENT_BONEWEIGHTS1: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_BONEWEIGHTS2: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_BONEWEIGHTS3: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_BONEWEIGHTS4: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_USERDATA1: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_USERDATA2: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_USERDATA3: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_USERDATA4: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_TEXCOORD1D_0: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_TEXCOORD1D_1: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_TEXCOORD1D_2: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_TEXCOORD1D_3: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_TEXCOORD1D_4: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_TEXCOORD1D_5: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_TEXCOORD1D_6: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_TEXCOORD1D_7: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_TEXCOORD2D_0: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_TEXCOORD2D_1: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_TEXCOORD2D_2: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_TEXCOORD2D_3: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_TEXCOORD2D_4: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_TEXCOORD2D_5: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_TEXCOORD2D_6: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_TEXCOORD2D_7: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_TEXCOORD3D_0: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_TEXCOORD3D_1: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_TEXCOORD3D_2: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_TEXCOORD3D_3: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_TEXCOORD3D_4: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_TEXCOORD3D_5: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_TEXCOORD3D_6: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_TEXCOORD3D_7: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_TEXCOORD4D_0: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_TEXCOORD4D_1: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_TEXCOORD4D_2: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_TEXCOORD4D_3: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_TEXCOORD4D_4: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_TEXCOORD4D_5: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_TEXCOORD4D_6: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_TEXCOORD4D_7: return D3DDECLTYPE_FLOAT4;
|
||||
default:
|
||||
Assert(0);
|
||||
return D3DDECLTYPE_UNUSED;
|
||||
};
|
||||
}
|
||||
|
||||
void PrintVertexDeclaration( const D3DVERTEXELEMENT9 *pDecl )
|
||||
{
|
||||
int i;
|
||||
static D3DVERTEXELEMENT9 declEnd = D3DDECL_END();
|
||||
for ( i = 0; ; i++ )
|
||||
{
|
||||
if ( memcmp( &pDecl[i], &declEnd, sizeof( declEnd ) ) == 0 )
|
||||
{
|
||||
Warning( "D3DDECL_END\n" );
|
||||
break;
|
||||
}
|
||||
Msg( "%d: Stream: %d, Offset: %d, Type: %s, Method: %s, Usage: %s, UsageIndex: %d\n",
|
||||
i, ( int )pDecl[i].Stream, ( int )pDecl[i].Offset,
|
||||
DeclTypeToString( pDecl[i].Type ),
|
||||
DeclMethodToString( pDecl[i].Method ),
|
||||
DeclUsageToString( pDecl[i].Usage ),
|
||||
( int )pDecl[i].UsageIndex );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Converts format to a vertex decl
|
||||
//-----------------------------------------------------------------------------
|
||||
void ComputeVertexSpec( VertexFormat_t fmt, D3DVERTEXELEMENT9 *pDecl, bool bStaticLit, bool bUsingFlex, bool bUsingMorph )
|
||||
{
|
||||
int i = 0;
|
||||
int offset = 0;
|
||||
|
||||
VertexCompressionType_t compressionType = CompressionType( fmt );
|
||||
|
||||
if ( IsX360() )
|
||||
{
|
||||
// On 360, there's a performance penalty for reading more than 2 streams in the vertex shader
|
||||
// (we don't do this yet, but we should be aware if we start doing it)
|
||||
#ifdef _DEBUG
|
||||
int numStreams = 1 + ( bStaticLit ? 1 : 0 ) + ( bUsingFlex ? 1 : 0 ) + ( bUsingMorph ? 1 : 0 );
|
||||
Assert( numStreams <= 2 );
|
||||
#endif
|
||||
}
|
||||
|
||||
if ( fmt & VERTEX_POSITION )
|
||||
{
|
||||
pDecl[i].Stream = 0;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_POSITION;
|
||||
pDecl[i].UsageIndex = 0;
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_POSITION, compressionType );
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_POSITION, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
int numBones = NumBoneWeights(fmt);
|
||||
if ( numBones > 0 )
|
||||
{
|
||||
pDecl[i].Stream = 0;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_BLENDWEIGHT;
|
||||
pDecl[i].UsageIndex = 0;
|
||||
|
||||
// Always exactly two weights
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_BONEWEIGHTS2, compressionType );
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_BONEWEIGHTS2, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
if ( fmt & VERTEX_BONE_INDEX )
|
||||
{
|
||||
// this isn't FVF!!!!!
|
||||
pDecl[i].Stream = 0;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_BLENDINDICES;
|
||||
pDecl[i].UsageIndex = 0;
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_BONEINDEX, compressionType );
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_BONEINDEX, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
int normalOffset = -1;
|
||||
if ( fmt & VERTEX_NORMAL )
|
||||
{
|
||||
pDecl[i].Stream = 0;
|
||||
pDecl[i].Offset = offset;
|
||||
normalOffset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_NORMAL;
|
||||
pDecl[i].UsageIndex = 0;
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_NORMAL, compressionType );
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_NORMAL, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
if ( fmt & VERTEX_COLOR )
|
||||
{
|
||||
pDecl[i].Stream = 0;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_COLOR;
|
||||
pDecl[i].UsageIndex = 0;
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_COLOR, compressionType );
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_COLOR, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
if ( fmt & VERTEX_SPECULAR )
|
||||
{
|
||||
Assert( !bStaticLit );
|
||||
pDecl[i].Stream = 0;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_COLOR;
|
||||
pDecl[i].UsageIndex = 1; // SPECULAR goes in the second COLOR slot
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_SPECULAR, compressionType );
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_SPECULAR, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
VertexElement_t texCoordDimensions[4] = { VERTEX_ELEMENT_TEXCOORD1D_0,
|
||||
VERTEX_ELEMENT_TEXCOORD2D_0,
|
||||
VERTEX_ELEMENT_TEXCOORD3D_0,
|
||||
VERTEX_ELEMENT_TEXCOORD4D_0 };
|
||||
for ( int j = 0; j < VERTEX_MAX_TEXTURE_COORDINATES; ++j )
|
||||
{
|
||||
int nCoordSize = TexCoordSize( j, fmt );
|
||||
if ( nCoordSize <= 0 )
|
||||
continue;
|
||||
Assert( nCoordSize <= 4 );
|
||||
|
||||
pDecl[i].Stream = 0;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TEXCOORD;
|
||||
pDecl[i].UsageIndex = j;
|
||||
VertexElement_t texCoordElement = (VertexElement_t)( texCoordDimensions[ nCoordSize - 1 ] + j );
|
||||
pDecl[i].Type = VertexElementToDeclType( texCoordElement, compressionType );
|
||||
offset += GetVertexElementSize( texCoordElement, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
if ( fmt & VERTEX_TANGENT_S )
|
||||
{
|
||||
pDecl[i].Stream = 0;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TANGENT;
|
||||
pDecl[i].UsageIndex = 0;
|
||||
// NOTE: this is currently *not* compressed
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_TANGENT_S, compressionType );
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_TANGENT_S, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
if ( fmt & VERTEX_TANGENT_T )
|
||||
{
|
||||
pDecl[i].Stream = 0;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_BINORMAL;
|
||||
pDecl[i].UsageIndex = 0;
|
||||
// NOTE: this is currently *not* compressed
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_TANGENT_T, compressionType );
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_TANGENT_T, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
int userDataSize = UserDataSize(fmt);
|
||||
if ( userDataSize > 0 )
|
||||
{
|
||||
Assert( userDataSize == 4 ); // This is actually only ever used for tangents
|
||||
pDecl[i].Stream = 0;
|
||||
if ( ( compressionType == VERTEX_COMPRESSION_ON ) &&
|
||||
( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 ) )
|
||||
{
|
||||
// FIXME: Normals and tangents are packed together into a single UBYTE4 element,
|
||||
// so just point this back at the same data while we're testing UBYTE4 out.
|
||||
pDecl[i].Offset = normalOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
pDecl[i].Offset = offset;
|
||||
}
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TANGENT;
|
||||
pDecl[i].UsageIndex = 0;
|
||||
VertexElement_t userDataElement = (VertexElement_t)( VERTEX_ELEMENT_USERDATA1 + ( userDataSize - 1 ) );
|
||||
pDecl[i].Type = VertexElementToDeclType( userDataElement, compressionType );
|
||||
offset += GetVertexElementSize( userDataElement, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
if ( bStaticLit )
|
||||
{
|
||||
// force stream 1 to have specular color in it, which is used for baked static lighting
|
||||
pDecl[i].Stream = 1;
|
||||
pDecl[i].Offset = 0;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_COLOR;
|
||||
pDecl[i].UsageIndex = 1; // SPECULAR goes into the second COLOR slot
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_SPECULAR, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
if ( HardwareConfig()->SupportsVertexAndPixelShaders() )
|
||||
{
|
||||
// FIXME: There needs to be a better way of doing this
|
||||
// In 2.0b, assume position is 4d, storing wrinkle in pos.w.
|
||||
bool bUseWrinkle = HardwareConfig()->SupportsPixelShaders_2_b();
|
||||
|
||||
// Force stream 2 to have flex deltas in it
|
||||
pDecl[i].Stream = 2;
|
||||
pDecl[i].Offset = 0;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_POSITION;
|
||||
pDecl[i].UsageIndex = 1;
|
||||
// FIXME: unify this with VertexElementToDeclType():
|
||||
pDecl[i].Type = bUseWrinkle ? D3DDECLTYPE_FLOAT4 : D3DDECLTYPE_FLOAT3;
|
||||
++i;
|
||||
|
||||
int normalOffset = GetVertexElementSize( VERTEX_ELEMENT_POSITION, compressionType );
|
||||
if ( bUseWrinkle )
|
||||
{
|
||||
normalOffset += GetVertexElementSize( VERTEX_ELEMENT_WRINKLE, compressionType );
|
||||
}
|
||||
|
||||
// Normal deltas
|
||||
pDecl[i].Stream = 2;
|
||||
pDecl[i].Offset = normalOffset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_NORMAL;
|
||||
pDecl[i].UsageIndex = 1;
|
||||
// NOTE: this is currently *not* compressed
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_NORMAL, VERTEX_COMPRESSION_NONE );
|
||||
++i;
|
||||
}
|
||||
|
||||
if ( bUsingMorph )
|
||||
{
|
||||
// force stream 3 to have vertex index in it, which is used for doing vertex texture reads
|
||||
pDecl[i].Stream = 3;
|
||||
pDecl[i].Offset = 0;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_POSITION;
|
||||
pDecl[i].UsageIndex = 2;
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_USERDATA1, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
static D3DVERTEXELEMENT9 declEnd = D3DDECL_END();
|
||||
pDecl[i] = declEnd;
|
||||
|
||||
//PrintVertexDeclaration( pDecl );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the declspec associated with a vertex format
|
||||
//-----------------------------------------------------------------------------
|
||||
struct VertexDeclLookup_t
|
||||
{
|
||||
enum LookupFlags_t
|
||||
{
|
||||
STATIC_LIT = 0x1,
|
||||
USING_MORPH = 0x2,
|
||||
USING_FLEX = 0x4,
|
||||
};
|
||||
|
||||
VertexFormat_t m_VertexFormat;
|
||||
int m_nFlags;
|
||||
IDirect3DVertexDeclaration9 *m_pDecl;
|
||||
|
||||
bool operator==( const VertexDeclLookup_t &src ) const
|
||||
{
|
||||
return ( m_VertexFormat == src.m_VertexFormat ) && ( m_nFlags == src.m_nFlags );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Dictionary of vertex decls
|
||||
// FIXME: stick this in the class?
|
||||
// FIXME: Does anything cause this to get flushed?
|
||||
//-----------------------------------------------------------------------------
|
||||
static bool VertexDeclLessFunc( const VertexDeclLookup_t &src1, const VertexDeclLookup_t &src2 )
|
||||
{
|
||||
if ( src1.m_nFlags == src2.m_nFlags )
|
||||
return src1.m_VertexFormat < src2.m_VertexFormat;
|
||||
|
||||
return ( src1.m_nFlags < src2.m_nFlags );
|
||||
}
|
||||
|
||||
static CUtlRBTree<VertexDeclLookup_t, int> s_VertexDeclDict( 0, 256, VertexDeclLessFunc );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the declspec associated with a vertex format
|
||||
//-----------------------------------------------------------------------------
|
||||
IDirect3DVertexDeclaration9 *FindOrCreateVertexDecl( VertexFormat_t fmt, bool bStaticLit, bool bUsingFlex, bool bUsingMorph )
|
||||
{
|
||||
MEM_ALLOC_D3D_CREDIT();
|
||||
|
||||
VertexDeclLookup_t lookup;
|
||||
lookup.m_VertexFormat = fmt;
|
||||
lookup.m_nFlags = 0;
|
||||
if ( bStaticLit )
|
||||
{
|
||||
lookup.m_nFlags |= VertexDeclLookup_t::STATIC_LIT;
|
||||
}
|
||||
if ( bUsingMorph )
|
||||
{
|
||||
lookup.m_nFlags |= VertexDeclLookup_t::USING_MORPH;
|
||||
}
|
||||
if ( bUsingFlex )
|
||||
{
|
||||
lookup.m_nFlags |= VertexDeclLookup_t::USING_FLEX;
|
||||
}
|
||||
|
||||
int i = s_VertexDeclDict.Find( lookup );
|
||||
if ( i != s_VertexDeclDict.InvalidIndex() )
|
||||
{
|
||||
// found
|
||||
return s_VertexDeclDict[i].m_pDecl;
|
||||
}
|
||||
|
||||
D3DVERTEXELEMENT9 decl[32];
|
||||
ComputeVertexSpec( fmt, decl, bStaticLit, bUsingFlex, bUsingMorph );
|
||||
|
||||
HRESULT hr =
|
||||
Dx9Device()->CreateVertexDeclaration( decl, &lookup.m_pDecl );
|
||||
|
||||
// NOTE: can't record until we have m_pDecl!
|
||||
RECORD_COMMAND( DX8_CREATE_VERTEX_DECLARATION, 2 );
|
||||
RECORD_INT( ( int )lookup.m_pDecl );
|
||||
RECORD_STRUCT( decl, sizeof( decl ) );
|
||||
COMPILE_TIME_ASSERT( sizeof( decl ) == sizeof( D3DVERTEXELEMENT9 ) * 32 );
|
||||
|
||||
Assert( hr == D3D_OK );
|
||||
if ( hr != D3D_OK )
|
||||
{
|
||||
Warning( " ERROR: failed to create vertex decl for vertex format 0x%08llX! You'll probably see messed-up mesh rendering - to diagnose, build shaderapidx9.dll in debug.\n", fmt );
|
||||
}
|
||||
|
||||
s_VertexDeclDict.Insert( lookup );
|
||||
return lookup.m_pDecl;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Clears out all declspecs
|
||||
//-----------------------------------------------------------------------------
|
||||
void ReleaseAllVertexDecl()
|
||||
{
|
||||
int i = s_VertexDeclDict.FirstInorder();
|
||||
while ( i != s_VertexDeclDict.InvalidIndex() )
|
||||
{
|
||||
if ( s_VertexDeclDict[i].m_pDecl )
|
||||
s_VertexDeclDict[i].m_pDecl->Release();
|
||||
i = s_VertexDeclDict.NextInorder( i );
|
||||
}
|
||||
}
|
||||
|
||||
32
materialsystem/shaderapidx9/vertexdecl.h
Normal file
32
materialsystem/shaderapidx9/vertexdecl.h
Normal file
@@ -0,0 +1,32 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef VERTEXDECL_H
|
||||
#define VERTEXDECL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "locald3dtypes.h"
|
||||
#include "materialsystem/imaterial.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the declspec associated with a vertex format
|
||||
//-----------------------------------------------------------------------------
|
||||
IDirect3DVertexDeclaration9 *FindOrCreateVertexDecl( VertexFormat_t fmt, bool bStaticLit, bool bUsingFlex, bool bUsingMorph );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Clears out all declspecs
|
||||
//-----------------------------------------------------------------------------
|
||||
void ReleaseAllVertexDecl( );
|
||||
|
||||
|
||||
#endif // VERTEXDECL_H
|
||||
|
||||
3783
materialsystem/shaderapidx9/vertexshaderdx8.cpp
Normal file
3783
materialsystem/shaderapidx9/vertexshaderdx8.cpp
Normal file
File diff suppressed because it is too large
Load Diff
135
materialsystem/shaderapidx9/vertexshaderdx8.h
Normal file
135
materialsystem/shaderapidx9/vertexshaderdx8.h
Normal file
@@ -0,0 +1,135 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef VERTEXSHADERDX8_H
|
||||
#define VERTEXSHADERDX8_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
#include "locald3dtypes.h"
|
||||
|
||||
|
||||
// uncomment to get dynamic compilation for HLSL shaders
|
||||
// X360 NOTE: By default, the system looks for a shared folder named "stdshaders" on the host machine and is completely compatible with -dvd. Ensure that the share is writable if you plan on generating UPDB's.
|
||||
//#define DYNAMIC_SHADER_COMPILE
|
||||
|
||||
// Uncomment to use remoteshadercompiler.exe as a shader compile server
|
||||
// Must also set mat_remoteshadercompile to remote shader compile machine name
|
||||
//#define REMOTE_DYNAMIC_SHADER_COMPILE
|
||||
|
||||
// uncomment to get spew about what combos are being compiled.
|
||||
//#define DYNAMIC_SHADER_COMPILE_VERBOSE
|
||||
|
||||
// Uncomment to use remoteshadercompiler.exe as a shader compile server
|
||||
// Must also set mat_remoteshadercompile to remote shader compile machine name
|
||||
//#define REMOTE_DYNAMIC_SHADER_COMPILE
|
||||
|
||||
// uncomment and fill in with a path to use a specific set of shader source files. Meant for network use.
|
||||
// PC path format is of style "\\\\somemachine\\sourcetreeshare\\materialsystem\\stdshaders"
|
||||
// Xbox path format is of style "net:\\smb\\somemachine\\sourcetreeshare\\materialsystem\\stdshaders"
|
||||
// - Xbox dynamic compiles without a custom path default to look directly for "stdshaders" share on host pc
|
||||
|
||||
//#define DYNAMIC_SHADER_COMPILE_CUSTOM_PATH ""
|
||||
|
||||
// uncomment to get disassembled (asm) shader code in your game dir as *.asm
|
||||
//#define DYNAMIC_SHADER_COMPILE_WRITE_ASSEMBLY
|
||||
|
||||
// uncomment to get disassembled (asm) shader code in your game dir as *.asm
|
||||
//#define WRITE_ASSEMBLY
|
||||
|
||||
|
||||
enum VertexShaderLightTypes_t
|
||||
{
|
||||
LIGHT_NONE = -1,
|
||||
LIGHT_SPOT = 0,
|
||||
LIGHT_POINT = 1,
|
||||
LIGHT_DIRECTIONAL = 2,
|
||||
LIGHT_STATIC = 3,
|
||||
LIGHT_AMBIENTCUBE = 4,
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Vertex + pixel shader manager
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class IShaderManager
|
||||
{
|
||||
protected:
|
||||
|
||||
// The current vertex and pixel shader index
|
||||
int m_nVertexShaderIndex;
|
||||
int m_nPixelShaderIndex;
|
||||
|
||||
public:
|
||||
// Initialize, shutdown
|
||||
virtual void Init() = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
|
||||
// Compiles vertex shaders
|
||||
virtual IShaderBuffer *CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ) = 0;
|
||||
|
||||
// New version of these methods [dx10 port]
|
||||
virtual VertexShaderHandle_t CreateVertexShader( IShaderBuffer* pShaderBuffer ) = 0;
|
||||
virtual void DestroyVertexShader( VertexShaderHandle_t hShader ) = 0;
|
||||
virtual PixelShaderHandle_t CreatePixelShader( IShaderBuffer* pShaderBuffer ) = 0;
|
||||
virtual void DestroyPixelShader( PixelShaderHandle_t hShader ) = 0;
|
||||
|
||||
// Creates vertex, pixel shaders
|
||||
virtual VertexShader_t CreateVertexShader( const char *pVertexShaderFile, int nStaticVshIndex = 0, char *debugLabel = NULL ) = 0;
|
||||
virtual PixelShader_t CreatePixelShader( const char *pPixelShaderFile, int nStaticPshIndex = 0, char *debugLabel = NULL ) = 0;
|
||||
|
||||
// Sets which dynamic version of the vertex + pixel shader to use
|
||||
FORCEINLINE void SetVertexShaderIndex( int vshIndex );
|
||||
FORCEINLINE void SetPixelShaderIndex( int pshIndex );
|
||||
|
||||
// Sets the vertex + pixel shader render state
|
||||
virtual void SetVertexShader( VertexShader_t shader ) = 0;
|
||||
virtual void SetPixelShader( PixelShader_t shader ) = 0;
|
||||
|
||||
// Resets the vertex + pixel shader state
|
||||
virtual void ResetShaderState() = 0;
|
||||
|
||||
// Returns the current vertex + pixel shaders
|
||||
virtual void *GetCurrentVertexShader() = 0;
|
||||
virtual void *GetCurrentPixelShader() = 0;
|
||||
|
||||
virtual void ClearVertexAndPixelShaderRefCounts() = 0;
|
||||
virtual void PurgeUnusedVertexAndPixelShaders() = 0;
|
||||
|
||||
// The low-level dx call to set the vertex shader state
|
||||
virtual void BindVertexShader( VertexShaderHandle_t shader ) = 0;
|
||||
virtual void BindPixelShader( PixelShaderHandle_t shader ) = 0;
|
||||
|
||||
#if defined( _X360 )
|
||||
virtual const char *GetActiveVertexShaderName() = 0;
|
||||
virtual const char *GetActivePixelShaderName() = 0;
|
||||
#endif
|
||||
|
||||
#if defined( DX_TO_GL_ABSTRACTION )
|
||||
virtual void DoStartupShaderPreloading() = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Methods related to setting vertex + pixel shader state
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE void IShaderManager::SetVertexShaderIndex( int vshIndex )
|
||||
{
|
||||
m_nVertexShaderIndex = vshIndex;
|
||||
}
|
||||
|
||||
FORCEINLINE void IShaderManager::SetPixelShaderIndex( int pshIndex )
|
||||
{
|
||||
m_nPixelShaderIndex = pshIndex;
|
||||
}
|
||||
|
||||
#endif // VERTEXSHADERDX8_H
|
||||
93
materialsystem/shaderapidx9/winutils.cpp
Normal file
93
materialsystem/shaderapidx9/winutils.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// winutils.cpp
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "winutils.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "appframework/ilaunchermgr.h"
|
||||
|
||||
// LINUX path taken from //Steam/main/src/tier0/platform_posix.cpp - Returns installed RAM in MB.
|
||||
static unsigned long GetInstalledRAM()
|
||||
{
|
||||
unsigned long ulTotalRamMB = 2047;
|
||||
|
||||
#ifdef LINUX
|
||||
char rgchLine[256];
|
||||
FILE *fpMemInfo = fopen( "/proc/meminfo", "r" );
|
||||
if ( !fpMemInfo )
|
||||
return ulTotalRamMB;
|
||||
|
||||
const char *pszSearchString = "MemTotal:";
|
||||
const uint cchSearchString = strlen( pszSearchString );
|
||||
while ( fgets( rgchLine, sizeof(rgchLine), fpMemInfo ) )
|
||||
{
|
||||
if ( !strncasecmp( pszSearchString, rgchLine, cchSearchString ) )
|
||||
{
|
||||
char *pszVal = rgchLine+cchSearchString;
|
||||
while( isspace(*pszVal) )
|
||||
++pszVal;
|
||||
ulTotalRamMB = atol( pszVal ) / 1024; // go from kB to MB
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose( fpMemInfo );
|
||||
#endif
|
||||
|
||||
// 128 Gb limit for now (should future proof us for a while)
|
||||
ulTotalRamMB = MIN( ulTotalRamMB, 1024 * 128 );
|
||||
return ulTotalRamMB;
|
||||
}
|
||||
|
||||
void GlobalMemoryStatus( MEMORYSTATUS *pOut )
|
||||
{
|
||||
unsigned long nInstalledRamInMB = GetInstalledRAM();
|
||||
|
||||
// For safety assume at least 128MB
|
||||
nInstalledRamInMB = MAX( nInstalledRamInMB, 128 );
|
||||
|
||||
uint64 ulTotalRam = static_cast<uint64>( nInstalledRamInMB ) * ( 1024 * 1024 );
|
||||
ulTotalRam = MIN( ulTotalRam, 0xFFFFFFFF );
|
||||
|
||||
pOut->dwTotalPhys = static_cast<SIZE_T>( ulTotalRam );
|
||||
}
|
||||
|
||||
void Sleep( unsigned int ms )
|
||||
{
|
||||
DebuggerBreak();
|
||||
ThreadSleep( ms );
|
||||
}
|
||||
|
||||
bool IsIconic( VD3DHWND hWnd )
|
||||
{
|
||||
// FIXME for now just act non-minimized all the time
|
||||
//DebuggerBreak();
|
||||
return false;
|
||||
}
|
||||
|
||||
BOOL ClientToScreen( VD3DHWND hWnd, LPPOINT pPoint )
|
||||
{
|
||||
DebuggerBreak();
|
||||
return true;
|
||||
}
|
||||
|
||||
void* GetCurrentThread()
|
||||
{
|
||||
DebuggerBreak();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SetThreadAffinityMask( void *hThread, int nMask )
|
||||
{
|
||||
DebuggerBreak();
|
||||
}
|
||||
|
||||
bool GUID::operator==( const struct _GUID &other ) const
|
||||
{
|
||||
DebuggerBreak();
|
||||
return memcmp( this, &other, sizeof( GUID ) ) == 0;
|
||||
}
|
||||
#endif
|
||||
21
materialsystem/shaderapidx9/winutils.h
Normal file
21
materialsystem/shaderapidx9/winutils.h
Normal file
@@ -0,0 +1,21 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
#ifndef WINUTILS_H
|
||||
#define WINUTILS_H
|
||||
|
||||
#include "togl/rendermechanism.h" // for win types
|
||||
|
||||
#if !defined(_WIN32)
|
||||
|
||||
void Sleep( unsigned int ms );
|
||||
bool IsIconic( VD3DHWND hWnd );
|
||||
BOOL ClientToScreen( VD3DHWND hWnd, LPPOINT pPoint );
|
||||
void* GetCurrentThread();
|
||||
void SetThreadAffinityMask( void *hThread, int nMask );
|
||||
void GlobalMemoryStatus( MEMORYSTATUS *pOut );
|
||||
#endif
|
||||
|
||||
#endif // WINUTILS_H
|
||||
182
materialsystem/shaderapidx9/wmi.cpp
Normal file
182
materialsystem/shaderapidx9/wmi.cpp
Normal file
@@ -0,0 +1,182 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "resource.h"
|
||||
|
||||
// Avoid conflicts with MSVC headers and memdbgon.h
|
||||
#undef PROTECTED_THINGS_ENABLE
|
||||
#include "basetypes.h"
|
||||
|
||||
#define _WIN32_DCOM
|
||||
#include <comdef.h>
|
||||
#pragma warning( disable : 4127 ) // VS 2010 warning?
|
||||
#pragma warning( disable : 4805 ) // VS 2013 warning: warning C4805: '==' : unsafe mix of type 'INT' and type 'bool' in operation
|
||||
#include <atlcomtime.h>
|
||||
#pragma warning( default : 4805 )
|
||||
#pragma warning( default : 4127 )
|
||||
#include <wbemidl.h>
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
# pragma comment(lib, "wbemuuid.lib")
|
||||
|
||||
uint64 GetVidMemBytes( void )
|
||||
{
|
||||
static int bBeenHere = false;
|
||||
static uint64 nBytes = 0;
|
||||
|
||||
if( bBeenHere )
|
||||
{
|
||||
return nBytes;
|
||||
}
|
||||
|
||||
bBeenHere = true;
|
||||
|
||||
// Initialize COM
|
||||
HRESULT hr = CoInitialize( NULL );
|
||||
if ( FAILED( hr ) )
|
||||
{
|
||||
OutputDebugString ( "GetWMIDeviceStats - Unable to initialize COM library.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Obtain the initial locator to WMI
|
||||
IWbemLocator *pLoc = NULL;
|
||||
|
||||
hr = CoCreateInstance(
|
||||
CLSID_WbemLocator,
|
||||
0,
|
||||
CLSCTX_INPROC_SERVER,
|
||||
IID_IWbemLocator, (LPVOID *) &pLoc);
|
||||
|
||||
if ( FAILED( hr ) )
|
||||
{
|
||||
OutputDebugString ( "GetWMIDeviceStats - Failed to create IWbemLocator object.\n");
|
||||
CoUninitialize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Connect to WMI through the IWbemLocator::ConnectServer method
|
||||
|
||||
IWbemServices *pSvc = NULL;
|
||||
|
||||
// Connect to the root\cimv2 namespace with
|
||||
// the current user and obtain pointer pSvc
|
||||
// to make IWbemServices calls.
|
||||
hr = pLoc->ConnectServer(
|
||||
_bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace
|
||||
NULL, // User name. NULL = current user
|
||||
NULL, // User password. NULL = current
|
||||
0, // Locale. NULL indicates current
|
||||
NULL, // Security flags.
|
||||
0, // Authority (e.g. Kerberos)
|
||||
0, // Context object
|
||||
&pSvc // pointer to IWbemServices proxy
|
||||
);
|
||||
|
||||
if ( FAILED( hr ) )
|
||||
{
|
||||
OutputDebugString ( "GetWMIDeviceStats - Could not connect.\n");
|
||||
pLoc->Release();
|
||||
CoUninitialize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// OutputDebugString ( L"GetWMIDeviceStats - Connected to ROOT\\CIMV2 WMI namespace\n");
|
||||
|
||||
|
||||
// Set security levels on the proxy
|
||||
|
||||
hr = CoSetProxyBlanket(
|
||||
pSvc, // Indicates the proxy to set
|
||||
RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx
|
||||
RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx
|
||||
NULL, // Server principal name
|
||||
RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx
|
||||
RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
|
||||
NULL, // client identity
|
||||
EOAC_NONE // proxy capabilities
|
||||
);
|
||||
|
||||
if ( FAILED( hr ) )
|
||||
{
|
||||
OutputDebugString ( "GetWMIDeviceStats - Could not set proxy blanket.\n");
|
||||
pSvc->Release();
|
||||
pLoc->Release();
|
||||
CoUninitialize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Use the IWbemServices pointer to make requests of WMI
|
||||
|
||||
//
|
||||
// --- Win32_VideoController --------------------------------------------------
|
||||
//
|
||||
|
||||
IEnumWbemClassObject* pEnumerator = NULL;
|
||||
hr = pSvc->ExecQuery( bstr_t("WQL"), bstr_t("SELECT * FROM Win32_VideoController"),
|
||||
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
|
||||
|
||||
if ( FAILED( hr ) )
|
||||
{
|
||||
OutputDebugString ( "GetWMIDeviceStats - Query for Win32_VideoController failed.\n");
|
||||
|
||||
pSvc->Release();
|
||||
pLoc->Release();
|
||||
CoUninitialize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Get the data from the above query
|
||||
IWbemClassObject *pclsObj = NULL;
|
||||
ULONG uReturn = 0;
|
||||
|
||||
while ( pEnumerator )
|
||||
{
|
||||
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
|
||||
|
||||
if(0 == uReturn)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
VARIANT vtProp;
|
||||
VariantInit(&vtProp);
|
||||
|
||||
// Pluck a series of properties out of the query from Win32_VideoController
|
||||
|
||||
// hr = pclsObj->Get(L"Description", 0, &vtProp, 0, 0); // Basically the same as "VideoProcessor"
|
||||
// if ( SUCCEEDED( hr ) )
|
||||
// {
|
||||
// wsprintf( pAdapter->m_szPrimaryAdapterDescription, vtProp.bstrVal );
|
||||
// }
|
||||
|
||||
hr = pclsObj->Get(L"AdapterRAM", 0, &vtProp, 0, 0);
|
||||
if ( SUCCEEDED( hr ) )
|
||||
{
|
||||
nBytes = vtProp.ulVal; // Video RAM in bytes, AdatperRam is returned as the I4 type so we read it out as unsigned int,
|
||||
// see http://msdn.microsoft.com/en-us/library/windows/desktop/aa394512(v=vs.85).aspx
|
||||
}
|
||||
|
||||
VariantClear(&vtProp);
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
pSvc->Release();
|
||||
pLoc->Release();
|
||||
pEnumerator->Release();
|
||||
if ( pclsObj )
|
||||
{
|
||||
pclsObj->Release();
|
||||
}
|
||||
CoUninitialize();
|
||||
|
||||
return nBytes;
|
||||
}
|
||||
17
materialsystem/shaderapidx9/wmi.h
Normal file
17
materialsystem/shaderapidx9/wmi.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef WMI_H
|
||||
#define WMI_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
uint64 GetVidMemBytes( void );
|
||||
|
||||
|
||||
#endif // WMI_H
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -25,6 +25,7 @@ $Group "game"
|
||||
"engine"
|
||||
"materialsystem"
|
||||
"studiorender"
|
||||
"shaderapidx9"
|
||||
"filesystem_stdio"
|
||||
"filesystem_steam"
|
||||
"vpklib"
|
||||
@@ -36,6 +37,7 @@ $Group "game"
|
||||
$Group "shaders"
|
||||
{
|
||||
"game_shader_dx9"
|
||||
"shaderapidx9"
|
||||
}
|
||||
|
||||
$Group "everything"
|
||||
@@ -53,6 +55,7 @@ $Group "everything"
|
||||
"qc_eyes"
|
||||
"server"
|
||||
"serverplugin_empty"
|
||||
"shaderapidx9"
|
||||
"tgadiff"
|
||||
"tier1"
|
||||
"vbsp"
|
||||
|
||||
@@ -80,6 +80,11 @@ $Project "serverplugin_empty"
|
||||
"utils\serverplugin_sample\serverplugin_empty.vpc" [$WIN32||$POSIX]
|
||||
}
|
||||
|
||||
$Project "shaderapidx9"
|
||||
{
|
||||
"materialsystem\shaderapidx9\shaderapidx9.vpc"
|
||||
}
|
||||
|
||||
$Project "tgadiff"
|
||||
{
|
||||
"utils\tgadiff\tgadiff.vpc" [$WIN32]
|
||||
|
||||
Reference in New Issue
Block a user