[dxgi] cache the input shader resource view of the src texture

This commit is contained in:
Geoffrey McRae 2023-10-29 21:53:48 +11:00
parent 52410beea7
commit 1e30539fb2
3 changed files with 48 additions and 33 deletions

View file

@ -54,6 +54,8 @@ extern const DXGIPostProcess DXGIPP_SDRWhiteLevel;
typedef struct
{
ID3D11Texture2D * src;
ID3D11ShaderResourceView * srv;
const DXGIPostProcess * pp;
void * opaque;
}
@ -1336,7 +1338,42 @@ static ID3D11Texture2D * ppRun(Texture * tex, ID3D11Texture2D * src)
{
PostProcessInstance * inst;
vector_forEachRef(inst, &tex->pp)
src = inst->pp->run(inst->opaque, src);
{
// if the srv exists and the src has changed, release it
if (inst->src != src && inst->srv)
{
ID3D11ShaderResourceView_Release(inst->srv);
inst->srv = NULL;
}
// if the srv is not set, create one
if (!inst->srv)
{
D3D11_TEXTURE2D_DESC desc;
ID3D11Texture2D_GetDesc(src, &desc);
const D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc =
{
.Format = desc.Format,
.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D,
.Texture2D.MipLevels = 1
};
HRESULT status = ID3D11Device_CreateShaderResourceView(
*this->device, (ID3D11Resource *)src, &srvDesc, &inst->srv);
if (FAILED(status))
{
DEBUG_WINERROR("Failed to create the source resource view", status);
continue;
}
inst->src = src;
}
// run the post processor
src = inst->pp->run(inst->opaque, inst->srv);
}
return src;
}
@ -1352,6 +1389,9 @@ static void ppFreeAll(void)
PostProcessInstance * inst;
vector_forEachRef(inst, &tex->pp)
{
if(inst->srv)
ID3D11ShaderResourceView_Release(inst->srv);
inst->pp->free(inst->opaque);
if (i == this->maxTextures - 1)
inst->pp->finish();

View file

@ -43,7 +43,7 @@ typedef struct
bool shareable);
/* perform the processing */
ID3D11Texture2D * (*run)(void * opaque, ID3D11Texture2D * src);
ID3D11Texture2D * (*run)(void * opaque, ID3D11ShaderResourceView * srv);
/* instance destruction */
void (*free)(void * opaque);

View file

@ -313,40 +313,19 @@ static void updateConsts(void)
0, NULL, &consts, 0, 0);
}
static ID3D11Texture2D * sdrWhiteLevel_run(void * opaque, ID3D11Texture2D * src)
static ID3D11Texture2D * sdrWhiteLevel_run(void * opaque,
ID3D11ShaderResourceView * srv)
{
comRef_scopePush();
ID3D11Texture2D * result = NULL;
SDRWhiteLevelInst * inst = (SDRWhiteLevelInst *)opaque;
HRESULT status;
updateConsts();
// setup the pixel shader input resource view
comRef_defineLocal(ID3D11ShaderResourceView, inputSRV);
D3D11_TEXTURE2D_DESC desc;
ID3D11Texture2D_GetDesc(src, &desc);
const D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc =
{
.Format = desc.Format,
.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D,
.Texture2D.MipLevels = 1
};
status = ID3D11Device_CreateShaderResourceView(
*this.device, (ID3D11Resource *)src, &srvDesc, inputSRV);
if (FAILED(status))
{
DEBUG_WINERROR("Failed to create the source resource view", status);
goto exit;
}
// set the vertex and pixel shader
ID3D11DeviceContext_VSSetShader(*this.context, *this.vshader, NULL, 0);
ID3D11DeviceContext_PSSetShader(*this.context, *this.pshader, NULL, 0);
// set the pixel shader resources
ID3D11DeviceContext_PSSetShaderResources(*this.context, 0, 1, inputSRV );
ID3D11DeviceContext_PSSetShaderResources(*this.context, 0, 1, &srv );
ID3D11DeviceContext_PSSetSamplers (*this.context, 0, 1, this.sampler);
ID3D11DeviceContext_PSSetConstantBuffers(*this.context, 0, 1, this.buffer );
@ -358,11 +337,7 @@ static ID3D11Texture2D * sdrWhiteLevel_run(void * opaque, ID3D11Texture2D * src)
ID3D11DeviceContext_Draw(*this.context, 4, 0);
result = *inst->tex;
exit:
comRef_scopePop();
return result;
return *inst->tex;
}
DXGIPostProcess DXGIPP_SDRWhiteLevel =