2021-11-26 17:08:41 +00:00
|
|
|
/*
|
|
|
|
Copyright 2021 flyinghead
|
|
|
|
|
|
|
|
This file is part of Flycast.
|
|
|
|
|
|
|
|
Flycast is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Flycast is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Flycast. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "types.h"
|
|
|
|
#include "hw/pvr/Renderer_if.h"
|
|
|
|
#include <d3d11.h>
|
|
|
|
#include "dx11context.h"
|
|
|
|
#include "rend/transform_matrix.h"
|
|
|
|
#include "dx11_quad.h"
|
|
|
|
#include "dx11_texture.h"
|
|
|
|
#include "dx11_shaders.h"
|
|
|
|
#include "dx11_renderstate.h"
|
2022-02-13 20:01:45 +00:00
|
|
|
#include "dx11_naomi2.h"
|
2022-02-14 17:38:58 +00:00
|
|
|
#ifndef LIBRETRO
|
|
|
|
#include "dx11_driver.h"
|
|
|
|
#endif
|
2021-11-26 17:08:41 +00:00
|
|
|
|
|
|
|
struct DX11Renderer : public Renderer
|
|
|
|
{
|
|
|
|
bool Init() override;
|
|
|
|
void Term() override;
|
2023-01-27 10:16:25 +00:00
|
|
|
void Process(TA_context* ctx) override;
|
2021-11-26 17:08:41 +00:00
|
|
|
bool Render() override;
|
2022-10-23 14:32:42 +00:00
|
|
|
void RenderFramebuffer(const FramebufferInfo& info) override;
|
2021-11-26 17:08:41 +00:00
|
|
|
|
|
|
|
bool Present() override
|
|
|
|
{
|
|
|
|
if (!frameRendered)
|
|
|
|
return false;
|
|
|
|
frameRendered = false;
|
2022-02-14 17:38:58 +00:00
|
|
|
#ifndef LIBRETRO
|
|
|
|
imguiDriver->setFrameRendered();
|
|
|
|
#endif
|
2021-11-26 17:08:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RenderLastFrame() override;
|
|
|
|
void DrawOSD(bool clear_screen) override;
|
|
|
|
BaseTextureCacheData *GetTexture(TSP tsp, TCW tcw) override;
|
|
|
|
|
2021-12-11 17:53:35 +00:00
|
|
|
protected:
|
|
|
|
struct VertexConstants
|
|
|
|
{
|
|
|
|
float transMatrix[4][4];
|
|
|
|
float leftPlane[4];
|
|
|
|
float topPlane[4];
|
|
|
|
float rightPlane[4];
|
|
|
|
float bottomPlane[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PixelConstants
|
|
|
|
{
|
|
|
|
float colorClampMin[4];
|
|
|
|
float colorClampMax[4];
|
|
|
|
float fog_col_vert[4];
|
|
|
|
float fog_col_ram[4];
|
2023-09-10 14:25:19 +00:00
|
|
|
float ditherColorMax[4];
|
2021-12-11 17:53:35 +00:00
|
|
|
float fogDensity;
|
|
|
|
float shadowScale;
|
|
|
|
float alphaTestValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PixelPolyConstants
|
|
|
|
{
|
|
|
|
float clipTest[4];
|
|
|
|
float paletteIndex;
|
|
|
|
float trilinearAlpha;
|
|
|
|
};
|
|
|
|
|
2022-10-23 14:32:42 +00:00
|
|
|
virtual void resize(int w, int h);
|
2021-12-11 17:53:35 +00:00
|
|
|
bool ensureBufferSize(ComPtr<ID3D11Buffer>& buffer, D3D11_BIND_FLAG bind, u32& currentSize, u32 minSize);
|
|
|
|
void createDepthTexAndView(ComPtr<ID3D11Texture2D>& texture, ComPtr<ID3D11DepthStencilView>& view, int width, int height, DXGI_FORMAT format = DXGI_FORMAT_D24_UNORM_S8_UINT, UINT bindFlags = 0);
|
|
|
|
void createTexAndRenderTarget(ComPtr<ID3D11Texture2D>& texture, ComPtr<ID3D11RenderTargetView>& renderTarget, int width, int height);
|
|
|
|
void configVertexShader();
|
|
|
|
void uploadGeometryBuffers();
|
|
|
|
void setupPixelShaderConstants();
|
|
|
|
void updateFogTexture();
|
|
|
|
void updatePaletteTexture();
|
|
|
|
void readRttRenderTarget(u32 texAddress);
|
2022-10-25 13:00:04 +00:00
|
|
|
void displayFramebuffer();
|
2021-12-11 17:53:35 +00:00
|
|
|
void setCullMode(int mode);
|
2022-05-03 15:47:43 +00:00
|
|
|
virtual void setRTTSize(int width, int height) {}
|
2022-10-23 14:32:42 +00:00
|
|
|
void writeFramebufferToVRAM();
|
2023-06-26 09:56:56 +00:00
|
|
|
void renderVideoRouting();
|
2021-12-11 17:53:35 +00:00
|
|
|
|
|
|
|
ComPtr<ID3D11Device> device;
|
|
|
|
ComPtr<ID3D11DeviceContext> deviceContext;
|
|
|
|
ComPtr<ID3D11Texture2D> depthTex;
|
|
|
|
ComPtr<ID3D11DepthStencilView> depthTexView;
|
|
|
|
ComPtr<ID3D11InputLayout> mainInputLayout;
|
|
|
|
ComPtr<ID3D11InputLayout> modVolInputLayout;
|
|
|
|
ComPtr<ID3D11Buffer> pxlPolyConstants;
|
|
|
|
ComPtr<ID3D11Buffer> vertexBuffer;
|
|
|
|
ComPtr<ID3D11Buffer> indexBuffer;
|
|
|
|
ComPtr<ID3D11Buffer> modvolBuffer;
|
|
|
|
ComPtr<ID3D11RenderTargetView> fbRenderTarget;
|
|
|
|
ComPtr<ID3D11RenderTargetView> rttRenderTarget;
|
2021-12-13 20:02:44 +00:00
|
|
|
ComPtr<ID3D11ShaderResourceView> fbTextureView;
|
2021-12-11 17:53:35 +00:00
|
|
|
|
|
|
|
BlendStates blendStates;
|
|
|
|
DepthStencilStates depthStencilStates;
|
|
|
|
Samplers *samplers;
|
|
|
|
TransformMatrix<COORD_DIRECTX> matrices;
|
|
|
|
D3D11_RECT scissorRect{};
|
|
|
|
u32 width = 0;
|
|
|
|
u32 height = 0;
|
|
|
|
bool frameRendered = false;
|
|
|
|
bool frameRenderedOnce = false;
|
2022-02-13 20:01:45 +00:00
|
|
|
Naomi2Helper n2Helper;
|
2022-10-25 13:00:04 +00:00
|
|
|
float aspectRatio = 4.f / 3.f;
|
2023-09-10 14:25:19 +00:00
|
|
|
bool dithering = false;
|
2021-12-11 17:53:35 +00:00
|
|
|
|
2021-11-26 17:08:41 +00:00
|
|
|
private:
|
|
|
|
void readDCFramebuffer();
|
|
|
|
void prepareRttRenderTarget(u32 texAddress);
|
|
|
|
void setBaseScissor();
|
|
|
|
void drawStrips();
|
|
|
|
template <u32 Type, bool SortingEnabled>
|
2023-01-26 13:13:28 +00:00
|
|
|
void drawList(const std::vector<PolyParam>& gply, int first, int count);
|
2021-11-26 17:08:41 +00:00
|
|
|
template <u32 Type, bool SortingEnabled>
|
|
|
|
void setRenderState(const PolyParam *gp);
|
2022-12-13 21:57:57 +00:00
|
|
|
void drawSorted(int first, int count, bool multipass);
|
2021-11-26 17:08:41 +00:00
|
|
|
void drawModVols(int first, int count);
|
|
|
|
|
|
|
|
u32 vertexBufferSize = 0;
|
|
|
|
u32 modvolBufferSize = 0;
|
|
|
|
u32 indexBufferSize = 0;
|
|
|
|
|
|
|
|
ComPtr<ID3D11Texture2D> fbTex;
|
|
|
|
ComPtr<ID3D11Texture2D> dcfbTexture;
|
|
|
|
ComPtr<ID3D11ShaderResourceView> dcfbTextureView;
|
|
|
|
ComPtr<ID3D11Texture2D> paletteTexture;
|
|
|
|
ComPtr<ID3D11ShaderResourceView> paletteTextureView;
|
|
|
|
ComPtr<ID3D11Texture2D> fogTexture;
|
|
|
|
ComPtr<ID3D11ShaderResourceView> fogTextureView;
|
|
|
|
ComPtr<ID3D11Texture2D> rttTexture;
|
|
|
|
ComPtr<ID3D11Texture2D> rttDepthTex;
|
|
|
|
ComPtr<ID3D11DepthStencilView> rttDepthTexView;
|
2021-11-29 17:22:25 +00:00
|
|
|
ComPtr<ID3D11Texture2D> whiteTexture;
|
|
|
|
ComPtr<ID3D11ShaderResourceView> whiteTextureView;
|
2022-10-23 14:32:42 +00:00
|
|
|
ComPtr<ID3D11Texture2D> fbScaledTexture;
|
|
|
|
ComPtr<ID3D11ShaderResourceView> fbScaledTextureView;
|
|
|
|
ComPtr<ID3D11RenderTargetView> fbScaledRenderTarget;
|
2023-06-26 09:56:56 +00:00
|
|
|
ComPtr<ID3D11Texture2D> vrStagingTexture;
|
|
|
|
ComPtr<ID3D11ShaderResourceView> vrStagingTextureSRV;
|
|
|
|
ComPtr<ID3D11Texture2D> vrScaledTexture;
|
|
|
|
ComPtr<ID3D11RenderTargetView> vrScaledRenderTarget;
|
2021-11-26 17:08:41 +00:00
|
|
|
|
|
|
|
ComPtr<ID3D11RasterizerState> rasterCullNone, rasterCullFront, rasterCullBack;
|
|
|
|
|
|
|
|
DX11TextureCache texCache;
|
2021-11-29 17:22:25 +00:00
|
|
|
DX11Shaders *shaders;
|
2021-11-26 17:08:41 +00:00
|
|
|
std::unique_ptr<Quad> quad;
|
|
|
|
ComPtr<ID3D11Buffer> vtxConstants;
|
|
|
|
ComPtr<ID3D11Buffer> pxlConstants;
|
|
|
|
bool scissorEnable = false;
|
|
|
|
};
|