Skip to content

Commit

Permalink
bind proper sampler for stretch rect emulate ops
Browse files Browse the repository at this point in the history
related to #206
  • Loading branch information
megai2 committed Jul 19, 2020
1 parent 5f34705 commit a9aeff8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
21 changes: 15 additions & 6 deletions d912pxy/d912pxy_surface_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ SOFTWARE.

d912pxy_surface_ops::d912pxy_surface_ops(d912pxy_device * dev) : d912pxy_noncom( L"surface_ops")
{
//TODO: write shaders
vs[SHSET_CLEAR] = d912pxy_shader::d912pxy_shader_com(1, 0, 0x4);
ps[SHSET_CLEAR] = d912pxy_shader::d912pxy_shader_com(0, 0, 0x5);
vs[SHSET_STRETCH] = d912pxy_shader::d912pxy_shader_com(1, 0, 0x6);
Expand Down Expand Up @@ -65,7 +64,7 @@ d912pxy_surface_ops::d912pxy_surface_ops(d912pxy_device * dev) : d912pxy_noncom(

vdcl = d912pxy_vdecl::d912pxy_vdecl_com(vDclElements);


bilinearSamplerId = d912pxy_s.render.state.tex.LookupSamplerId(bilinearSamplerDsc);
}

d912pxy_surface_ops::~d912pxy_surface_ops()
Expand Down Expand Up @@ -193,20 +192,27 @@ void d912pxy_surface_ops::StretchRect(d912pxy_surface* pSourceSurface, d912pxy_s

d912pxy_surface* oldRT = d912pxy_s.render.iframe.GetBindedSurface(1);
d912pxy_surface* oldDS = d912pxy_s.render.iframe.GetBindedSurface(0);
UINT oldTex0 = d912pxy_s.render.state.tex.GetTexStage(0);
d912pxy_surface* targetRT = dDst.Usage == D3DUSAGE_RENDERTARGET ?
pDestSurface :
d912pxy_s.pool.rtds.GetSurface(dDst.Width, dDst.Height, dDst.Format, 1, 1, D3DUSAGE_RENDERTARGET, nullptr);

D3D12_VIEWPORT wvp{ 0,0, (float)dDst.Width, (float)dDst.Height, 0, 1 };
d912pxy_s.render.iframe.SetViewport(&wvp);
d912pxy_s.render.state.tex.SetTexture(0, pSourceSurface->GetSRVHeapId());

d912pxy_batch_buffer_sub_element texSet, samplerSet = {};

texSet.ui[0] = pSourceSurface->GetSRVHeapId();
samplerSet.ui[0] = bilinearSamplerId;

d912pxy_s.render.state.tex.Use();
d912pxy_s.render.batch.GPUWrite(&texSet, 1, D912PXY_GPU_WRITE_OFFSET_TEXBIND);
d912pxy_s.render.batch.GPUWrite(&samplerSet, 1, D912PXY_GPU_WRITE_OFFSET_SAMPLER);

d912pxy_s.render.iframe.BindSurface(1, targetRT);
d912pxy_s.render.iframe.BindSurface(0, nullptr);

d912pxy_s.render.state.pso.SetCurrentDesc(localPSO);

//TODO: sampler for tex0
PXY_COM_CAST_(IDirect3DDevice9, &d912pxy_s.dev)->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2);

d912pxy_s.render.iframe.BindSurface(1, oldRT);
Expand All @@ -218,7 +224,10 @@ void d912pxy_surface_ops::StretchRect(d912pxy_surface* pSourceSurface, d912pxy_s
targetRT->Release();
}

d912pxy_s.render.state.tex.SetTexture(0, oldTex0);
//reset texture & sampler via dirty flag
d912pxy_s.render.state.tex.AddDirtyFlag(
d912pxy_s.render.state.tex.MakeDirtyFlagBit(0, false) | d912pxy_s.render.state.tex.MakeDirtyFlagBit(0, true)
);
}

void d912pxy_surface_ops::SetCommonState(shaderSet idx)
Expand Down
5 changes: 5 additions & 0 deletions d912pxy/d912pxy_surface_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,10 @@ class d912pxy_surface_ops : public d912pxy_noncom
d912pxy_vstream* vBuf;
d912pxy_vstream* iBuf;
d912pxy_trimmed_pso_desc localPSO;

// bilinear, uvw wrap
constexpr static d912pxy_trimmed_sampler_dsc bilinearSamplerDsc = { 0x92,0x49, 0, 0 };

UINT bilinearSamplerId;
};

11 changes: 10 additions & 1 deletion d912pxy/d912pxy_texture_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,18 @@ class d912pxy_texture_state : public d912pxy_noncom

void ClearActiveTextures();

private:
constexpr DWORD MakeDirtyFlagBit(const int stage, const bool sampler)
{
if (sampler)
return (1 << stage) << 8;
else
return 1 << (stage >> 2);
}

//this function is not thread safe
UINT LookupSamplerId(const d912pxy_trimmed_sampler_dsc& trimmedDsc);

private:
UINT LookupSamplerId(UINT stage);

void UpdateFullSplDsc(const d912pxy_trimmed_sampler_dsc& trimmedSpl);
Expand Down

0 comments on commit a9aeff8

Please sign in to comment.