@@ -725,6 +725,134 @@ void MaterialSystem::GenerateWorldCommandBuffer( std::vector<MaterialSurface>& s
725725 GL_CheckErrors ();
726726}
727727
728+ class ListMaterialsCmd : public Cmd ::StaticCmd {
729+ public:
730+ ListMaterialsCmd () : StaticCmd( " listMaterials" , Cmd::RENDERER, " list material system materials" ) {}
731+
732+ void Run ( const Cmd::Args& ) const override {
733+ if ( !glConfig.usingMaterialSystem ) {
734+ Print ( " Material system is disabled" );
735+ return ;
736+ }
737+
738+ // Taken from tr_shader.cpp
739+ static const std::unordered_map<shaderSort_t, std::string> shaderSortName = {
740+ { shaderSort_t::SS_BAD, " BAD" },
741+ { shaderSort_t::SS_PORTAL, " PORTAL" },
742+ { shaderSort_t::SS_DEPTH, " DEPTH" },
743+ { shaderSort_t::SS_ENVIRONMENT_FOG, " ENV_FOG" },
744+ { shaderSort_t::SS_ENVIRONMENT_NOFOG, " ENV_NOFOG" },
745+ { shaderSort_t::SS_OPAQUE, " OPAQUE" },
746+ { shaderSort_t::SS_DECAL, " DECAL" },
747+ { shaderSort_t::SS_SEE_THROUGH, " SEE_THROUGH" },
748+ { shaderSort_t::SS_BANNER, " BANNER" },
749+ { shaderSort_t::SS_FOG, " FOG" },
750+ { shaderSort_t::SS_UNDERWATER, " UNDERWATER" },
751+ { shaderSort_t::SS_FAR, " FAR" },
752+ { shaderSort_t::SS_MEDIUM, " MEDIUM" },
753+ { shaderSort_t::SS_CLOSE, " CLOSE" },
754+ { shaderSort_t::SS_BLEND0, " BLEND0" },
755+ { shaderSort_t::SS_BLEND1, " BLEND1" },
756+ { shaderSort_t::SS_ALMOST_NEAREST, " ALMOST_NEAREST" },
757+ { shaderSort_t::SS_NEAREST, " NEAREST" },
758+ { shaderSort_t::SS_POST_PROCESS, " POST_PROCESS" },
759+ };
760+
761+ for ( const MaterialSystem::MaterialPack& materialPack : materialSystem.materialPacks ) {
762+ Print ( " MaterialPack %s:%s:" ,
763+ shaderSortName.at ( materialPack.fromSort ), shaderSortName.at ( materialPack.toSort ) );
764+ for ( const Material& material : materialPack.materials ) {
765+ Print ( " id: %u, sync: %5s, stateBits: %10x, GLShader: %s, GLProgramID: %u,"
766+ " deform: %i, fog: %i, drawCmdCount: %u" ,
767+ material.id , material.useSync , material.stateBits ,
768+ material.shader ->_name , material.program ,
769+ material.deformIndex , material.fog , material.drawCommandCount );
770+ }
771+ }
772+ }
773+ };
774+ static ListMaterialsCmd listMaterialsCmdRegistration;
775+
776+ static std::string GetStageInfo ( const shaderStage_t* pStage, const uint32_t dynamicStagesOffset ) {
777+ static const std::unordered_map<stageShaderBinder_t, std::string> stageShaderNames = {
778+ { BindShaderNOP, " NOP " },
779+ { BindShaderGeneric3D, " genericMaterial " },
780+ { BindShaderLightMapping, " lightMappingMaterial" },
781+ { BindShaderHeatHaze, " heatHazeMaterial " },
782+ { BindShaderFog, " fogQuake3Material " },
783+ { BindShaderLiquid, " liquidMaterial " },
784+ { BindShaderScreen, " screenMaterial " },
785+ { BindShaderSkybox, " skyboxMaterial " },
786+ { BindShaderReflection, " reflectionMaterial " }
787+ };
788+
789+ std::string out = Str::Format ( " %s material offset: %3u, buffer offset: %4u\n " ,
790+ stageShaderNames.at ( pStage->shaderBinder ), pStage->materialOffset , pStage->bufferOffset );
791+
792+ static const char * stageVariants[] = {
793+ " base variant " ,
794+ " vertex overbright " ,
795+ " vertex-lit " ,
796+ " fullbright " ,
797+ " vertex overbright vertex-lit " ,
798+ " vertex overbright fullbright " ,
799+ " vertex-lit fullbright " ,
800+ " vertex overbright vertex-lit fullbright"
801+ };
802+
803+ uint32_t variants = 0 ;
804+ for ( int i = 0 ; i < ShaderStageVariant::ALL && variants < pStage->variantOffset ; i++ ) {
805+ if ( pStage->variantOffsets [i] != -1 ) {
806+ const uint32_t variantOffset = pStage->variantOffsets [i] * pStage->paddedSize ;
807+
808+ out += Str::Format ( " %s material array offset: %3u, material buffer offset: %4u, size: %2u\n " ,
809+ stageVariants[i],
810+ pStage->materialOffset + pStage->variantOffsets [i],
811+ pStage->bufferOffset + variantOffset + ( pStage->dynamic ? dynamicStagesOffset : 0 ),
812+ pStage->paddedSize );
813+
814+ variants++;
815+ }
816+ }
817+
818+ return out;
819+ }
820+
821+ class ListMaterialSystemStagesCmd : public Cmd ::StaticCmd {
822+ public:
823+ ListMaterialSystemStagesCmd () : StaticCmd( " listMaterialSystemStages" , Cmd::RENDERER, " list material system stages" ) {}
824+
825+ void Run ( const Cmd::Args& ) const override {
826+ if ( !glConfig.usingMaterialSystem ) {
827+ Print ( " Material system is disabled" );
828+ return ;
829+ }
830+
831+ Print ( " Total stages: %u, static: %u, dynamic: %u" ,
832+ materialSystem.materialStages .size (),
833+ materialSystem.materialStages .size () - materialSystem.dynamicStages .size (),
834+ materialSystem.dynamicStages .size () );
835+ Print ( " Total stage size: %u, static: %u, dynamic: %u (offset: %u)" ,
836+ materialSystem.totalStageSize , materialSystem.totalStageSize - materialSystem.dynamicStagesSize ,
837+ materialSystem.dynamicStagesSize , materialSystem.dynamicStagesOffset );
838+
839+ Print ( " \n Static stages:" );
840+ for ( const shaderStage_t* pStage : materialSystem.materialStages ) {
841+ if ( pStage->dynamic ) {
842+ continue ;
843+ }
844+
845+ Print ( GetStageInfo ( pStage, materialSystem.dynamicStagesOffset ) );
846+ }
847+
848+ Print ( " \n Dynamic stages:" );
849+ for ( const shaderStage_t* pStage : materialSystem.dynamicStages ) {
850+ Print ( GetStageInfo ( pStage, materialSystem.dynamicStagesOffset ) );
851+ }
852+ }
853+ };
854+ static ListMaterialSystemStagesCmd listMaterialSystemStagesCmdRegistration;
855+
728856void MaterialSystem::BindBuffers () {
729857 materialsUBO.BindBufferBase ();
730858 texDataBuffer.BindBufferBase ( texDataBufferType, texDataBindingPoint );
0 commit comments