2019-11-03 14:39:48 +00:00
|
|
|
#pragma once
|
2020-01-24 04:52:01 +00:00
|
|
|
#include "common/d3d11/shader_cache.h"
|
2019-11-03 14:39:48 +00:00
|
|
|
#include "common/d3d11/staging_texture.h"
|
|
|
|
#include "common/d3d11/stream_buffer.h"
|
|
|
|
#include "common/d3d11/texture.h"
|
|
|
|
#include "gpu_hw.h"
|
2020-12-25 08:02:38 +00:00
|
|
|
#include "texture_replacements.h"
|
2019-11-03 14:39:48 +00:00
|
|
|
#include <array>
|
|
|
|
#include <d3d11.h>
|
|
|
|
#include <memory>
|
|
|
|
#include <tuple>
|
|
|
|
#include <wrl/client.h>
|
|
|
|
|
|
|
|
class GPU_HW_D3D11 : public GPU_HW
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
template<typename T>
|
|
|
|
using ComPtr = Microsoft::WRL::ComPtr<T>;
|
|
|
|
|
|
|
|
GPU_HW_D3D11();
|
|
|
|
~GPU_HW_D3D11() override;
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
bool Initialize(HostDisplay* host_display) override;
|
2021-01-23 09:00:54 +00:00
|
|
|
void Reset(bool clear_vram) override;
|
|
|
|
bool DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display) override;
|
2019-11-03 14:39:48 +00:00
|
|
|
|
|
|
|
void ResetGraphicsAPIState() override;
|
|
|
|
void RestoreGraphicsAPIState() override;
|
|
|
|
void UpdateSettings() override;
|
|
|
|
|
|
|
|
protected:
|
2020-08-02 17:26:11 +00:00
|
|
|
void ClearDisplay() override;
|
2019-11-03 14:39:48 +00:00
|
|
|
void UpdateDisplay() override;
|
2019-11-14 07:16:59 +00:00
|
|
|
void ReadVRAM(u32 x, u32 y, u32 width, u32 height) override;
|
2019-11-03 14:39:48 +00:00
|
|
|
void FillVRAM(u32 x, u32 y, u32 width, u32 height, u32 color) override;
|
2020-12-14 16:19:28 +00:00
|
|
|
void UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void* data, bool set_mask, bool check_mask) override;
|
2019-11-03 14:39:48 +00:00
|
|
|
void CopyVRAM(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32 height) override;
|
2019-11-05 12:34:27 +00:00
|
|
|
void UpdateVRAMReadTexture() override;
|
2020-05-03 07:11:28 +00:00
|
|
|
void UpdateDepthBufferFromMaskBit() override;
|
2020-12-22 15:10:49 +00:00
|
|
|
void ClearDepthBuffer() override;
|
2020-04-18 05:30:46 +00:00
|
|
|
void SetScissorFromDrawingArea() override;
|
|
|
|
void MapBatchVertexPointer(u32 required_vertices) override;
|
|
|
|
void UnmapBatchVertexPointer(u32 used_vertices) override;
|
|
|
|
void UploadUniformBuffer(const void* data, u32 data_size) override;
|
|
|
|
void DrawBatchVertices(BatchRenderMode render_mode, u32 base_vertex, u32 num_vertices) override;
|
2019-11-03 14:39:48 +00:00
|
|
|
|
|
|
|
private:
|
2020-03-07 06:05:54 +00:00
|
|
|
enum : u32
|
|
|
|
{
|
|
|
|
// Currently we don't stream uniforms, instead just re-map the buffer every time and let the driver take care of it.
|
|
|
|
MAX_UNIFORM_BUFFER_SIZE = 64
|
|
|
|
};
|
|
|
|
|
2019-11-03 14:39:48 +00:00
|
|
|
void SetCapabilities();
|
|
|
|
bool CreateFramebuffer();
|
|
|
|
void ClearFramebuffer();
|
|
|
|
void DestroyFramebuffer();
|
|
|
|
|
|
|
|
bool CreateVertexBuffer();
|
|
|
|
bool CreateUniformBuffer();
|
|
|
|
bool CreateTextureBuffer();
|
|
|
|
bool CreateStateObjects();
|
2020-08-11 16:27:10 +00:00
|
|
|
void DestroyStateObjects();
|
2019-11-03 14:39:48 +00:00
|
|
|
|
|
|
|
bool CompileShaders();
|
2020-08-11 16:27:07 +00:00
|
|
|
void DestroyShaders();
|
2019-11-03 14:39:48 +00:00
|
|
|
void SetViewport(u32 x, u32 y, u32 width, u32 height);
|
|
|
|
void SetScissor(u32 x, u32 y, u32 width, u32 height);
|
|
|
|
void SetViewportAndScissor(u32 x, u32 y, u32 width, u32 height);
|
|
|
|
|
|
|
|
void DrawUtilityShader(ID3D11PixelShader* shader, const void* uniforms, u32 uniforms_size);
|
|
|
|
|
2020-12-25 08:02:38 +00:00
|
|
|
bool BlitVRAMReplacementTexture(const TextureReplacementTexture* tex, u32 dst_x, u32 dst_y, u32 width, u32 height);
|
|
|
|
|
2020-12-30 06:26:20 +00:00
|
|
|
void DownsampleFramebuffer(D3D11::Texture& source, u32 left, u32 top, u32 width, u32 height);
|
|
|
|
void DownsampleFramebufferAdaptive(D3D11::Texture& source, u32 left, u32 top, u32 width, u32 height);
|
|
|
|
void DownsampleFramebufferBoxFilter(D3D11::Texture& source, u32 left, u32 top, u32 width, u32 height);
|
|
|
|
|
2019-11-03 14:39:48 +00:00
|
|
|
ComPtr<ID3D11Device> m_device;
|
|
|
|
ComPtr<ID3D11DeviceContext> m_context;
|
|
|
|
|
|
|
|
// downsample texture - used for readbacks at >1xIR.
|
|
|
|
D3D11::Texture m_vram_texture;
|
2020-05-03 07:11:28 +00:00
|
|
|
D3D11::Texture m_vram_depth_texture;
|
|
|
|
ComPtr<ID3D11DepthStencilView> m_vram_depth_view;
|
2019-11-03 14:39:48 +00:00
|
|
|
D3D11::Texture m_vram_read_texture;
|
2019-11-14 06:58:27 +00:00
|
|
|
D3D11::Texture m_vram_encoding_texture;
|
2019-11-03 14:39:48 +00:00
|
|
|
D3D11::Texture m_display_texture;
|
|
|
|
|
|
|
|
D3D11::StreamBuffer m_vertex_stream_buffer;
|
|
|
|
|
|
|
|
D3D11::StreamBuffer m_uniform_stream_buffer;
|
|
|
|
|
|
|
|
D3D11::StreamBuffer m_texture_stream_buffer;
|
2019-11-14 06:58:27 +00:00
|
|
|
|
|
|
|
D3D11::StagingTexture m_vram_readback_texture;
|
|
|
|
|
2019-11-03 14:39:48 +00:00
|
|
|
ComPtr<ID3D11ShaderResourceView> m_texture_stream_buffer_srv_r16ui;
|
|
|
|
|
|
|
|
ComPtr<ID3D11RasterizerState> m_cull_none_rasterizer_state;
|
2020-10-30 14:38:06 +00:00
|
|
|
ComPtr<ID3D11RasterizerState> m_cull_none_rasterizer_state_no_msaa;
|
2019-11-03 14:39:48 +00:00
|
|
|
|
|
|
|
ComPtr<ID3D11DepthStencilState> m_depth_disabled_state;
|
2020-05-03 07:11:28 +00:00
|
|
|
ComPtr<ID3D11DepthStencilState> m_depth_test_always_state;
|
|
|
|
ComPtr<ID3D11DepthStencilState> m_depth_test_less_state;
|
2020-12-22 15:10:49 +00:00
|
|
|
ComPtr<ID3D11DepthStencilState> m_depth_test_greater_state;
|
2019-11-03 14:39:48 +00:00
|
|
|
|
|
|
|
ComPtr<ID3D11BlendState> m_blend_disabled_state;
|
2020-05-03 07:11:28 +00:00
|
|
|
ComPtr<ID3D11BlendState> m_blend_no_color_writes_state;
|
2019-11-03 14:39:48 +00:00
|
|
|
|
|
|
|
ComPtr<ID3D11SamplerState> m_point_sampler_state;
|
|
|
|
ComPtr<ID3D11SamplerState> m_linear_sampler_state;
|
2020-12-30 06:26:20 +00:00
|
|
|
ComPtr<ID3D11SamplerState> m_trilinear_sampler_state;
|
2019-11-03 14:39:48 +00:00
|
|
|
|
|
|
|
std::array<ComPtr<ID3D11BlendState>, 5> m_batch_blend_states; // [transparency_mode]
|
|
|
|
ComPtr<ID3D11InputLayout> m_batch_input_layout;
|
|
|
|
std::array<ComPtr<ID3D11VertexShader>, 2> m_batch_vertex_shaders; // [textured]
|
2020-04-03 14:11:33 +00:00
|
|
|
std::array<std::array<std::array<std::array<ComPtr<ID3D11PixelShader>, 2>, 2>, 9>, 4>
|
|
|
|
m_batch_pixel_shaders; // [render_mode][texture_mode][dithering][interlacing]
|
2019-11-03 14:39:48 +00:00
|
|
|
|
|
|
|
ComPtr<ID3D11VertexShader> m_screen_quad_vertex_shader;
|
2020-12-30 06:26:20 +00:00
|
|
|
ComPtr<ID3D11VertexShader> m_uv_quad_vertex_shader;
|
2019-11-03 14:39:48 +00:00
|
|
|
ComPtr<ID3D11PixelShader> m_copy_pixel_shader;
|
2020-04-03 14:11:39 +00:00
|
|
|
ComPtr<ID3D11PixelShader> m_vram_fill_pixel_shader;
|
|
|
|
ComPtr<ID3D11PixelShader> m_vram_interlaced_fill_pixel_shader;
|
2019-11-14 06:58:27 +00:00
|
|
|
ComPtr<ID3D11PixelShader> m_vram_read_pixel_shader;
|
2019-11-03 14:39:48 +00:00
|
|
|
ComPtr<ID3D11PixelShader> m_vram_write_pixel_shader;
|
2020-04-19 12:30:54 +00:00
|
|
|
ComPtr<ID3D11PixelShader> m_vram_copy_pixel_shader;
|
2020-05-03 07:11:28 +00:00
|
|
|
ComPtr<ID3D11PixelShader> m_vram_update_depth_pixel_shader;
|
2020-05-25 17:18:04 +00:00
|
|
|
std::array<std::array<ComPtr<ID3D11PixelShader>, 3>, 2> m_display_pixel_shaders; // [depth_24][interlaced]
|
2020-12-25 08:02:38 +00:00
|
|
|
|
|
|
|
D3D11::Texture m_vram_replacement_texture;
|
2020-12-30 06:26:20 +00:00
|
|
|
|
|
|
|
// downsampling
|
|
|
|
ComPtr<ID3D11PixelShader> m_downsample_first_pass_pixel_shader;
|
|
|
|
ComPtr<ID3D11PixelShader> m_downsample_mid_pass_pixel_shader;
|
|
|
|
ComPtr<ID3D11PixelShader> m_downsample_blur_pass_pixel_shader;
|
|
|
|
ComPtr<ID3D11PixelShader> m_downsample_composite_pixel_shader;
|
|
|
|
D3D11::Texture m_downsample_texture;
|
|
|
|
D3D11::Texture m_downsample_weight_texture;
|
|
|
|
std::vector<std::pair<ComPtr<ID3D11ShaderResourceView>, ComPtr<ID3D11RenderTargetView>>> m_downsample_mip_views;
|
2019-11-03 14:39:48 +00:00
|
|
|
};
|