MaterialSystem: correctly define 'CMaterialGlue'

Remove structure packing (not needed), and properly lay it out. The material glue class is a wrapper around the actual material struct, which is what has been seperated out in this path.

The material struct also contains more newly reversed members.
This commit is contained in:
Kawe Mazidjatari 2025-01-07 01:53:01 +01:00
parent 4445edac6d
commit 37e3c8c653
4 changed files with 119 additions and 97 deletions

View File

@ -287,50 +287,48 @@ Mat_CrossHair_f
Print the material under the crosshair. Print the material under the crosshair.
===================== =====================
*/ */
static void PrintChildMat(const CMaterialGlue* const materialGlue, const char* const text)
{
Msg(eDLL_T::MS, " |-+\n");
Msg(eDLL_T::MS, " | |-+ Child material ----------------------------------------\n");
Msg(eDLL_T::MS, text, materialGlue);
if (materialGlue)
{
const MaterialGlue_s* const material = materialGlue->Get();
Msg(eDLL_T::MS, " | |-- Pak GUID: '%llX'\n", material->guid);
Msg(eDLL_T::MS, " | |-- Material name: '%s'\n", material->name);
}
}
void Mat_CrossHair_f(const CCommand& args) void Mat_CrossHair_f(const CCommand& args)
{ {
CMaterialGlue* material = v_GetMaterialAtCrossHair(); const CMaterialGlue* const materialGlue = v_GetMaterialAtCrossHair();
const MaterialGlue_s* const material = materialGlue->Get();
if (material) if (material)
{ {
Msg(eDLL_T::MS, "______________________________________________________________\n"); Msg(eDLL_T::MS, "______________________________________________________________\n");
Msg(eDLL_T::MS, "-+ Material --------------------------------------------------\n"); Msg(eDLL_T::MS, "-+ Material --------------------------------------------------\n");
Msg(eDLL_T::MS, " |-- ADDR: '%llX'\n", material); Msg(eDLL_T::MS, " |-- Address: '%llX'\n", material);
Msg(eDLL_T::MS, " |-- GUID: '%llX'\n", material->assetGuid); Msg(eDLL_T::MS, " |-- Pak GUID: '%llX'\n", material->guid);
Msg(eDLL_T::MS, " |-- Num Streaming Textures: '%d'\n", material->numStreamingTextureHandles); Msg(eDLL_T::MS, " |-- Samplers: '%08X'\n", *(uint32*)material->samplers);
Msg(eDLL_T::MS, " |-- Material width: '%d'\n", material->width); Msg(eDLL_T::MS, " |-- Streaming handles: '%hu'\n", material->streamingTextureHandleCount);
Msg(eDLL_T::MS, " |-- Material height: '%d'\n", material->height); Msg(eDLL_T::MS, " |-- Material width: '%hu'\n", material->width);
Msg(eDLL_T::MS, " |-- Samplers: '%08X'\n", material->samplers); Msg(eDLL_T::MS, " |-- Material height: '%hu'\n", material->height);
std::function<void(CMaterialGlue*, const char*)> fnPrintChild = [](CMaterialGlue* material, const char* print)
{
Msg(eDLL_T::MS, " |-+\n");
Msg(eDLL_T::MS, " | |-+ Child material ----------------------------------------\n");
Msg(eDLL_T::MS, print, material);
Msg(eDLL_T::MS, " | |-- GUID: '%llX'\n", material->assetGuid);
Msg(eDLL_T::MS, " | |-- Material name: '%s'\n", material->name);
};
Msg(eDLL_T::MS, " |-- Material name: '%s'\n", material->name); Msg(eDLL_T::MS, " |-- Material name: '%s'\n", material->name);
Msg(eDLL_T::MS, " |-- Material surface name 1: '%s'\n", material->surfaceProp); Msg(eDLL_T::MS, " |-- Material surface name 1: '%s'\n", material->surfaceProp);
Msg(eDLL_T::MS, " |-- Material surface name 2: '%s'\n", material->surfaceProp2); Msg(eDLL_T::MS, " |-- Material surface name 2: '%s'\n", material->surfaceProp2);
Msg(eDLL_T::MS, " |-- DX buffer: '%llX'\n", material->dxBuffer); Msg(eDLL_T::MS, " |-- Uber buffer: '%llX'\n", material->uberBuffer);
Msg(eDLL_T::MS, " |-- DX buffer VFTable: '%llX'\n", material->unkD3DPointer); Msg(eDLL_T::MS, " |-- View buffer: '%llX'\n", material->viewBuffer);
material->depthShadowMaterial PrintChildMat(material->depthMaterials[DEPTH_SHADOW], " | |-+ Depth shadow: '%llX'\n");
? fnPrintChild(material->depthShadowMaterial, " | |-+ DepthShadow: '%llX'\n") PrintChildMat(material->depthMaterials[DEPTH_PREPASS], " | |-+ Depth prepass: '%llX'\n");
: Msg(eDLL_T::MS, " | |-+ DepthShadow: 'NULL'\n"); PrintChildMat(material->depthMaterials[DEPTH_VSM], " | |-+ Depth VSM: '%llX'\n");
material->depthPrepassMaterial PrintChildMat(material->depthMaterials[DEPTH_SHADOW_TIGHT], " | |-+ Depth shadow tight: '%llX'\n");
? fnPrintChild(material->depthPrepassMaterial, " | |-+ DepthPrepass: '%llX'\n") PrintChildMat(material->colpassMaterial, " | |-+ Color pass: '%llX'\n");
: Msg(eDLL_T::MS, " | |-+ DepthPrepass: 'NULL'\n");
material->depthVSMMaterial
? fnPrintChild(material->depthVSMMaterial, " | |-+ DepthVSM: '%llX'\n")
: Msg(eDLL_T::MS, " | |-+ DepthVSM: 'NULL'\n");
material->depthShadowTightMaterial
? fnPrintChild(material->depthShadowTightMaterial, " | |-+ DepthShadowTight: '%llX'\n")
: Msg(eDLL_T::MS, " | |-+ DepthShadowTight: 'NULL'\n");
material->colpassMaterial
? fnPrintChild(material->colpassMaterial, " | |-+ ColPass: '%llX'\n")
: Msg(eDLL_T::MS, " | |-+ ColPass: 'NULL'\n");
Msg(eDLL_T::MS, "-+ Texture GUID map ------------------------------------------\n"); Msg(eDLL_T::MS, "-+ Texture GUID map ------------------------------------------\n");
Msg(eDLL_T::MS, " |-- Texture handles: '%llX'\n", material->textureHandles); Msg(eDLL_T::MS, " |-- Texture handles: '%llX'\n", material->textureHandles);

View File

@ -6,67 +6,88 @@
#include "public/rendersystem/schema/texture.g.h" #include "public/rendersystem/schema/texture.g.h"
#define MATERIAL_RENDER_PARAMS_COUNT 2 // the same for r2 and r5 #define MATERIAL_RENDER_PARAMS_COUNT 2 // the same for r2 and r5
#define MATERIAL_SAMPLER_COUNT 4
class CMaterialGlue;
enum MaterialDepthPass_e
{
DEPTH_SHADOW,
DEPTH_PREPASS,
DEPTH_VSM,
DEPTH_SHADOW_TIGHT,
MATERIAL_DEPTH_PASS_MAT_COUNT,
};
// Virtual function-less material instance.
struct MaterialGlue_s
{
PakGuid_t guid;
const char* name;
const char* surfaceProp;
const char* surfaceProp2;
CMaterialGlue* depthMaterials[MATERIAL_DEPTH_PASS_MAT_COUNT];
CMaterialGlue* colpassMaterial;
CShaderGlue* shaderset;
TextureAsset_s** textureHandles;
TextureAsset_s** streamingTextureHandles;
uint16 streamingTextureHandleCount;
uint16 width;
uint16 height;
uint16 depth;
// An array of indices into sampler states array. must be set properly to
// have accurate texture tiling. Used in CShaderGlue::SetupShader (1403B3C60)
byte samplers[MATERIAL_SAMPLER_COUNT];// example: 0x1D0300;
uint32 unk_7C;
// some features? mostly differs per material with different shader types, but
// it seems mostly unused by the runtime too.
uint32 unk_80_0x1F5A92BD;
uint32 unk_84;
uint32 materialFlags;
uint32 materialFlags2;
MaterialRenderParams_s renderParams[MATERIAL_RENDER_PARAMS_COUNT];
uint32 numAnimationFrames;
MaterialShaderType_e materialType;
uint8 uberBufferFlags;
int dwordf4;
void* textureAnim;
ID3D11Buffer* uberBuffer;
void** pID3D11BufferVTable;
void* viewBuffer;
// Last frame this material was used to shift the texture streaming histogram.
uint32 lastFrame;
uint16 m_iUnknown4;
uint16 m_iUnknown5;
uint16 m_iUnknown6;
};
#pragma pack(push, 1)
class CMaterialGlue : public IMaterialInternal class CMaterialGlue : public IMaterialInternal
{ {
public: public:
uint8_t pad_0008[8]; //0x0008 inline const MaterialGlue_s* Get() const { return &material; }
uint64_t assetGuid; //0x0010 inline MaterialGlue_s* Get() { return &material; }
const char* name; //0x0018
const char* surfaceProp; //0x0020 private:
const char* surfaceProp2; //0x0028 byte reserved[8];
MaterialGlue_s material;
CMaterialGlue* depthShadowMaterial; //0x0030
CMaterialGlue* depthPrepassMaterial; //0x0038
CMaterialGlue* depthVSMMaterial; //0x0040
CMaterialGlue* depthShadowTightMaterial; //0x0048
CMaterialGlue* colpassMaterial; //0x0050
CShaderGlue* shaderset; //0x0058
TextureAsset_s** textureHandles; //0x0060
TextureAsset_s** streamingTextureHandles; //0x0068
int16_t numStreamingTextureHandles; //0x0070
int16_t width; //0x0072
int16_t height; //0x0074
int16_t depth; //0x0076
uint32_t samplers; //0x0078
char padding_7C[4]; //0x007C
uint32_t unk_80;
uint32_t unk_84;
uint64_t flags; // 0x0088
MaterialRenderParams_s renderParams[MATERIAL_RENDER_PARAMS_COUNT];
uint16_t numAnimationFrames; // used in CMaterialGlue::GetNumAnimationFrames (0x1403B4250), which is called from GetSpriteInfo @ 0x1402561FC
uint8_t materialType;
uint8_t bytef3;
char padding_F4[4];
void* textureAnim;
void** dxBuffer;
void** unkD3DPointer; // was m_pID3D11BufferVTable
void* viewsBuffer;
uint32_t unknown3; //0x0118
uint16_t unknown4; //0x011C
uint16_t unknown5; //0x011E
uint16_t unknown6; //0x0120
uint64_t unknown7; //0x0122
uint32_t unknown8; //0x012A
uint16_t unknown9; //0x012E
}; //Size: 0x0130 confirmed end size. }; //Size: 0x0130 confirmed end size.
static_assert(sizeof(CMaterialGlue) == 0x130); static_assert(sizeof(CMaterialGlue) == 0x130);
#pragma pack(pop)
#endif // !DEDICATED #endif // !DEDICATED
inline void* g_pMaterialGlueVFTable = nullptr; inline void* g_pMaterialGlueVFTable = nullptr;

View File

@ -13,7 +13,7 @@
#define TEXTURESTREAMING_H #define TEXTURESTREAMING_H
#include "public/rtech/istreamdb.h" #include "public/rtech/istreamdb.h"
struct MaterialGlue_t; struct MaterialGlue_s;
struct TextureAsset_s; struct TextureAsset_s;
struct TextureStreamMgr_Task_s struct TextureStreamMgr_Task_s
@ -78,7 +78,7 @@ struct TextureStreamMgr_s
char* stringBuffer; char* stringBuffer;
StreamDB_Header_s header; StreamDB_Header_s header;
StreamDB_ResidentPage_s* residentPages; StreamDB_ResidentPage_s* residentPages;
MaterialGlue_t** materials; MaterialGlue_s** materials;
StreamDB_Material_s* materialInfo; StreamDB_Material_s* materialInfo;
int64 maxResidentPageSize; int64 maxResidentPageSize;
StreamDB_PageState_s pageStates[4]; StreamDB_PageState_s pageStates[4];

View File

@ -297,18 +297,21 @@ void CTextOverlay::DrawGPUStats(void) const
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void CTextOverlay::DrawCrosshairMaterial(void) const void CTextOverlay::DrawCrosshairMaterial(void) const
{ {
CMaterialGlue* pMaterialGlue = v_GetMaterialAtCrossHair(); const CMaterialGlue* const materialGlue = v_GetMaterialAtCrossHair();
if (!pMaterialGlue)
if (!materialGlue)
return; return;
const MaterialGlue_s* const material = materialGlue->Get();
static const Color c = { 255, 255, 255, 255 }; static const Color c = { 255, 255, 255, 255 };
DrawFormat(cl_materialinfo_offset_x.GetInt(), cl_materialinfo_offset_y.GetInt(), c, "name: %s\nguid: %llx\ndimensions: %d x %d\nsurface: %s/%s\nstc: %i\ntc: %i",
pMaterialGlue->name, DrawFormat(cl_materialinfo_offset_x.GetInt(), cl_materialinfo_offset_y.GetInt(), c, "name: %s\nguid: %llx\ndimensions: %hu x %hu\nsurface: %s/%s\nstc: %hu\ntc: %hu",
pMaterialGlue->assetGuid, material->name,
pMaterialGlue->width, pMaterialGlue->height, material->guid,
pMaterialGlue->surfaceProp, pMaterialGlue->surfaceProp2, material->width, material->height,
pMaterialGlue->numStreamingTextureHandles, material->surfaceProp, material->surfaceProp2,
pMaterialGlue->shaderset->m_nTextureInputCount); material->streamingTextureHandleCount,
material->shaderset->m_nTextureInputCount);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------