GPU/D3D11: Use shader bytecode cache

This commit is contained in:
Connor McLaughlin 2020-01-24 14:52:01 +10:00
parent 82da9a4505
commit a83cad5872
2 changed files with 20 additions and 20 deletions

View File

@ -38,6 +38,9 @@ bool GPU_HW_D3D11::Initialize(HostDisplay* host_display, System* system, DMA* dm
if (!m_device || !m_context) if (!m_device || !m_context)
return false; return false;
m_shader_cache.Open(system->GetHostInterface()->GetUserDirectoryRelativePath("cache"), m_device->GetFeatureLevel(),
system->GetSettings().gpu_use_debug_device);
if (!CreateFramebuffer()) if (!CreateFramebuffer())
{ {
Log_ErrorPrintf("Failed to create framebuffer"); Log_ErrorPrintf("Failed to create framebuffer");
@ -241,8 +244,8 @@ bool GPU_HW_D3D11::CreateBatchInputLayout()
// we need a vertex shader... // we need a vertex shader...
GPU_HW_ShaderGen shadergen(m_host_display->GetRenderAPI(), m_resolution_scale, m_true_color, m_texture_filtering, GPU_HW_ShaderGen shadergen(m_host_display->GetRenderAPI(), m_resolution_scale, m_true_color, m_texture_filtering,
m_supports_dual_source_blend); m_supports_dual_source_blend);
ComPtr<ID3DBlob> vs_bytecode = D3D11::ShaderCompiler::CompileShader( ComPtr<ID3DBlob> vs_bytecode =
D3D11::ShaderCompiler::Type::Vertex, m_device->GetFeatureLevel(), shadergen.GenerateBatchVertexShader(true), false); m_shader_cache.GetShaderBlob(D3D11::ShaderCompiler::Type::Vertex, shadergen.GenerateBatchVertexShader(true));
if (!vs_bytecode) if (!vs_bytecode)
return false; return false;
@ -322,19 +325,18 @@ bool GPU_HW_D3D11::CreateStateObjects()
bool GPU_HW_D3D11::CompileShaders() bool GPU_HW_D3D11::CompileShaders()
{ {
const bool debug = false;
GPU_HW_ShaderGen shadergen(m_host_display->GetRenderAPI(), m_resolution_scale, m_true_color, m_texture_filtering, GPU_HW_ShaderGen shadergen(m_host_display->GetRenderAPI(), m_resolution_scale, m_true_color, m_texture_filtering,
m_supports_dual_source_blend); m_supports_dual_source_blend);
m_screen_quad_vertex_shader = D3D11::ShaderCompiler::CompileAndCreateVertexShader( m_screen_quad_vertex_shader =
m_device.Get(), shadergen.GenerateScreenQuadVertexShader(), debug); m_shader_cache.GetVertexShader(m_device.Get(), shadergen.GenerateScreenQuadVertexShader());
if (!m_screen_quad_vertex_shader) if (!m_screen_quad_vertex_shader)
return false; return false;
for (u8 textured = 0; textured < 2; textured++) for (u8 textured = 0; textured < 2; textured++)
{ {
const std::string vs = shadergen.GenerateBatchVertexShader(ConvertToBoolUnchecked(textured)); const std::string vs = shadergen.GenerateBatchVertexShader(ConvertToBoolUnchecked(textured));
m_batch_vertex_shaders[textured] = D3D11::ShaderCompiler::CompileAndCreateVertexShader(m_device.Get(), vs, debug); m_batch_vertex_shaders[textured] = m_shader_cache.GetVertexShader(m_device.Get(), vs);
if (!m_batch_vertex_shaders[textured]) if (!m_batch_vertex_shaders[textured])
return false; return false;
} }
@ -349,8 +351,7 @@ bool GPU_HW_D3D11::CompileShaders()
static_cast<TextureMode>(texture_mode), static_cast<TextureMode>(texture_mode),
ConvertToBoolUnchecked(dithering)); ConvertToBoolUnchecked(dithering));
m_batch_pixel_shaders[render_mode][texture_mode][dithering] = m_batch_pixel_shaders[render_mode][texture_mode][dithering] = m_shader_cache.GetPixelShader(m_device.Get(), ps);
D3D11::ShaderCompiler::CompileAndCreatePixelShader(m_device.Get(), ps, debug);
if (!m_batch_pixel_shaders[render_mode][texture_mode][dithering]) if (!m_batch_pixel_shaders[render_mode][texture_mode][dithering])
return false; return false;
} }
@ -360,29 +361,26 @@ bool GPU_HW_D3D11::CompileShaders()
m_batch_line_expand_geometry_shader.Reset(); m_batch_line_expand_geometry_shader.Reset();
if (m_resolution_scale > 1) if (m_resolution_scale > 1)
{ {
m_batch_line_expand_geometry_shader = D3D11::ShaderCompiler::CompileAndCreateGeometryShader( m_batch_line_expand_geometry_shader =
m_device.Get(), shadergen.GenerateBatchLineExpandGeometryShader(), debug); m_shader_cache.GetGeometryShader(m_device.Get(), shadergen.GenerateBatchLineExpandGeometryShader());
if (!m_batch_line_expand_geometry_shader) if (!m_batch_line_expand_geometry_shader)
return false; return false;
} }
m_copy_pixel_shader = m_copy_pixel_shader = m_shader_cache.GetPixelShader(m_device.Get(), shadergen.GenerateCopyFragmentShader());
D3D11::ShaderCompiler::CompileAndCreatePixelShader(m_device.Get(), shadergen.GenerateCopyFragmentShader(), debug);
if (!m_copy_pixel_shader) if (!m_copy_pixel_shader)
return false; return false;
m_fill_pixel_shader = m_fill_pixel_shader = m_shader_cache.GetPixelShader(m_device.Get(), shadergen.GenerateFillFragmentShader());
D3D11::ShaderCompiler::CompileAndCreatePixelShader(m_device.Get(), shadergen.GenerateFillFragmentShader(), debug);
if (!m_fill_pixel_shader) if (!m_fill_pixel_shader)
return false; return false;
m_vram_read_pixel_shader = D3D11::ShaderCompiler::CompileAndCreatePixelShader( m_vram_read_pixel_shader = m_shader_cache.GetPixelShader(m_device.Get(), shadergen.GenerateVRAMReadFragmentShader());
m_device.Get(), shadergen.GenerateVRAMReadFragmentShader(), debug);
if (!m_vram_read_pixel_shader) if (!m_vram_read_pixel_shader)
return false; return false;
m_vram_write_pixel_shader = D3D11::ShaderCompiler::CompileAndCreatePixelShader( m_vram_write_pixel_shader =
m_device.Get(), shadergen.GenerateVRAMWriteFragmentShader(), debug); m_shader_cache.GetPixelShader(m_device.Get(), shadergen.GenerateVRAMWriteFragmentShader());
if (!m_vram_write_pixel_shader) if (!m_vram_write_pixel_shader)
return false; return false;
@ -392,8 +390,7 @@ bool GPU_HW_D3D11::CompileShaders()
{ {
const std::string ps = shadergen.GenerateDisplayFragmentShader(ConvertToBoolUnchecked(depth_24bit), const std::string ps = shadergen.GenerateDisplayFragmentShader(ConvertToBoolUnchecked(depth_24bit),
ConvertToBoolUnchecked(interlaced)); ConvertToBoolUnchecked(interlaced));
m_display_pixel_shaders[depth_24bit][interlaced] = m_display_pixel_shaders[depth_24bit][interlaced] = m_shader_cache.GetPixelShader(m_device.Get(), ps);
D3D11::ShaderCompiler::CompileAndCreatePixelShader(m_device.Get(), ps, debug);
if (!m_display_pixel_shaders[depth_24bit][interlaced]) if (!m_display_pixel_shaders[depth_24bit][interlaced])
return false; return false;
} }

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include "common/d3d11/shader_cache.h"
#include "common/d3d11/staging_texture.h" #include "common/d3d11/staging_texture.h"
#include "common/d3d11/stream_buffer.h" #include "common/d3d11/stream_buffer.h"
#include "common/d3d11/texture.h" #include "common/d3d11/texture.h"
@ -66,6 +67,8 @@ private:
ComPtr<ID3D11Device> m_device; ComPtr<ID3D11Device> m_device;
ComPtr<ID3D11DeviceContext> m_context; ComPtr<ID3D11DeviceContext> m_context;
D3D11::ShaderCache m_shader_cache;
// downsample texture - used for readbacks at >1xIR. // downsample texture - used for readbacks at >1xIR.
D3D11::Texture m_vram_texture; D3D11::Texture m_vram_texture;
D3D11::Texture m_vram_read_texture; D3D11::Texture m_vram_read_texture;