Skip to content

Commit

Permalink
Properly handle submitted array textures, as the newest Blade & Sorce…
Browse files Browse the repository at this point in the history
…ry update now does
  • Loading branch information
fholger committed Oct 30, 2021
1 parent 196715a commit 561efd9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
27 changes: 23 additions & 4 deletions src/postprocess/PostProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ namespace vr {
CheckResult("Creating copy SRV", device->CreateShaderResourceView(copiedTexture.Get(), &srv, copiedTextureView.GetAddressOf()));
}

ID3D11ShaderResourceView * PostProcessor::GetInputView( ID3D11Texture2D *inputTexture ) {
ID3D11ShaderResourceView * PostProcessor::GetInputView( ID3D11Texture2D *inputTexture, int eye ) {
if (requiresCopy) {
D3D11_TEXTURE2D_DESC td;
inputTexture->GetDesc(&td);
Expand Down Expand Up @@ -238,14 +238,33 @@ namespace vr {
svd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
svd.Texture2D.MostDetailedMip = 0;
svd.Texture2D.MipLevels = 1;
HRESULT result = device->CreateShaderResourceView( inputTexture, &svd, inputTextureViews[inputTexture].GetAddressOf() );
EyeViews &views = inputTextureViews[inputTexture];
HRESULT result = device->CreateShaderResourceView( inputTexture, &svd, views.view[0].GetAddressOf() );
if (FAILED(result)) {
Log() << "Failed to create resource view: " << std::hex << (unsigned long)result << std::dec << std::endl;
inputTextureViews.erase( inputTexture );
return nullptr;
}
if (std.ArraySize > 1) {
// if an array texture was submitted, the right eye will be placed in the second entry, so we need
// a separate view for that eye
Log() << "Texture is an array texture, using separate subview for right eye\n";
svd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
svd.Texture2DArray.ArraySize = 1;
svd.Texture2DArray.FirstArraySlice = D3D11CalcSubresource( 0, 1, 1 );
svd.Texture2DArray.MostDetailedMip = 0;
svd.Texture2DArray.MipLevels = 1;
result = device->CreateShaderResourceView( inputTexture, &svd, views.view[1].GetAddressOf() );
if (FAILED(result)) {
Log() << "Failed to create secondary resource view: " << std::hex << (unsigned long)result << std::dec << std::endl;
inputTextureViews.erase( inputTexture );
return nullptr;
}
} else {
views.view[1] = views.view[0];
}
}
return inputTextureViews[inputTexture].Get();
return inputTextureViews[inputTexture].view[eye].Get();
}

struct UpscaleConstants {
Expand Down Expand Up @@ -481,7 +500,7 @@ namespace vr {

outputTexture = inputTexture;

ID3D11ShaderResourceView *inputView = GetInputView(inputTexture);
ID3D11ShaderResourceView *inputView = GetInputView(inputTexture, eEye);
if (inputView == nullptr) {
return;
}
Expand Down
7 changes: 5 additions & 2 deletions src/postprocess/PostProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ namespace vr {
ComPtr<ID3D11DeviceContext> context;
ComPtr<ID3D11SamplerState> sampler;

std::unordered_map<ID3D11Texture2D*, ComPtr<ID3D11ShaderResourceView>> inputTextureViews;
struct EyeViews {
ComPtr<ID3D11ShaderResourceView> view[2];
};
std::unordered_map<ID3D11Texture2D*, EyeViews> inputTextureViews;
// in case the incoming texture can't be bound as an SRV, we'll need to prepare a copy
ComPtr<ID3D11Texture2D> copiedTexture;
ComPtr<ID3D11ShaderResourceView> copiedTextureView;

void PrepareCopyResources(DXGI_FORMAT format);
ID3D11ShaderResourceView *GetInputView(ID3D11Texture2D *inputTexture);
ID3D11ShaderResourceView *GetInputView(ID3D11Texture2D *inputTexture, int eye);

// FSR upscale
ComPtr<ID3D11ComputeShader> upscaleShader;
Expand Down

0 comments on commit 561efd9

Please sign in to comment.