d3d11: do a full copy of textures

This commit is contained in:
chyyran 2022-12-10 01:50:54 -05:00
parent 6ce7af12e1
commit e8a1e2f165
2 changed files with 10 additions and 10 deletions

View file

@ -69,7 +69,7 @@ Please report an issue if you run into a shader that works in RetroArch, but not
It is the caller's responsibility to blit the surface back to the backbuffer.
* Runtime-specific differences
* OpenGL
* Copying of in-flight framebuffer contents is done via `glBlitFramebuffer` rather than drawing a quad into an intermediate FBO.
* Copying of in-flight framebuffer contents to history is done via `glBlitFramebuffer` rather than drawing a quad into an intermediate FBO.
* Sampler objects are used rather than `glTexParameter`.
* Sampler inputs and outputs are not renamed. This is useful for debugging shaders in RenderDoc.
* UBO and Push Constant Buffer sizes are padded to 16-byte boundaries.
@ -78,7 +78,7 @@ Please report an issue if you run into a shader that works in RetroArch, but not
* Should work on OpenGL 4.5 but this is not guaranteed. The OpenGL 4.6 runtime may eventually switch to using `ARB_spirv_extensions` for loading shaders, and this will not be marked as a breaking change.
* The OpenGL 4.6 runtime uses Direct State Access to minimize changes to the OpenGL state. For recent GPUs, this may improve performance.
* Direct3D 11
* The staging buffer is not kept around when loading static textures (LUTs).
* Framebuffer copies are done via `ID3D11DeviceContext::CopySubresourceRegion` rather than a CPU conversion + copy.
* HDR10 support is not part of the shader runtime and is not supported.
Most, if not all shader presets should work fine on librashader. The runtime specific differences should not affect the output,

View file

@ -5,7 +5,7 @@ use librashader_common::{ImageFormat, Size};
use librashader_presets::Scale2D;
use windows::core::Interface;
use windows::Win32::Graphics::Direct3D::D3D_SRV_DIMENSION_TEXTURE2D;
use windows::Win32::Graphics::Direct3D11::{ID3D11Device, ID3D11RenderTargetView, ID3D11ShaderResourceView, ID3D11Texture2D, D3D11_BIND_RENDER_TARGET, D3D11_BIND_SHADER_RESOURCE, D3D11_CPU_ACCESS_WRITE, D3D11_FORMAT_SUPPORT_RENDER_TARGET, D3D11_FORMAT_SUPPORT_SHADER_SAMPLE, D3D11_FORMAT_SUPPORT_TEXTURE2D, D3D11_RENDER_TARGET_VIEW_DESC, D3D11_RENDER_TARGET_VIEW_DESC_0, D3D11_RTV_DIMENSION_TEXTURE2D, D3D11_SHADER_RESOURCE_VIEW_DESC, D3D11_SHADER_RESOURCE_VIEW_DESC_0, D3D11_TEX2D_RTV, D3D11_TEX2D_SRV, D3D11_TEXTURE2D_DESC, D3D11_USAGE_DEFAULT, D3D11_VIEWPORT, D3D11_RESOURCE_MISC_GENERATE_MIPS, ID3D11DeviceContext};
use windows::Win32::Graphics::Direct3D11::{ID3D11Device, ID3D11RenderTargetView, ID3D11ShaderResourceView, ID3D11Texture2D, D3D11_BIND_RENDER_TARGET, D3D11_BIND_SHADER_RESOURCE, D3D11_CPU_ACCESS_WRITE, D3D11_FORMAT_SUPPORT_RENDER_TARGET, D3D11_FORMAT_SUPPORT_SHADER_SAMPLE, D3D11_FORMAT_SUPPORT_TEXTURE2D, D3D11_RENDER_TARGET_VIEW_DESC, D3D11_RENDER_TARGET_VIEW_DESC_0, D3D11_RTV_DIMENSION_TEXTURE2D, D3D11_SHADER_RESOURCE_VIEW_DESC, D3D11_SHADER_RESOURCE_VIEW_DESC_0, D3D11_TEX2D_RTV, D3D11_TEX2D_SRV, D3D11_TEXTURE2D_DESC, D3D11_USAGE_DEFAULT, D3D11_VIEWPORT, D3D11_RESOURCE_MISC_GENERATE_MIPS, ID3D11DeviceContext, D3D11_BOX};
use windows::Win32::Graphics::Dxgi::Common::{DXGI_FORMAT, DXGI_SAMPLE_DESC};
#[derive(Debug, Clone)]
@ -144,7 +144,7 @@ impl OwnedFramebuffer {
}
pub fn copy_from(&mut self, image: &DxImageView) -> error::Result<()> {
let resource: ID3D11Texture2D = unsafe {
let original_resource: ID3D11Texture2D = unsafe {
let mut resource = None;
image.handle.GetResource(&mut resource);
let Some(resource) = resource else {
@ -155,7 +155,7 @@ impl OwnedFramebuffer {
let format = unsafe {
let mut desc = Default::default();
resource.GetDesc(&mut desc);
original_resource.GetDesc(&mut desc);
desc.Format
};
@ -166,8 +166,6 @@ impl OwnedFramebuffer {
// todo: improve mipmap generation?
// will need a staging texture + full so might not be worth it.
#[cfg(feature = "testing_full_gpu_copy")]
unsafe {
self.context.CopySubresourceRegion(
&self.texture,
@ -175,7 +173,7 @@ impl OwnedFramebuffer {
0,
0,
0,
&resource,
&original_resource,
0,
Some(&D3D11_BOX {
left: 0,
@ -188,8 +186,10 @@ impl OwnedFramebuffer {
)
}
self.texture = resource;
let srvs = self.create_shader_resource_view()?;
unsafe {
self.context.GenerateMips(&srvs);
}
Ok(())
}
}