Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "stdafx.h"

#include "Headers/ResourceCache.h"

#include "Core/Headers/Console.h"
#include "Utility/Headers/Localization.h"
#include "Environment/Terrain/Headers/TerrainLoader.h"
#include "Core/Time/Headers/ApplicationTimer.h"

namespace Divide {

void DeleteResource::operator()(CachedResource* res)
{
    _context.remove(res);
    if (res && res->getType() != ResourceType::GPU_OBJECT) {
        MemoryManager::DELETE(res);
    }
}

ResourceCache::ResourceCache(PlatformContext& context)
    : PlatformContextComponent(context)
{
}

ResourceCache::~ResourceCache()
{
    Console::printfn(Locale::get(_ID("RESOURCE_CACHE_DELETE")));
    clear();
    // DELETE(_loadingPool);
}


void ResourceCache::clear() {
    WriteLock w_lock(_creationMutex);
    Console::printfn(Locale::get(_ID("STOP_RESOURCE_CACHE")));
    while (!_resDB.empty()) {
        for (ResourceMap::iterator it = std::begin(_resDB); it != std::end(_resDB);)
        {
            if (it->second.expired() ||
                it->second.lock()->getType() == ResourceType::GPU_OBJECT)
            {
                it = _resDB.erase(it);
            } else {
                ++it;
            }
        }
    }
}

void ResourceCache::add(CachedResource_wptr res) {
    CachedResource_ptr resource = res.lock();

    if (resource == nullptr) {
        Console::errorfn(Locale::get(_ID("ERROR_RESOURCE_CACHE_LOAD_RES")));
        return;
    }

    size_t hash = resource->getDescriptorHash();
    DIVIDE_ASSERT(hash != 0, "ResourceCache add error: Invalid resource hash!");

    Console::printfn(Locale::get(_ID("RESOURCE_CACHE_ADD")), resource->getName().c_str(), hash);
    WriteLock w_lock(_creationMutex);
    hashAlg::insert(_resDB, std::make_pair(hash, resource));
}

CachedResource_ptr ResourceCache::loadResource(size_t descriptorHash, const stringImpl& resourceName) {
    const CachedResource_ptr& resource = find(descriptorHash);
    if (resource) {
        WAIT_FOR_CONDITION(resource->getState() == ResourceState::RES_LOADED);
    } else {
        Console::printfn(Locale::get(_ID("RESOURCE_CACHE_GET_RES")), resourceName.c_str(), descriptorHash);
    }

    return resource;
}

CachedResource_ptr ResourceCache::find(size_t descriptorHash) {
    static CachedResource_ptr emptyResource;
    /// Search in our resource cache
    ReadLock r_lock(_creationMutex);
    ResourceMap::const_iterator it = _resDB.find(descriptorHash);
    if (it != std::end(_resDB)) {
        return it->second.lock();
    }

    return emptyResource;
}

void ResourceCache::remove(CachedResource* resource) {
    WAIT_FOR_CONDITION(resource->getState() != ResourceState::RES_LOADING);

    size_t resourceHash = resource->getDescriptorHash();
    const stringImpl& name = resource->getName();

    DIVIDE_ASSERT(resourceHash != 0, Locale::get(_ID("ERROR_RESOURCE_CACHE_INVALID_NAME")));

    bool resDBEmpty = false;
    {
        ReadLock r_lock(_creationMutex);
        DIVIDE_ASSERT(_resDB.find(resourceHash) != std::end(_resDB),
                      Locale::get(_ID("ERROR_RESOURCE_CACHE_UNKNOWN_RESOURCE")));
        resDBEmpty = _resDB.empty();
    }


    Console::printfn(Locale::get(_ID("RESOURCE_CACHE_REM_RES")), name.c_str(), resourceHash);
    resource->setState(ResourceState::RES_LOADING);
    if (resource->unload()) {
        resource->setState(ResourceState::RES_CREATED);
    } else {
        Console::errorfn(Locale::get(_ID("ERROR_RESOURCE_REM")), name.c_str());
        resource->setState(ResourceState::RES_UNKNOWN);
    }
    
    if (resDBEmpty) {
        Console::errorfn(Locale::get(_ID("RESOURCE_CACHE_REMOVE_NO_DB")), name.c_str());
    } else {
        WriteLock w_lock(_creationMutex);
        _resDB.erase(_resDB.find(resourceHash));
    }
}

};

