Add dynamic allocation alignment to be able to load T6 MemoryBlock asset which isnt used at all so why am i doing this again

This commit is contained in:
Jan 2021-03-05 09:23:37 +01:00
parent 286eaadd1c
commit 88c48e8107
12 changed files with 91 additions and 11 deletions

View File

@ -2422,6 +2422,12 @@ namespace T6
int customBool2; int customBool2;
}; };
union MemoryBlockData
{
char* mainData;
char* videoData;
char* streamData;
};
struct MemoryBlock struct MemoryBlock
{ {
@ -2431,7 +2437,7 @@ namespace T6
bool streamMem; bool streamMem;
unsigned int size; unsigned int size;
unsigned int alignment; unsigned int alignment;
char* data; MemoryBlockData data;
}; };
struct cmodel_t2 struct cmodel_t2

View File

@ -60,6 +60,7 @@ block delay XFILE_BLOCK_DELAY_VIRTUAL default;
block delay XFILE_BLOCK_DELAY_PHYSICAL; block delay XFILE_BLOCK_DELAY_PHYSICAL;
block normal XFILE_BLOCK_VIRTUAL default; block normal XFILE_BLOCK_VIRTUAL default;
block normal XFILE_BLOCK_PHYSICAL; block normal XFILE_BLOCK_PHYSICAL;
block normal XFILE_BLOCK_STREAMER_RESERVE;
// Asset commands // Asset commands
#include "XAssets/PhysPreset.txt" #include "XAssets/PhysPreset.txt"

View File

@ -4,3 +4,18 @@
use MemoryBlock; use MemoryBlock;
set string name; set string name;
set name name; set name name;
set condition data::mainData mainMem;
set count data::mainData size;
set allocalign data::mainData alignment;
set block data::mainData XFILE_BLOCK_RUNTIME_VIRTUAL;
set condition data::videoData videoMem;
set count data::videoData size;
set allocalign data::videoData alignment;
set block data::videoData XFILE_BLOCK_RUNTIME_PHYSICAL;
set condition data::streamData streamMem;
set count data::streamData size;
set allocalign data::streamData alignment;
set block data::streamData XFILE_BLOCK_STREAMER_RESERVE;

View File

@ -20,6 +20,7 @@ public:
bool m_is_reusable; bool m_is_reusable;
bool m_is_leaf; bool m_is_leaf;
std::unique_ptr<IEvaluation> m_condition; std::unique_ptr<IEvaluation> m_condition;
std::unique_ptr<IEvaluation> m_alloc_alignment;
const FastFileBlock* m_fast_file_block; const FastFileBlock* m_fast_file_block;
MemberInformation(StructureInformation* parent, StructureInformation* type, Variable* member); MemberInformation(StructureInformation* parent, StructureInformation* type, Variable* member);

View File

