mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-09-07 10:05:47 +00:00
direct asset library
This commit is contained in:
parent
2f00829937
commit
bf2414f150
2 changed files with 172 additions and 0 deletions
|
@ -126,6 +126,118 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadPixelShader(const
|
||||||
return LoadInfo{approx_mem_size};
|
return LoadInfo{approx_mem_size};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadShader(const AssetID& asset_id,
|
||||||
|
RasterShaderData* data)
|
||||||
|
{
|
||||||
|
const auto asset_map = GetAssetMapForID(asset_id);
|
||||||
|
|
||||||
|
// Asset map for a pixel shader is the shader and some metadata
|
||||||
|
if (asset_map.size() != 3)
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(VIDEO, "Asset '{}' expected to have three files mapped!", asset_id);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto metadata = asset_map.find("metadata");
|
||||||
|
if (metadata == asset_map.end())
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(VIDEO, "Asset '{}' expected to have a metadata entry mapped!", asset_id);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto vertex_shader = asset_map.find("vertex_shader");
|
||||||
|
if (vertex_shader == asset_map.end())
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(VIDEO, "Asset '{}' expected to have a vertex shader entry mapped!", asset_id);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto pixel_shader = asset_map.find("pixel_shader");
|
||||||
|
if (pixel_shader == asset_map.end())
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(VIDEO, "Asset '{}' expected to have a pixel shader entry mapped!", asset_id);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t metadata_size;
|
||||||
|
{
|
||||||
|
std::error_code ec;
|
||||||
|
metadata_size = std::filesystem::file_size(metadata->second, ec);
|
||||||
|
if (ec)
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(VIDEO,
|
||||||
|
"Asset '{}' error - failed to get shader metadata file size with error '{}'!",
|
||||||
|
asset_id, ec);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::size_t vertex_shader_size;
|
||||||
|
{
|
||||||
|
std::error_code ec;
|
||||||
|
vertex_shader_size = std::filesystem::file_size(vertex_shader->second, ec);
|
||||||
|
if (ec)
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(
|
||||||
|
VIDEO, "Asset '{}' error - failed to get vertex shader source file size with error '{}'!",
|
||||||
|
asset_id, ec);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::size_t pixel_shader_size;
|
||||||
|
{
|
||||||
|
std::error_code ec;
|
||||||
|
pixel_shader_size = std::filesystem::file_size(pixel_shader->second, ec);
|
||||||
|
if (ec)
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(
|
||||||
|
VIDEO, "Asset '{}' error - failed to get pixel shader source file size with error '{}'!",
|
||||||
|
asset_id, ec);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const auto approx_mem_size = metadata_size + vertex_shader_size + pixel_shader_size;
|
||||||
|
|
||||||
|
if (!File::ReadFileToString(PathToString(vertex_shader->second), data->m_vertex_source))
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(VIDEO, "Asset '{}' error - failed to load the vertex shader file '{}',",
|
||||||
|
asset_id, PathToString(vertex_shader->second));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!File::ReadFileToString(PathToString(pixel_shader->second), data->m_pixel_source))
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(VIDEO, "Asset '{}' error - failed to load the pixel shader file '{}',", asset_id,
|
||||||
|
PathToString(pixel_shader->second));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
picojson::value root;
|
||||||
|
std::string error;
|
||||||
|
if (!JsonFromFile(PathToString(metadata->second), &root, &error))
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(VIDEO,
|
||||||
|
"Asset '{}' error - failed to load the json file '{}', due to parse error: {}",
|
||||||
|
asset_id, PathToString(metadata->second), error);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!root.is<picojson::object>())
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(
|
||||||
|
VIDEO,
|
||||||
|
"Asset '{}' error - failed to load the json file '{}', due to root not being an object!",
|
||||||
|
asset_id, PathToString(metadata->second));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& root_obj = root.get<picojson::object>();
|
||||||
|
|
||||||
|
if (!RasterShaderData::FromJson(asset_id, root_obj, data))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
return LoadInfo{approx_mem_size, GetLastAssetWriteTime(asset_id)};
|
||||||
|
}
|
||||||
|
|
||||||
CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMaterial(const AssetID& asset_id,
|
CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMaterial(const AssetID& asset_id,
|
||||||
MaterialData* data)
|
MaterialData* data)
|
||||||
{
|
{
|
||||||
|
@ -184,6 +296,64 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMaterial(const As
|
||||||
return LoadInfo{metadata_size};
|
return LoadInfo{metadata_size};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMaterial(const AssetID& asset_id,
|
||||||
|
RasterMaterialData* data)
|
||||||
|
{
|
||||||
|
const auto asset_map = GetAssetMapForID(asset_id);
|
||||||
|
|
||||||
|
// Material is expected to have one asset mapped
|
||||||
|
if (asset_map.empty() || asset_map.size() > 1)
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(VIDEO, "Asset '{}' error - material expected to have one file mapped!", asset_id);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
const auto& asset_path = asset_map.begin()->second;
|
||||||
|
|
||||||
|
std::size_t metadata_size;
|
||||||
|
{
|
||||||
|
std::error_code ec;
|
||||||
|
metadata_size = std::filesystem::file_size(asset_path, ec);
|
||||||
|
if (ec)
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(VIDEO, "Asset '{}' error - failed to get material file size with error '{}'!",
|
||||||
|
asset_id, ec);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
picojson::value root;
|
||||||
|
std::string error;
|
||||||
|
if (!JsonFromFile(PathToString(asset_path), &root, &error))
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(
|
||||||
|
VIDEO,
|
||||||
|
"Asset '{}' error - material failed to load the json file '{}', due to parse error: {}",
|
||||||
|
asset_id, PathToString(asset_path), error);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
if (!root.is<picojson::object>())
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(VIDEO,
|
||||||
|
"Asset '{}' error - material failed to load the json file '{}', due to root not "
|
||||||
|
"being an object!",
|
||||||
|
asset_id, PathToString(asset_path));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& root_obj = root.get<picojson::object>();
|
||||||
|
|
||||||
|
if (!RasterMaterialData::FromJson(asset_id, root_obj, data))
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(VIDEO,
|
||||||
|
"Asset '{}' error - material failed to load the json file '{}', as material "
|
||||||
|
"json could not be parsed!",
|
||||||
|
asset_id, PathToString(asset_path));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return LoadInfo{metadata_size, GetLastAssetWriteTime(asset_id)};
|
||||||
|
}
|
||||||
|
|
||||||
CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMesh(const AssetID& asset_id,
|
CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMesh(const AssetID& asset_id,
|
||||||
MeshData* data)
|
MeshData* data)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,9 @@ public:
|
||||||
LoadInfo LoadTexture(const AssetID& asset_id, TextureAndSamplerData* data) override;
|
LoadInfo LoadTexture(const AssetID& asset_id, TextureAndSamplerData* data) override;
|
||||||
LoadInfo LoadTexture(const AssetID& asset_id, CustomTextureData* data) override;
|
LoadInfo LoadTexture(const AssetID& asset_id, CustomTextureData* data) override;
|
||||||
LoadInfo LoadPixelShader(const AssetID& asset_id, PixelShaderData* data) override;
|
LoadInfo LoadPixelShader(const AssetID& asset_id, PixelShaderData* data) override;
|
||||||
|
LoadInfo LoadShader(const AssetID& asset_id, RasterShaderData* data) override;
|
||||||
LoadInfo LoadMaterial(const AssetID& asset_id, MaterialData* data) override;
|
LoadInfo LoadMaterial(const AssetID& asset_id, MaterialData* data) override;
|
||||||
|
LoadInfo LoadMaterial(const AssetID& asset_id, RasterMaterialData* data) override;
|
||||||
LoadInfo LoadMesh(const AssetID& asset_id, MeshData* data) override;
|
LoadInfo LoadMesh(const AssetID& asset_id, MeshData* data) override;
|
||||||
|
|
||||||
// Assigns the asset id to a map of files, how this map is read is dependent on the data
|
// Assigns the asset id to a map of files, how this map is read is dependent on the data
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue