D3D11 device refactoring

This commit is contained in:
Stenzek 2023-07-30 22:10:36 +10:00
parent 02d379116e
commit 12fbeb9280
40 changed files with 1521 additions and 1363 deletions

View File

@ -36,8 +36,8 @@
<ClCompile Include="gpu\d3d11\shader_cache.cpp" />
<ClCompile Include="gpu\d3d11\shader_compiler.cpp" />
<ClCompile Include="gpu\d3d11\stream_buffer.cpp" />
<ClCompile Include="gpu\d3d11\texture.cpp" />
<ClCompile Include="gpu\d3d11_gpu_device.cpp" />
<ClCompile Include="gpu\d3d11_device.cpp" />
<ClCompile Include="gpu\d3d11_texture.cpp" />
<ClCompile Include="gpu\d3d12\context.cpp" />
<ClCompile Include="gpu\d3d12\descriptor_heap_manager.cpp" />
<ClCompile Include="gpu\d3d12\shader_cache.cpp" />
@ -69,7 +69,6 @@
</ClCompile>
<ClCompile Include="gpu\gpu_device.cpp" />
<ClCompile Include="gpu\gpu_texture.cpp" />
<ClCompile Include="gpu\imgui_impl_dx11.cpp" />
<ClCompile Include="gpu\imgui_impl_dx12.cpp" />
<ClCompile Include="gpu\imgui_impl_opengl3.cpp" />
<ClCompile Include="gpu\imgui_impl_vulkan.cpp" />
@ -161,8 +160,9 @@
<ClInclude Include="gpu\d3d11\shader_cache.h" />
<ClInclude Include="gpu\d3d11\shader_compiler.h" />
<ClInclude Include="gpu\d3d11\stream_buffer.h" />
<ClInclude Include="gpu\d3d11\texture.h" />
<ClInclude Include="gpu\d3d11_gpu_device.h" />
<ClInclude Include="gpu\d3d11_device.h" />
<ClInclude Include="gpu\d3d_shaders.h" />
<ClInclude Include="gpu\d3d11_texture.h" />
<ClInclude Include="gpu\d3d12\context.h" />
<ClInclude Include="gpu\d3d12\descriptor_heap_manager.h" />
<ClInclude Include="gpu\d3d12\shader_cache.h" />
@ -198,7 +198,6 @@
</ClInclude>
<ClInclude Include="gpu\gpu_device.h" />
<ClInclude Include="gpu\gpu_texture.h" />
<ClInclude Include="gpu\imgui_impl_dx11.h" />
<ClInclude Include="gpu\imgui_impl_dx12.h" />
<ClInclude Include="gpu\imgui_impl_opengl3.h" />
<ClInclude Include="gpu\imgui_impl_vulkan.h" />

View File

@ -59,7 +59,7 @@
<ClCompile Include="host.cpp" />
<ClCompile Include="game_database.cpp" />
<ClCompile Include="pcdrv.cpp" />
<ClCompile Include="gpu\d3d11_gpu_device.cpp">
<ClCompile Include="gpu\d3d11_device.cpp">
<Filter>gpu</Filter>
</ClCompile>
<ClCompile Include="gpu\d3d12_gpu_device.cpp">
@ -77,9 +77,6 @@
<ClCompile Include="gpu\d3d11\stream_buffer.cpp">
<Filter>gpu\d3d11</Filter>
</ClCompile>
<ClCompile Include="gpu\d3d11\texture.cpp">
<Filter>gpu\d3d11</Filter>
</ClCompile>
<ClCompile Include="gpu\d3d11\shader_cache.cpp">
<Filter>gpu\d3d11</Filter>
</ClCompile>
@ -185,10 +182,10 @@
<ClCompile Include="gpu\imgui_impl_vulkan.cpp">
<Filter>gpu</Filter>
</ClCompile>
<ClCompile Include="gpu\imgui_impl_dx11.cpp">
<ClCompile Include="gpu\gpu_texture.cpp">
<Filter>gpu</Filter>
</ClCompile>
<ClCompile Include="gpu\gpu_texture.cpp">
<ClCompile Include="gpu\d3d11_texture.cpp">
<Filter>gpu</Filter>
</ClCompile>
</ItemGroup>
@ -257,7 +254,7 @@
<ClInclude Include="game_database.h" />
<ClInclude Include="input_types.h" />
<ClInclude Include="pcdrv.h" />
<ClInclude Include="gpu\d3d11_gpu_device.h">
<ClInclude Include="gpu\d3d11_device.h">
<Filter>gpu</Filter>
</ClInclude>
<ClInclude Include="gpu\d3d12_gpu_device.h">
@ -278,9 +275,6 @@
<ClInclude Include="gpu\d3d11\stream_buffer.h">
<Filter>gpu\d3d11</Filter>
</ClInclude>
<ClInclude Include="gpu\d3d11\texture.h">
<Filter>gpu\d3d11</Filter>
</ClInclude>
<ClInclude Include="gpu\d3d11\shader_cache.h">
<Filter>gpu\d3d11</Filter>
</ClInclude>
@ -392,10 +386,13 @@
<ClInclude Include="gpu\imgui_impl_vulkan.h">
<Filter>gpu</Filter>
</ClInclude>
<ClInclude Include="gpu\imgui_impl_dx11.h">
<ClInclude Include="gpu\gpu_texture.h">
<Filter>gpu</Filter>
</ClInclude>
<ClInclude Include="gpu\gpu_texture.h">
<ClInclude Include="gpu\d3d11_texture.h">
<Filter>gpu</Filter>
</ClInclude>
<ClInclude Include="gpu\d3d_shaders.h">
<Filter>gpu</Filter>
</ClInclude>
</ItemGroup>

View File

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
#include "d3d11_gpu_device.h"
#include "d3d11_device.h"
#include "../host_settings.h"
#include "../settings.h"
#include "../shader_cache_version.h"
@ -10,24 +10,21 @@
#include "common/string_util.h"
#include "d3d11/shader_cache.h"
#include "d3d11/shader_compiler.h"
#include "display_ps.hlsl.h"
#include "display_ps_alpha.hlsl.h"
#include "display_vs.hlsl.h"
#include "d3d_shaders.h"
#include "imgui.h"
#include "imgui_impl_dx11.h"
#include "postprocessing_shadergen.h"
#include <array>
#include <dxgi1_5.h>
Log_SetChannel(D3D11GPUDevice);
Log_SetChannel(D3D11Device);
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dxgi.lib")
static constexpr std::array<float, 4> s_clear_color = {};
D3D11GPUDevice::D3D11GPUDevice() = default;
D3D11Device::D3D11Device() = default;
D3D11GPUDevice::~D3D11GPUDevice()
D3D11Device::~D3D11Device()
{
DestroyStagingBuffer();
DestroyResources();
@ -36,86 +33,46 @@ D3D11GPUDevice::~D3D11GPUDevice()
m_device.Reset();
}
RenderAPI D3D11GPUDevice::GetRenderAPI() const
RenderAPI D3D11Device::GetRenderAPI() const
{
return RenderAPI::D3D11;
}
void* D3D11GPUDevice::GetDevice() const
void* D3D11Device::GetDevice() const
{
return m_device.Get();
}
void* D3D11GPUDevice::GetContext() const
void* D3D11Device::GetContext() const
{
return m_context.Get();
}
bool D3D11GPUDevice::HasDevice() const
bool D3D11Device::HasDevice() const
{
return static_cast<bool>(m_device);
}
bool D3D11GPUDevice::HasSurface() const
bool D3D11Device::HasSurface() const
{
return static_cast<bool>(m_swap_chain);
}
std::unique_ptr<GPUTexture> D3D11GPUDevice::CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
GPUTexture::Format format, const void* data, u32 data_stride,
bool dynamic /* = false */)
std::unique_ptr<GPUTexture> D3D11Device::CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
GPUTexture::Type type, GPUTexture::Format format,
const void* data, u32 data_stride, bool dynamic /* = false */)
{
std::unique_ptr<D3D11::Texture> tex(std::make_unique<D3D11::Texture>());
if (!tex->Create(m_device.Get(), width, height, layers, levels, samples, format, D3D11_BIND_SHADER_RESOURCE, data,
data_stride, dynamic))
{
std::unique_ptr<D3D11Texture> tex = std::make_unique<D3D11Texture>();
if (!tex->Create(m_device.Get(), width, height, layers, levels, samples, type, format, data, data_stride, dynamic))
tex.reset();
}
return tex;
}
bool D3D11GPUDevice::BeginTextureUpdate(GPUTexture* texture, u32 width, u32 height, void** out_buffer, u32* out_pitch)
bool D3D11Device::DownloadTexture(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, void* out_data,
u32 out_data_stride)
{
D3D11::Texture* tex = static_cast<D3D11::Texture*>(texture);
if (!tex->IsDynamic() || tex->GetWidth() != width || tex->GetHeight() != height)
return false;
D3D11_MAPPED_SUBRESOURCE sr;
HRESULT hr = m_context->Map(tex->GetD3DTexture(), 0, D3D11_MAP_WRITE_DISCARD, 0, &sr);
if (FAILED(hr))
{
Log_ErrorPrintf("Map pixels texture failed: %08X", hr);
return false;
}
*out_buffer = sr.pData;
*out_pitch = sr.RowPitch;
return true;
}
void D3D11GPUDevice::EndTextureUpdate(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height)
{
D3D11::Texture* tex = static_cast<D3D11::Texture*>(texture);
m_context->Unmap(tex->GetD3DTexture(), 0);
}
bool D3D11GPUDevice::UpdateTexture(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, const void* data,
u32 pitch)
{
D3D11::Texture* tex = static_cast<D3D11::Texture*>(texture);
if (tex->IsDynamic())
return GPUDevice::UpdateTexture(texture, x, y, width, height, data, pitch);
const CD3D11_BOX dst_box(x, y, 0, x + width, y + height, 1);
m_context->UpdateSubresource(tex->GetD3DTexture(), 0, &dst_box, data, pitch, pitch * height);
return true;
}
bool D3D11GPUDevice::DownloadTexture(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, void* out_data,
u32 out_data_stride)
{
const D3D11::Texture* tex = static_cast<const D3D11::Texture*>(texture);
const D3D11Texture* tex = static_cast<const D3D11Texture*>(texture);
if (!CheckStagingBufferSize(width, height, tex->GetDXGIFormat()))
return false;
@ -137,7 +94,7 @@ bool D3D11GPUDevice::DownloadTexture(GPUTexture* texture, u32 x, u32 y, u32 widt
return true;
}
bool D3D11GPUDevice::CheckStagingBufferSize(u32 width, u32 height, DXGI_FORMAT format)
bool D3D11Device::CheckStagingBufferSize(u32 width, u32 height, DXGI_FORMAT format)
{
if (m_readback_staging_texture_width >= width && m_readback_staging_texture_width >= height &&
m_readback_staging_texture_format == format)
@ -156,7 +113,7 @@ bool D3D11GPUDevice::CheckStagingBufferSize(u32 width, u32 height, DXGI_FORMAT f
return true;
}
void D3D11GPUDevice::DestroyStagingBuffer()
void D3D11Device::DestroyStagingBuffer()
{
m_readback_staging_texture.Reset();
m_readback_staging_texture_width = 0;
@ -164,9 +121,9 @@ void D3D11GPUDevice::DestroyStagingBuffer()
m_readback_staging_texture_format = DXGI_FORMAT_UNKNOWN;
}
bool D3D11GPUDevice::SupportsTextureFormat(GPUTexture::Format format) const
bool D3D11Device::SupportsTextureFormat(GPUTexture::Format format) const
{
const DXGI_FORMAT dfmt = D3D11::Texture::GetDXGIFormat(format);
const DXGI_FORMAT dfmt = D3D11Texture::GetDXGIFormat(format);
if (dfmt == DXGI_FORMAT_UNKNOWN)
return false;
@ -175,7 +132,7 @@ bool D3D11GPUDevice::SupportsTextureFormat(GPUTexture::Format format) const
return (SUCCEEDED(m_device->CheckFormatSupport(dfmt, &support)) && ((support & required) == required));
}
bool D3D11GPUDevice::GetHostRefreshRate(float* refresh_rate)
bool D3D11Device::GetHostRefreshRate(float* refresh_rate)
{
if (m_swap_chain && IsFullscreen())
{
@ -194,12 +151,12 @@ bool D3D11GPUDevice::GetHostRefreshRate(float* refresh_rate)
return GPUDevice::GetHostRefreshRate(refresh_rate);
}
void D3D11GPUDevice::SetVSync(bool enabled)
void D3D11Device::SetVSync(bool enabled)
{
m_vsync_enabled = enabled;
}
bool D3D11GPUDevice::CreateDevice(const WindowInfo& wi, bool vsync)
bool D3D11Device::CreateDevice(const WindowInfo& wi, bool vsync)
{
UINT create_flags = 0;
if (g_settings.gpu_use_debug_device)
@ -319,7 +276,7 @@ bool D3D11GPUDevice::CreateDevice(const WindowInfo& wi, bool vsync)
return true;
}
bool D3D11GPUDevice::SetupDevice()
bool D3D11Device::SetupDevice()
{
if (!CreateResources())
return false;
@ -327,17 +284,17 @@ bool D3D11GPUDevice::SetupDevice()
return true;
}
bool D3D11GPUDevice::MakeCurrent()
bool D3D11Device::MakeCurrent()
{
return true;
}
bool D3D11GPUDevice::DoneCurrent()
bool D3D11Device::DoneCurrent()
{
return true;
}
bool D3D11GPUDevice::CreateSwapChain(const DXGI_MODE_DESC* fullscreen_mode)
bool D3D11Device::CreateSwapChain(const DXGI_MODE_DESC* fullscreen_mode)
{
HRESULT hr;
@ -407,7 +364,7 @@ bool D3D11GPUDevice::CreateSwapChain(const DXGI_MODE_DESC* fullscreen_mode)
return CreateSwapChainRTV();
}
bool D3D11GPUDevice::CreateSwapChainRTV()
bool D3D11Device::CreateSwapChainRTV()
{
ComPtr<ID3D11Texture2D> backbuffer;
HRESULT hr = m_swap_chain->GetBuffer(0, IID_PPV_ARGS(backbuffer.GetAddressOf()));
@ -452,7 +409,7 @@ bool D3D11GPUDevice::CreateSwapChainRTV()
return true;
}
bool D3D11GPUDevice::ChangeWindow(const WindowInfo& new_wi)
bool D3D11Device::ChangeWindow(const WindowInfo& new_wi)
{
DestroySurface();
@ -460,7 +417,7 @@ bool D3D11GPUDevice::ChangeWindow(const WindowInfo& new_wi)
return CreateSwapChain(nullptr);
}
void D3D11GPUDevice::DestroySurface()
void D3D11Device::DestroySurface()
{
m_window_info.SetSurfaceless();
if (IsFullscreen())
@ -470,7 +427,7 @@ void D3D11GPUDevice::DestroySurface()
m_swap_chain.Reset();
}
void D3D11GPUDevice::ResizeWindow(s32 new_window_width, s32 new_window_height)
void D3D11Device::ResizeWindow(s32 new_window_width, s32 new_window_height)
{
if (!m_swap_chain)
return;
@ -486,18 +443,18 @@ void D3D11GPUDevice::ResizeWindow(s32 new_window_width, s32 new_window_height)
Panic("Failed to recreate swap chain RTV after resize");
}
bool D3D11GPUDevice::SupportsFullscreen() const
bool D3D11Device::SupportsFullscreen() const
{
return true;
}
bool D3D11GPUDevice::IsFullscreen()
bool D3D11Device::IsFullscreen()
{
BOOL is_fullscreen = FALSE;
return (m_swap_chain && SUCCEEDED(m_swap_chain->GetFullscreenState(&is_fullscreen, nullptr)) && is_fullscreen);
}
bool D3D11GPUDevice::SetFullscreen(bool fullscreen, u32 width, u32 height, float refresh_rate)
bool D3D11Device::SetFullscreen(bool fullscreen, u32 width, u32 height, float refresh_rate)
{
if (!m_swap_chain)
return false;
@ -559,7 +516,7 @@ bool D3D11GPUDevice::SetFullscreen(bool fullscreen, u32 width, u32 height, float
return true;
}
bool D3D11GPUDevice::CreateResources()
bool D3D11Device::CreateResources()
{
HRESULT hr;
@ -627,13 +584,18 @@ bool D3D11GPUDevice::CreateResources()
if (FAILED(hr))
return false;
if (!CreateImGuiResources())
return false;
return true;
}
void D3D11GPUDevice::DestroyResources()
void D3D11Device::DestroyResources()
{
GPUDevice::DestroyResources();
DestroyImGuiResources();
m_post_processing_chain.ClearStages();
m_post_processing_input_texture.Destroy();
m_post_processing_stages.clear();
@ -650,23 +612,142 @@ void D3D11GPUDevice::DestroyResources()
m_display_rasterizer_state.Reset();
}
bool D3D11GPUDevice::CreateImGuiContext()
bool D3D11Device::CreateImGuiResources()
{
return ImGui_ImplDX11_Init(m_device.Get(), m_context.Get());
}
if (!m_imgui_vertex_buffer.Create(m_device.Get(), D3D11_BIND_VERTEX_BUFFER, IMGUI_VERTEX_BUFFER_SIZE))
{
Log_ErrorPrintf("Failed to create ImGui vertex buffer.");
return false;
}
void D3D11GPUDevice::DestroyImGuiContext()
{
ImGui_ImplDX11_Shutdown();
}
if (!m_imgui_index_buffer.Create(m_device.Get(), D3D11_BIND_INDEX_BUFFER, IMGUI_INDEX_BUFFER_SIZE))
{
Log_ErrorPrintf("Failed to create ImGui index buffer.");
return false;
}
HRESULT hr;
D3D11_BLEND_DESC blend_desc = {};
blend_desc.RenderTarget[0].BlendEnable = true;
blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
if (FAILED(hr = m_device->CreateBlendState(&blend_desc, m_imgui_blend_state.ReleaseAndGetAddressOf())))
{
Log_ErrorPrintf("Failed to create ImGui blend state: %08X", hr);
return false;
}
m_imgui_vertex_shader =
D3D11::ShaderCompiler::CreateVertexShader(m_device.Get(), s_imgui_vs_bytecode, sizeof(s_imgui_vs_bytecode));
m_imgui_pixel_shader =
D3D11::ShaderCompiler::CreatePixelShader(m_device.Get(), s_imgui_ps_bytecode, sizeof(s_imgui_ps_bytecode));
if (!m_imgui_vertex_shader || !m_imgui_pixel_shader)
return false;
static constexpr D3D11_INPUT_ELEMENT_DESC layout[] = {
{"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)IM_OFFSETOF(ImDrawVert, pos), D3D11_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)IM_OFFSETOF(ImDrawVert, uv), D3D11_INPUT_PER_VERTEX_DATA, 0},
{"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (UINT)IM_OFFSETOF(ImDrawVert, col), D3D11_INPUT_PER_VERTEX_DATA, 0},
};
if (FAILED(hr =
m_device->CreateInputLayout(layout, static_cast<u32>(std::size(layout)), s_imgui_vs_bytecode,
sizeof(s_imgui_vs_bytecode), m_imgui_input_layout.ReleaseAndGetAddressOf())))
{
Log_ErrorPrintf("Failed to create ImGui input layout: %08X", hr);
return false;
}
bool D3D11GPUDevice::UpdateImGuiFontTexture()
{
ImGui_ImplDX11_CreateFontsTexture();
return true;
}
bool D3D11GPUDevice::Render(bool skip_present)
void D3D11Device::DestroyImGuiResources()
{
m_imgui_blend_state.Reset();
m_imgui_index_buffer.Release();
m_imgui_vertex_buffer.Release();
m_imgui_texture.Destroy();
}
void D3D11Device::RenderImGui()
{
ImGui::Render();
const ImDrawData* draw_data = ImGui::GetDrawData();
if (draw_data->CmdListsCount == 0)
return;
m_context->IASetInputLayout(m_imgui_input_layout.Get());
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->VSSetShader(m_imgui_vertex_shader.Get(), nullptr, 0);
m_context->PSSetShader(m_imgui_pixel_shader.Get(), nullptr, 0);
m_context->PSSetSamplers(0, 1, m_linear_sampler.GetAddressOf());
m_context->OMSetBlendState(m_imgui_blend_state.Get(), nullptr, 0xFFFFFFFFu);
m_context->OMSetDepthStencilState(m_display_depth_stencil_state.Get(), 0);
{
const float L = 0.0f;
const float R = static_cast<float>(m_window_info.surface_width);
const float T = 0.0f;
const float B = static_cast<float>(m_window_info.surface_height);
const float ortho_projection[4][4] = {
{2.0f / (R - L), 0.0f, 0.0f, 0.0f},
{0.0f, 2.0f / (T - B), 0.0f, 0.0f},
{0.0f, 0.0f, 0.5f, 0.0f},
{(R + L) / (L - R), (T + B) / (B - T), 0.5f, 1.0f},
};
auto res = m_display_uniform_buffer.Map(m_context.Get(), DISPLAY_UNIFORM_BUFFER_SIZE, DISPLAY_UNIFORM_BUFFER_SIZE);
std::memcpy(res.pointer, ortho_projection, sizeof(ortho_projection));
m_display_uniform_buffer.Unmap(m_context.Get(), sizeof(ortho_projection));
m_context->VSSetConstantBuffers(0, 1, m_display_uniform_buffer.GetD3DBufferArray());
}
const UINT vb_stride = sizeof(ImDrawVert);
const UINT vb_offset = 0;
static_assert(sizeof(ImDrawIdx) == sizeof(u16));
m_context->IASetVertexBuffers(0, 1, m_imgui_vertex_buffer.GetD3DBufferArray(), &vb_stride, &vb_offset);
m_context->IASetIndexBuffer(m_imgui_index_buffer.GetD3DBuffer(), DXGI_FORMAT_R16_UINT, 0);
// Render command lists
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
const ImDrawList* cmd_list = draw_data->CmdLists[n];
const u32 vert_size = cmd_list->VtxBuffer.Size * sizeof(ImDrawVert);
const auto vb_map = m_imgui_vertex_buffer.Map(m_context.Get(), sizeof(ImDrawVert), vert_size);
std::memcpy(vb_map.pointer, cmd_list->VtxBuffer.Data, vert_size);
m_imgui_vertex_buffer.Unmap(m_context.Get(), vert_size);
const u32 idx_size = cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx);
const auto ib_map = m_imgui_index_buffer.Map(m_context.Get(), sizeof(ImDrawIdx), idx_size);
std::memcpy(ib_map.pointer, cmd_list->IdxBuffer.Data, idx_size);
m_imgui_index_buffer.Unmap(m_context.Get(), idx_size);
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
{
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
DebugAssert(!pcmd->UserCallback);
if (pcmd->ClipRect.z <= pcmd->ClipRect.x || pcmd->ClipRect.w <= pcmd->ClipRect.x)
continue;
const CD3D11_RECT rc(static_cast<LONG>(pcmd->ClipRect.x), static_cast<LONG>(pcmd->ClipRect.y),
static_cast<LONG>(pcmd->ClipRect.z), static_cast<LONG>(pcmd->ClipRect.w));
m_context->RSSetScissorRects(1, &rc);
m_context->PSSetShaderResources(0, 1, reinterpret_cast<const D3D11Texture*>(pcmd->TextureId)->GetD3DSRVArray());
m_context->DrawIndexed(pcmd->ElemCount, ib_map.index_aligned + pcmd->IdxOffset,
vb_map.index_aligned + pcmd->VtxOffset);
}
}
}
bool D3D11Device::Render(bool skip_present)
{
if (skip_present || !m_swap_chain)
{
@ -685,6 +766,11 @@ bool D3D11GPUDevice::Render(bool skip_present)
RenderDisplay();
// TODO: move up...
const CD3D11_VIEWPORT vp(0.0f, 0.0f, static_cast<float>(m_window_info.surface_width),
static_cast<float>(m_window_info.surface_height), 0.0f, 1.0f);
m_context->RSSetViewports(1, &vp);
if (ImGui::GetCurrentContext())
RenderImGui();
@ -704,13 +790,13 @@ bool D3D11GPUDevice::Render(bool skip_present)
return true;
}
bool D3D11GPUDevice::RenderScreenshot(u32 width, u32 height, const Common::Rectangle<s32>& draw_rect,
std::vector<u32>* out_pixels, u32* out_stride, GPUTexture::Format* out_format)
bool D3D11Device::RenderScreenshot(u32 width, u32 height, const Common::Rectangle<s32>& draw_rect,
std::vector<u32>* out_pixels, u32* out_stride, GPUTexture::Format* out_format)
{
static constexpr GPUTexture::Format hdformat = GPUTexture::Format::RGBA8;
D3D11::Texture render_texture;
if (!render_texture.Create(m_device.Get(), width, height, 1, 1, 1, hdformat, D3D11_BIND_RENDER_TARGET))
D3D11Texture render_texture;
if (!render_texture.Create(m_device.Get(), width, height, 1, 1, 1, GPUTexture::Type::RenderTarget, hdformat))
return false;
static constexpr std::array<float, 4> clear_color = {};
@ -722,14 +808,14 @@ bool D3D11GPUDevice::RenderScreenshot(u32 width, u32 height, const Common::Recta
if (!m_post_processing_chain.IsEmpty())
{
ApplyPostProcessingChain(render_texture.GetD3DRTV(), draw_rect.left, draw_rect.top, draw_rect.GetWidth(),
draw_rect.GetHeight(), static_cast<D3D11::Texture*>(m_display_texture),
draw_rect.GetHeight(), static_cast<D3D11Texture*>(m_display_texture),
m_display_texture_view_x, m_display_texture_view_y, m_display_texture_view_width,
m_display_texture_view_height, width, height);
}
else
{
RenderDisplay(draw_rect.left, draw_rect.top, draw_rect.GetWidth(), draw_rect.GetHeight(),
static_cast<D3D11::Texture*>(m_display_texture), m_display_texture_view_x, m_display_texture_view_y,
static_cast<D3D11Texture*>(m_display_texture), m_display_texture_view_x, m_display_texture_view_y,
m_display_texture_view_width, m_display_texture_view_height, IsUsingLinearFiltering());
}
}
@ -746,20 +832,14 @@ bool D3D11GPUDevice::RenderScreenshot(u32 width, u32 height, const Common::Recta
return true;
}
void D3D11GPUDevice::RenderImGui()
{
ImGui::Render();
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
}
void D3D11GPUDevice::RenderDisplay()
void D3D11Device::RenderDisplay()
{
const auto [left, top, width, height] = CalculateDrawRect(GetWindowWidth(), GetWindowHeight());
if (HasDisplayTexture() && !m_post_processing_chain.IsEmpty())
{
ApplyPostProcessingChain(m_swap_chain_rtv.Get(), left, top, width, height,
static_cast<D3D11::Texture*>(m_display_texture), m_display_texture_view_x,
static_cast<D3D11Texture*>(m_display_texture), m_display_texture_view_x,
m_display_texture_view_y, m_display_texture_view_width, m_display_texture_view_height,
GetWindowWidth(), GetWindowHeight());
return;
@ -771,14 +851,13 @@ void D3D11GPUDevice::RenderDisplay()
if (!HasDisplayTexture())
return;
RenderDisplay(left, top, width, height, static_cast<D3D11::Texture*>(m_display_texture), m_display_texture_view_x,
RenderDisplay(left, top, width, height, static_cast<D3D11Texture*>(m_display_texture), m_display_texture_view_x,
m_display_texture_view_y, m_display_texture_view_width, m_display_texture_view_height,
IsUsingLinearFiltering());
}
void D3D11GPUDevice::RenderDisplay(s32 left, s32 top, s32 width, s32 height, D3D11::Texture* texture,
s32 texture_view_x, s32 texture_view_y, s32 texture_view_width,
s32 texture_view_height, bool linear_filter)
void D3D11Device::RenderDisplay(s32 left, s32 top, s32 width, s32 height, D3D11Texture* texture, s32 texture_view_x,
s32 texture_view_y, s32 texture_view_width, s32 texture_view_height, bool linear_filter)
{
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->VSSetShader(m_display_vertex_shader.Get(), nullptr, 0);
@ -809,7 +888,7 @@ void D3D11GPUDevice::RenderDisplay(s32 left, s32 top, s32 width, s32 height, D3D
m_context->Draw(3, 0);
}
void D3D11GPUDevice::RenderSoftwareCursor()
void D3D11Device::RenderSoftwareCursor()
{
if (!HasSoftwareCursor())
return;
@ -818,12 +897,12 @@ void D3D11GPUDevice::RenderSoftwareCursor()
RenderSoftwareCursor(left, top, width, height, m_cursor_texture.get());
}
void D3D11GPUDevice::RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 height, GPUTexture* texture_handle)
void D3D11Device::RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 height, GPUTexture* texture_handle)
{
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->VSSetShader(m_display_vertex_shader.Get(), nullptr, 0);
m_context->PSSetShader(m_display_alpha_pixel_shader.Get(), nullptr, 0);
m_context->PSSetShaderResources(0, 1, static_cast<D3D11::Texture*>(texture_handle)->GetD3DSRVArray());
m_context->PSSetShaderResources(0, 1, static_cast<D3D11Texture*>(texture_handle)->GetD3DSRVArray());
m_context->PSSetSamplers(0, 1, m_linear_sampler.GetAddressOf());
const float uniforms[4] = {0.0f, 0.0f, 1.0f, 1.0f};
@ -842,7 +921,7 @@ void D3D11GPUDevice::RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 heig
m_context->Draw(3, 0);
}
GPUDevice::AdapterAndModeList D3D11GPUDevice::StaticGetAdapterAndModeList()
GPUDevice::AdapterAndModeList D3D11Device::StaticGetAdapterAndModeList()
{
ComPtr<IDXGIFactory> dxgi_factory;
HRESULT hr = CreateDXGIFactory(IID_PPV_ARGS(dxgi_factory.GetAddressOf()));
@ -852,7 +931,7 @@ GPUDevice::AdapterAndModeList D3D11GPUDevice::StaticGetAdapterAndModeList()
return GetAdapterAndModeList(dxgi_factory.Get());
}
GPUDevice::AdapterAndModeList D3D11GPUDevice::GetAdapterAndModeList(IDXGIFactory* dxgi_factory)
GPUDevice::AdapterAndModeList D3D11Device::GetAdapterAndModeList(IDXGIFactory* dxgi_factory)
{
AdapterAndModeList adapter_info;
ComPtr<IDXGIAdapter> current_adapter;
@ -920,12 +999,12 @@ GPUDevice::AdapterAndModeList D3D11GPUDevice::GetAdapterAndModeList(IDXGIFactory
return adapter_info;
}
GPUDevice::AdapterAndModeList D3D11GPUDevice::GetAdapterAndModeList()
GPUDevice::AdapterAndModeList D3D11Device::GetAdapterAndModeList()
{
return GetAdapterAndModeList(m_dxgi_factory.Get());
}
bool D3D11GPUDevice::SetPostProcessingChain(const std::string_view& config)
bool D3D11Device::SetPostProcessingChain(const std::string_view& config)
{
if (config.empty())
{
@ -982,21 +1061,18 @@ bool D3D11GPUDevice::SetPostProcessingChain(const std::string_view& config)
return true;
}
bool D3D11GPUDevice::CheckPostProcessingRenderTargets(u32 target_width, u32 target_height)
bool D3D11Device::CheckPostProcessingRenderTargets(u32 target_width, u32 target_height)
{
DebugAssert(!m_post_processing_stages.empty());
const GPUTexture::Type type = GPUTexture::Type::RenderTarget;
const GPUTexture::Format format = GPUTexture::Format::RGBA8;
const u32 bind_flags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
if (m_post_processing_input_texture.GetWidth() != target_width ||
m_post_processing_input_texture.GetHeight() != target_height)
{
if (!m_post_processing_input_texture.Create(m_device.Get(), target_width, target_height, 1, 1, 1, format,
bind_flags))
{
if (!m_post_processing_input_texture.Create(m_device.Get(), target_width, target_height, 1, 1, 1, type, format))
return false;
}
}
const u32 target_count = (static_cast<u32>(m_post_processing_stages.size()) - 1);
@ -1005,7 +1081,7 @@ bool D3D11GPUDevice::CheckPostProcessingRenderTargets(u32 target_width, u32 targ
PostProcessingStage& pps = m_post_processing_stages[i];
if (pps.output_texture.GetWidth() != target_width || pps.output_texture.GetHeight() != target_height)
{
if (!pps.output_texture.Create(m_device.Get(), target_width, target_height, 1, 1, 1, format, bind_flags))
if (!pps.output_texture.Create(m_device.Get(), target_width, target_height, 1, 1, 1, type, format))
return false;
}
}
@ -1013,10 +1089,10 @@ bool D3D11GPUDevice::CheckPostProcessingRenderTargets(u32 target_width, u32 targ
return true;
}
void D3D11GPUDevice::ApplyPostProcessingChain(ID3D11RenderTargetView* final_target, s32 final_left, s32 final_top,
s32 final_width, s32 final_height, D3D11::Texture* texture,
s32 texture_view_x, s32 texture_view_y, s32 texture_view_width,
s32 texture_view_height, u32 target_width, u32 target_height)
void D3D11Device::ApplyPostProcessingChain(ID3D11RenderTargetView* final_target, s32 final_left, s32 final_top,
s32 final_width, s32 final_height, D3D11Texture* texture, s32 texture_view_x,
s32 texture_view_y, s32 texture_view_width, s32 texture_view_height,
u32 target_width, u32 target_height)
{
if (!CheckPostProcessingRenderTargets(target_width, target_height))
{
@ -1073,7 +1149,7 @@ void D3D11GPUDevice::ApplyPostProcessingChain(ID3D11RenderTargetView* final_targ
m_context->PSSetShaderResources(0, 1, &null_srv);
}
bool D3D11GPUDevice::CreateTimestampQueries()
bool D3D11Device::CreateTimestampQueries()
{
for (u32 i = 0; i < NUM_TIMESTAMP_QUERIES; i++)
{
@ -1093,7 +1169,7 @@ bool D3D11GPUDevice::CreateTimestampQueries()
return true;
}
void D3D11GPUDevice::DestroyTimestampQueries()
void D3D11Device::DestroyTimestampQueries()
{
if (!m_timestamp_queries[0][0])
return;
@ -1108,7 +1184,7 @@ void D3D11GPUDevice::DestroyTimestampQueries()
m_timestamp_query_started = 0;
}
void D3D11GPUDevice::PopTimestampQuery()
void D3D11Device::PopTimestampQuery()
{
while (m_waiting_timestamp_queries > 0)
{
@ -1154,7 +1230,7 @@ void D3D11GPUDevice::PopTimestampQuery()
}
}
void D3D11GPUDevice::KickTimestampQuery()
void D3D11Device::KickTimestampQuery()
{
if (m_timestamp_query_started || !m_timestamp_queries[0][0] || m_waiting_timestamp_queries == NUM_TIMESTAMP_QUERIES)
return;
@ -1164,7 +1240,7 @@ void D3D11GPUDevice::KickTimestampQuery()
m_timestamp_query_started = true;
}
bool D3D11GPUDevice::SetGPUTimingEnabled(bool enabled)
bool D3D11Device::SetGPUTimingEnabled(bool enabled)
{
if (m_gpu_timing_enabled == enabled)
return true;
@ -1185,7 +1261,7 @@ bool D3D11GPUDevice::SetGPUTimingEnabled(bool enabled)
}
}
float D3D11GPUDevice::GetAndResetAccumulatedGPUTime()
float D3D11Device::GetAndResetAccumulatedGPUTime()
{
const float value = m_accumulated_gpu_time;
m_accumulated_gpu_time = 0.0f;

View File

@ -6,7 +6,7 @@
#include "common/window_info.h"
#include "common/windows_headers.h"
#include "d3d11/stream_buffer.h"
#include "d3d11/texture.h"
#include "d3d11_texture.h"
#include "gpu_device.h"
#include "postprocessing_chain.h"
#include <d3d11.h>
@ -17,14 +17,18 @@
#include <vector>
#include <wrl/client.h>
class D3D11GPUDevice final : public GPUDevice
class D3D11Device final : public GPUDevice
{
public:
template<typename T>
using ComPtr = Microsoft::WRL::ComPtr<T>;
D3D11GPUDevice();
~D3D11GPUDevice();
ALWAYS_INLINE static D3D11Device& GetInstance() { return *static_cast<D3D11Device*>(g_host_display.get()); }
ALWAYS_INLINE static ID3D11Device* GetD3DDevice() { return GetInstance().m_device.Get(); }
ALWAYS_INLINE static ID3D11DeviceContext* GetD3DContext() { return GetInstance().m_context.Get(); }
D3D11Device();
~D3D11Device();
RenderAPI GetRenderAPI() const override;
void* GetDevice() const override;
@ -50,11 +54,8 @@ public:
bool SetPostProcessingChain(const std::string_view& config) override;
std::unique_ptr<GPUTexture> CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
GPUTexture::Format format, const void* data, u32 data_stride,
bool dynamic = false) override;
bool BeginTextureUpdate(GPUTexture* texture, u32 width, u32 height, void** out_buffer, u32* out_pitch) override;
void EndTextureUpdate(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height) override;
bool UpdateTexture(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch) override;
GPUTexture::Type type, GPUTexture::Format format, const void* data,
u32 data_stride, bool dynamic = false) override;
bool DownloadTexture(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, void* out_data,
u32 out_data_stride) override;
bool SupportsTextureFormat(GPUTexture::Format format) const override;
@ -73,7 +74,9 @@ public:
static AdapterAndModeList StaticGetAdapterAndModeList();
protected:
static constexpr u32 DISPLAY_UNIFORM_BUFFER_SIZE = 16;
static constexpr u32 DISPLAY_UNIFORM_BUFFER_SIZE = 64;
static constexpr u32 IMGUI_VERTEX_BUFFER_SIZE = 4 * 1024 * 1024;
static constexpr u32 IMGUI_INDEX_BUFFER_SIZE = 2 * 1024 * 1024;
static constexpr u8 NUM_TIMESTAMP_QUERIES = 3;
static AdapterAndModeList GetAdapterAndModeList(IDXGIFactory* dxgi_factory);
@ -84,9 +87,8 @@ protected:
bool CreateResources() override;
void DestroyResources() override;
bool CreateImGuiContext() override;
void DestroyImGuiContext() override;
bool UpdateImGuiFontTexture() override;
bool CreateImGuiResources();
void DestroyImGuiResources();
bool CreateSwapChain(const DXGI_MODE_DESC* fullscreen_mode);
bool CreateSwapChainRTV();
@ -95,7 +97,7 @@ protected:
void RenderSoftwareCursor();
void RenderImGui();
void RenderDisplay(s32 left, s32 top, s32 width, s32 height, D3D11::Texture* texture, s32 texture_view_x,
void RenderDisplay(s32 left, s32 top, s32 width, s32 height, D3D11Texture* texture, s32 texture_view_x,
s32 texture_view_y, s32 texture_view_width, s32 texture_view_height, bool linear_filter);
void RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 height, GPUTexture* texture_handle);
@ -103,13 +105,13 @@ protected:
{
ComPtr<ID3D11VertexShader> vertex_shader;
ComPtr<ID3D11PixelShader> pixel_shader;
D3D11::Texture output_texture;
D3D11Texture output_texture;
u32 uniforms_size;
};
bool CheckPostProcessingRenderTargets(u32 target_width, u32 target_height);
void ApplyPostProcessingChain(ID3D11RenderTargetView* final_target, s32 final_left, s32 final_top, s32 final_width,
s32 final_height, D3D11::Texture* texture, s32 texture_view_x, s32 texture_view_y,
s32 final_height, D3D11Texture* texture, s32 texture_view_x, s32 texture_view_y,
s32 texture_view_width, s32 texture_view_height, u32 target_width, u32 target_height);
bool CreateTimestampQueries();
@ -145,8 +147,16 @@ protected:
bool m_using_flip_model_swap_chain = true;
bool m_using_allow_tearing = false;
D3D11Texture m_imgui_texture;
D3D11::StreamBuffer m_imgui_vertex_buffer;
D3D11::StreamBuffer m_imgui_index_buffer;
ComPtr<ID3D11InputLayout> m_imgui_input_layout;
ComPtr<ID3D11VertexShader> m_imgui_vertex_shader;
ComPtr<ID3D11PixelShader> m_imgui_pixel_shader;
ComPtr<ID3D11BlendState> m_imgui_blend_state;
FrontendCommon::PostProcessingChain m_post_processing_chain;
D3D11::Texture m_post_processing_input_texture;
D3D11Texture m_post_processing_input_texture;
std::vector<PostProcessingStage> m_post_processing_stages;
Common::Timer m_post_processing_timer;

View File

@ -1,8 +1,11 @@
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
#include "texture.h"
#include "d3d11_texture.h"
#include "common/assert.h"
#include "common/log.h"
#include "common/string_util.h"
#include "d3d11_device.h"
#include <array>
Log_SetChannel(D3D11);
@ -10,10 +13,10 @@ static constexpr std::array<DXGI_FORMAT, static_cast<u32>(GPUTexture::Format::Co
{DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B5G6R5_UNORM,
DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_D16_UNORM}};
D3D11::Texture::Texture() = default;
D3D11Texture::D3D11Texture() = default;
D3D11::Texture::Texture(ComPtr<ID3D11Texture2D> texture, ComPtr<ID3D11ShaderResourceView> srv,
ComPtr<ID3D11RenderTargetView> rtv)
D3D11Texture::D3D11Texture(ComPtr<ID3D11Texture2D> texture, ComPtr<ID3D11ShaderResourceView> srv,
ComPtr<ID3D11RenderTargetView> rtv)
: m_texture(std::move(texture)), m_srv(std::move(srv)), m_rtv(std::move(rtv))
{
const D3D11_TEXTURE2D_DESC desc = GetDesc();
@ -26,17 +29,17 @@ D3D11::Texture::Texture(ComPtr<ID3D11Texture2D> texture, ComPtr<ID3D11ShaderReso
m_dynamic = (desc.Usage == D3D11_USAGE_DYNAMIC);
}
D3D11::Texture::~Texture()
D3D11Texture::~D3D11Texture()
{
Destroy();
}
DXGI_FORMAT D3D11::Texture::GetDXGIFormat(Format format)
DXGI_FORMAT D3D11Texture::GetDXGIFormat(Format format)
{
return s_dxgi_mapping[static_cast<u8>(format)];
}
GPUTexture::Format D3D11::Texture::LookupBaseFormat(DXGI_FORMAT dformat)
GPUTexture::Format D3D11Texture::LookupBaseFormat(DXGI_FORMAT dformat)
{
for (u32 i = 0; i < static_cast<u32>(s_dxgi_mapping.size()); i++)
{
@ -46,21 +49,73 @@ GPUTexture::Format D3D11::Texture::LookupBaseFormat(DXGI_FORMAT dformat)
return GPUTexture::Format::Unknown;
}
D3D11_TEXTURE2D_DESC D3D11::Texture::GetDesc() const
D3D11_TEXTURE2D_DESC D3D11Texture::GetDesc() const
{
D3D11_TEXTURE2D_DESC desc;
m_texture->GetDesc(&desc);
return desc;
}
bool D3D11::Texture::IsValid() const
bool D3D11Texture::IsValid() const
{
return static_cast<bool>(m_texture);
}
bool D3D11::Texture::Create(ID3D11Device* device, u32 width, u32 height, u32 layers, u32 levels, u32 samples,
Format format, u32 bind_flags, const void* initial_data /* = nullptr */,
u32 initial_data_stride /* = 0 */, bool dynamic /* = false */)
bool D3D11Texture::Update(u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch, u32 layer /*= 0*/,
u32 level /*= 0*/)
{
if (m_dynamic)
{
void* map;
u32 map_stride;
if (!Map(&map, &map_stride, x, y, width, height, layer, level))
return false;
StringUtil::StrideMemCpy(map, map_stride, data, pitch, GetPixelSize() * width, height);
Unmap();
return true;
}
const CD3D11_BOX box(static_cast<LONG>(x), static_cast<LONG>(y), 0, static_cast<LONG>(x + width),
static_cast<LONG>(y + height), 1);
const u32 srnum = D3D11CalcSubresource(level, layer, m_levels);
D3D11Device::GetD3DContext()->UpdateSubresource(m_texture.Get(), srnum, &box, data, pitch, 0);
return true;
}
bool D3D11Texture::Map(void** map, u32* map_stride, u32 x, u32 y, u32 width, u32 height, u32 layer /*= 0*/,
u32 level /*= 0*/)
{
if (!m_dynamic || (x + width) > m_width || (y + height) > m_height || layer > m_layers || level > m_levels)
return false;
const bool discard = (width == m_width && height == m_height);
const u32 srnum = D3D11CalcSubresource(level, layer, m_levels);
D3D11_MAPPED_SUBRESOURCE sr;
HRESULT hr = D3D11Device::GetD3DContext()->Map(m_texture.Get(), srnum,
discard ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE, 0, &sr);
if (FAILED(hr))
{
Log_ErrorPrintf("Map pixels texture failed: %08X", hr);
return false;
}
*map = static_cast<u8*>(sr.pData) + (y * sr.RowPitch) + (x * GetPixelSize());
*map_stride = sr.RowPitch;
m_mapped_subresource = srnum;
return true;
}
void D3D11Texture::Unmap()
{
D3D11Device::GetD3DContext()->Unmap(m_texture.Get(), m_mapped_subresource);
m_mapped_subresource = 0;
}
bool D3D11Texture::Create(ID3D11Device* device, u32 width, u32 height, u32 layers, u32 levels, u32 samples, Type type,
Format format, const void* initial_data /* = nullptr */, u32 initial_data_stride /* = 0 */,
bool dynamic /* = false */)
{
if (width > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION || height > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION ||
layers > D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION || (layers > 1 && samples > 1))
@ -70,6 +125,25 @@ bool D3D11::Texture::Create(ID3D11Device* device, u32 width, u32 height, u32 lay
return false;
}
u32 bind_flags = 0;
switch (type)
{
case Type::RenderTarget:
bind_flags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
break;
case Type::DepthStencil:
bind_flags = D3D11_BIND_DEPTH_STENCIL; // | D3D11_BIND_SHADER_RESOURCE;
break;
case Type::Texture:
bind_flags = D3D11_BIND_SHADER_RESOURCE;
break;
case Type::RWTexture:
bind_flags = D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE;
break;
default:
break;
}
CD3D11_TEXTURE2D_DESC desc(GetDXGIFormat(format), width, height, layers, levels, bind_flags,
dynamic ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT, dynamic ? D3D11_CPU_ACCESS_WRITE : 0,
samples, 0, 0);
@ -132,7 +206,7 @@ bool D3D11::Texture::Create(ID3D11Device* device, u32 width, u32 height, u32 lay
return true;
}
bool D3D11::Texture::Adopt(ID3D11Device* device, ComPtr<ID3D11Texture2D> texture)
bool D3D11Texture::Adopt(ID3D11Device* device, ComPtr<ID3D11Texture2D> texture)
{
D3D11_TEXTURE2D_DESC desc;
texture->GetDesc(&desc);
@ -177,7 +251,7 @@ bool D3D11::Texture::Adopt(ID3D11Device* device, ComPtr<ID3D11Texture2D> texture
return true;
}
void D3D11::Texture::Destroy()
void D3D11Texture::Destroy()
{
m_rtv.Reset();
m_srv.Reset();

View File

@ -1,23 +1,22 @@
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
#pragma once
#include "../gpu_texture.h"
#include "common/windows_headers.h"
#include "gpu_texture.h"
#include <d3d11.h>
#include <wrl/client.h>
namespace D3D11 {
class Texture final : public GPUTexture
class D3D11Texture final : public GPUTexture
{
public:
template<typename T>
using ComPtr = Microsoft::WRL::ComPtr<T>;
Texture();
Texture(ComPtr<ID3D11Texture2D> texture, ComPtr<ID3D11ShaderResourceView> srv, ComPtr<ID3D11RenderTargetView> rtv);
~Texture();
D3D11Texture();
D3D11Texture(ComPtr<ID3D11Texture2D> texture, ComPtr<ID3D11ShaderResourceView> srv,
ComPtr<ID3D11RenderTargetView> rtv);
~D3D11Texture();
static DXGI_FORMAT GetDXGIFormat(Format format);
static Format LookupBaseFormat(DXGI_FORMAT dformat);
@ -35,21 +34,24 @@ public:
ALWAYS_INLINE operator ID3D11RenderTargetView*() const { return m_rtv.Get(); }
ALWAYS_INLINE operator bool() const { return static_cast<bool>(m_texture); }
bool Create(ID3D11Device* device, u32 width, u32 height, u32 layers, u32 levels, u32 samples, Type type,
Format format, const void* initial_data = nullptr, u32 initial_data_stride = 0, bool dynamic = false);
bool Adopt(ID3D11Device* device, ComPtr<ID3D11Texture2D> texture);
void Destroy();
D3D11_TEXTURE2D_DESC GetDesc() const;
bool IsValid() const override;
bool Create(ID3D11Device* device, u32 width, u32 height, u32 layers, u32 levels, u32 samples, Format format,
u32 bind_flags, const void* initial_data = nullptr, u32 initial_data_stride = 0, bool dynamic = false);
bool Adopt(ID3D11Device* device, ComPtr<ID3D11Texture2D> texture);
void Destroy();
bool Update(u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch, u32 layer = 0, u32 level = 0) override;
bool Map(void** map, u32* map_stride, u32 x, u32 y, u32 width, u32 height, u32 layer = 0, u32 level = 0) override;
void Unmap() override;
private:
ComPtr<ID3D11Texture2D> m_texture;
ComPtr<ID3D11ShaderResourceView> m_srv;
ComPtr<ID3D11RenderTargetView> m_rtv;
u32 m_mapped_subresource = 0;
bool m_dynamic = false;
};
} // namespace D3D11

View File

@ -98,6 +98,25 @@ bool D3D12::Texture::IsValid() const
return static_cast<bool>(m_resource);
}
bool D3D12::Texture::Update(u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch, u32 layer /*= 0*/,
u32 level /*= 0*/)
{
UnreachableCode();
return false;
}
bool D3D12::Texture::Map(void** map, u32* map_stride, u32 x, u32 y, u32 width, u32 height, u32 layer /*= 0*/,
u32 level /*= 0*/)
{
UnreachableCode();
return false;
}
void D3D12::Texture::Unmap()
{
UnreachableCode();
}
bool D3D12::Texture::Create(u32 width, u32 height, u32 layers, u32 levels, u32 samples, DXGI_FORMAT format,
DXGI_FORMAT srv_format, DXGI_FORMAT rtv_format, DXGI_FORMAT dsv_format,
D3D12_RESOURCE_FLAGS flags)

View File

@ -37,6 +37,9 @@ public:
ALWAYS_INLINE operator bool() const { return static_cast<bool>(m_resource); }
bool IsValid() const override;
bool Update(u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch, u32 layer = 0, u32 level = 0) override;
bool Map(void** map, u32* map_stride, u32 x, u32 y, u32 width, u32 height, u32 layer = 0, u32 level = 0) override;
void Unmap() override;
bool Create(u32 width, u32 height, u32 layers, u32 levels, u32 samples, DXGI_FORMAT format, DXGI_FORMAT srv_format, DXGI_FORMAT rtv_format,
DXGI_FORMAT dsv_format, D3D12_RESOURCE_FLAGS flags);

View File

@ -10,9 +10,7 @@
#include "d3d12/context.h"
#include "d3d12/shader_cache.h"
#include "d3d12/util.h"
#include "display_ps.hlsl.h"
#include "display_ps_alpha.hlsl.h"
#include "display_vs.hlsl.h"
#include "d3d_shaders.h"
#include "imgui.h"
#include "imgui_impl_dx12.h"
#include "postprocessing_shadergen.h"
@ -61,8 +59,8 @@ bool D3D12GPUDevice::HasSurface() const
}
std::unique_ptr<GPUTexture> D3D12GPUDevice::CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
GPUTexture::Format format, const void* data, u32 data_stride,
bool dynamic /* = false */)
GPUTexture::Type type, GPUTexture::Format format,
const void* data, u32 data_stride, bool dynamic /* = false */)
{
const DXGI_FORMAT dformat = D3D12::Texture::GetDXGIFormat(format);
if (dformat == DXGI_FORMAT_UNKNOWN)
@ -81,6 +79,7 @@ std::unique_ptr<GPUTexture> D3D12GPUDevice::CreateTexture(u32 width, u32 height,
return tex;
}
#if 0
bool D3D12GPUDevice::BeginTextureUpdate(GPUTexture* texture, u32 width, u32 height, void** out_buffer, u32* out_pitch)
{
return static_cast<D3D12::Texture*>(texture)->BeginStreamUpdate(0, 0, width, height, out_buffer, out_pitch);
@ -96,6 +95,7 @@ bool D3D12GPUDevice::UpdateTexture(GPUTexture* texture, u32 x, u32 y, u32 width,
{
return GPUDevice::UpdateTexture(texture, x, y, width, height, data, pitch);
}
#endif
bool D3D12GPUDevice::DownloadTexture(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, void* out_data,
u32 out_data_stride)
@ -563,6 +563,7 @@ void D3D12GPUDevice::DestroyResources()
m_display_root_signature.Reset();
}
#if 0
bool D3D12GPUDevice::CreateImGuiContext()
{
ImGui::GetIO().DisplaySize.x = static_cast<float>(m_window_info.surface_width);
@ -582,6 +583,7 @@ bool D3D12GPUDevice::UpdateImGuiFontTexture()
{
return ImGui_ImplDX12_CreateFontsTexture();
}
#endif
bool D3D12GPUDevice::Render(bool skip_present)
{

View File

@ -52,11 +52,8 @@ public:
bool SetPostProcessingChain(const std::string_view& config) override;
std::unique_ptr<GPUTexture> CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
GPUTexture::Format format, const void* data, u32 data_stride,
bool dynamic = false) override;
bool BeginTextureUpdate(GPUTexture* texture, u32 width, u32 height, void** out_buffer, u32* out_pitch) override;
void EndTextureUpdate(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height) override;
bool UpdateTexture(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch) override;
GPUTexture::Type type, GPUTexture::Format format, const void* data,
u32 data_stride, bool dynamic = false) override;
bool DownloadTexture(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, void* out_data,
u32 out_data_stride) override;
bool SupportsTextureFormat(GPUTexture::Format format) const override;
@ -91,10 +88,6 @@ protected:
virtual bool CreateResources() override;
virtual void DestroyResources() override;
virtual bool CreateImGuiContext() override;
virtual void DestroyImGuiContext() override;
virtual bool UpdateImGuiFontTexture() override;
bool CreateSwapChain(const DXGI_MODE_DESC* fullscreen_mode);
bool CreateSwapChainRTV();
void DestroySwapChainRTVs();

930
src/core/gpu/d3d_shaders.h Normal file
View File

@ -0,0 +1,930 @@
#if 0
cbuffer UBOBlock : register(b0)
{
float4 u_src_rect;
};
void main(in uint vertex_id : SV_VertexID,
out float2 v_tex0 : TEXCOORD0,
out float4 o_pos : SV_Position)
{
float2 pos = float2(float((vertex_id << 1) & 2u), float(vertex_id & 2u));
v_tex0 = u_src_rect.xy + pos * u_src_rect.zw;
o_pos = float4(pos * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), 0.0f, 1.0f);
}
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//
// Buffer Definitions:
//
// cbuffer UBOBlock
// {
//
// float4 u_src_rect; // Offset: 0 Size: 16
//
// }
//
//
// Resource Bindings:
//
// Name Type Format Dim HLSL Bind Count
// ------------------------------ ---------- ------- ----------- -------------- ------
// UBOBlock cbuffer NA NA cb0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_VertexID 0 x 0 VERTID uint x
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD 0 xy 0 NONE float xy
// SV_Position 0 xyzw 1 POS float xyzw
//
vs_4_0
dcl_constantbuffer CB0[1], immediateIndexed
dcl_input_sgv v0.x, vertex_id
dcl_output o0.xy
dcl_output_siv o1.xyzw, position
dcl_temps 1
ishl r0.x, v0.x, l(1)
and r0.x, r0.x, l(2)
and r0.z, v0.x, l(2)
utof r0.xy, r0.xzxx
mad o0.xy, r0.xyxx, cb0[0].zwzz, cb0[0].xyxx
mad o1.xy, r0.xyxx, l(2.000000, -2.000000, 0.000000, 0.000000), l(-1.000000, 1.000000, 0.000000, 0.000000)
mov o1.zw, l(0,0,0,1.000000)
ret
// Approximately 8 instruction slots used
#endif
const BYTE static s_display_vs_bytecode[] =
{
68, 88, 66, 67, 37, 97,
157, 234, 112, 10, 38, 98,
114, 228, 143, 118, 71, 158,
122, 195, 1, 0, 0, 0,
72, 3, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
248, 0, 0, 0, 44, 1,
0, 0, 132, 1, 0, 0,
204, 2, 0, 0, 82, 68,
69, 70, 188, 0, 0, 0,
1, 0, 0, 0, 72, 0,
0, 0, 1, 0, 0, 0,
28, 0, 0, 0, 0, 4,
254, 255, 0, 129, 0, 0,
148, 0, 0, 0, 60, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0,
85, 66, 79, 66, 108, 111,
99, 107, 0, 171, 171, 171,
60, 0, 0, 0, 1, 0,
0, 0, 96, 0, 0, 0,
16, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
120, 0, 0, 0, 0, 0,
0, 0, 16, 0, 0, 0,
2, 0, 0, 0, 132, 0,
0, 0, 0, 0, 0, 0,
117, 95, 115, 114, 99, 95,
114, 101, 99, 116, 0, 171,
1, 0, 3, 0, 1, 0,
4, 0, 0, 0, 0, 0,
0, 0, 0, 0, 77, 105,
99, 114, 111, 115, 111, 102,
116, 32, 40, 82, 41, 32,
72, 76, 83, 76, 32, 83,
104, 97, 100, 101, 114, 32,
67, 111, 109, 112, 105, 108,
101, 114, 32, 49, 48, 46,
49, 0, 73, 83, 71, 78,
44, 0, 0, 0, 1, 0,
0, 0, 8, 0, 0, 0,
32, 0, 0, 0, 0, 0,
0, 0, 6, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 1, 1, 0, 0,
83, 86, 95, 86, 101, 114,
116, 101, 120, 73, 68, 0,
79, 83, 71, 78, 80, 0,
0, 0, 2, 0, 0, 0,
8, 0, 0, 0, 56, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
3, 12, 0, 0, 65, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 3, 0,
0, 0, 1, 0, 0, 0,
15, 0, 0, 0, 84, 69,
88, 67, 79, 79, 82, 68,
0, 83, 86, 95, 80, 111,
115, 105, 116, 105, 111, 110,
0, 171, 171, 171, 83, 72,
68, 82, 64, 1, 0, 0,
64, 0, 1, 0, 80, 0,
0, 0, 89, 0, 0, 4,
70, 142, 32, 0, 0, 0,
0, 0, 1, 0, 0, 0,
96, 0, 0, 4, 18, 16,
16, 0, 0, 0, 0, 0,
6, 0, 0, 0, 101, 0,
0, 3, 50, 32, 16, 0,
0, 0, 0, 0, 103, 0,
0, 4, 242, 32, 16, 0,
1, 0, 0, 0, 1, 0,
0, 0, 104, 0, 0, 2,
1, 0, 0, 0, 41, 0,
0, 7, 18, 0, 16, 0,
0, 0, 0, 0, 10, 16,
16, 0, 0, 0, 0, 0,
1, 64, 0, 0, 1, 0,
0, 0, 1, 0, 0, 7,
18, 0, 16, 0, 0, 0,
0, 0, 10, 0, 16, 0,
0, 0, 0, 0, 1, 64,
0, 0, 2, 0, 0, 0,
1, 0, 0, 7, 66, 0,
16, 0, 0, 0, 0, 0,
10, 16, 16, 0, 0, 0,
0, 0, 1, 64, 0, 0,
2, 0, 0, 0, 86, 0,
0, 5, 50, 0, 16, 0,
0, 0, 0, 0, 134, 0,
16, 0, 0, 0, 0, 0,
50, 0, 0, 11, 50, 32,
16, 0, 0, 0, 0, 0,
70, 0, 16, 0, 0, 0,
0, 0, 230, 138, 32, 0,
0, 0, 0, 0, 0, 0,
0, 0, 70, 128, 32, 0,
0, 0, 0, 0, 0, 0,
0, 0, 50, 0, 0, 15,
50, 32, 16, 0, 1, 0,
0, 0, 70, 0, 16, 0,
0, 0, 0, 0, 2, 64,
0, 0, 0, 0, 0, 64,
0, 0, 0, 192, 0, 0,
0, 0, 0, 0, 0, 0,
2, 64, 0, 0, 0, 0,
128, 191, 0, 0, 128, 63,
0, 0, 0, 0, 0, 0,
0, 0, 54, 0, 0, 8,
194, 32, 16, 0, 1, 0,
0, 0, 2, 64, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 128, 63, 62, 0,
0, 1, 83, 84, 65, 84,
116, 0, 0, 0, 8, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 2, 0, 0, 0,
1, 0, 0, 0, 2, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0
};
#if 0
Texture2D samp0 : register(t0);
SamplerState samp0_ss : register(s0);
void main(in float2 v_tex0 : TEXCOORD0,
out float4 o_col0 : SV_Target)
{
#ifdef ALPHA
o_col0 = samp0.Sample(samp0_ss, v_tex0);
#else
o_col0 = float4(samp0.Sample(samp0_ss, v_tex0).rgb, 1.0);
#endif
}
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//
// Resource Bindings:
//
// Name Type Format Dim HLSL Bind Count
// ------------------------------ ---------- ------- ----------- -------------- ------
// samp0_ss sampler NA NA s0 1
// samp0 texture float4 2d t0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD 0 xy 0 NONE float xy
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target 0 xyzw 0 TARGET float xyzw
//
ps_4_0
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps linear v0.xy
dcl_output o0.xyzw
dcl_temps 1
sample r0.xyzw, v0.xyxx, t0.xyzw, s0
mov o0.xyz, r0.xyzx
mov o0.w, l(1.000000)
ret
// Approximately 4 instruction slots used
#endif
const BYTE static s_display_ps_bytecode[] =
{
68, 88, 66, 67, 192, 215,
150, 96, 210, 93, 209, 128,
113, 254, 100, 56, 49, 113,
128, 72, 1, 0, 0, 0,
80, 2, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
208, 0, 0, 0, 4, 1,
0, 0, 56, 1, 0, 0,
212, 1, 0, 0, 82, 68,
69, 70, 148, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
28, 0, 0, 0, 0, 4,
255, 255, 0, 129, 0, 0,
107, 0, 0, 0, 92, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0,
101, 0, 0, 0, 2, 0,
0, 0, 5, 0, 0, 0,
4, 0, 0, 0, 255, 255,
255, 255, 0, 0, 0, 0,
1, 0, 0, 0, 13, 0,
0, 0, 115, 97, 109, 112,
48, 95, 115, 115, 0, 115,
97, 109, 112, 48, 0, 77,
105, 99, 114, 111, 115, 111,
102, 116, 32, 40, 82, 41,
32, 72, 76, 83, 76, 32,
83, 104, 97, 100, 101, 114,
32, 67, 111, 109, 112, 105,
108, 101, 114, 32, 49, 48,
46, 49, 0, 171, 73, 83,
71, 78, 44, 0, 0, 0,
1, 0, 0, 0, 8, 0,
0, 0, 32, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 3, 3,
0, 0, 84, 69, 88, 67,
79, 79, 82, 68, 0, 171,
171, 171, 79, 83, 71, 78,
44, 0, 0, 0, 1, 0,
0, 0, 8, 0, 0, 0,
32, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0,
83, 86, 95, 84, 97, 114,
103, 101, 116, 0, 171, 171,
83, 72, 68, 82, 148, 0,
0, 0, 64, 0, 0, 0,
37, 0, 0, 0, 90, 0,
0, 3, 0, 96, 16, 0,
0, 0, 0, 0, 88, 24,
0, 4, 0, 112, 16, 0,
0, 0, 0, 0, 85, 85,
0, 0, 98, 16, 0, 3,
50, 16, 16, 0, 0, 0,
0, 0, 101, 0, 0, 3,
242, 32, 16, 0, 0, 0,
0, 0, 104, 0, 0, 2,
1, 0, 0, 0, 69, 0,
0, 9, 242, 0, 16, 0,
0, 0, 0, 0, 70, 16,
16, 0, 0, 0, 0, 0,
70, 126, 16, 0, 0, 0,
0, 0, 0, 96, 16, 0,
0, 0, 0, 0, 54, 0,
0, 5, 114, 32, 16, 0,
0, 0, 0, 0, 70, 2,
16, 0, 0, 0, 0, 0,
54, 0, 0, 5, 130, 32,
16, 0, 0, 0, 0, 0,
1, 64, 0, 0, 0, 0,
128, 63, 62, 0, 0, 1,
83, 84, 65, 84, 116, 0,
0, 0, 4, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
2, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0
};
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//
// Resource Bindings:
//
// Name Type Format Dim HLSL Bind Count
// ------------------------------ ---------- ------- ----------- -------------- ------
// samp0_ss sampler NA NA s0 1
// samp0 texture float4 2d t0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD 0 xy 0 NONE float xy
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target 0 xyzw 0 TARGET float xyzw
//
ps_4_0
dcl_sampler s0, mode_default
dcl_resource_texture2d(float, float, float, float) t0
dcl_input_ps linear v0.xy
dcl_output o0.xyzw
sample o0.xyzw, v0.xyxx, t0.xyzw, s0
ret
// Approximately 2 instruction slots used
#endif
const BYTE static s_display_ps_alpha_bytecode[] =
{
68, 88, 66, 67, 140, 134,
46, 29, 68, 36, 193, 23,
94, 171, 102, 123, 183, 66,
19, 177, 1, 0, 0, 0,
32, 2, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
208, 0, 0, 0, 4, 1,
0, 0, 56, 1, 0, 0,
164, 1, 0, 0, 82, 68,
69, 70, 148, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
28, 0, 0, 0, 0, 4,
255, 255, 0, 129, 0, 0,
107, 0, 0, 0, 92, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0,
101, 0, 0, 0, 2, 0,
0, 0, 5, 0, 0, 0,
4, 0, 0, 0, 255, 255,
255, 255, 0, 0, 0, 0,
1, 0, 0, 0, 13, 0,
0, 0, 115, 97, 109, 112,
48, 95, 115, 115, 0, 115,
97, 109, 112, 48, 0, 77,
105, 99, 114, 111, 115, 111,
102, 116, 32, 40, 82, 41,
32, 72, 76, 83, 76, 32,
83, 104, 97, 100, 101, 114,
32, 67, 111, 109, 112, 105,
108, 101, 114, 32, 49, 48,
46, 49, 0, 171, 73, 83,
71, 78, 44, 0, 0, 0,
1, 0, 0, 0, 8, 0,
0, 0, 32, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 3, 3,
0, 0, 84, 69, 88, 67,
79, 79, 82, 68, 0, 171,
171, 171, 79, 83, 71, 78,
44, 0, 0, 0, 1, 0,
0, 0, 8, 0, 0, 0,
32, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0,
83, 86, 95, 84, 97, 114,
103, 101, 116, 0, 171, 171,
83, 72, 68, 82, 100, 0,
0, 0, 64, 0, 0, 0,
25, 0, 0, 0, 90, 0,
0, 3, 0, 96, 16, 0,
0, 0, 0, 0, 88, 24,
0, 4, 0, 112, 16, 0,
0, 0, 0, 0, 85, 85,
0, 0, 98, 16, 0, 3,
50, 16, 16, 0, 0, 0,
0, 0, 101, 0, 0, 3,
242, 32, 16, 0, 0, 0,
0, 0, 69, 0, 0, 9,
242, 32, 16, 0, 0, 0,
0, 0, 70, 16, 16, 0,
0, 0, 0, 0, 70, 126,
16, 0, 0, 0, 0, 0,
0, 96, 16, 0, 0, 0,
0, 0, 62, 0, 0, 1,
83, 84, 65, 84, 116, 0,
0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0
};
#if 0
cbuffer vertexBuffer : register(b0)
{
float4x4 ProjectionMatrix;
};
struct VS_INPUT
{
float2 pos : POSITION;
float4 col : COLOR0;
float2 uv : TEXCOORD0;
};
struct PS_INPUT
{
float4 pos : SV_POSITION;
float4 col : COLOR0;
float2 uv : TEXCOORD0;
};
PS_INPUT vs_main(VS_INPUT input)
{
PS_INPUT output;
output.pos = mul(ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));
output.col = input.col;
output.uv = input.uv;
return output;
}
sampler sampler0 : register(s0);
Texture2D texture0 : register(t0);
float4 ps_main(PS_INPUT input) : SV_Target
{
float4 out_col = input.col * texture0.Sample(sampler0, input.uv);
return out_col;
}
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//
// Buffer Definitions:
//
// cbuffer vertexBuffer
// {
//
// float4x4 ProjectionMatrix; // Offset: 0 Size: 64
//
// }
//
//
// Resource Bindings:
//
// Name Type Format Dim HLSL Bind Count
// ------------------------------ ---------- ------- ----------- -------------- ------
// vertexBuffer cbuffer NA NA cb0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// POSITION 0 xy 0 NONE float xy
// COLOR 0 xyzw 1 NONE float xyzw
// TEXCOORD 0 xy 2 NONE float xy
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION 0 xyzw 0 POS float xyzw
// COLOR 0 xyzw 1 NONE float xyzw
// TEXCOORD 0 xy 2 NONE float xy
//
vs_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer CB0[4], immediateIndexed
dcl_input v0.xy
dcl_input v1.xyzw
dcl_input v2.xy
dcl_output_siv o0.xyzw, position
dcl_output o1.xyzw
dcl_output o2.xy
dcl_temps 1
mul r0.xyzw, v0.yyyy, cb0[1].xyzw
mad r0.xyzw, cb0[0].xyzw, v0.xxxx, r0.xyzw
add o0.xyzw, r0.xyzw, cb0[3].xyzw
mov o1.xyzw, v1.xyzw
mov o2.xy, v2.xyxx
ret
// Approximately 6 instruction slots used
#endif
const BYTE static s_imgui_vs_bytecode[] =
{
68, 88, 66, 67, 115, 32,
121, 4, 196, 220, 218, 4,
63, 218, 114, 0, 25, 78,
192, 97, 1, 0, 0, 0,
220, 3, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
80, 1, 0, 0, 192, 1,
0, 0, 52, 2, 0, 0,
64, 3, 0, 0, 82, 68,
69, 70, 20, 1, 0, 0,
1, 0, 0, 0, 108, 0,
0, 0, 1, 0, 0, 0,
60, 0, 0, 0, 0, 5,
254, 255, 0, 129, 0, 0,
236, 0, 0, 0, 82, 68,
49, 49, 60, 0, 0, 0,
24, 0, 0, 0, 32, 0,
0, 0, 40, 0, 0, 0,
36, 0, 0, 0, 12, 0,
0, 0, 0, 0, 0, 0,
92, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 1, 0,
0, 0, 118, 101, 114, 116,
101, 120, 66, 117, 102, 102,
101, 114, 0, 171, 171, 171,
92, 0, 0, 0, 1, 0,
0, 0, 132, 0, 0, 0,
64, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
172, 0, 0, 0, 0, 0,
0, 0, 64, 0, 0, 0,
2, 0, 0, 0, 200, 0,
0, 0, 0, 0, 0, 0,
255, 255, 255, 255, 0, 0,
0, 0, 255, 255, 255, 255,
0, 0, 0, 0, 80, 114,
111, 106, 101, 99, 116, 105,
111, 110, 77, 97, 116, 114,
105, 120, 0, 102, 108, 111,
97, 116, 52, 120, 52, 0,
171, 171, 3, 0, 3, 0,
4, 0, 4, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 189, 0,
0, 0, 77, 105, 99, 114,
111, 115, 111, 102, 116, 32,
40, 82, 41, 32, 72, 76,
83, 76, 32, 83, 104, 97,
100, 101, 114, 32, 67, 111,
109, 112, 105, 108, 101, 114,
32, 49, 48, 46, 49, 0,
73, 83, 71, 78, 104, 0,
0, 0, 3, 0, 0, 0,
8, 0, 0, 0, 80, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
3, 3, 0, 0, 89, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 1, 0, 0, 0,
15, 15, 0, 0, 95, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 2, 0, 0, 0,
3, 3, 0, 0, 80, 79,
83, 73, 84, 73, 79, 78,
0, 67, 79, 76, 79, 82,
0, 84, 69, 88, 67, 79,
79, 82, 68, 0, 79, 83,
71, 78, 108, 0, 0, 0,
3, 0, 0, 0, 8, 0,
0, 0, 80, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 15, 0,
0, 0, 92, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
1, 0, 0, 0, 15, 0,
0, 0, 98, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
2, 0, 0, 0, 3, 12,
0, 0, 83, 86, 95, 80,
79, 83, 73, 84, 73, 79,
78, 0, 67, 79, 76, 79,
82, 0, 84, 69, 88, 67,
79, 79, 82, 68, 0, 171,
83, 72, 69, 88, 4, 1,
0, 0, 80, 0, 1, 0,
65, 0, 0, 0, 106, 8,
0, 1, 89, 0, 0, 4,
70, 142, 32, 0, 0, 0,
0, 0, 4, 0, 0, 0,
95, 0, 0, 3, 50, 16,
16, 0, 0, 0, 0, 0,
95, 0, 0, 3, 242, 16,
16, 0, 1, 0, 0, 0,
95, 0, 0, 3, 50, 16,
16, 0, 2, 0, 0, 0,
103, 0, 0, 4, 242, 32,
16, 0, 0, 0, 0, 0,
1, 0, 0, 0, 101, 0,
0, 3, 242, 32, 16, 0,
1, 0, 0, 0, 101, 0,
0, 3, 50, 32, 16, 0,
2, 0, 0, 0, 104, 0,
0, 2, 1, 0, 0, 0,
56, 0, 0, 8, 242, 0,
16, 0, 0, 0, 0, 0,
86, 21, 16, 0, 0, 0,
0, 0, 70, 142, 32, 0,
0, 0, 0, 0, 1, 0,
0, 0, 50, 0, 0, 10,
242, 0, 16, 0, 0, 0,
0, 0, 70, 142, 32, 0,
0, 0, 0, 0, 0, 0,
0, 0, 6, 16, 16, 0,
0, 0, 0, 0, 70, 14,
16, 0, 0, 0, 0, 0,
0, 0, 0, 8, 242, 32,
16, 0, 0, 0, 0, 0,
70, 14, 16, 0, 0, 0,
0, 0, 70, 142, 32, 0,
0, 0, 0, 0, 3, 0,
0, 0, 54, 0, 0, 5,
242, 32, 16, 0, 1, 0,
0, 0, 70, 30, 16, 0,
1, 0, 0, 0, 54, 0,
0, 5, 50, 32, 16, 0,
2, 0, 0, 0, 70, 16,
16, 0, 2, 0, 0, 0,
62, 0, 0, 1, 83, 84,
65, 84, 148, 0, 0, 0,
6, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
6, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0
};
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//
// Resource Bindings:
//
// Name Type Format Dim HLSL Bind Count
// ------------------------------ ---------- ------- ----------- -------------- ------
// sampler0 sampler NA NA s0 1
// texture0 texture float4 2d t0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION 0 xyzw 0 POS float
// COLOR 0 xyzw 1 NONE float xyzw
// TEXCOORD 0 xy 2 NONE float xy
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target 0 xyzw 0 TARGET float xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps linear v1.xyzw
dcl_input_ps linear v2.xy
dcl_output o0.xyzw
dcl_temps 1
sample_indexable(texture2d)(float,float,float,float) r0.xyzw, v2.xyxx, t0.xyzw, s0
mul o0.xyzw, r0.xyzw, v1.xyzw
ret
// Approximately 3 instruction slots used
#endif
const BYTE static s_imgui_ps_bytecode[] =
{
68, 88, 66, 67, 219, 131,
126, 77, 0, 201, 229, 66,
111, 92, 42, 162, 229, 97,
51, 114, 1, 0, 0, 0,
224, 2, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
244, 0, 0, 0, 104, 1,
0, 0, 156, 1, 0, 0,
68, 2, 0, 0, 82, 68,
69, 70, 184, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
60, 0, 0, 0, 0, 5,
255, 255, 0, 129, 0, 0,
142, 0, 0, 0, 82, 68,
49, 49, 60, 0, 0, 0,
24, 0, 0, 0, 32, 0,
0, 0, 40, 0, 0, 0,
36, 0, 0, 0, 12, 0,
0, 0, 0, 0, 0, 0,
124, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 1, 0,
0, 0, 133, 0, 0, 0,
2, 0, 0, 0, 5, 0,
0, 0, 4, 0, 0, 0,
255, 255, 255, 255, 0, 0,
0, 0, 1, 0, 0, 0,
13, 0, 0, 0, 115, 97,
109, 112, 108, 101, 114, 48,
0, 116, 101, 120, 116, 117,
114, 101, 48, 0, 77, 105,
99, 114, 111, 115, 111, 102,
116, 32, 40, 82, 41, 32,
72, 76, 83, 76, 32, 83,
104, 97, 100, 101, 114, 32,
67, 111, 109, 112, 105, 108,
101, 114, 32, 49, 48, 46,
49, 0, 171, 171, 73, 83,
71, 78, 108, 0, 0, 0,
3, 0, 0, 0, 8, 0,
0, 0, 80, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 15, 0,
0, 0, 92, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
1, 0, 0, 0, 15, 15,
0, 0, 98, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
2, 0, 0, 0, 3, 3,
0, 0, 83, 86, 95, 80,
79, 83, 73, 84, 73, 79,
78, 0, 67, 79, 76, 79,
82, 0, 84, 69, 88, 67,
79, 79, 82, 68, 0, 171,
79, 83, 71, 78, 44, 0,
0, 0, 1, 0, 0, 0,
8, 0, 0, 0, 32, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
15, 0, 0, 0, 83, 86,
95, 84, 97, 114, 103, 101,
116, 0, 171, 171, 83, 72,
69, 88, 160, 0, 0, 0,
80, 0, 0, 0, 40, 0,
0, 0, 106, 8, 0, 1,
90, 0, 0, 3, 0, 96,
16, 0, 0, 0, 0, 0,
88, 24, 0, 4, 0, 112,
16, 0, 0, 0, 0, 0,
85, 85, 0, 0, 98, 16,
0, 3, 242, 16, 16, 0,
1, 0, 0, 0, 98, 16,
0, 3, 50, 16, 16, 0,
2, 0, 0, 0, 101, 0,
0, 3, 242, 32, 16, 0,
0, 0, 0, 0, 104, 0,
0, 2, 1, 0, 0, 0,
69, 0, 0, 139, 194, 0,
0, 128, 67, 85, 21, 0,
242, 0, 16, 0, 0, 0,
0, 0, 70, 16, 16, 0,
2, 0, 0, 0, 70, 126,
16, 0, 0, 0, 0, 0,
0, 96, 16, 0, 0, 0,
0, 0, 56, 0, 0, 7,
242, 32, 16, 0, 0, 0,
0, 0, 70, 14, 16, 0,
0, 0, 0, 0, 70, 30,
16, 0, 1, 0, 0, 0,
62, 0, 0, 1, 83, 84,
65, 84, 148, 0, 0, 0,
3, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0
};

View File

@ -1,12 +0,0 @@
Texture2D samp0 : register(t0);
SamplerState samp0_ss : register(s0);
void main(in float2 v_tex0 : TEXCOORD0,
out float4 o_col0 : SV_Target)
{
#ifdef ALPHA
o_col0 = samp0.Sample(samp0_ss, v_tex0);
#else
o_col0 = float4(samp0.Sample(samp0_ss, v_tex0).rgb, 1.0);
#endif
}

View File

@ -1,142 +0,0 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//
// Resource Bindings:
//
// Name Type Format Dim HLSL Bind Count
// ------------------------------ ---------- ------- ----------- -------------- ------
// samp0_ss sampler NA NA s0 1
// samp0 texture float4 2d t0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD 0 xy 0 NONE float xy
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target 0 xyzw 0 TARGET float xyzw
//
ps_4_0
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps linear v0.xy
dcl_output o0.xyzw
dcl_temps 1
sample r0.xyzw, v0.xyxx, t0.xyzw, s0
mov o0.xyz, r0.xyzx
mov o0.w, l(1.000000)
ret
// Approximately 4 instruction slots used
#endif
const BYTE static s_display_ps_bytecode[] =
{
68, 88, 66, 67, 192, 215,
150, 96, 210, 93, 209, 128,
113, 254, 100, 56, 49, 113,
128, 72, 1, 0, 0, 0,
80, 2, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
208, 0, 0, 0, 4, 1,
0, 0, 56, 1, 0, 0,
212, 1, 0, 0, 82, 68,
69, 70, 148, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
28, 0, 0, 0, 0, 4,
255, 255, 0, 129, 0, 0,
107, 0, 0, 0, 92, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0,
101, 0, 0, 0, 2, 0,
0, 0, 5, 0, 0, 0,
4, 0, 0, 0, 255, 255,
255, 255, 0, 0, 0, 0,
1, 0, 0, 0, 13, 0,
0, 0, 115, 97, 109, 112,
48, 95, 115, 115, 0, 115,
97, 109, 112, 48, 0, 77,
105, 99, 114, 111, 115, 111,
102, 116, 32, 40, 82, 41,
32, 72, 76, 83, 76, 32,
83, 104, 97, 100, 101, 114,
32, 67, 111, 109, 112, 105,
108, 101, 114, 32, 49, 48,
46, 49, 0, 171, 73, 83,
71, 78, 44, 0, 0, 0,
1, 0, 0, 0, 8, 0,
0, 0, 32, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 3, 3,
0, 0, 84, 69, 88, 67,
79, 79, 82, 68, 0, 171,
171, 171, 79, 83, 71, 78,
44, 0, 0, 0, 1, 0,
0, 0, 8, 0, 0, 0,
32, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0,
83, 86, 95, 84, 97, 114,
103, 101, 116, 0, 171, 171,
83, 72, 68, 82, 148, 0,
0, 0, 64, 0, 0, 0,
37, 0, 0, 0, 90, 0,
0, 3, 0, 96, 16, 0,
0, 0, 0, 0, 88, 24,
0, 4, 0, 112, 16, 0,
0, 0, 0, 0, 85, 85,
0, 0, 98, 16, 0, 3,
50, 16, 16, 0, 0, 0,
0, 0, 101, 0, 0, 3,
242, 32, 16, 0, 0, 0,
0, 0, 104, 0, 0, 2,
1, 0, 0, 0, 69, 0,
0, 9, 242, 0, 16, 0,
0, 0, 0, 0, 70, 16,
16, 0, 0, 0, 0, 0,
70, 126, 16, 0, 0, 0,
0, 0, 0, 96, 16, 0,
0, 0, 0, 0, 54, 0,
0, 5, 114, 32, 16, 0,
0, 0, 0, 0, 70, 2,
16, 0, 0, 0, 0, 0,
54, 0, 0, 5, 130, 32,
16, 0, 0, 0, 0, 0,
1, 64, 0, 0, 0, 0,
128, 63, 62, 0, 0, 1,
83, 84, 65, 84, 116, 0,
0, 0, 4, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
2, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0
};

View File

@ -1,131 +0,0 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//
// Resource Bindings:
//
// Name Type Format Dim HLSL Bind Count
// ------------------------------ ---------- ------- ----------- -------------- ------
// samp0_ss sampler NA NA s0 1
// samp0 texture float4 2d t0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD 0 xy 0 NONE float xy
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target 0 xyzw 0 TARGET float xyzw
//
ps_4_0
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps linear v0.xy
dcl_output o0.xyzw
sample o0.xyzw, v0.xyxx, t0.xyzw, s0
ret
// Approximately 2 instruction slots used
#endif
const BYTE static s_display_ps_alpha_bytecode[] =
{
68, 88, 66, 67, 140, 134,
46, 29, 68, 36, 193, 23,
94, 171, 102, 123, 183, 66,
19, 177, 1, 0, 0, 0,
32, 2, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
208, 0, 0, 0, 4, 1,
0, 0, 56, 1, 0, 0,
164, 1, 0, 0, 82, 68,
69, 70, 148, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
28, 0, 0, 0, 0, 4,
255, 255, 0, 129, 0, 0,
107, 0, 0, 0, 92, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0,
101, 0, 0, 0, 2, 0,
0, 0, 5, 0, 0, 0,
4, 0, 0, 0, 255, 255,
255, 255, 0, 0, 0, 0,
1, 0, 0, 0, 13, 0,
0, 0, 115, 97, 109, 112,
48, 95, 115, 115, 0, 115,
97, 109, 112, 48, 0, 77,
105, 99, 114, 111, 115, 111,
102, 116, 32, 40, 82, 41,
32, 72, 76, 83, 76, 32,
83, 104, 97, 100, 101, 114,
32, 67, 111, 109, 112, 105,
108, 101, 114, 32, 49, 48,
46, 49, 0, 171, 73, 83,
71, 78, 44, 0, 0, 0,
1, 0, 0, 0, 8, 0,
0, 0, 32, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 3, 3,
0, 0, 84, 69, 88, 67,
79, 79, 82, 68, 0, 171,
171, 171, 79, 83, 71, 78,
44, 0, 0, 0, 1, 0,
0, 0, 8, 0, 0, 0,
32, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0,
83, 86, 95, 84, 97, 114,
103, 101, 116, 0, 171, 171,
83, 72, 68, 82, 100, 0,
0, 0, 64, 0, 0, 0,
25, 0, 0, 0, 90, 0,
0, 3, 0, 96, 16, 0,
0, 0, 0, 0, 88, 24,
0, 4, 0, 112, 16, 0,
0, 0, 0, 0, 85, 85,
0, 0, 98, 16, 0, 3,
50, 16, 16, 0, 0, 0,
0, 0, 101, 0, 0, 3,
242, 32, 16, 0, 0, 0,
0, 0, 69, 0, 0, 9,
242, 32, 16, 0, 0, 0,
0, 0, 70, 16, 16, 0,
0, 0, 0, 0, 70, 126,
16, 0, 0, 0, 0, 0,
0, 96, 16, 0, 0, 0,
0, 0, 62, 0, 0, 1,
83, 84, 65, 84, 116, 0,
0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0
};

View File

@ -1,13 +0,0 @@
cbuffer UBOBlock : register(b0)
{
float4 u_src_rect;
};
void main(in uint vertex_id : SV_VertexID,
out float2 v_tex0 : TEXCOORD0,
out float4 o_pos : SV_Position)
{
float2 pos = float2(float((vertex_id << 1) & 2u), float(vertex_id & 2u));
v_tex0 = u_src_rect.xy + pos * u_src_rect.zw;
o_pos = float4(pos * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), 0.0f, 1.0f);
}

View File

@ -1,197 +0,0 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//
// Buffer Definitions:
//
// cbuffer UBOBlock
// {
//
// float4 u_src_rect; // Offset: 0 Size: 16
//
// }
//
//
// Resource Bindings:
//
// Name Type Format Dim HLSL Bind Count
// ------------------------------ ---------- ------- ----------- -------------- ------
// UBOBlock cbuffer NA NA cb0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_VertexID 0 x 0 VERTID uint x
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD 0 xy 0 NONE float xy
// SV_Position 0 xyzw 1 POS float xyzw
//
vs_4_0
dcl_constantbuffer CB0[1], immediateIndexed
dcl_input_sgv v0.x, vertex_id
dcl_output o0.xy
dcl_output_siv o1.xyzw, position
dcl_temps 1
ishl r0.x, v0.x, l(1)
and r0.x, r0.x, l(2)
and r0.z, v0.x, l(2)
utof r0.xy, r0.xzxx
mad o0.xy, r0.xyxx, cb0[0].zwzz, cb0[0].xyxx
mad o1.xy, r0.xyxx, l(2.000000, -2.000000, 0.000000, 0.000000), l(-1.000000, 1.000000, 0.000000, 0.000000)
mov o1.zw, l(0,0,0,1.000000)
ret
// Approximately 8 instruction slots used
#endif
const BYTE static s_display_vs_bytecode[] =
{
68, 88, 66, 67, 37, 97,
157, 234, 112, 10, 38, 98,
114, 228, 143, 118, 71, 158,
122, 195, 1, 0, 0, 0,
72, 3, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
248, 0, 0, 0, 44, 1,
0, 0, 132, 1, 0, 0,
204, 2, 0, 0, 82, 68,
69, 70, 188, 0, 0, 0,
1, 0, 0, 0, 72, 0,
0, 0, 1, 0, 0, 0,
28, 0, 0, 0, 0, 4,
254, 255, 0, 129, 0, 0,
148, 0, 0, 0, 60, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0,
85, 66, 79, 66, 108, 111,
99, 107, 0, 171, 171, 171,
60, 0, 0, 0, 1, 0,
0, 0, 96, 0, 0, 0,
16, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
120, 0, 0, 0, 0, 0,
0, 0, 16, 0, 0, 0,
2, 0, 0, 0, 132, 0,
0, 0, 0, 0, 0, 0,
117, 95, 115, 114, 99, 95,
114, 101, 99, 116, 0, 171,
1, 0, 3, 0, 1, 0,
4, 0, 0, 0, 0, 0,
0, 0, 0, 0, 77, 105,
99, 114, 111, 115, 111, 102,
116, 32, 40, 82, 41, 32,
72, 76, 83, 76, 32, 83,
104, 97, 100, 101, 114, 32,
67, 111, 109, 112, 105, 108,
101, 114, 32, 49, 48, 46,
49, 0, 73, 83, 71, 78,
44, 0, 0, 0, 1, 0,
0, 0, 8, 0, 0, 0,
32, 0, 0, 0, 0, 0,
0, 0, 6, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 1, 1, 0, 0,
83, 86, 95, 86, 101, 114,
116, 101, 120, 73, 68, 0,
79, 83, 71, 78, 80, 0,
0, 0, 2, 0, 0, 0,
8, 0, 0, 0, 56, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
3, 12, 0, 0, 65, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 3, 0,
0, 0, 1, 0, 0, 0,
15, 0, 0, 0, 84, 69,
88, 67, 79, 79, 82, 68,
0, 83, 86, 95, 80, 111,
115, 105, 116, 105, 111, 110,
0, 171, 171, 171, 83, 72,
68, 82, 64, 1, 0, 0,
64, 0, 1, 0, 80, 0,
0, 0, 89, 0, 0, 4,
70, 142, 32, 0, 0, 0,
0, 0, 1, 0, 0, 0,
96, 0, 0, 4, 18, 16,
16, 0, 0, 0, 0, 0,
6, 0, 0, 0, 101, 0,
0, 3, 50, 32, 16, 0,
0, 0, 0, 0, 103, 0,
0, 4, 242, 32, 16, 0,
1, 0, 0, 0, 1, 0,
0, 0, 104, 0, 0, 2,
1, 0, 0, 0, 41, 0,
0, 7, 18, 0, 16, 0,
0, 0, 0, 0, 10, 16,
16, 0, 0, 0, 0, 0,
1, 64, 0, 0, 1, 0,
0, 0, 1, 0, 0, 7,
18, 0, 16, 0, 0, 0,
0, 0, 10, 0, 16, 0,
0, 0, 0, 0, 1, 64,
0, 0, 2, 0, 0, 0,
1, 0, 0, 7, 66, 0,
16, 0, 0, 0, 0, 0,
10, 16, 16, 0, 0, 0,
0, 0, 1, 64, 0, 0,
2, 0, 0, 0, 86, 0,
0, 5, 50, 0, 16, 0,
0, 0, 0, 0, 134, 0,
16, 0, 0, 0, 0, 0,
50, 0, 0, 11, 50, 32,
16, 0, 0, 0, 0, 0,
70, 0, 16, 0, 0, 0,
0, 0, 230, 138, 32, 0,
0, 0, 0, 0, 0, 0,
0, 0, 70, 128, 32, 0,
0, 0, 0, 0, 0, 0,
0, 0, 50, 0, 0, 15,
50, 32, 16, 0, 1, 0,
0, 0, 70, 0, 16, 0,
0, 0, 0, 0, 2, 64,
0, 0, 0, 0, 0, 64,
0, 0, 0, 192, 0, 0,
0, 0, 0, 0, 0, 0,
2, 64, 0, 0, 0, 0,
128, 191, 0, 0, 128, 63,
0, 0, 0, 0, 0, 0,
0, 0, 54, 0, 0, 8,
194, 32, 16, 0, 1, 0,
0, 0, 2, 64, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 128, 63, 62, 0,
0, 1, 83, 84, 65, 84,
116, 0, 0, 0, 8, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 2, 0, 0, 0,
1, 0, 0, 0, 2, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0
};

View File

@ -39,6 +39,25 @@ const std::tuple<GLenum, GLenum, GLenum>& GL::Texture::GetPixelFormatMapping(GPU
return mapping_gles2[static_cast<u32>(format)];
}
bool GL::Texture::Update(u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch, u32 layer /*= 0*/,
u32 level /*= 0*/)
{
UnreachableCode();
return false;
}
bool GL::Texture::Map(void** map, u32* map_stride, u32 x, u32 y, u32 width, u32 height, u32 layer /*= 0*/,
u32 level /*= 0*/)
{
UnreachableCode();
return false;
}
void GL::Texture::Unmap()
{
UnreachableCode();
}
GL::Texture::Texture() = default;
GL::Texture::Texture(Texture&& moved) : m_id(moved.m_id), m_fbo_id(moved.m_fbo_id)

View File

@ -20,6 +20,9 @@ public:
ALWAYS_INLINE GLuint GetGLId() const { return m_id; }
bool IsValid() const override { return m_id != 0; }
bool Update(u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch, u32 layer = 0, u32 level = 0) override;
bool Map(void** map, u32* map_stride, u32 x, u32 y, u32 width, u32 height, u32 layer = 0, u32 level = 0) override;
void Unmap() override;
bool Create(u32 width, u32 height, u32 layers, u32 levels, u32 samples, Format format, const void* data = nullptr,
u32 data_pitch = 0, bool linear = true, bool wrap = true);

View File

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
#include "gpu_device.h"
@ -9,6 +9,7 @@
#include "common/log.h"
#include "common/string_util.h"
#include "common/timer.h"
#include "imgui.h"
#include "stb_image.h"
#include "stb_image_resize.h"
#include "stb_image_write.h"
@ -35,18 +36,7 @@ RenderAPI GPUDevice::GetPreferredAPI()
void GPUDevice::DestroyResources()
{
m_cursor_texture.reset();
}
bool GPUDevice::UpdateTexture(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch)
{
void* map_ptr;
u32 map_pitch;
if (!BeginTextureUpdate(texture, width, height, &map_ptr, &map_pitch))
return false;
StringUtil::StrideMemCpy(map_ptr, map_pitch, data, pitch, std::min(pitch, map_pitch), height);
EndTextureUpdate(texture, x, y, width, height);
return true;
m_imgui_font_texture.reset();
}
bool GPUDevice::ParseFullscreenMode(const std::string_view& mode, u32* width, u32* height, float* refresh_rate)
@ -100,6 +90,34 @@ std::string GPUDevice::GetFullscreenModeString(u32 width, u32 height, float refr
return StringUtil::StdStringFromFormat("%u x %u @ %f hz", width, height, refresh_rate);
}
bool GPUDevice::UpdateImGuiFontTexture()
{
ImGuiIO& io = ImGui::GetIO();
unsigned char* pixels;
int width, height;
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
const u32 pitch = sizeof(u32) * width;
if (m_imgui_font_texture && m_imgui_font_texture->GetWidth() == static_cast<u32>(width) &&
m_imgui_font_texture->GetHeight() == static_cast<u32>(height) &&
m_imgui_font_texture->Update(0, 0, static_cast<u32>(width), static_cast<u32>(height), pixels, pitch))
{
io.Fonts->SetTexID(m_imgui_font_texture.get());
return true;
}
std::unique_ptr<GPUTexture> new_font =
CreateTexture(width, height, 1, 1, 1, GPUTexture::Type::Texture, GPUTexture::Format::RGBA8, pixels, pitch);
if (!new_font)
return false;
m_imgui_font_texture = std::move(new_font);
io.Fonts->SetTexID(m_imgui_font_texture.get());
return true;
}
bool GPUDevice::UsesLowerLeftOrigin() const
{
const RenderAPI api = GetRenderAPI();
@ -173,7 +191,7 @@ void GPUDevice::SetSoftwareCursor(std::unique_ptr<GPUTexture> texture, float sca
bool GPUDevice::SetSoftwareCursor(const void* pixels, u32 width, u32 height, u32 stride, float scale /*= 1.0f*/)
{
std::unique_ptr<GPUTexture> tex =
CreateTexture(width, height, 1, 1, 1, GPUTexture::Format::RGBA8, pixels, stride, false);
CreateTexture(width, height, 1, 1, 1, GPUTexture::Type::Texture, GPUTexture::Format::RGBA8, pixels, stride, false);
if (!tex)
return false;
@ -199,8 +217,8 @@ bool GPUDevice::SetSoftwareCursor(const char* path, float scale /*= 1.0f*/)
}
std::unique_ptr<GPUTexture> tex =
CreateTexture(static_cast<u32>(width), static_cast<u32>(height), 1, 1, 1, GPUTexture::Format::RGBA8, pixel_data,
sizeof(u32) * static_cast<u32>(width), false);
CreateTexture(static_cast<u32>(width), static_cast<u32>(height), 1, 1, 1, GPUTexture::Type::Texture,
GPUTexture::Format::RGBA8, pixel_data, sizeof(u32) * static_cast<u32>(width), false);
stbi_image_free(pixel_data);
if (!tex)
return false;

View File

@ -90,13 +90,8 @@ public:
/// Creates an abstracted RGBA8 texture. If dynamic, the texture can be updated with UpdateTexture() below.
virtual std::unique_ptr<GPUTexture> CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
GPUTexture::Format format, const void* data, u32 data_stride,
bool dynamic = false) = 0;
virtual bool BeginTextureUpdate(GPUTexture* texture, u32 width, u32 height, void** out_buffer, u32* out_pitch) = 0;
virtual void EndTextureUpdate(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height) = 0;
virtual bool UpdateTexture(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch);
GPUTexture::Type type, GPUTexture::Format format, const void* data,
u32 data_stride, bool dynamic = false) = 0;
virtual bool DownloadTexture(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, void* out_data,
u32 out_data_stride) = 0;
@ -110,11 +105,7 @@ public:
ALWAYS_INLINE bool IsVsyncEnabled() const { return m_vsync_enabled; }
virtual void SetVSync(bool enabled) = 0;
/// ImGui context management, usually called by derived classes.
virtual bool CreateImGuiContext() = 0;
virtual void DestroyImGuiContext() = 0;
virtual bool UpdateImGuiFontTexture() = 0;
bool UpdateImGuiFontTexture();
bool UsesLowerLeftOrigin() const;
void SetDisplayMaxFPS(float max_fps);
bool ShouldSkipDisplayingFrame();
@ -243,6 +234,8 @@ protected:
s32 m_display_texture_view_width = 0;
s32 m_display_texture_view_height = 0;
std::unique_ptr<GPUTexture> m_imgui_font_texture;
std::unique_ptr<GPUTexture> m_cursor_texture;
float m_cursor_texture_scale = 1.0f;

View File

@ -18,6 +18,15 @@ public:
MAX_SAMPLES = 255,
};
enum class Type : u8
{
Unknown,
RenderTarget,
DepthStencil,
Texture,
RWTexture,
};
enum class Format : u8
{
Unknown,
@ -38,7 +47,8 @@ public:
ALWAYS_INLINE u32 GetLayers() const { return m_layers; }
ALWAYS_INLINE u32 GetLevels() const { return m_levels; }
ALWAYS_INLINE u32 GetSamples() const { return m_samples; }
ALWAYS_INLINE GPUTexture::Format GetFormat() const { return m_format; }
ALWAYS_INLINE Type GetType() const { return m_type; }
ALWAYS_INLINE Format GetFormat() const { return m_format; }
ALWAYS_INLINE bool IsTextureArray() const { return m_layers > 1; }
ALWAYS_INLINE bool IsMultisampled() const { return m_samples > 1; }
@ -47,8 +57,6 @@ public:
ALWAYS_INLINE u32 GetMipWidth(u32 level) const { return std::max<u32>(m_width >> level, 1u); }
ALWAYS_INLINE u32 GetMipHeight(u32 level) const { return std::max<u32>(m_height >> level, 1u); }
virtual bool IsValid() const = 0;
static u32 GetPixelSize(GPUTexture::Format format);
static bool IsDepthFormat(GPUTexture::Format format);
@ -56,6 +64,13 @@ public:
GPUTexture::Format format);
static void FlipTextureDataRGBA8(u32 width, u32 height, std::vector<u32>& texture_data, u32 texture_data_stride);
virtual bool IsValid() const = 0;
virtual bool Update(u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch, u32 layer = 0,
u32 level = 0) = 0;
virtual bool Map(void** map, u32* map_stride, u32 x, u32 y, u32 width, u32 height, u32 layer = 0, u32 level = 0) = 0;
virtual void Unmap() = 0;
protected:
GPUTexture();
GPUTexture(u16 width, u16 height, u8 layers, u8 levels, u8 samples, Format format);
@ -67,5 +82,13 @@ protected:
u8 m_layers = 0;
u8 m_levels = 0;
u8 m_samples = 0;
Type m_type = Type::Unknown;
Format m_format = Format::Unknown;
// u16 m_map_x = 0;
// u16 m_map_y = 0;
// u16 m_map_width = 0;
// u16 m_map_height = 0;
// u8 m_map_layer = 0;
// u8 m_map_level = 0;
};

View File

@ -1,499 +0,0 @@
// dear imgui: Renderer Backend for DirectX11
// This needs to be used along with a Platform Backend (e.g. Win32)
// Implemented features:
// [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID!
// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices.
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
// Read online: https://github.com/ocornut/imgui/tree/master/docs
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
// 2021-05-19: DirectX11: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
// 2021-02-18: DirectX11: Change blending equation to preserve alpha in output buffer.
// 2019-08-01: DirectX11: Fixed code querying the Geometry Shader state (would generally error with Debug layer enabled).
// 2019-07-21: DirectX11: Backup, clear and restore Geometry Shader is any is bound when calling ImGui_ImplDX10_RenderDrawData. Clearing Hull/Domain/Compute shaders without backup/restore.
// 2019-05-29: DirectX11: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
// 2019-04-30: DirectX11: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
// 2018-12-03: Misc: Added #pragma comment statement to automatically link with d3dcompiler.lib when using D3DCompile().
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
// 2018-08-01: DirectX11: Querying for IDXGIFactory instead of IDXGIFactory1 to increase compatibility.
// 2018-07-13: DirectX11: Fixed unreleased resources in Init and Shutdown functions.
// 2018-06-08: Misc: Extracted imgui_impl_dx11.cpp/.h away from the old combined DX11+Win32 example.
// 2018-06-08: DirectX11: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplDX11_RenderDrawData() in the .h file so you can call it yourself.
// 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
// 2016-05-07: DirectX11: Disabling depth-write.
#include "imgui.h"
#include "imgui_impl_dx11.h"
#include "d3d11/texture.h"
// DirectX
#include <stdio.h>
#include <d3d11.h>
#include <d3dcompiler.h>
#ifdef _MSC_VER
#pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below.
#endif
// DirectX11 data
struct ImGui_ImplDX11_Data
{
ID3D11Device* pd3dDevice;
ID3D11DeviceContext* pd3dDeviceContext;
IDXGIFactory* pFactory;
ID3D11Buffer* pVB;
ID3D11Buffer* pIB;
ID3D11VertexShader* pVertexShader;
ID3D11InputLayout* pInputLayout;
ID3D11Buffer* pVertexConstantBuffer;
ID3D11PixelShader* pPixelShader;
ID3D11SamplerState* pFontSampler;
ID3D11RasterizerState* pRasterizerState;
ID3D11BlendState* pBlendState;
ID3D11DepthStencilState* pDepthStencilState;
int VertexBufferSize;
int IndexBufferSize;
D3D11::Texture FontTexture;
ImGui_ImplDX11_Data() { memset((void*)this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; }
};
struct VERTEX_CONSTANT_BUFFER
{
float mvp[4][4];
};
// Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
static ImGui_ImplDX11_Data* ImGui_ImplDX11_GetBackendData()
{
return ImGui::GetCurrentContext() ? (ImGui_ImplDX11_Data*)ImGui::GetIO().BackendRendererUserData : NULL;
}
// Functions
static void ImGui_ImplDX11_SetupRenderState(ImDrawData* draw_data, ID3D11DeviceContext* ctx)
{
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
// Setup viewport
D3D11_VIEWPORT vp;
memset(&vp, 0, sizeof(D3D11_VIEWPORT));
vp.Width = draw_data->DisplaySize.x;
vp.Height = draw_data->DisplaySize.y;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.TopLeftX = vp.TopLeftY = 0;
ctx->RSSetViewports(1, &vp);
// Setup shader and vertex buffers
unsigned int stride = sizeof(ImDrawVert);
unsigned int offset = 0;
ctx->IASetInputLayout(bd->pInputLayout);
ctx->IASetVertexBuffers(0, 1, &bd->pVB, &stride, &offset);
ctx->IASetIndexBuffer(bd->pIB, sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0);
ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
ctx->VSSetShader(bd->pVertexShader, NULL, 0);
ctx->VSSetConstantBuffers(0, 1, &bd->pVertexConstantBuffer);
ctx->PSSetShader(bd->pPixelShader, NULL, 0);
ctx->PSSetSamplers(0, 1, &bd->pFontSampler);
ctx->GSSetShader(NULL, NULL, 0);
ctx->HSSetShader(NULL, NULL, 0); // In theory we should backup and restore this as well.. very infrequently used..
ctx->DSSetShader(NULL, NULL, 0); // In theory we should backup and restore this as well.. very infrequently used..
ctx->CSSetShader(NULL, NULL, 0); // In theory we should backup and restore this as well.. very infrequently used..
// Setup blend state
const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f };
ctx->OMSetBlendState(bd->pBlendState, blend_factor, 0xffffffff);
ctx->OMSetDepthStencilState(bd->pDepthStencilState, 0);
ctx->RSSetState(bd->pRasterizerState);
}
// Render function
void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
{
// Avoid rendering when minimized
if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f)
return;
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
ID3D11DeviceContext* ctx = bd->pd3dDeviceContext;
// Create and grow vertex/index buffers if needed
if (!bd->pVB || bd->VertexBufferSize < draw_data->TotalVtxCount)
{
if (bd->pVB) { bd->pVB->Release(); bd->pVB = NULL; }
bd->VertexBufferSize = draw_data->TotalVtxCount + 5000;
D3D11_BUFFER_DESC desc;
memset(&desc, 0, sizeof(D3D11_BUFFER_DESC));
desc.Usage = D3D11_USAGE_DYNAMIC;
desc.ByteWidth = bd->VertexBufferSize * sizeof(ImDrawVert);
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
desc.MiscFlags = 0;
if (bd->pd3dDevice->CreateBuffer(&desc, NULL, &bd->pVB) < 0)
return;
}
if (!bd->pIB || bd->IndexBufferSize < draw_data->TotalIdxCount)
{
if (bd->pIB) { bd->pIB->Release(); bd->pIB = NULL; }
bd->IndexBufferSize = draw_data->TotalIdxCount + 10000;
D3D11_BUFFER_DESC desc;
memset(&desc, 0, sizeof(D3D11_BUFFER_DESC));
desc.Usage = D3D11_USAGE_DYNAMIC;
desc.ByteWidth = bd->IndexBufferSize * sizeof(ImDrawIdx);
desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
if (bd->pd3dDevice->CreateBuffer(&desc, NULL, &bd->pIB) < 0)
return;
}
// Upload vertex/index data into a single contiguous GPU buffer
D3D11_MAPPED_SUBRESOURCE vtx_resource, idx_resource;
if (ctx->Map(bd->pVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &vtx_resource) != S_OK)
return;
if (ctx->Map(bd->pIB, 0, D3D11_MAP_WRITE_DISCARD, 0, &idx_resource) != S_OK)
return;
ImDrawVert* vtx_dst = (ImDrawVert*)vtx_resource.pData;
ImDrawIdx* idx_dst = (ImDrawIdx*)idx_resource.pData;
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
const ImDrawList* cmd_list = draw_data->CmdLists[n];
memcpy(vtx_dst, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert));
memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx));
vtx_dst += cmd_list->VtxBuffer.Size;
idx_dst += cmd_list->IdxBuffer.Size;
}
ctx->Unmap(bd->pVB, 0);
ctx->Unmap(bd->pIB, 0);
// Setup orthographic projection matrix into our constant buffer
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
{
D3D11_MAPPED_SUBRESOURCE mapped_resource;
if (ctx->Map(bd->pVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource) != S_OK)
return;
VERTEX_CONSTANT_BUFFER* constant_buffer = (VERTEX_CONSTANT_BUFFER*)mapped_resource.pData;
float L = draw_data->DisplayPos.x;
float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
float T = draw_data->DisplayPos.y;
float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
float mvp[4][4] =
{
{ 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
{ 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.5f, 0.0f },
{ (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f },
};
memcpy(&constant_buffer->mvp, mvp, sizeof(mvp));
ctx->Unmap(bd->pVertexConstantBuffer, 0);
}
// Setup desired DX state
ImGui_ImplDX11_SetupRenderState(draw_data, ctx);
// Render command lists
// (Because we merged all buffers into a single one, we maintain our own offset into them)
int global_idx_offset = 0;
int global_vtx_offset = 0;
ImVec2 clip_off = draw_data->DisplayPos;
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
const ImDrawList* cmd_list = draw_data->CmdLists[n];
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
{
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
if (pcmd->UserCallback != NULL)
{
// User callback, registered via ImDrawList::AddCallback()
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
ImGui_ImplDX11_SetupRenderState(draw_data, ctx);
else
pcmd->UserCallback(cmd_list, pcmd);
}
else
{
// Project scissor/clipping rectangles into framebuffer space
ImVec2 clip_min(pcmd->ClipRect.x - clip_off.x, pcmd->ClipRect.y - clip_off.y);
ImVec2 clip_max(pcmd->ClipRect.z - clip_off.x, pcmd->ClipRect.w - clip_off.y);
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
continue;
// Apply scissor/clipping rectangle
const D3D11_RECT r = { (LONG)clip_min.x, (LONG)clip_min.y, (LONG)clip_max.x, (LONG)clip_max.y };
ctx->RSSetScissorRects(1, &r);
// Bind texture, Draw
const D3D11::Texture* tex = static_cast<D3D11::Texture*>(pcmd->GetTexID());
ID3D11ShaderResourceView* texture_srv = tex ? tex->GetD3DSRV() : nullptr;
ctx->PSSetShaderResources(0, 1, &texture_srv);
ctx->DrawIndexed(pcmd->ElemCount, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset);
}
}
global_idx_offset += cmd_list->IdxBuffer.Size;
global_vtx_offset += cmd_list->VtxBuffer.Size;
}
}
bool ImGui_ImplDX11_CreateFontsTexture()
{
// Build texture atlas
ImGuiIO& io = ImGui::GetIO();
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
unsigned char* pixels;
int width, height;
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
const u32 stride = sizeof(u32) * width;
if (!bd->FontTexture.Create(bd->pd3dDevice, width, height, 1, 1, 1, GPUTexture::Format::RGBA8, D3D11_BIND_SHADER_RESOURCE, pixels, stride))
return false;
// Store our identifier
io.Fonts->SetTexID((ImTextureID)&bd->FontTexture);
// Create texture sampler
// (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
if (!bd->pFontSampler)
{
D3D11_SAMPLER_DESC desc;
ZeroMemory(&desc, sizeof(desc));
desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
desc.MipLODBias = 0.f;
desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
desc.MinLOD = 0.f;
desc.MaxLOD = 0.f;
bd->pd3dDevice->CreateSamplerState(&desc, &bd->pFontSampler);
}
return true;
}
bool ImGui_ImplDX11_CreateDeviceObjects()
{
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
if (!bd->pd3dDevice)
return false;
if (bd->pFontSampler)
ImGui_ImplDX11_InvalidateDeviceObjects();
// By using D3DCompile() from <d3dcompiler.h> / d3dcompiler.lib, we introduce a dependency to a given version of d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A)
// If you would like to use this DX11 sample code but remove this dependency you can:
// 1) compile once, save the compiled shader blobs into a file or source code and pass them to CreateVertexShader()/CreatePixelShader() [preferred solution]
// 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL.
// See https://github.com/ocornut/imgui/pull/638 for sources and details.
// Create the vertex shader
{
static const char* vertexShader =
"cbuffer vertexBuffer : register(b0) \
{\
float4x4 ProjectionMatrix; \
};\
struct VS_INPUT\
{\
float2 pos : POSITION;\
float4 col : COLOR0;\
float2 uv : TEXCOORD0;\
};\
\
struct PS_INPUT\
{\
float4 pos : SV_POSITION;\
float4 col : COLOR0;\
float2 uv : TEXCOORD0;\
};\
\
PS_INPUT main(VS_INPUT input)\
{\
PS_INPUT output;\
output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\
output.col = input.col;\
output.uv = input.uv;\
return output;\
}";
ID3DBlob* vertexShaderBlob;
if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_4_0", 0, 0, &vertexShaderBlob, NULL)))
return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
if (bd->pd3dDevice->CreateVertexShader(vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), NULL, &bd->pVertexShader) != S_OK)
{
vertexShaderBlob->Release();
return false;
}
// Create the input layout
D3D11_INPUT_ELEMENT_DESC local_layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)IM_OFFSETOF(ImDrawVert, pos), D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)IM_OFFSETOF(ImDrawVert, uv), D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (UINT)IM_OFFSETOF(ImDrawVert, col), D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
if (bd->pd3dDevice->CreateInputLayout(local_layout, 3, vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), &bd->pInputLayout) != S_OK)
{
vertexShaderBlob->Release();
return false;
}
vertexShaderBlob->Release();
// Create the constant buffer
{
D3D11_BUFFER_DESC desc;
desc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER);
desc.Usage = D3D11_USAGE_DYNAMIC;
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
desc.MiscFlags = 0;
bd->pd3dDevice->CreateBuffer(&desc, NULL, &bd->pVertexConstantBuffer);
}
}
// Create the pixel shader
{
static const char* pixelShader =
"struct PS_INPUT\
{\
float4 pos : SV_POSITION;\
float4 col : COLOR0;\
float2 uv : TEXCOORD0;\
};\
sampler sampler0;\
Texture2D texture0;\
\
float4 main(PS_INPUT input) : SV_Target\
{\
float4 out_col = input.col * texture0.Sample(sampler0, input.uv); \
return out_col; \
}";
ID3DBlob* pixelShaderBlob;
if (FAILED(D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_4_0", 0, 0, &pixelShaderBlob, NULL)))
return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
if (bd->pd3dDevice->CreatePixelShader(pixelShaderBlob->GetBufferPointer(), pixelShaderBlob->GetBufferSize(), NULL, &bd->pPixelShader) != S_OK)
{
pixelShaderBlob->Release();
return false;
}
pixelShaderBlob->Release();
}
// Create the blending setup
{
D3D11_BLEND_DESC desc;
ZeroMemory(&desc, sizeof(desc));
desc.AlphaToCoverageEnable = false;
desc.RenderTarget[0].BlendEnable = true;
desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
bd->pd3dDevice->CreateBlendState(&desc, &bd->pBlendState);
}
// Create the rasterizer state
{
D3D11_RASTERIZER_DESC desc;
ZeroMemory(&desc, sizeof(desc));
desc.FillMode = D3D11_FILL_SOLID;
desc.CullMode = D3D11_CULL_NONE;
desc.ScissorEnable = true;
desc.DepthClipEnable = true;
bd->pd3dDevice->CreateRasterizerState(&desc, &bd->pRasterizerState);
}
// Create depth-stencil State
{
D3D11_DEPTH_STENCIL_DESC desc;
ZeroMemory(&desc, sizeof(desc));
desc.DepthEnable = false;
desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
desc.DepthFunc = D3D11_COMPARISON_ALWAYS;
desc.StencilEnable = false;
desc.FrontFace.StencilFailOp = desc.FrontFace.StencilDepthFailOp = desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
desc.BackFace = desc.FrontFace;
bd->pd3dDevice->CreateDepthStencilState(&desc, &bd->pDepthStencilState);
}
return ImGui_ImplDX11_CreateFontsTexture();
}
void ImGui_ImplDX11_InvalidateDeviceObjects()
{
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
if (!bd->pd3dDevice)
return;
if (bd->pFontSampler) { bd->pFontSampler->Release(); bd->pFontSampler = NULL; }
if (bd->FontTexture) { bd->FontTexture.Destroy(); ImGui::GetIO().Fonts->SetTexID(NULL); } // We copied data->pFontTextureView to io.Fonts->TexID so let's clear that as well.
if (bd->pIB) { bd->pIB->Release(); bd->pIB = NULL; }
if (bd->pVB) { bd->pVB->Release(); bd->pVB = NULL; }
if (bd->pBlendState) { bd->pBlendState->Release(); bd->pBlendState = NULL; }
if (bd->pDepthStencilState) { bd->pDepthStencilState->Release(); bd->pDepthStencilState = NULL; }
if (bd->pRasterizerState) { bd->pRasterizerState->Release(); bd->pRasterizerState = NULL; }
if (bd->pPixelShader) { bd->pPixelShader->Release(); bd->pPixelShader = NULL; }
if (bd->pVertexConstantBuffer) { bd->pVertexConstantBuffer->Release(); bd->pVertexConstantBuffer = NULL; }
if (bd->pInputLayout) { bd->pInputLayout->Release(); bd->pInputLayout = NULL; }
if (bd->pVertexShader) { bd->pVertexShader->Release(); bd->pVertexShader = NULL; }
}
bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context)
{
ImGuiIO& io = ImGui::GetIO();
IM_ASSERT(io.BackendRendererUserData == NULL && "Already initialized a renderer backend!");
// Setup backend capabilities flags
ImGui_ImplDX11_Data* bd = IM_NEW(ImGui_ImplDX11_Data)();
io.BackendRendererUserData = (void*)bd;
io.BackendRendererName = "imgui_impl_dx11";
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
// Get factory from device
IDXGIDevice* pDXGIDevice = NULL;
IDXGIAdapter* pDXGIAdapter = NULL;
IDXGIFactory* pFactory = NULL;
if (device->QueryInterface(IID_PPV_ARGS(&pDXGIDevice)) == S_OK)
if (pDXGIDevice->GetParent(IID_PPV_ARGS(&pDXGIAdapter)) == S_OK)
if (pDXGIAdapter->GetParent(IID_PPV_ARGS(&pFactory)) == S_OK)
{
bd->pd3dDevice = device;
bd->pd3dDeviceContext = device_context;
bd->pFactory = pFactory;
}
if (pDXGIDevice) pDXGIDevice->Release();
if (pDXGIAdapter) pDXGIAdapter->Release();
bd->pd3dDevice->AddRef();
bd->pd3dDeviceContext->AddRef();
return ImGui_ImplDX11_CreateDeviceObjects();
}
void ImGui_ImplDX11_Shutdown()
{
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
IM_ASSERT(bd != NULL && "No renderer backend to shutdown, or already shutdown?");
if (bd == NULL)
return;
ImGui_ImplDX11_InvalidateDeviceObjects();
if (bd->pFactory) { bd->pFactory->Release(); }
if (bd->pd3dDevice) { bd->pd3dDevice->Release(); }
if (bd->pd3dDeviceContext) { bd->pd3dDeviceContext->Release(); }
ImGuiIO& io = ImGui::GetIO();
io.BackendRendererName = NULL;
io.BackendRendererUserData = NULL;
IM_DELETE(bd);
}

View File

@ -1,17 +0,0 @@
// dear imgui: Renderer Backend for DirectX11
// This needs to be used along with a Platform Backend (e.g. Win32)
#pragma once
#include "imgui.h" // IMGUI_IMPL_API
struct ID3D11Device;
struct ID3D11DeviceContext;
bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context);
void ImGui_ImplDX11_Shutdown();
void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data);
// Use if you want to reset your rendering device without losing Dear ImGui state.
void ImGui_ImplDX11_InvalidateDeviceObjects();
bool ImGui_ImplDX11_CreateDeviceObjects();
bool ImGui_ImplDX11_CreateFontsTexture();

View File

@ -48,7 +48,8 @@ void* OpenGLGPUDevice::GetContext() const
}
std::unique_ptr<GPUTexture> OpenGLGPUDevice::CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
GPUTexture::Format format, const void* data, u32 data_stride,
GPUTexture::Type type, GPUTexture::Format format,
const void* data, u32 data_stride,
bool dynamic /* = false */)
{
std::unique_ptr<GL::Texture> tex(std::make_unique<GL::Texture>());
@ -58,6 +59,7 @@ std::unique_ptr<GPUTexture> OpenGLGPUDevice::CreateTexture(u32 width, u32 height
return tex;
}
#if 0
bool OpenGLGPUDevice::BeginTextureUpdate(GPUTexture* texture, u32 width, u32 height, void** out_buffer, u32* out_pitch)
{
const u32 pixel_size = texture->GetPixelSize();
@ -172,6 +174,8 @@ bool OpenGLGPUDevice::UpdateTexture(GPUTexture* texture, u32 x, u32 y, u32 width
return true;
}
#endif
bool OpenGLGPUDevice::DownloadTexture(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, void* out_data,
u32 out_data_stride)
{
@ -432,7 +436,7 @@ void OpenGLGPUDevice::DestroySurface()
if (!m_gl_context->ChangeSurface(m_window_info))
Log_ErrorPrintf("Failed to switch to surfaceless");
}
#if 0
bool OpenGLGPUDevice::CreateImGuiContext()
{
return ImGui_ImplOpenGL3_Init(GetGLSLVersionString());
@ -448,6 +452,7 @@ bool OpenGLGPUDevice::UpdateImGuiFontTexture()
ImGui_ImplOpenGL3_DestroyFontsTexture();
return ImGui_ImplOpenGL3_CreateFontsTexture();
}
#endif
bool OpenGLGPUDevice::CreateResources()
{

View File

@ -43,11 +43,8 @@ public:
bool SetPostProcessingChain(const std::string_view& config) override;
std::unique_ptr<GPUTexture> CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
GPUTexture::Format format, const void* data, u32 data_stride,
bool dynamic = false) override;
bool BeginTextureUpdate(GPUTexture* texture, u32 width, u32 height, void** out_buffer, u32* out_pitch) override;
void EndTextureUpdate(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height) override;
bool UpdateTexture(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch) override;
GPUTexture::Type type, GPUTexture::Format format, const void* data,
u32 data_stride, bool dynamic = false) override;
bool DownloadTexture(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, void* out_data,
u32 out_data_stride) override;
bool SupportsTextureFormat(GPUTexture::Format format) const override;
@ -77,10 +74,6 @@ protected:
bool CreateResources() override;
void DestroyResources() override;
bool CreateImGuiContext() override;
void DestroyImGuiContext() override;
bool UpdateImGuiFontTexture() override;
void SetSwapInterval();
void RenderDisplay();

View File

@ -64,6 +64,25 @@ bool Vulkan::Texture::IsValid() const
return (m_image != VK_NULL_HANDLE);
}
bool Vulkan::Texture::Update(u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch, u32 layer /*= 0*/,
u32 level /*= 0*/)
{
UnreachableCode();
return false;
}
bool Vulkan::Texture::Map(void** map, u32* map_stride, u32 x, u32 y, u32 width, u32 height, u32 layer /*= 0*/,
u32 level /*= 0*/)
{
UnreachableCode();
return false;
}
void Vulkan::Texture::Unmap()
{
UnreachableCode();
}
Vulkan::Texture& Vulkan::Texture::operator=(Texture&& move)
{
if (IsValid())

View File

@ -24,6 +24,9 @@ public:
static Format LookupBaseFormat(VkFormat vformat);
bool IsValid() const override;
bool Update(u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch, u32 layer = 0, u32 level = 0) override;
bool Map(void** map, u32* map_stride, u32 x, u32 y, u32 width, u32 height, u32 layer = 0, u32 level = 0) override;
void Unmap() override;
/// An image is considered owned/managed if we control the memory.
ALWAYS_INLINE bool IsOwned() const { return (m_allocation != VK_NULL_HANDLE); }

View File

@ -140,7 +140,7 @@ void VulkanGPUDevice::DestroySurface()
m_swap_chain.reset();
}
std::unique_ptr<GPUTexture> VulkanGPUDevice::CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
std::unique_ptr<GPUTexture> VulkanGPUDevice::CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples, GPUTexture::Type type,
GPUTexture::Format format, const void* data, u32 data_stride,
bool dynamic /* = false */)
{
@ -179,6 +179,7 @@ std::unique_ptr<GPUTexture> VulkanGPUDevice::CreateTexture(u32 width, u32 height
return texture;
}
#if 0
bool VulkanGPUDevice::BeginTextureUpdate(GPUTexture* texture, u32 width, u32 height, void** out_buffer, u32* out_pitch)
{
return static_cast<Vulkan::Texture*>(texture)->BeginUpdate(width, height, out_buffer, out_pitch);
@ -194,6 +195,7 @@ bool VulkanGPUDevice::UpdateTexture(GPUTexture* texture, u32 x, u32 y, u32 width
{
return static_cast<Vulkan::Texture*>(texture)->Update(x, y, width, height, 0, 0, data, pitch);
}
#endif
bool VulkanGPUDevice::SupportsTextureFormat(GPUTexture::Format format) const
{
@ -565,6 +567,7 @@ void VulkanGPUDevice::DestroyResources()
Vulkan::Util::SafeDestroySampler(m_linear_sampler);
}
#if 0
bool VulkanGPUDevice::CreateImGuiContext()
{
const VkRenderPass render_pass =
@ -589,6 +592,7 @@ bool VulkanGPUDevice::UpdateImGuiFontTexture()
g_vulkan_context->ExecuteCommandBuffer(true);
return ImGui_ImplVulkan_CreateFontsTexture();
}
#endif
bool VulkanGPUDevice::MakeCurrent()
{

View File

@ -47,11 +47,8 @@ public:
bool SetPostProcessingChain(const std::string_view& config) override;
std::unique_ptr<GPUTexture> CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
GPUTexture::Format format, const void* data, u32 data_stride,
bool dynamic = false) override;
bool BeginTextureUpdate(GPUTexture* texture, u32 width, u32 height, void** out_buffer, u32* out_pitch) override;
void EndTextureUpdate(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height) override;
bool UpdateTexture(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch) override;
GPUTexture::Type type, GPUTexture::Format format, const void* data,
u32 data_stride, bool dynamic = false) override;
bool DownloadTexture(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, void* out_data,
u32 out_data_stride) override;
bool SupportsTextureFormat(GPUTexture::Format format) const override;
@ -101,10 +98,6 @@ protected:
bool CreateResources() override;
void DestroyResources() override;
bool CreateImGuiContext() override;
void DestroyImGuiContext() override;
bool UpdateImGuiFontTexture() override;
void BeginSwapChainRenderPass(VkFramebuffer framebuffer, u32 width, u32 height);
void RenderDisplay();
void RenderImGui();

View File

@ -90,7 +90,7 @@ bool GPU_HW_D3D11::DoState(StateWrapper& sw, GPUTexture** host_texture, bool upd
{
ComPtr<ID3D11Resource> resource;
D3D11::Texture* tex = static_cast<D3D11::Texture*>(*host_texture);
D3D11Texture* tex = static_cast<D3D11Texture*>(*host_texture);
if (sw.IsReading())
{
if (tex->GetWidth() != m_vram_texture.GetWidth() || tex->GetHeight() != m_vram_texture.GetHeight() ||
@ -108,11 +108,11 @@ bool GPU_HW_D3D11::DoState(StateWrapper& sw, GPUTexture** host_texture, bool upd
{
delete tex;
tex = static_cast<D3D11::Texture*>(g_host_display
->CreateTexture(m_vram_texture.GetWidth(), m_vram_texture.GetHeight(), 1,
1, m_vram_texture.GetSamples(), GPUTexture::Format::RGBA8,
nullptr, 0, false)
.release());
tex = static_cast<D3D11Texture*>(g_host_display
->CreateTexture(m_vram_texture.GetWidth(), m_vram_texture.GetHeight(), 1, 1,
m_vram_texture.GetSamples(), GPUTexture::Type::RenderTarget,
GPUTexture::Format::RGBA8, nullptr, 0, false)
.release());
*host_texture = tex;
if (!tex)
return false;
@ -243,26 +243,25 @@ bool GPU_HW_D3D11::CreateFramebuffer()
const GPUTexture::Format texture_format = GPUTexture::Format::RGBA8;
const GPUTexture::Format depth_format = GPUTexture::Format::D16;
if (!m_vram_texture.Create(m_device.Get(), texture_width, texture_height, 1, 1, samples, texture_format,
D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET) ||
!m_vram_depth_texture.Create(m_device.Get(), texture_width, texture_height, 1, 1, samples, depth_format,
D3D11_BIND_DEPTH_STENCIL) ||
!m_vram_read_texture.Create(m_device.Get(), texture_width, texture_height, 1, 1, 1, texture_format,
D3D11_BIND_SHADER_RESOURCE) ||
if (!m_vram_texture.Create(m_device.Get(), texture_width, texture_height, 1, 1, samples,
GPUTexture::Type::RenderTarget, texture_format) ||
!m_vram_depth_texture.Create(m_device.Get(), texture_width, texture_height, 1, 1, samples,
GPUTexture::Type::DepthStencil, depth_format) ||
!m_vram_read_texture.Create(m_device.Get(), texture_width, texture_height, 1, 1, 1, GPUTexture::Type::Texture,
texture_format) ||
!m_display_texture.Create(
m_device.Get(),
((m_downsample_mode == GPUDownsampleMode::Adaptive) ? VRAM_WIDTH : GPU_MAX_DISPLAY_WIDTH) * m_resolution_scale,
GPU_MAX_DISPLAY_HEIGHT * m_resolution_scale, 1, 1, 1, texture_format,
D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET) ||
!m_vram_encoding_texture.Create(m_device.Get(), VRAM_WIDTH / 2, VRAM_HEIGHT, 1, 1, 1, texture_format,
D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET))
GPU_MAX_DISPLAY_HEIGHT * m_resolution_scale, 1, 1, 1, GPUTexture::Type::RenderTarget, texture_format) ||
!m_vram_encoding_texture.Create(m_device.Get(), VRAM_WIDTH / 2, VRAM_HEIGHT, 1, 1, 1,
GPUTexture::Type::RenderTarget, texture_format))
{
return false;
}
const CD3D11_DEPTH_STENCIL_VIEW_DESC depth_view_desc(samples > 1 ? D3D11_DSV_DIMENSION_TEXTURE2DMS :
D3D11_DSV_DIMENSION_TEXTURE2D,
D3D11::Texture::GetDXGIFormat(depth_format));
D3D11Texture::GetDXGIFormat(depth_format));
HRESULT hr =
m_device->CreateDepthStencilView(m_vram_depth_texture, &depth_view_desc, m_vram_depth_view.GetAddressOf());
if (FAILED(hr))
@ -273,10 +272,10 @@ bool GPU_HW_D3D11::CreateFramebuffer()
const u32 levels = GetAdaptiveDownsamplingMipLevels();
if (!m_downsample_texture.Create(m_device.Get(), texture_width, texture_height, 1, static_cast<u16>(levels), 1,
texture_format, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET) ||
GPUTexture::Type::RenderTarget, texture_format) ||
!m_downsample_weight_texture.Create(m_device.Get(), texture_width >> (levels - 1),
texture_height >> (levels - 1), 1, 1, 1, GPUTexture::Format::R8,
D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET))
texture_height >> (levels - 1), 1, 1, 1, GPUTexture::Type::RenderTarget,
GPUTexture::Format::R8))
{
return false;
}
@ -302,8 +301,8 @@ bool GPU_HW_D3D11::CreateFramebuffer()
}
else if (m_downsample_mode == GPUDownsampleMode::Box)
{
if (!m_downsample_texture.Create(m_device.Get(), VRAM_WIDTH, VRAM_HEIGHT, 1, 1, 1, texture_format,
D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET))
if (!m_downsample_texture.Create(m_device.Get(), VRAM_WIDTH, VRAM_HEIGHT, 1, 1, 1, GPUTexture::Type::RenderTarget,
texture_format))
{
return false;
}
@ -735,7 +734,7 @@ bool GPU_HW_D3D11::BlitVRAMReplacementTexture(const TextureReplacementTexture* t
m_vram_replacement_texture.GetHeight() < tex->GetHeight())
{
if (!m_vram_replacement_texture.Create(m_device.Get(), tex->GetWidth(), tex->GetHeight(), 1, 1, 1,
GPUTexture::Format::RGBA8, D3D11_BIND_SHADER_RESOURCE, tex->GetPixels(),
GPUTexture::Type::Texture, GPUTexture::Format::RGBA8, tex->GetPixels(),
tex->GetPitch(), true))
{
return false;
@ -1093,7 +1092,7 @@ void GPU_HW_D3D11::ClearDepthBuffer()
m_last_depth_z = 1.0f;
}
void GPU_HW_D3D11::DownsampleFramebuffer(D3D11::Texture& source, u32 left, u32 top, u32 width, u32 height)
void GPU_HW_D3D11::DownsampleFramebuffer(D3D11Texture& source, u32 left, u32 top, u32 width, u32 height)
{
if (m_downsample_mode == GPUDownsampleMode::Adaptive)
DownsampleFramebufferAdaptive(source, left, top, width, height);
@ -1101,7 +1100,7 @@ void GPU_HW_D3D11::DownsampleFramebuffer(D3D11::Texture& source, u32 left, u32 t
DownsampleFramebufferBoxFilter(source, left, top, width, height);
}
void GPU_HW_D3D11::DownsampleFramebufferAdaptive(D3D11::Texture& source, u32 left, u32 top, u32 width, u32 height)
void GPU_HW_D3D11::DownsampleFramebufferAdaptive(D3D11Texture& source, u32 left, u32 top, u32 width, u32 height)
{
CD3D11_BOX src_box(left, top, 0, left + width, top + height, 1);
m_context->OMSetDepthStencilState(m_depth_disabled_state.Get(), 0);
@ -1170,7 +1169,7 @@ void GPU_HW_D3D11::DownsampleFramebufferAdaptive(D3D11::Texture& source, u32 lef
g_host_display->SetDisplayTexture(&m_display_texture, left, top, width, height);
}
void GPU_HW_D3D11::DownsampleFramebufferBoxFilter(D3D11::Texture& source, u32 left, u32 top, u32 width, u32 height)
void GPU_HW_D3D11::DownsampleFramebufferBoxFilter(D3D11Texture& source, u32 left, u32 top, u32 width, u32 height)
{
const u32 ds_left = left / m_resolution_scale;
const u32 ds_top = top / m_resolution_scale;

View File

@ -4,7 +4,7 @@
#pragma once
#include "gpu/d3d11/shader_cache.h"
#include "gpu/d3d11/stream_buffer.h"
#include "gpu/d3d11/texture.h"
#include "gpu/d3d11_texture.h"
#include "gpu_hw.h"
#include "texture_replacements.h"
#include <array>
@ -76,20 +76,20 @@ private:
bool BlitVRAMReplacementTexture(const TextureReplacementTexture* tex, u32 dst_x, u32 dst_y, u32 width, u32 height);
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);
void DownsampleFramebuffer(D3D11Texture& source, u32 left, u32 top, u32 width, u32 height);
void DownsampleFramebufferAdaptive(D3D11Texture& source, u32 left, u32 top, u32 width, u32 height);
void DownsampleFramebufferBoxFilter(D3D11Texture& source, u32 left, u32 top, u32 width, u32 height);
ComPtr<ID3D11Device> m_device;
ComPtr<ID3D11DeviceContext> m_context;
// downsample texture - used for readbacks at >1xIR.
D3D11::Texture m_vram_texture;
D3D11::Texture m_vram_depth_texture;
D3D11Texture m_vram_texture;
D3D11Texture m_vram_depth_texture;
ComPtr<ID3D11DepthStencilView> m_vram_depth_view;
D3D11::Texture m_vram_read_texture;
D3D11::Texture m_vram_encoding_texture;
D3D11::Texture m_display_texture;
D3D11Texture m_vram_read_texture;
D3D11Texture m_vram_encoding_texture;
D3D11Texture m_display_texture;
D3D11::StreamBuffer m_vertex_stream_buffer;
@ -130,14 +130,14 @@ private:
ComPtr<ID3D11PixelShader> m_vram_update_depth_pixel_shader;
std::array<std::array<ComPtr<ID3D11PixelShader>, 3>, 2> m_display_pixel_shaders; // [depth_24][interlaced]
D3D11::Texture m_vram_replacement_texture;
D3D11Texture m_vram_replacement_texture;
// 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;
D3D11Texture m_downsample_texture;
D3D11Texture m_downsample_weight_texture;
std::vector<std::pair<ComPtr<ID3D11ShaderResourceView>, ComPtr<ID3D11RenderTargetView>>> m_downsample_mip_views;
};

View File

@ -113,10 +113,11 @@ bool GPU_HW_OpenGL::DoState(StateWrapper& sw, GPUTexture** host_texture, bool up
{
delete tex;
tex = g_host_display
->CreateTexture(m_vram_texture.GetWidth(), m_vram_texture.GetHeight(), 1, 1,
m_vram_texture.GetSamples(), GPUTexture::Format::RGBA8, nullptr, 0, false)
.release();
tex =
g_host_display
->CreateTexture(m_vram_texture.GetWidth(), m_vram_texture.GetHeight(), 1, 1, m_vram_texture.GetSamples(),
GPUTexture::Type::RenderTarget, GPUTexture::Format::RGBA8, nullptr, 0, false)
.release();
*host_texture = tex;
if (!tex)
return false;

View File

@ -134,11 +134,11 @@ bool GPU_HW_Vulkan::DoState(StateWrapper& sw, GPUTexture** host_texture, bool up
{
delete tex;
tex = static_cast<Vulkan::Texture*>(g_host_display
->CreateTexture(m_vram_texture.GetWidth(), m_vram_texture.GetHeight(), 1,
1, m_vram_texture.GetSamples(), GPUTexture::Format::RGBA8,
nullptr, 0, false)
.release());
tex = static_cast<Vulkan::Texture*>(
g_host_display
->CreateTexture(m_vram_texture.GetWidth(), m_vram_texture.GetHeight(), 1, 1, m_vram_texture.GetSamples(),
GPUTexture::Type::RenderTarget, GPUTexture::Format::RGBA8, nullptr, 0, false)
.release());
*host_texture = tex;
if (!tex)
return false;

View File

@ -107,7 +107,8 @@ GPUTexture* GPU_SW::GetDisplayTexture(u32 width, u32 height, GPUTexture::Format
{
g_host_display->ClearDisplayTexture();
m_display_texture.reset();
m_display_texture = g_host_display->CreateTexture(width, height, 1, 1, 1, format, nullptr, 0, true);
m_display_texture =
g_host_display->CreateTexture(width, height, 1, 1, 1, GPUTexture::Type::Texture, format, nullptr, 0, true);
if (!m_display_texture)
Log_ErrorPrintf("Failed to create %ux%u %u texture", width, height, static_cast<u32>(format));
}
@ -264,7 +265,7 @@ void GPU_SW::CopyOut15Bit(u32 src_x, u32 src_y, u32 width, u32 height, u32 field
if (!interlaced)
{
if (!g_host_display->BeginTextureUpdate(texture, width, height, reinterpret_cast<void**>(&dst_ptr), &dst_stride))
if (!texture->Map(reinterpret_cast<void**>(&dst_ptr), &dst_stride, 0, 0, width, height))
return;
}
else
@ -312,9 +313,9 @@ void GPU_SW::CopyOut15Bit(u32 src_x, u32 src_y, u32 width, u32 height, u32 field
}
if (!interlaced)
g_host_display->EndTextureUpdate(texture, 0, 0, width, height);
texture->Unmap();
else
g_host_display->UpdateTexture(texture, 0, 0, width, height, m_display_texture_buffer.data(), output_stride);
texture->Update(0, 0, width, height, m_display_texture_buffer.data(), output_stride);
g_host_display->SetDisplayTexture(texture, 0, 0, width, height);
}
@ -358,7 +359,7 @@ void GPU_SW::CopyOut24Bit(u32 src_x, u32 src_y, u32 skip_x, u32 width, u32 heigh
if (!interlaced)
{
if (!g_host_display->BeginTextureUpdate(texture, width, height, reinterpret_cast<void**>(&dst_ptr), &dst_stride))
if (!texture->Map(reinterpret_cast<void**>(&dst_ptr), &dst_stride, 0, 0, width, height))
return;
}
else
@ -470,9 +471,9 @@ void GPU_SW::CopyOut24Bit(u32 src_x, u32 src_y, u32 skip_x, u32 width, u32 heigh
}
if (!interlaced)
g_host_display->EndTextureUpdate(texture, 0, 0, width, height);
texture->Unmap();
else
g_host_display->UpdateTexture(texture, 0, 0, width, height, m_display_texture_buffer.data(), output_stride);
texture->Update(0, 0, width, height, m_display_texture_buffer.data(), output_stride);
g_host_display->SetDisplayTexture(texture, 0, 0, width, height);
}

View File

@ -12,7 +12,7 @@
// For enumerating adapters.
#ifdef _WIN32
#include "core/gpu/d3d11_gpu_device.h"
#include "core/gpu/d3d11_device.h"
#include "core/gpu/d3d12_gpu_device.h"
#endif
#ifdef WITH_VULKAN
@ -196,7 +196,7 @@ void DisplaySettingsWidget::populateGPUAdaptersAndResolutions()
{
#ifdef _WIN32
case GPURenderer::HardwareD3D11:
aml = D3D11GPUDevice::StaticGetAdapterAndModeList();
aml = D3D11Device::StaticGetAdapterAndModeList();
break;
case GPURenderer::HardwareD3D12:

View File

@ -55,7 +55,7 @@
#ifdef _WIN32
#include "common/windows_headers.h"
#include "core/gpu/d3d11_gpu_device.h"
#include "core/gpu/d3d11_device.h"
#include "core/gpu/d3d12_gpu_device.h"
#include <KnownFolders.h>
#include <ShlObj.h>
@ -159,14 +159,14 @@ std::unique_ptr<GPUDevice> Host::CreateDisplayForAPI(RenderAPI api)
return std::make_unique<D3D12GPUDevice>();
case RenderAPI::D3D11:
return std::make_unique<D3D11GPUDevice>();
return std::make_unique<D3D11Device>();
#endif
default:
#if defined(_WIN32) && defined(_M_ARM64)
return std::make_unique<D3D12GPUDevice>();
#elif defined(_WIN32)
return std::make_unique<D3D11GPUDevice>();
return std::make_unique<D3D11Device>();
#elif defined(WITH_OPENGL)
return std::make_unique<OpenGLGPUDevice>();
#elif defined(WITH_VULKAN)

View File

@ -4858,15 +4858,15 @@ void FullscreenUI::PopulateSaveStateScreenshot(SaveStateListEntry* li, const Ext
li->preview_texture.reset();
if (ssi && !ssi->screenshot_data.empty())
{
li->preview_texture =
g_host_display->CreateTexture(ssi->screenshot_width, ssi->screenshot_height, 1, 1, 1, GPUTexture::Format::RGBA8,
ssi->screenshot_data.data(), sizeof(u32) * ssi->screenshot_width, false);
li->preview_texture = g_host_display->CreateTexture(
ssi->screenshot_width, ssi->screenshot_height, 1, 1, 1, GPUTexture::Type::Texture, GPUTexture::Format::RGBA8,
ssi->screenshot_data.data(), sizeof(u32) * ssi->screenshot_width, false);
}
else
{
li->preview_texture =
g_host_display->CreateTexture(PLACEHOLDER_ICON_WIDTH, PLACEHOLDER_ICON_HEIGHT, 1, 1, 1, GPUTexture::Format::RGBA8,
PLACEHOLDER_ICON_DATA, sizeof(u32) * PLACEHOLDER_ICON_WIDTH, false);
li->preview_texture = g_host_display->CreateTexture(
PLACEHOLDER_ICON_WIDTH, PLACEHOLDER_ICON_HEIGHT, 1, 1, 1, GPUTexture::Type::Texture, GPUTexture::Format::RGBA8,
PLACEHOLDER_ICON_DATA, sizeof(u32) * PLACEHOLDER_ICON_WIDTH, false);
}
if (!li->preview_texture)

View File

@ -267,8 +267,9 @@ std::optional<Common::RGBA8Image> ImGuiFullscreen::LoadTextureImage(const char*
std::shared_ptr<GPUTexture> ImGuiFullscreen::UploadTexture(const char* path, const Common::RGBA8Image& image)
{
std::unique_ptr<GPUTexture> texture = g_host_display->CreateTexture(
image.GetWidth(), image.GetHeight(), 1, 1, 1, GPUTexture::Format::RGBA8, image.GetPixels(), image.GetPitch());
std::unique_ptr<GPUTexture> texture =
g_host_display->CreateTexture(image.GetWidth(), image.GetHeight(), 1, 1, 1, GPUTexture::Type::Texture,
GPUTexture::Format::RGBA8, image.GetPixels(), image.GetPitch());
if (!texture)
{
Log_ErrorPrintf("failed to create %ux%u texture for resource", image.GetWidth(), image.GetHeight());

View File

@ -110,18 +110,9 @@ bool ImGuiManager::Initialize()
AssertMsg(!FullscreenUI::IsInitialized(), "Fullscreen UI is not initialized on ImGui init");
if (!g_host_display->CreateImGuiContext())
{
Panic("Failed to create ImGui device context");
g_host_display->DestroyImGuiContext();
ImGui::DestroyContext();
return false;
}
if (!AddImGuiFonts(false) || !g_host_display->UpdateImGuiFontTexture())
{
Panic("Failed to create ImGui font text");
g_host_display->DestroyImGuiContext();
ImGui::DestroyContext();
return false;
}
@ -137,8 +128,6 @@ void ImGuiManager::Shutdown()
{
FullscreenUI::Shutdown();
if (g_host_display)
g_host_display->DestroyImGuiContext();
if (ImGui::GetCurrentContext())
ImGui::DestroyContext();

View File

@ -723,15 +723,15 @@ void SaveStateSelectorUI::InitializeListEntry(ListEntry* li, ExtendedSaveStateIn
{
if (ssi && !ssi->screenshot_data.empty())
{
li->preview_texture =
g_host_display->CreateTexture(ssi->screenshot_width, ssi->screenshot_height, 1, 1, 1, GPUTexture::Format::RGBA8,
ssi->screenshot_data.data(), sizeof(u32) * ssi->screenshot_width, false);
li->preview_texture = g_host_display->CreateTexture(
ssi->screenshot_width, ssi->screenshot_height, 1, 1, 1, GPUTexture::Type::Texture, GPUTexture::Format::RGBA8,
ssi->screenshot_data.data(), sizeof(u32) * ssi->screenshot_width, false);
}
else
{
li->preview_texture = g_host_display->CreateTexture(PLACEHOLDER_ICON_WIDTH, PLACEHOLDER_ICON_HEIGHT, 1, 1, 1,
GPUTexture::Format::RGBA8, PLACEHOLDER_ICON_DATA,
sizeof(u32) * PLACEHOLDER_ICON_WIDTH, false);
li->preview_texture = g_host_display->CreateTexture(
PLACEHOLDER_ICON_WIDTH, PLACEHOLDER_ICON_HEIGHT, 1, 1, 1, GPUTexture::Type::Texture, GPUTexture::Format::RGBA8,
PLACEHOLDER_ICON_DATA, sizeof(u32) * PLACEHOLDER_ICON_WIDTH, false);
}
if (!li->preview_texture)
@ -750,9 +750,9 @@ void SaveStateSelectorUI::InitializePlaceholderListEntry(ListEntry* li, std::str
if (g_host_display)
{
li->preview_texture =
g_host_display->CreateTexture(PLACEHOLDER_ICON_WIDTH, PLACEHOLDER_ICON_HEIGHT, 1, 1, 1, GPUTexture::Format::RGBA8,
PLACEHOLDER_ICON_DATA, sizeof(u32) * PLACEHOLDER_ICON_WIDTH, false);
li->preview_texture = g_host_display->CreateTexture(
PLACEHOLDER_ICON_WIDTH, PLACEHOLDER_ICON_HEIGHT, 1, 1, 1, GPUTexture::Type::Texture, GPUTexture::Format::RGBA8,
PLACEHOLDER_ICON_DATA, sizeof(u32) * PLACEHOLDER_ICON_WIDTH, false);
if (!li->preview_texture)
Log_ErrorPrintf("Failed to upload save state image to GPU");
}