You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
3.2 KiB
86 lines
3.2 KiB
#include "common.h"
|
|
#include <psml_mfsr.h>
|
|
#include <agc/core/sync.h>
|
|
|
|
using namespace sce::Psml;
|
|
|
|
struct MfsrCommandInitializationData
|
|
{
|
|
MfsrProfile profile;
|
|
uint16_t outputColorWidth;
|
|
uint16_t outputColorHeight;
|
|
};
|
|
|
|
struct MfsrCommandExecutionData
|
|
{
|
|
|
|
};
|
|
|
|
struct MfsrTextureTable
|
|
{
|
|
sce::Agc::Core::Texture* colorInput;
|
|
sce::Agc::Core::Texture* colorOutput;
|
|
sce::Agc::Core::Texture* depth;
|
|
sce::Agc::Core::Texture* exposureTexture;
|
|
sce::Agc::Core::Texture* motionVectors;
|
|
sce::Agc::Core::Texture* reactiveMask;
|
|
};
|
|
|
|
PSML_EXPORT bool CreateMfsrContext(const MfsrCommandInitializationData* initSettings, MfsrContext* context, MfsrSharedResources* sharedResources)
|
|
{
|
|
int res = initMfsr();
|
|
if (res != SCE_OK && res != SCE_PSML_MFSR_ERROR_ALREADY_INITIALIZED)
|
|
{
|
|
// TODO: log error code
|
|
return false;
|
|
}
|
|
|
|
// TODO: figure out what the exact purpose of the shared resources is exactly.
|
|
// Does it map one-to-one with the MfsrContext or do we only ever need a single shared resources instance?
|
|
// This affects how we should model the internal data and the interface exposed to C#.
|
|
//
|
|
// Seems to be shared between all contexts. Just use a fixed MfsrProfile as Quality is the only one that exists right now anyway.
|
|
// See also: https://p.siedev.net/resources/documents/SDK/9.000/PSML_MFSR-Overview/0002.html#__document_toc_00000011
|
|
MfsrSharedResourcesInitParameters resParams;
|
|
resParams.init();
|
|
resParams.m_profile = initSettings->profile;
|
|
|
|
createMfsrSharedResources(sharedResources, &resParams); // TODO: handle error
|
|
|
|
MfsrContextInitParameters initParams;
|
|
initParams.init();
|
|
initParams.m_profile = initSettings->profile;
|
|
initParams.m_outputColorWidth = initSettings->outputColorWidth;
|
|
initParams.m_outputColorHeight = initSettings->outputColorHeight;
|
|
// TODO: allocate buffers for previous frames
|
|
|
|
createMfsrContext(context, &initParams); // TODO: handle error
|
|
|
|
return true;
|
|
}
|
|
|
|
PSML_EXPORT void DestroyMfsrContext(MfsrContext context, MfsrSharedResources sharedResources)
|
|
{
|
|
releaseMfsrContext(context);
|
|
releaseMfsrSharedResources(sharedResources);
|
|
}
|
|
|
|
PSML_EXPORT void ExecuteMfsr(sce::Agc::DrawCommandBuffer* cmd, MfsrContext context, const MfsrTextureTable* textures) // TODO: add dispatch params (initData & executeData)
|
|
{
|
|
// TODO: flushing cache on input textures equivalent to SyncCacheOp::kFlushWritesToGl2 may be necessary, depending on what Unity does or doesn't do internally.
|
|
// This means basically invalidating all write caches, making sure that dispatchMfsr() gets to see all the latest data when it reads from the input textures.
|
|
// See technote: https://p.siedev.net/technotes/view/644/1
|
|
|
|
DispatchMfsrParameters dispatchParams;
|
|
dispatchParams.init(); // TODO: might want to reuse these params as init() is relatively expensive
|
|
dispatchParams.m_color = textures->colorInput;
|
|
dispatchParams.m_outputColor = textures->colorOutput;
|
|
dispatchParams.m_depth = textures->depth;
|
|
dispatchParams.m_exposure = textures->exposureTexture;
|
|
dispatchParams.m_motionVectors = textures->motionVectors;
|
|
dispatchParams.m_reactiveMask = textures->reactiveMask;
|
|
// TODO: add data from initData & executeData
|
|
// TODO: where exactly do the shared resources feature in all this?
|
|
|
|
dispatchMfsr(context, cmd, &dispatchParams); // TODO: handle error
|
|
}
|