Skip to content

Commit

Permalink
Merge pull request H-uru#1512 from dgelessus/pipelines_and_profiler_s…
Browse files Browse the repository at this point in the history
…t_string

Migrate pipelines and profiling code to `ST::string`
  • Loading branch information
Hoikas authored Mar 30, 2024
2 parents 21c036c + 924070e commit 629152d
Show file tree
Hide file tree
Showing 47 changed files with 429 additions and 515 deletions.
14 changes: 6 additions & 8 deletions Sources/Plasma/Apps/plClient/plClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,19 +495,17 @@ bool plClient::InitPipeline(hsWindowHndl display, uint32_t devType)
}

plPipeline *pipe = ICreatePipeline(display, fWindowHndl, &dmr);
if (pipe->GetErrorString() != nullptr)
{
if (!pipe->GetErrorString().empty()) {
ISetGraphicsDefaults();
#ifdef PLASMA_EXTERNAL_RELEASE
hsMessageBox(ST_LITERAL("There was an error initializing the video card.\nSetting defaults."), ST_LITERAL("Error"), hsMessageBoxNormal);
#else
hsMessageBox(ST::string(pipe->GetErrorString()), ST_LITERAL("Error creating pipeline"), hsMessageBoxNormal);
hsMessageBox(pipe->GetErrorString(), ST_LITERAL("Error creating pipeline"), hsMessageBoxNormal);
#endif
delete pipe;
devSel.GetDefault(&dmr);
pipe = ICreatePipeline(display, fWindowHndl, &dmr);
if (pipe->GetErrorString() != nullptr)
{
if (!pipe->GetErrorString().empty()) {
// not much else we can do
return true;
}
Expand Down Expand Up @@ -1617,7 +1615,7 @@ bool plClient::IUpdate()
plgDispatch::MsgSend(eval);
plProfile_EndTiming(EvalMsg);

const char *xFormLap1 = "Main";
const ST::string xFormLap1 = ST_LITERAL("Main");
plProfile_BeginLap(TransformMsg, xFormLap1);
plTransformMsg* xform = new plTransformMsg(nullptr, nullptr, nullptr, nullptr);
plgDispatch::MsgSend(xform);
Expand All @@ -1635,15 +1633,15 @@ bool plClient::IUpdate()
// At this point, we just register for a plDelayedTransformMsg when dirtied.
if (!plCoordinateInterface::GetDelayedTransformsEnabled())
{
const char *xFormLap2 = "Simulation";
const ST::string xFormLap2 = ST_LITERAL("Simulation");
plProfile_BeginLap(TransformMsg, xFormLap2);
xform = new plTransformMsg(nullptr, nullptr, nullptr, nullptr);
plgDispatch::MsgSend(xform);
plProfile_EndLap(TransformMsg, xFormLap2);
}
else
{
const char *xFormLap3 = "Delayed";
const ST::string xFormLap3 = ST_LITERAL("Delayed");
plProfile_BeginLap(TransformMsg, xFormLap3);
xform = new plDelayedTransformMsg(nullptr, nullptr, nullptr, nullptr);
plgDispatch::MsgSend(xform);
Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/FeatureLib/pfAnimation/plFollowMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ bool plFollowMod::MsgReceive(plMessage* msg)
plRenderMsg* rend = plRenderMsg::ConvertNoRef(msg);
if( rend )
{
plProfile_BeginLap(FollowMod, this->GetKey()->GetUoid().GetObjectName().c_str());
plProfile_BeginLap(FollowMod, this->GetKey()->GetUoid().GetObjectName());
fLeaderL2W = rend->Pipeline()->GetCameraToWorld();
fLeaderW2L = rend->Pipeline()->GetWorldToCamera();
fLeaderSet = true;
plProfile_EndLap(FollowMod, this->GetKey()->GetUoid().GetObjectName().c_str());
plProfile_EndLap(FollowMod, this->GetKey()->GetUoid().GetObjectName());
return true;
}
plListenerMsg* list = plListenerMsg::ConvertNoRef(msg);
Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/FeatureLib/pfAnimation/plLineFollowMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ bool plLineFollowMod::MsgReceive(plMessage* msg)
plRenderMsg* rend = plRenderMsg::ConvertNoRef(msg);
if( rend )
{
plProfile_BeginLap(LineFollow, this->GetKey()->GetUoid().GetObjectName().c_str());
plProfile_BeginLap(LineFollow, this->GetKey()->GetUoid().GetObjectName());
hsPoint3 oldPos = fSearchPos;
fSearchPos = rend->Pipeline()->GetViewPositionWorld();
ICheckForPop(oldPos, fSearchPos);
plProfile_EndLap(LineFollow, this->GetKey()->GetUoid().GetObjectName().c_str());
plProfile_EndLap(LineFollow, this->GetKey()->GetUoid().GetObjectName());
return true;
}
plListenerMsg* list = plListenerMsg::ConvertNoRef(msg);
Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/FeatureLib/pfAnimation/plViewFaceModifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ bool plViewFaceModifier::MsgReceive(plMessage* msg)

if( rend )
{
plProfile_BeginLap(ViewFace, this->GetKey()->GetUoid().GetObjectName().c_str());
plProfile_BeginLap(ViewFace, this->GetKey()->GetUoid().GetObjectName());

if( HasFlag(kFaceCam) )
{
Expand Down Expand Up @@ -310,7 +310,7 @@ bool plViewFaceModifier::MsgReceive(plMessage* msg)

IFacePoint(rend->Pipeline(), fFacePoint);

plProfile_EndLap(ViewFace, this->GetKey()->GetUoid().GetObjectName().c_str());
plProfile_EndLap(ViewFace, this->GetKey()->GetUoid().GetObjectName());
return true;
}
plArmatureUpdateMsg* armMsg = plArmatureUpdateMsg::ConvertNoRef(msg);
Expand Down
31 changes: 11 additions & 20 deletions Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,12 @@ PF_CONSOLE_CMD( Stats, Show, // Group name, Function name
"Shows or hides a given category of statistics.\n"
"List the valid categories using Stats.ListGroups")
{
const ST::string& group = numParams > 0 ? params[0] : ST::string();

if (numParams > 1) {
const ST::string& stat = params[1];
plProfileManagerFull::Instance().ShowLaps(group.c_str(), stat.c_str());
plProfileManagerFull::Instance().ShowLaps(params[0], params[1]);
} else if (numParams > 0) {
plProfileManagerFull::Instance().ShowGroup(params[0]);
} else {
plProfileManagerFull::Instance().ShowGroup(group.c_str());
plProfileManagerFull::Instance().ShowGroup(ST_LITERAL("General"));
}
}

Expand All @@ -506,9 +505,7 @@ PF_CONSOLE_CMD(Stats, ShowLaps,
"string group, string stat",
"")
{
const ST::string& group = params[0];
const ST::string& stat = params[1];
plProfileManagerFull::Instance().ShowLaps(group.c_str(), stat.c_str());
plProfileManagerFull::Instance().ShowLaps(params[0], params[1]);
}

PF_CONSOLE_CMD(Stats, ListGroups, "", "Prints the names of all the stat groups to the console")
Expand Down Expand Up @@ -554,8 +551,7 @@ PF_CONSOLE_CMD(Stats, SetAvgTime, "int ms", "Sets the amount of time stats are a

PF_CONSOLE_CMD(Stats, Graph, "string stat, int min, int max", "Graphs the specified stat")
{
const ST::string& stat = params[0];
plProfileManagerFull::Instance().CreateGraph(stat.c_str(), (int)params[1], (int)params[2]);
plProfileManagerFull::Instance().CreateGraph(params[0], (int)params[1], (int)params[2]);
}

PF_CONSOLE_CMD(Stats, ShowDetail, "", "Shows the detail stat graph")
Expand All @@ -575,36 +571,31 @@ PF_CONSOLE_CMD(Stats, ResetDetailDefaults, "", "Resets the detail graph's defaul

PF_CONSOLE_CMD(Stats, AddDetailVar, "string stat", "Adds the specified var to the detail graph with the default range of 0->100")
{
const ST::string& stat = params[0];
plProfileManagerFull::Instance().AddDetailVar(stat.c_str(), 0, 100);
plProfileManagerFull::Instance().AddDetailVar(params[0], 0, 100);
}

PF_CONSOLE_CMD(Stats, AddDetailVarWithOffset, "string stat, int offset", "Adds the specified var to the detail graph with a offset and default range\n"
"of 0->(100-offset)")
{
const ST::string& stat = params[0];
int offset = (int)params[1];
plProfileManagerFull::Instance().AddDetailVar(stat.c_str(), -offset, 100-offset);
plProfileManagerFull::Instance().AddDetailVar(params[0], -offset, 100-offset);
}

PF_CONSOLE_CMD(Stats, AddDetailVarWithRange, "string stat, int min, int max", "Adds the specified var to the detail graph")
{
const ST::string& stat = params[0];
plProfileManagerFull::Instance().AddDetailVar(stat.c_str(), (int)params[1], (int)params[2]);
plProfileManagerFull::Instance().AddDetailVar(params[0], (int)params[1], (int)params[2]);
}

PF_CONSOLE_CMD(Stats, AddDetailVarWithOffsetAndRange, "string stat, int offset, int min, int max", "Adds the specified var to the detail graph with an\n"
"offset and a range of min->(max-offset)")
{
const ST::string& stat = params[0];
int offset = (int)params[1];
plProfileManagerFull::Instance().AddDetailVar(stat.c_str(), (int)params[2]-offset, (int)params[3]-offset);
plProfileManagerFull::Instance().AddDetailVar(params[0], (int)params[2]-offset, (int)params[3]-offset);
}

PF_CONSOLE_CMD(Stats, RemoveDetailVar, "string stat", "Removes the specified var from the detail graph")
{
const ST::string& stat = params[0];
plProfileManagerFull::Instance().RemoveDetailVar(stat.c_str());
plProfileManagerFull::Instance().RemoveDetailVar(params[0]);
}


Expand Down
6 changes: 4 additions & 2 deletions Sources/Plasma/FeatureLib/pfDXPipeline/plDXDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include "plDXVertexShader.h"
#include "plDXPixelShader.h"

#include <string_theory/string>

//// Macros for D3D error handling
#define INIT_ERROR_CHECK( cond, errMsg ) if( FAILED( fPipeline->fSettings.fDXError = cond ) ) { return fPipeline->ICreateFail( errMsg ); }
#define INIT_ERROR_CHECK(cond, errMsg) if (FAILED(fSettings.fDXError = cond)) { return ICreateFail(ST_LITERAL(errMsg)); }

#if 1 // DEBUG
#define STRONG_ERROR_CHECK( cond ) if( FAILED( fPipeline->fSettings.fDXError = cond ) ) { fPipeline->IGetD3DError(); fPipeline->IShowErrorMessage(); }
Expand Down Expand Up @@ -189,7 +191,7 @@ void plDXDevice::SetLocalToWorldMatrix(const hsMatrix44& src)
fD3DDevice->SetTransform(D3DTS_WORLD, &mat);
}

const char* plDXDevice::GetErrorString() const
ST::string plDXDevice::GetErrorString() const
{
return fPipeline->fSettings.fErrorStr;
}
3 changes: 2 additions & 1 deletion Sources/Plasma/FeatureLib/pfDXPipeline/plDXDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class plDXPipeline;
class plRenderTarget;
struct IDirect3DDevice9;
struct IDirect3DSurface9;
namespace ST { class string; }

class plDXDevice
{
Expand Down Expand Up @@ -98,7 +99,7 @@ class plDXDevice
void SetWorldToCameraMatrix(const hsMatrix44& src);
void SetLocalToWorldMatrix(const hsMatrix44& src);

const char* GetErrorString() const;
ST::string GetErrorString() const;
};

#endif
6 changes: 3 additions & 3 deletions Sources/Plasma/FeatureLib/pfDXPipeline/plDXDeviceRefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void plDXVertexBufferRef::Release()
if (!Volatile())
{
plProfile_DelMem(MemVertex, fCount * fVertexSize);
PROFILE_POOL_MEM(D3DPOOL_MANAGED, fCount * fVertexSize, false, "VtxBuff");
PROFILE_POOL_MEM(D3DPOOL_MANAGED, fCount * fVertexSize, false, ST_LITERAL("VtxBuff"));
plDXPipeline::FreeManagedVertex(fCount * fVertexSize);
}
}
Expand All @@ -159,7 +159,7 @@ void plDXIndexBufferRef::Release()
if (fD3DBuffer != nullptr)
{
plProfile_DelMem(MemIndex, fCount * sizeof(uint16_t));
PROFILE_POOL_MEM(fPoolType, fCount * sizeof(uint16_t), false, "IndexBuff");
PROFILE_POOL_MEM(fPoolType, fCount * sizeof(uint16_t), false, ST_LITERAL("IndexBuff"));
ReleaseObject( fD3DBuffer );
}

Expand Down Expand Up @@ -221,7 +221,7 @@ void plDXTextureRef::Release()
{
plProfile_DelMem(MemTexture, fDataSize + sizeof(plDXTextureRef));
plProfile_Extern(ManagedMem);
PROFILE_POOL_MEM(D3DPOOL_MANAGED, fDataSize, false, (fOwner ? fOwner->GetKey() ? fOwner->GetKey()->GetUoid().GetObjectName().c_str() : "(UnknownTexture)" : "(UnknownTexture)"));
PROFILE_POOL_MEM(D3DPOOL_MANAGED, fDataSize, false, fOwner && fOwner->GetKey() ? fOwner->GetKey()->GetUoid().GetObjectName() : ST_LITERAL("(UnknownTexture)"));
plDXPipeline::FreeManagedTexture(fDataSize);
fDataSize = 0;

Expand Down
55 changes: 21 additions & 34 deletions Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,17 @@ bool hsGDirect3DTnLEnumerate::SelectFromDevMode(const hsG3DDeviceRecord* devRec,
D3DEnum_SelectDefaultDisplay(0);
if( !GetCurrentDisplay() || !GetCurrentRenderer() )
{
if( !*GetEnumeErrorStr() )
SetEnumeErrorStr("Error finding device");
if (GetEnumeErrorStr().empty()) {
fEnumeErrorStr = ST_LITERAL("Error finding device");
}
return true;
}
D3DEnum_SelectDefaultMode(width, height, colorDepth);
if( !GetCurrentMode() )
{
if( !*GetEnumeErrorStr() )
SetEnumeErrorStr("Error finding mode");
if (GetEnumeErrorStr().empty()) {
fEnumeErrorStr = ST_LITERAL("Error finding mode");
}
return true;
}

Expand Down Expand Up @@ -260,16 +262,14 @@ HRESULT hsGDirect3DTnLEnumerate::D3DEnum_SelectDefaultDisplay( DWORD dwFlags )

hsGDirect3DTnLEnumerate::hsGDirect3DTnLEnumerate()
{
memset( &fEnumeErrorStr[0], 0x00, sizeof(fEnumeErrorStr) );

fCurrentDisplay = nullptr; // The selected DD driver
fDisplays.clear(); // List of DD drivers

// Create a D3D object to use
IDirect3D9* pD3D = hsGDirect3D::GetDirect3D();
if (!pD3D)
{
strcpy( fEnumeErrorStr, "Cannot load DirectX!" );
fEnumeErrorStr = ST_LITERAL("Cannot load DirectX!");
return;
}

Expand All @@ -285,8 +285,8 @@ hsGDirect3DTnLEnumerate::hsGDirect3DTnLEnumerate()
pD3D->GetAdapterDisplayMode(iAdapter, &newDriver.fDesktopMode);

newDriver.fAdapterInfo = adapterInfo;
strncpy(newDriver.fStrName, adapterInfo.Driver, 39);
strncpy(newDriver.fStrDesc, adapterInfo.Description, 39);
newDriver.fStrName = ST::string::from_latin_1(adapterInfo.Driver);
newDriver.fStrDesc = ST::string::from_latin_1(adapterInfo.Description);
newDriver.fGuid = adapterInfo.DeviceIdentifier;
newDriver.fMemory = 16 * 1024 * 1024; /// Simulate 16 MB

Expand All @@ -307,7 +307,7 @@ void hsGDirect3DTnLEnumerate::IEnumAdapterDevices( IDirect3D9 *pD3D, UINT iAd
// Then we can enum through the modes for each format.

const DWORD numDeviceTypes = 2;
const TCHAR* strDeviceDescs[] = { "HAL", "REF" };
const ST::string strDeviceDescs[] = {ST_LITERAL("HAL"), ST_LITERAL("REF")};
const D3DDEVTYPE deviceTypes[] = { D3DDEVTYPE_HAL, D3DDEVTYPE_REF };

BOOL *formatWorks = new BOOL[kNumDisplayFormats + 1]; // One for each format
Expand All @@ -318,7 +318,7 @@ void hsGDirect3DTnLEnumerate::IEnumAdapterDevices( IDirect3D9 *pD3D, UINT iAd
D3DEnum_RendererInfo& deviceInfo = drivInfo->fRenderers.emplace_back();

pD3D->GetDeviceCaps(iAdapter, deviceTypes[iDevice], &deviceInfo.fDDCaps);
strncpy(deviceInfo.fStrName, strDeviceDescs[iDevice], 39);
deviceInfo.fStrName = strDeviceDescs[iDevice];
deviceInfo.fDDType = deviceTypes[iDevice];
deviceInfo.fIsHardware = deviceInfo.fDDCaps.DevCaps & D3DDEVCAPS_HWRASTERIZATION;

Expand Down Expand Up @@ -408,7 +408,7 @@ void hsGDirect3DTnLEnumerate::IEnumAdapterDevices( IDirect3D9 *pD3D, UINT iAd
/// Add it to our driver's global mode list
D3DEnum_ModeInfo& modeInfo = drivInfo->fModes.emplace_back();
modeInfo.fDDmode = dispMode;
sprintf(modeInfo.fStrDesc, TEXT("%ld x %ld x %ld"), dispMode.Width, dispMode.Height, bitDepth);
modeInfo.fStrDesc = ST::format("{} x {} x {}", dispMode.Width, dispMode.Height, bitDepth);
modeInfo.fBitDepth = bitDepth;

// Add it to the device
Expand All @@ -434,7 +434,7 @@ void hsGDirect3DTnLEnumerate::IEnumAdapterDevices( IDirect3D9 *pD3D, UINT iAd
pModeInfo.fDDmode = dispMode;
pModeInfo.fDDBehavior = behavior[iFormat];
pModeInfo.fBitDepth = bitDepth;
sprintf(pModeInfo.fStrDesc, TEXT("Windowed"));
pModeInfo.fStrDesc = ST_LITERAL("Windowed");
pModeInfo.fWindowed = true;

IFindDepthFormats(pD3D, iAdapter, deviceInfo.fDDType, &pModeInfo);
Expand Down Expand Up @@ -556,15 +556,6 @@ VOID hsGDirect3DTnLEnumerate::D3DEnum_FreeResources()
{
}

//-----------------------------------------------------------------------------
// Name: SetEnumeErrorStr()
// Desc:
//-----------------------------------------------------------------------------
void hsGDirect3DTnLEnumerate::SetEnumeErrorStr(const char* s)
{
hsStrncpy(fEnumeErrorStr, s, 128);
}

//// IGetDXBitDepth //////////////////////////////////////////////////////////
//
// From a D3DFORMAT enumeration, return the bit depth associated with it.
Expand Down Expand Up @@ -602,7 +593,7 @@ bool hsG3DDeviceSelector::IGetD3DCardInfo( hsG3DDeviceRecord &record,
void *driverInfo,
void *deviceInfo,
uint32_t *vendorID, uint32_t *deviceID, // Out
char **driverString, char **descString )
ST::string& driverString, ST::string& descString)
{
D3DEnum_DisplayInfo *driverD3DInfo = (D3DEnum_DisplayInfo *)driverInfo;
D3DEnum_RendererInfo *deviceD3DInfo = (D3DEnum_RendererInfo *)deviceInfo;
Expand All @@ -613,8 +604,8 @@ bool hsG3DDeviceSelector::IGetD3DCardInfo( hsG3DDeviceRecord &record,

*vendorID = adapterInfo->VendorId;
*deviceID = adapterInfo->DeviceId;
*driverString = adapterInfo->Driver;
*descString = adapterInfo->Description;
driverString = ST::string::from_latin_1(adapterInfo->Driver);
descString = ST::string::from_latin_1(adapterInfo->Description);

return true;
}
Expand Down Expand Up @@ -644,15 +635,11 @@ void hsG3DDeviceSelector::ITryDirect3DTnLDriver(D3DEnum_DisplayInfo* drivInfo)
devRec.SetDriverName( drivInfo->fAdapterInfo.Driver );
devRec.SetDriverDesc( drivInfo->fAdapterInfo.Description );

char buff[ 256 ];
sprintf( buff, "%d.%02d.%02d.%04d",
HIWORD( drivInfo->fAdapterInfo.DriverVersion.u.HighPart ),
LOWORD( drivInfo->fAdapterInfo.DriverVersion.u.HighPart ),
HIWORD( drivInfo->fAdapterInfo.DriverVersion.u.LowPart ),
LOWORD( drivInfo->fAdapterInfo.DriverVersion.u.LowPart ) );


devRec.SetDriverVersion(buff);
devRec.SetDriverVersion(ST::format("{}.{02d}.{02d}.{04d}",
HIWORD(drivInfo->fAdapterInfo.DriverVersion.u.HighPart),
LOWORD(drivInfo->fAdapterInfo.DriverVersion.u.HighPart),
HIWORD(drivInfo->fAdapterInfo.DriverVersion.u.LowPart),
LOWORD(drivInfo->fAdapterInfo.DriverVersion.u.LowPart)));

devRec.SetMemoryBytes(drivInfo->fMemory);

Expand Down
Loading

0 comments on commit 629152d

Please sign in to comment.