@ -554,7 +554,14 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
// (Alignment specified via `__declspec(align())` showing as correct via intellisense but is incorrect when compiled for types that have a larger alignment than the specified value) // (Alignment specified via `__declspec(align())` showing as correct via intellisense but is incorrect when compiled for types that have a larger alignment than the specified value)
// this was changed to make ZoneCodeGenerator calculate what is supposed to be used as alignment when allocating. // this was changed to make ZoneCodeGenerator calculate what is supposed to be used as alignment when allocating.
// This is more reliable when being used with different compilers and the value used can be seen in the source code directly // This is more reliable when being used with different compilers and the value used can be seen in the source code directly
LINE(MakeMemberAccess(info, member, modifier)<<" = m_stream->Alloc<"<<typeDecl<<followingReferences<<">("<<modifier.GetAlignment()<<");") if (member->m_alloc_alignment)
{
LINE(MakeMemberAccess(info, member, modifier)<<" = m_stream->Alloc<"<<typeDecl<<followingReferences<<">("<<MakeEvaluation(member->m_alloc_alignment.get())<<");")
}
else
{
LINE(MakeMemberAccess(info, member, modifier)<<" = m_stream->Alloc<"<<typeDecl<<followingReferences<<">("<<modifier.GetAlignment()<<");")
}
if (computations.IsInTempBlock()) if (computations.IsInTempBlock())
{ {

View File

@ -1,6 +1,7 @@
#include "CommandsParser.h" #include "CommandsParser.h"
#include "Parsing/Commands/Sequence/SequenceAction.h" #include "Parsing/Commands/Sequence/SequenceAction.h"
#include "Parsing/Commands/Sequence/SequenceAllocAlign.h"
#include "Parsing/Commands/Sequence/SequenceArchitecture.h" #include "Parsing/Commands/Sequence/SequenceArchitecture.h"
#include "Parsing/Commands/Sequence/SequenceArrayCount.h" #include "Parsing/Commands/Sequence/SequenceArrayCount.h"
#include "Parsing/Commands/Sequence/SequenceArraySize.h" #include "Parsing/Commands/Sequence/SequenceArraySize.h"
@ -27,6 +28,7 @@ const std::vector<CommandsParser::sequence_t*>& CommandsParser::GetTestsForState
{ {
static std::vector<sequence_t*> tests({ static std::vector<sequence_t*> tests({
new SequenceAction(), new SequenceAction(),
new SequenceAllocAlign(),
new SequenceArchitecture(), new SequenceArchitecture(),
new SequenceArrayCount(), new SequenceArrayCount(),
new SequenceArraySize(), new SequenceArraySize(),

View File

@ -0,0 +1,34 @@
#include "SequenceAllocAlign.h"
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
SequenceAllocAlign::SequenceAllocAlign()
{
const CommandsMatcherFactory create(this);
AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME);
AddLabeledMatchers(CommandsCommonMatchers::Evaluation(this), CommandsCommonMatchers::LABEL_EVALUATION);
AddMatchers({
create.Keyword("set"),
create.Keyword("allocalign"),
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
create.Label(CommandsCommonMatchers::LABEL_EVALUATION),
create.Char(';')
});
}
void SequenceAllocAlign::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
{
const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE);
StructureInformation* type;
std::vector<MemberInformation*> memberChain;
if (!state->GetTypenameAndMembersFromTypename(typeNameToken.TypeNameValue(), type, memberChain))
throw ParsingException(typeNameToken.GetPos(), "Unknown type");
if(memberChain.empty())
throw ParsingException(typeNameToken.GetPos(), "Need to specify a member");
auto allocAlignEvaluation = CommandsCommonMatchers::ProcessEvaluation(state, result, type);
memberChain.back()->m_alloc_alignment = std::move(allocAlignEvaluation);
}

View File

@ -0,0 +1,14 @@
#pragma once
#include "Parsing/Commands/Impl/CommandsParser.h"
class SequenceAllocAlign final : public CommandsParser::sequence_t
{
static constexpr auto CAPTURE_TYPE = 1;
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
public:
SequenceAllocAlign();
};

View File

@ -28,7 +28,7 @@
#include "Game/T6/XAssets/mapents/mapents_load_db.h" #include "Game/T6/XAssets/mapents/mapents_load_db.h"
#include "Game/T6/XAssets/material/material_load_db.h" #include "Game/T6/XAssets/material/material_load_db.h"
#include "Game/T6/XAssets/materialtechniqueset/materialtechniqueset_load_db.h" #include "Game/T6/XAssets/materialtechniqueset/materialtechniqueset_load_db.h"
//#include "Game/T6/XAssets/memoryblock/memoryblock_load_db.h" #include "Game/T6/XAssets/memoryblock/memoryblock_load_db.h"
#include "Game/T6/XAssets/menudef_t/menudef_t_load_db.h" #include "Game/T6/XAssets/menudef_t/menudef_t_load_db.h"
#include "Game/T6/XAssets/menulist/menulist_load_db.h" #include "Game/T6/XAssets/menulist/menulist_load_db.h"
#include "Game/T6/XAssets/physconstraints/physconstraints_load_db.h" #include "Game/T6/XAssets/physconstraints/physconstraints_load_db.h"
@ -153,7 +153,7 @@ void ContentLoader::LoadXAsset(const bool atStreamStart)
LOAD_ASSET(ASSET_TYPE_SCRIPTPARSETREE, ScriptParseTree, scriptParseTree) LOAD_ASSET(ASSET_TYPE_SCRIPTPARSETREE, ScriptParseTree, scriptParseTree)
LOAD_ASSET(ASSET_TYPE_KEYVALUEPAIRS, KeyValuePairs, keyValuePairs) LOAD_ASSET(ASSET_TYPE_KEYVALUEPAIRS, KeyValuePairs, keyValuePairs)
LOAD_ASSET(ASSET_TYPE_VEHICLEDEF, VehicleDef, vehicleDef) LOAD_ASSET(ASSET_TYPE_VEHICLEDEF, VehicleDef, vehicleDef)
// LOAD_ASSET(ASSET_TYPE_MEMORYBLOCK, MemoryBlock, memoryBlock); LOAD_ASSET(ASSET_TYPE_MEMORYBLOCK, MemoryBlock, memoryBlock);
LOAD_ASSET(ASSET_TYPE_ADDON_MAP_ENTS, AddonMapEnts, addonMapEnts) LOAD_ASSET(ASSET_TYPE_ADDON_MAP_ENTS, AddonMapEnts, addonMapEnts)
LOAD_ASSET(ASSET_TYPE_TRACER, TracerDef, tracerDef) LOAD_ASSET(ASSET_TYPE_TRACER, TracerDef, tracerDef)
LOAD_ASSET(ASSET_TYPE_SKINNEDVERTS, SkinnedVertsDef, skinnedVertsDef) LOAD_ASSET(ASSET_TYPE_SKINNEDVERTS, SkinnedVertsDef, skinnedVertsDef)

View File

@ -8,10 +8,10 @@
class IZoneInputStream : public IZoneStream class IZoneInputStream : public IZoneStream
{ {
public: public:
virtual void* Alloc(int align) = 0; virtual void* Alloc(unsigned align) = 0;
template<typename T> template<typename T>
T* Alloc(const int align) T* Alloc(const unsigned align)
{ {
return static_cast<T*>(Alloc(align)); return static_cast<T*>(Alloc(align));
} }

View File

@ -30,7 +30,7 @@ XBlockInputStream::~XBlockInputStream()
assert(m_block_stack.empty()); assert(m_block_stack.empty());
} }
void XBlockInputStream::Align(const int align) void XBlockInputStream::Align(const unsigned align)
{ {
assert(!m_block_stack.empty()); assert(!m_block_stack.empty());
@ -78,7 +78,7 @@ block_t XBlockInputStream::PopBlock()
return poppedBlock->m_index; return poppedBlock->m_index;
} }
void* XBlockInputStream::Alloc(const int align) void* XBlockInputStream::Alloc(const unsigned align)
{ {
assert(!m_block_stack.empty()); assert(!m_block_stack.empty());

View File

@ -19,7 +19,7 @@ class XBlockInputStream final : public IZoneInputStream
int m_block_bit_count; int m_block_bit_count;
XBlock* m_insert_block; XBlock* m_insert_block;
void Align(int align); void Align(unsigned align);
public: public:
XBlockInputStream(std::vector<XBlock*>& blocks, ILoadingStream* stream, int blockBitCount, block_t insertBlock); XBlockInputStream(std::vector<XBlock*>& blocks, ILoadingStream* stream, int blockBitCount, block_t insertBlock);
@ -28,7 +28,7 @@ public:
void PushBlock(block_t block) override; void PushBlock(block_t block) override;
block_t PopBlock() override; block_t PopBlock() override;
void* Alloc(int align) override; void* Alloc(unsigned align) override;
void LoadDataRaw(void* dst, size_t size) override; void LoadDataRaw(void* dst, size_t size) override;
void LoadDataInBlock(void* dst, size_t size) override; void LoadDataInBlock(void* dst, size_t size) override;