<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Mar 14, 2017 at 10:57 PM, Timothy Arceri <span dir="ltr"><<a href="mailto:tarceri@itsqueeze.com" target="_blank">tarceri@itsqueeze.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">If the app provided and in-memory pipeline caches don't contain<br>
what we are looking for then we fallback to the on-disk cache.<br></blockquote><div><br></div><div><soapbox><br><br></div><div>Not my driver so my opinion doesn't count for much here, but this seems like a very un-Vulkan thing to do.  The API has a VkPipelineCache and apps should be using it.  If an app doesn't take advantage of that API and its users suffer from crummy load times or stutter, then it's a broken app.  The only thing this is doing (assuming good apps) is using double the disk space to cache shaders twice.<br><br></div><div>In GL, there's just not much we can do besides provide a transparent on-disk cache.  There are things like GL_ARB_get_program_binary but, thanks to the way the GL API is designed, there is no real solution to the recompile problem.  You can guess all you want but on hardware like AMDs where you have lots of recompiles, it's kind-of worthless to do so.  The answer:  The driver has a transparent cache.  In the Vulkan world, this problem has been solved and we should use this solution.  We're also not supposed to be doing things behind the client's back and, given that we have a pipeline cache API, this definitely falls into that category.<br><br></div><div>Finally, I really don't want, in these early days of Vulkan, for drivers to start doing transparent caching because it sends exactly the wrong message to developers.  "You know that caching API?  If you find it hard to use, just don't bother.  The driver will do it for you."  That's not the message we want to send.<br><br></div><div></soapbox><br><br></div><div>Do whatever you want. #notmydriver<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
 src/amd/vulkan/radv_pipeline_<wbr>cache.c | 13 +++++++++++--<br>
 1 file changed, 11 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/src/amd/vulkan/radv_<wbr>pipeline_cache.c b/src/amd/vulkan/radv_<wbr>pipeline_cache.c<br>
index 3a58f6a..ffcb8e5 100644<br>
--- a/src/amd/vulkan/radv_<wbr>pipeline_cache.c<br>
+++ b/src/amd/vulkan/radv_<wbr>pipeline_cache.c<br>
@@ -16,20 +16,21 @@<br>
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
  * IN THE SOFTWARE.<br>
  */<br>
<br>
 #include "util/mesa-sha1.h"<br>
 #include "util/debug.h"<br>
+#include "util/disk_cache.h"<br>
 #include "radv_private.h"<br>
<br>
 #include "ac_nir_to_llvm.h"<br>
<br>
 struct cache_entry {<br>
        union {<br>
                unsigned char sha1[20];<br>
                uint32_t sha1_dw[5];<br>
        };<br>
        uint32_t code_size;<br>
@@ -152,22 +153,28 @@ radv_create_shader_variant_<wbr>from_pipeline_cache(struct radv_device *device,<br>
                                               struct radv_pipeline_cache *cache,<br>
                                               const unsigned char *sha1)<br>
 {<br>
        struct cache_entry *entry = NULL;<br>
<br>
        if (cache)<br>
                entry = radv_pipeline_cache_search(<wbr>cache, sha1);<br>
        else<br>
                entry = radv_pipeline_cache_search(<wbr>device->mem_cache, sha1);<br>
<br>
-       if (!entry)<br>
-               return NULL;<br>
+       if (!entry) {<br>
+               size_t entry_size;<br>
+               entry = (struct cache_entry *)<br>
+                       disk_cache_get(device-><wbr>physical_device->disk_cache,<br>
+                                      sha1, &entry_size);<br>
+               if (!entry)<br>
+                       return NULL;<br>
+       }<br>
<br>
        if (!entry->variant) {<br>
                struct radv_shader_variant *variant;<br>
<br>
                variant = calloc(1, sizeof(struct radv_shader_variant));<br>
                if (!variant)<br>
                        return NULL;<br>
<br>
                variant->config = entry->config;<br>
                variant->info = entry->variant_info;<br>
@@ -294,20 +301,22 @@ radv_pipeline_cache_insert_<wbr>shader(struct radv_device *device,<br>
        memcpy(entry->code, code, code_size);<br>
        entry->config = variant->config;<br>
        entry->variant_info = variant->info;<br>
        entry->rsrc1 = variant->rsrc1;<br>
        entry->rsrc2 = variant->rsrc2;<br>
        entry->code_size = code_size;<br>
        entry->variant = variant;<br>
        __sync_fetch_and_add(&variant-<wbr>>ref_count, 1);<br>
<br>
        radv_pipeline_cache_add_entry(<wbr>cache, entry);<br>
+       disk_cache_put(device-><wbr>physical_device->disk_cache,<br>
+                      sha1, entry, sizeof(*entry) + code_size);<br>
<br>
        cache->modified = true;<br>
        pthread_mutex_unlock(&cache-><wbr>mutex);<br>
        return variant;<br>
 }<br>
<br>
 struct cache_header {<br>
        uint32_t header_size;<br>
        uint32_t header_version;<br>
        uint32_t vendor_id;<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.9.3<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>