Commits for Divide-Framework/trunk/Source Code/Core/Resources/ResourceCache.cpp

Diff revisions: vs.
Revision Author Commited Message
1021 Diff Diff IonutCava picture IonutCava Sun 21 Jan, 2018 22:19:16 +0000

[Ionut]
- Performance optimizations

969 Diff Diff IonutCava picture IonutCava Mon 13 Nov, 2017 00:15:57 +0000

[Ionut]
- Further improve DisplayWindow <-> Input relationship
- Add Flip-Y 2D camera (D3D style projection)
- Fix IMGUI rendering
- Add IMGUI sample and IMWINDOW sample rendering at the same time
- Improve IMWINDOW multi-window support
— Bug: nothing rendering in child platform windows
- Add draw command to move render context from one window to another

920 Diff Diff IonutCava picture IonutCava Thu 27 Jul, 2017 22:16:17 +0000

[Ionut]
- Attempt to fix HiZConstructions. Didn’t work, but fixed some bugs in the process.

914 Diff Diff IonutCava picture IonutCava Thu 06 Jul, 2017 21:50:27 +0000

[Ionut]
- Terrain:
— Properly use terrain world matrix
— Make ToggleWireframe a compile time define since it’s rarely used
- Material:
— Do not assign ShaderProgram::defaultShader() to material shaderInfo slots by default (helps track bugs)
— Make sure we load shadow shaders in terrain and vegetation after pre-pass shader (to not override them)
- Wait for resources to fully load before unloading them

912 Diff Diff IonutCava picture IonutCava Sun 02 Jul, 2017 23:42:39 +0000

[Ionut]
- Add experimental Weighted Blended Order Independed Transparency (ref: http://casual-effects.blogspot.co.uk/2015/03/implemented-weighted-blended-order.html)
— Add per drawbuffer blend
— All translucent renderbin items go via the new OIT 2-step rendering: accumulation and composition
- Make sure we have proper blend enabled for text rendering
- Add a primitive form of PushConstants (unused yet. Emulated via Uniform calls)
- Fix bug with XMLParser not using case insensitive key lookups

890 Diff Diff IonutCava picture IonutCava Sun 14 May, 2017 20:54:59 +0000

[Ionut]
- Add pre-compiled header support
- Initial code for per-stage tessellation computation

883 Diff Diff IonutCava picture IonutCava Fri 24 Mar, 2017 17:15:58 +0000

[IonutCava]
- More terrain work
- Removed GS-based multi pass for shadows. Replaced with a regular multi-draw submit system (ease-of-use reasons)

863 Diff Diff IonutCava picture IonutCava Wed 15 Feb, 2017 16:27:26 +0000

[IonutCava]
- Split Resource class into Resource and CachedResource
— CachedResource is the only resource held in a ResourceCache and loaded from a ResourceDescriptor
— CachedResource is mapped by its creation descriptor’s hash value, instead of the resource name
-— Multiple cached resources can now exist with the same name if the have different properties, for example.

830 Diff Diff IonutCava picture IonutCava Wed 25 Jan, 2017 17:29:44 +0000

[IonutCava]
- Add a new Platform element: File
— Move all predefined paths to FileManagement System
- Split MathHelper into MathHelper and StringHelper

804 IonutCava picture IonutCava Thu 01 Dec, 2016 17:20:59 +0000

[IonutCava]
- Singleton elimination update Part I: get it to compile
— The following classes are no longer Singletons: GFXDevice, GL_API, DX_API, SFXWrapper, FmodWrapper, SDLWrapper, ALWrapper, PXDevice, InputInterface, RenderPassManager, SceneManager and ResourceManager;
— Refactor system to a Context / Component based implementation (Pass relevant context to objects: e.g. GFXDevice object to Textures, GUI to GUIElements, etc)
— Make devices and managers components of the kernel
— Allow multiple Resource caches to co-exist. This may prove useful for later when a more fragmented memory model is need (per frame / per scene / global caches / etc)

  • next steps: part II – cleanup/refactor new code, part III – optimise code, part IV – remove remaining Singletons (e.g. Application, ParamHandler, FrameListenerManager, Recast, PostFX and DebugInterface)