mirror of
https://github.com/LizardByte/Sunshine.git
synced 2025-02-22 03:40:43 +00:00
Render NV12 color format
This commit is contained in:
parent
127b5501d9
commit
37a9256587
@ -1,27 +1,32 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// CombinedUVMipsPS.hlsl
|
||||
//--------------------------------------------------------------------------------------
|
||||
Texture2D txInputU : register(t0);
|
||||
Texture2D txInputV : register(t1);
|
||||
Texture1D txInputShift : register(t2);
|
||||
Texture2D image : register(t0);
|
||||
|
||||
SamplerState GenericSampler : register(s0);
|
||||
SamplerState def_sampler : register(s0);
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float2 Tex : TEXCOORD;
|
||||
struct FragTexWide {
|
||||
float3 uuv : TEXCOORD0;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Pixel Shader
|
||||
//--------------------------------------------------------------------------------------
|
||||
float PS(PS_INPUT input) : SV_Target
|
||||
float2 PS(FragTexWide input) : SV_Target
|
||||
{
|
||||
float fShift = (float)txInputShift.Sample(GenericSampler, input.Tex.x);
|
||||
// float4 color_vec_y = { 0.301f, 0.586f, 0.113f, 0.0f };
|
||||
// float4 color_vec_u = { -0.168f, -0.328f, 0.496f, 128.0f / 256.0f };
|
||||
// float4 color_vec_v = { 0.496f, 0.414f, 0.082f, 128.0f / 256.0f };
|
||||
float4 color_vec_y = { 0.299, 0.587, 0.114, 0.0625 };
|
||||
float4 color_vec_u = { -0.168736, -0.331264, 0.5, 0.5 };
|
||||
float4 color_vec_v = { 0.5, -0.418688, -0.081312, 0.5 };
|
||||
|
||||
if(fShift == 0.0f)
|
||||
return (float)txInputU.SampleLevel(GenericSampler, input.Tex, 1.0f);
|
||||
else
|
||||
return (float)txInputV.SampleLevel(GenericSampler, input.Tex, 1.0f);
|
||||
// float4 color_vec_y = { 0.2578f, 0.5039f, 0.0977, 0.0625 };
|
||||
// float4 color_vec_u = { -0.1484, 0.2891, 0.4375, 128.0f / 256.0f };
|
||||
// float4 color_vec_v = { 0.4375, -0.3672, -0.0703, 128.0f / 256.0f };
|
||||
|
||||
float3 rgb_left = image.Sample(def_sampler, input.uuv.xz).rgb;
|
||||
float3 rgb_right = image.Sample(def_sampler, input.uuv.yz).rgb;
|
||||
float3 rgb = (rgb_left + rgb_right) * 0.5;
|
||||
|
||||
float u = dot(color_vec_u.xyz, rgb) + color_vec_u.w;
|
||||
float v = dot(color_vec_v.xyz, rgb) + color_vec_v.w;
|
||||
return float2(u, v);
|
||||
}
|
@ -1,23 +1,26 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// CombinedUVVS.hlsl
|
||||
//--------------------------------------------------------------------------------------
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float2 Tex : TEXCOORD;
|
||||
struct VertTexPosWide {
|
||||
float3 uuv : TEXCOORD;
|
||||
float4 pos : SV_POSITION;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Vertex Shader
|
||||
//--------------------------------------------------------------------------------------
|
||||
PS_INPUT VS(uint vI : SV_VERTEXID)
|
||||
VertTexPosWide VS(uint vI : SV_VERTEXID)
|
||||
{
|
||||
PS_INPUT output = (PS_INPUT)0;
|
||||
float width_i = 1.0f / 1920.0f;
|
||||
float idHigh = float(vI >> 1);
|
||||
float idLow = float(vI & uint(1));
|
||||
|
||||
float2 texcoord = float2(vI & 1, vI >> 1);
|
||||
float x = idHigh * 4.0 - 1.0;
|
||||
float y = idLow * 4.0 - 1.0;
|
||||
|
||||
output.Pos = float4((texcoord.x - 0.5f) * 2.0f, -(texcoord.y + 0.0f) * 0.5f, 0.0f, 1.0f);
|
||||
output.Tex = texcoord;
|
||||
float u_right = idHigh * 2.0;
|
||||
float u_left = u_right - width_i;
|
||||
float v = 1.0 - idLow * 2.0;
|
||||
|
||||
return output;
|
||||
VertTexPosWide vert_out;
|
||||
vert_out.uuv = float3(u_left, u_right, v);
|
||||
vert_out.pos = float4(x, y, 0.0, 1.0);
|
||||
return vert_out;
|
||||
}
|
26
assets/MergeYPS.hlsl
Normal file
26
assets/MergeYPS.hlsl
Normal file
@ -0,0 +1,26 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// YCbCrPS2.hlsl
|
||||
//--------------------------------------------------------------------------------------
|
||||
Texture2D image : register(t0);
|
||||
|
||||
SamplerState def_sampler : register(s0);
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 tex : TEXCOORD;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Pixel Shader
|
||||
//--------------------------------------------------------------------------------------
|
||||
float PS(PS_INPUT frag_in) : SV_Target
|
||||
{
|
||||
float4 color_vec_y = { 0.299, 0.587, 0.114, 0.0625 };
|
||||
float4 color_vec_u = { -0.168736, -0.331264, 0.5, 0.5 };
|
||||
float4 color_vec_v = { 0.5, -0.418688, -0.081312, 0.5 };
|
||||
|
||||
float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
|
||||
float y = dot(color_vec_y.xyz, rgb) + color_vec_y.w;
|
||||
return y;
|
||||
}
|
22
assets/MergeYVS.hlsl
Normal file
22
assets/MergeYVS.hlsl
Normal file
@ -0,0 +1,22 @@
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 tex : TEXCOORD;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Vertex Shader
|
||||
//--------------------------------------------------------------------------------------
|
||||
PS_INPUT VS(uint vI : SV_VERTEXID)
|
||||
{
|
||||
float idHigh = float(vI >> 1);
|
||||
float idLow = float(vI & uint(1));
|
||||
|
||||
float x = idHigh * 4.0 - 1.0;
|
||||
float y = idLow * 4.0 - 1.0;
|
||||
|
||||
PS_INPUT vert_out;
|
||||
vert_out.pos = float4(x, y, 0.0, 1.0);
|
||||
vert_out.tex = float2(idHigh, idLow);
|
||||
return vert_out;
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// ScreenPS.hlsl
|
||||
//--------------------------------------------------------------------------------------
|
||||
Texture2D txInput : register(t0);
|
||||
|
||||
SamplerState GenericSampler : register(s0);
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float2 Tex : TEXCOORD;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Pixel Shader
|
||||
//--------------------------------------------------------------------------------------
|
||||
float4 PS(PS_INPUT input) : SV_Target
|
||||
{
|
||||
return txInput.Sample(GenericSampler, input.Tex);
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// ScreenVS.hlsl
|
||||
//--------------------------------------------------------------------------------------
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float2 Tex : TEXCOORD;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Vertex Shader
|
||||
//--------------------------------------------------------------------------------------
|
||||
PS_INPUT VS(uint vI : SV_VERTEXID)
|
||||
{
|
||||
PS_INPUT output = (PS_INPUT)0;
|
||||
|
||||
float2 texcoord = float2(vI & 1, vI >> 1);
|
||||
|
||||
output.Pos = float4((texcoord.x - 0.5f) * 2.0f, -(texcoord.y - 0.5f) * 2.0f, 0.0f, 1.0f);
|
||||
output.Tex = texcoord;
|
||||
|
||||
return output;
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// YCbCrPS2.hlsl
|
||||
//--------------------------------------------------------------------------------------
|
||||
Texture2D txInput : register(t0);
|
||||
|
||||
SamplerState GenericSampler : register(s0);
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float2 Tex : TEXCOORD;
|
||||
};
|
||||
|
||||
struct PS_OUTPUT
|
||||
{
|
||||
float ColorY : SV_Target0;
|
||||
float2 ColorU: SV_Target1;
|
||||
float2 ColorV: SV_Target2;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Pixel Shader
|
||||
//--------------------------------------------------------------------------------------
|
||||
PS_OUTPUT PS(PS_INPUT input) : SV_Target
|
||||
{
|
||||
PS_OUTPUT output;
|
||||
|
||||
float4 InputColor = txInput.Sample(GenericSampler, input.Tex);
|
||||
|
||||
// Range 0-255
|
||||
output.ColorY = (0.257f * InputColor.r + 0.504f * InputColor.g + 0.098f * InputColor.b) + (16 / 256.0f);
|
||||
output.ColorU = (-0.148f * InputColor.r - 0.291f * InputColor.g + 0.439f * InputColor.b) + (128.0f / 256.0f);
|
||||
output.ColorV = (0.439f * InputColor.r - 0.368f * InputColor.g - 0.071f * InputColor.b) + (128.0f / 256.0f);
|
||||
|
||||
output.ColorY = clamp(output.ColorY, 0.0f, 255.0f);
|
||||
output.ColorU = clamp(output.ColorU, 0.0f, 255.0f);
|
||||
output.ColorV = clamp(output.ColorV, 0.0f, 255.0f);
|
||||
|
||||
return output;
|
||||
}
|
@ -138,6 +138,10 @@ int main(int argc, char *argv[]) {
|
||||
proc::proc = std::move(*proc_opt);
|
||||
|
||||
auto deinit_guard = platf::init();
|
||||
if(!deinit_guard) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
input::init();
|
||||
reed_solomon_init();
|
||||
if(video::init()) {
|
||||
|
@ -502,5 +502,5 @@ void freeInput(void *p) {
|
||||
delete input;
|
||||
}
|
||||
|
||||
std::unique_ptr<deinit_t> init() { return nullptr; }
|
||||
std::unique_ptr<deinit_t> init() { return std::make_unique<deinit_t>(); }
|
||||
}
|
||||
|
@ -319,6 +319,12 @@ public:
|
||||
}
|
||||
|
||||
namespace platf {
|
||||
|
||||
// It's not big enough to justify it's own source file :/
|
||||
namespace dxgi {
|
||||
int init();
|
||||
}
|
||||
|
||||
std::unique_ptr<mic_t> microphone(std::uint32_t sample_rate) {
|
||||
auto mic = std::make_unique<audio::mic_wasapi_t>();
|
||||
|
||||
@ -330,6 +336,9 @@ std::unique_ptr<mic_t> microphone(std::uint32_t sample_rate) {
|
||||
}
|
||||
|
||||
std::unique_ptr<deinit_t> init() {
|
||||
if(dxgi::init()) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_unique<platf::audio::co_init_t>();
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ constexpr float aquamarine[] { 0.498039246f, 1.000000000f, 0.831372619f, 1.00000
|
||||
using input_layout_t = util::safe_ptr<ID3D11InputLayout, Release<ID3D11InputLayout>>;
|
||||
using render_target_t = util::safe_ptr<ID3D11RenderTargetView, Release<ID3D11RenderTargetView>>;
|
||||
using shader_res_t = util::safe_ptr<ID3D11ShaderResourceView, Release<ID3D11ShaderResourceView>>;
|
||||
using blend_t = util::safe_ptr<ID3D11BlendState, Release<ID3D11BlendState>>;
|
||||
using raster_state_t = util::safe_ptr<ID3D11RasterizerState, Release<ID3D11RasterizerState>>;
|
||||
using sampler_state_t = util::safe_ptr<ID3D11SamplerState, Release<ID3D11SamplerState>>;
|
||||
using vs_t = util::safe_ptr<ID3D11VertexShader, Release<ID3D11VertexShader>>;
|
||||
@ -25,9 +26,8 @@ using depth_stencil_view_t = util::safe_ptr<ID3D11DepthStencilView, Release<ID3
|
||||
|
||||
blob_t merge_UV_vs_hlsl;
|
||||
blob_t merge_UV_ps_hlsl;
|
||||
blob_t screen_vs_hlsl;
|
||||
blob_t screen_ps_hlsl;
|
||||
blob_t YCrCb_ps_hlsl;
|
||||
blob_t merge_Y_vs_hlsl;
|
||||
blob_t merge_Y_ps_hlsl;
|
||||
|
||||
struct img_d3d_t : public platf::img_t {
|
||||
shader_res_t input_res;
|
||||
@ -216,50 +216,30 @@ public:
|
||||
img.input_res.reset(input_rec_p);
|
||||
}
|
||||
|
||||
auto nv12_rt_p = nv12_rt.get();
|
||||
auto sampler_point_p = sampler_point.get();
|
||||
auto sampler_linear_p = sampler_linear.get();
|
||||
auto input_res_p = img.input_res.get();
|
||||
auto luma_sr_p = luma_sr.get();
|
||||
|
||||
render_target_t::pointer pYCbCrRT[] {
|
||||
luma_rt.get(), chromaCB_rt.get(), chromaCR_rt.get()
|
||||
};
|
||||
|
||||
shader_res_t::pointer merge_ress[] {
|
||||
chromaCB_sr.get(), chromaCR_sr.get(), shift_sr.get()
|
||||
};
|
||||
auto Y_rt_p = nv12_Y_rt.get();
|
||||
auto UV_rt_p = nv12_UV_rt.get();
|
||||
|
||||
// device_ctx_p->OMSetBlendState(blend.get(), nullptr, 0xffffffff);
|
||||
_init_view_port(out_width, out_height);
|
||||
device_ctx_p->PSSetSamplers(0, 1, &sampler_point_p);
|
||||
device_ctx_p->PSSetSamplers(0, 1, &sampler_linear_p);
|
||||
|
||||
device_ctx_p->OMSetRenderTargets(3, pYCbCrRT, nullptr);
|
||||
for(auto rt : pYCbCrRT) {
|
||||
device_ctx_p->ClearRenderTargetView(rt, aquamarine);
|
||||
}
|
||||
device_ctx_p->VSSetShader(screen_vs.get(), nullptr, 0);
|
||||
device_ctx_p->PSSetShader(YCrCb_ps.get(), nullptr, 0);
|
||||
device_ctx_p->OMSetRenderTargets(1, &Y_rt_p, nullptr);
|
||||
device_ctx_p->ClearRenderTargetView(Y_rt_p, aquamarine);
|
||||
device_ctx_p->VSSetShader(merge_Y_vs.get(), nullptr, 0);
|
||||
device_ctx_p->PSSetShader(merge_Y_ps.get(), nullptr, 0);
|
||||
device_ctx_p->PSSetShaderResources(0, 1, &input_res_p);
|
||||
device_ctx_p->Draw(4, 0);
|
||||
device_ctx_p->Flush();
|
||||
|
||||
// downsample
|
||||
device_ctx_p->GenerateMips(chromaCR_sr.get());
|
||||
device_ctx_p->GenerateMips(chromaCB_sr.get());
|
||||
|
||||
device_ctx_p->OMSetRenderTargets(1, &nv12_rt_p, nullptr);
|
||||
device_ctx_p->ClearRenderTargetView(nv12_rt_p, aquamarine);
|
||||
device_ctx_p->VSSetShader(screen_vs.get(), nullptr, 0);
|
||||
device_ctx_p->PSSetShader(screen_ps.get(), nullptr, 0);
|
||||
device_ctx_p->PSSetShaderResources(0, 1, &luma_sr_p);
|
||||
device_ctx_p->Draw(4, 0);
|
||||
device_ctx_p->Flush();
|
||||
|
||||
_init_view_port(out_width, out_height *2);
|
||||
_init_view_port(out_width / 2, out_height / 2);
|
||||
device_ctx_p->OMSetRenderTargets(1, &UV_rt_p, nullptr);
|
||||
device_ctx_p->ClearRenderTargetView(UV_rt_p, aquamarine);
|
||||
device_ctx_p->VSSetShader(merge_UV_vs.get(), nullptr, 0);
|
||||
device_ctx_p->PSSetShader(merge_UV_ps.get(), nullptr, 0);
|
||||
for(int x = 0; x < ARRAYSIZE(merge_ress); ++x) {
|
||||
device_ctx_p->PSSetShaderResources(x, 1, &merge_ress[x]);
|
||||
}
|
||||
device_ctx_p->PSSetShaderResources(0, 1, &input_res_p);
|
||||
device_ctx_p->Draw(4, 0);
|
||||
device_ctx_p->Flush();
|
||||
|
||||
@ -289,45 +269,35 @@ public:
|
||||
this->in_width = in_width;
|
||||
this->in_height = in_height;
|
||||
|
||||
vs_t::pointer screen_vs_p;
|
||||
status = device_p->CreateVertexShader(screen_vs_hlsl->GetBufferPointer(), screen_vs_hlsl->GetBufferSize(), nullptr, &screen_vs_p);
|
||||
vs_t::pointer vs_p;
|
||||
status = device_p->CreateVertexShader(merge_Y_vs_hlsl->GetBufferPointer(), merge_Y_vs_hlsl->GetBufferSize(), nullptr, &vs_p);
|
||||
if(status) {
|
||||
BOOST_LOG(error) << "Failed to create screen vertex shader [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
return -1;
|
||||
}
|
||||
screen_vs.reset(screen_vs_p);
|
||||
merge_Y_vs.reset(vs_p);
|
||||
|
||||
ps_t::pointer screen_ps_p;
|
||||
status = device_p->CreatePixelShader(screen_ps_hlsl->GetBufferPointer(), screen_ps_hlsl->GetBufferSize(), nullptr, &screen_ps_p);
|
||||
if(status) {
|
||||
BOOST_LOG(error) << "Failed to create screen pixel shader [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
return -1;
|
||||
}
|
||||
screen_ps.reset(screen_ps_p);
|
||||
|
||||
ps_t::pointer YCrCb_ps_p;
|
||||
status = device_p->CreatePixelShader(YCrCb_ps_hlsl->GetBufferPointer(), YCrCb_ps_hlsl->GetBufferSize(), nullptr, &YCrCb_ps_p);
|
||||
ps_t::pointer ps_p;
|
||||
status = device_p->CreatePixelShader(merge_Y_ps_hlsl->GetBufferPointer(), merge_Y_ps_hlsl->GetBufferSize(), nullptr, &ps_p);
|
||||
if(status) {
|
||||
BOOST_LOG(error) << "Failed to create YCrCb pixel shader [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
return -1;
|
||||
}
|
||||
YCrCb_ps.reset(YCrCb_ps_p);
|
||||
merge_Y_ps.reset(ps_p);
|
||||
|
||||
ps_t::pointer merge_UV_ps_p;
|
||||
status = device_p->CreatePixelShader(merge_UV_ps_hlsl->GetBufferPointer(), merge_UV_ps_hlsl->GetBufferSize(), nullptr, &merge_UV_ps_p);
|
||||
status = device_p->CreatePixelShader(merge_UV_ps_hlsl->GetBufferPointer(), merge_UV_ps_hlsl->GetBufferSize(), nullptr, &ps_p);
|
||||
if(status) {
|
||||
BOOST_LOG(error) << "Failed to create mergeUV pixel shader [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
return -1;
|
||||
}
|
||||
merge_UV_ps.reset(merge_UV_ps_p);
|
||||
merge_UV_ps.reset(ps_p);
|
||||
|
||||
vs_t::pointer merge_UV_vs_p;
|
||||
status = device_p->CreateVertexShader(merge_UV_vs_hlsl->GetBufferPointer(), merge_UV_vs_hlsl->GetBufferSize(), nullptr, &merge_UV_vs_p);
|
||||
status = device_p->CreateVertexShader(merge_UV_vs_hlsl->GetBufferPointer(), merge_UV_vs_hlsl->GetBufferSize(), nullptr, &vs_p);
|
||||
if(status) {
|
||||
BOOST_LOG(error) << "Failed to create mergeUV vertex shader [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
return -1;
|
||||
}
|
||||
merge_UV_vs.reset(merge_UV_vs_p);
|
||||
merge_UV_vs.reset(vs_p);
|
||||
|
||||
D3D11_INPUT_ELEMENT_DESC layout_desc {
|
||||
"SV_Position", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0
|
||||
@ -340,6 +310,20 @@ public:
|
||||
&input_layout_p);
|
||||
input_layout.reset(input_layout_p);
|
||||
|
||||
D3D11_BLEND_DESC blend_desc {};
|
||||
blend_desc.RenderTarget[0].BlendEnable = FALSE;
|
||||
blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
|
||||
blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
|
||||
blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
|
||||
|
||||
blend_t::pointer blend_p;
|
||||
status = device_p->CreateBlendState(&blend_desc, &blend_p);
|
||||
if(status) {
|
||||
BOOST_LOG(error) << "Failed to create blend state [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
return -1;
|
||||
}
|
||||
blend.reset(blend_p);
|
||||
|
||||
D3D11_TEXTURE2D_DESC t {};
|
||||
t.Width = out_width;
|
||||
t.Height = out_height;
|
||||
@ -376,30 +360,20 @@ public:
|
||||
BOOST_LOG(error) << "Failed to create render target view [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
return -1;
|
||||
}
|
||||
nv12_rt.reset(nv12_rt_p);
|
||||
nv12_Y_rt.reset(nv12_rt_p);
|
||||
|
||||
if(
|
||||
_init_rt(&luma_sr, &luma_rt, out_width, out_height, 1, DXGI_FORMAT_R8_UNORM) ||
|
||||
_init_rt(&chromaCB_sr, &chromaCB_rt, out_width, out_height, 2, DXGI_FORMAT_R8_UNORM, D3D11_RESOURCE_MISC_GENERATE_MIPS) ||
|
||||
_init_rt(&chromaCR_sr, &chromaCR_rt, out_width, out_height, 2, DXGI_FORMAT_R8_UNORM, D3D11_RESOURCE_MISC_GENERATE_MIPS) ||
|
||||
_init_shift_sr(out_width))
|
||||
{
|
||||
nv12_rt_desc.Format = DXGI_FORMAT_R8G8_UNORM;
|
||||
status = device_p->CreateRenderTargetView(img.texture.get(), &nv12_rt_desc, &nv12_rt_p);
|
||||
if(FAILED(status)) {
|
||||
BOOST_LOG(error) << "Failed to create render target view [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
return -1;
|
||||
}
|
||||
|
||||
// t.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
||||
// t.BindFlags = D3D11_BIND_DEPTH_STENCIL;
|
||||
// status = device_p->CreateTexture2D(&t, nullptr, &tex_p);
|
||||
// if(FAILED(status)) {
|
||||
// BOOST_LOG(error) << "Failed to create depth stencil texture [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
// return -1;
|
||||
// }
|
||||
// depth_stencil.reset(tex_p);
|
||||
nv12_UV_rt.reset(nv12_rt_p);
|
||||
|
||||
D3D11_SAMPLER_DESC sampler_desc {};
|
||||
sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
|
||||
sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
||||
sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
|
||||
sampler_desc.MinLOD = 0;
|
||||
@ -411,69 +385,16 @@ public:
|
||||
BOOST_LOG(error) << "Failed to create point sampler state [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
return -1;
|
||||
}
|
||||
sampler_linear.reset(sampler_state_p);
|
||||
|
||||
sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
|
||||
status = device_p->CreateSamplerState(&sampler_desc, &sampler_state_p);
|
||||
if(FAILED(status)) {
|
||||
BOOST_LOG(error) << "Failed to create point sampler state [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
return -1;
|
||||
}
|
||||
sampler_point.reset(sampler_state_p);
|
||||
|
||||
// D3D11_DEPTH_STENCIL_DESC depth_stencil_desc {};
|
||||
// depth_stencil_desc.DepthEnable = FALSE;
|
||||
// depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
|
||||
// depth_stencil_desc.StencilEnable = true;
|
||||
// depth_stencil_desc.StencilReadMask = 0xFF;
|
||||
// depth_stencil_desc.StencilWriteMask = 0xFF;
|
||||
|
||||
// depth_stencil_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
|
||||
// depth_stencil_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
|
||||
// depth_stencil_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
|
||||
// depth_stencil_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
||||
|
||||
// depth_stencil_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
|
||||
// depth_stencil_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
|
||||
// depth_stencil_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
|
||||
// depth_stencil_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
||||
|
||||
// depth_stencil_state_t::pointer depth_state_p;
|
||||
// status = device_p->CreateDepthStencilState(&depth_stencil_desc, &depth_state_p);
|
||||
// if(FAILED(status)) {
|
||||
// BOOST_LOG(error) << "Failed to create depth stencil state [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
// return -1;
|
||||
// }
|
||||
// depth_state.reset(depth_state_p);
|
||||
|
||||
// D3D11_DEPTH_STENCIL_VIEW_DESC depth_view_desc {};
|
||||
// depth_view_desc.Format = t.Format;
|
||||
// depth_view_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
|
||||
|
||||
// depth_stencil_view_t::pointer depth_view_p;
|
||||
// status = device_p->CreateDepthStencilView(depth_stencil.get(), &depth_view_desc, &depth_view_p);
|
||||
// if(FAILED(status)) {
|
||||
// BOOST_LOG(error) << "Failed to create depth stencil view [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
// return -1;
|
||||
// }
|
||||
// depth_view.reset(depth_view_p);
|
||||
|
||||
// // Setup the raster description which will determine how and what polygons will be drawn.
|
||||
// D3D11_RASTERIZER_DESC raster_desc;
|
||||
// raster_desc.AntialiasedLineEnable = false;
|
||||
// raster_desc.CullMode = D3D11_CULL_BACK;
|
||||
// raster_desc.DepthBias = 0;
|
||||
// raster_desc.DepthBiasClamp = 0.0f;
|
||||
// raster_desc.DepthClipEnable = true;
|
||||
// raster_desc.FillMode = D3D11_FILL_SOLID;
|
||||
// raster_desc.FrontCounterClockwise = false;
|
||||
// raster_desc.MultisampleEnable = false;
|
||||
// raster_desc.ScissorEnable = false;
|
||||
// raster_desc.SlopeScaledDepthBias = 0.0f;
|
||||
|
||||
// raster_state_t::pointer raster_state_p;
|
||||
// status = device_p->CreateRasterizerState(&raster_desc, &raster_state_p);
|
||||
// if(FAILED(status)) {
|
||||
// BOOST_LOG(error) << "Failed to create rasterizer state [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
// return -1;
|
||||
// }
|
||||
// raster_state.reset(raster_state_p);
|
||||
|
||||
auto sampler_p = sampler_point.get();
|
||||
device_ctx_p->PSSetSamplers(0, 1, &sampler_p);
|
||||
// device_ctx_p->RSSetState(raster_state.get());
|
||||
device_ctx_p->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
||||
device_ctx_p->IASetInputLayout(input_layout.get());
|
||||
|
||||
@ -491,9 +412,9 @@ public:
|
||||
}
|
||||
}
|
||||
private:
|
||||
void _init_view_port(float width, float height) {
|
||||
void _init_view_port(float x, float y, float width, float height) {
|
||||
D3D11_VIEWPORT view {
|
||||
0.0f, 0.0f,
|
||||
x, y,
|
||||
width, height,
|
||||
0.0f, 1.0f
|
||||
};
|
||||
@ -501,7 +422,11 @@ private:
|
||||
device_ctx_p->RSSetViewports(1, &view);
|
||||
}
|
||||
|
||||
int _init_rt(shader_res_t *shader_res, render_target_t *render_target, int width, int height, int mip_levels, DXGI_FORMAT format, int flags = 0) {
|
||||
void _init_view_port(float width, float height) {
|
||||
_init_view_port(0.0f, 0.0f, width, height);
|
||||
}
|
||||
|
||||
int _init_rt(shader_res_t &shader_res, render_target_t &render_target, int width, int height, DXGI_FORMAT format) {
|
||||
D3D11_TEXTURE2D_DESC desc {};
|
||||
|
||||
desc.Width = width;
|
||||
@ -509,10 +434,9 @@ private:
|
||||
desc.Format = format;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.MipLevels = mip_levels;
|
||||
desc.MipLevels = 1;
|
||||
desc.ArraySize = 1;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.MiscFlags = flags;
|
||||
|
||||
auto device = (device_t::pointer)data;
|
||||
|
||||
@ -524,114 +448,54 @@ private:
|
||||
}
|
||||
texture2d_t tex { tex_p };
|
||||
|
||||
if(shader_res) {
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC shader_resource_desc {
|
||||
format,
|
||||
D3D11_SRV_DIMENSION_TEXTURE2D
|
||||
};
|
||||
shader_resource_desc.Texture2D.MipLevels = mip_levels;
|
||||
|
||||
shader_res_t::pointer shader_res_p;
|
||||
device->CreateShaderResourceView(tex_p, &shader_resource_desc, &shader_res_p);
|
||||
if(status) {
|
||||
BOOST_LOG(error) << "Failed to create render target texture for luma [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
return -1;
|
||||
}
|
||||
shader_res->reset(shader_res_p);
|
||||
}
|
||||
|
||||
if(render_target) {
|
||||
D3D11_RENDER_TARGET_VIEW_DESC render_target_desc {
|
||||
format,
|
||||
D3D11_RTV_DIMENSION_TEXTURE2D
|
||||
};
|
||||
|
||||
render_target_t::pointer render_target_p;
|
||||
device->CreateRenderTargetView(tex_p, &render_target_desc, &render_target_p);
|
||||
if(status) {
|
||||
BOOST_LOG(error) << "Failed to create render target view [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
return -1;
|
||||
}
|
||||
render_target->reset(render_target_p);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _init_shift_sr(int width) {
|
||||
auto device = (device_t::pointer)data;
|
||||
D3D11_TEXTURE1D_DESC desc {};
|
||||
desc.Width = width;
|
||||
desc.MipLevels = 1;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = DXGI_FORMAT_R8_UNORM;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
|
||||
util::buffer_t<BYTE> data { (std::size_t)width };
|
||||
for(int x = 0; x < data.size(); ++x) {
|
||||
data[x] = x & 1;
|
||||
}
|
||||
|
||||
D3D11_SUBRESOURCE_DATA data_res {
|
||||
std::begin(data),
|
||||
(UINT)data.size()
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC shader_resource_desc {
|
||||
format,
|
||||
D3D11_SRV_DIMENSION_TEXTURE2D
|
||||
};
|
||||
|
||||
texture1d_t::pointer tex_p {};
|
||||
auto status = device->CreateTexture1D(&desc, &data_res, &tex_p);
|
||||
if(FAILED(status)) {
|
||||
BOOST_LOG(error) << "Failed to create shift texture [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
return -1;
|
||||
}
|
||||
texture1d_t tex { tex_p };
|
||||
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC res_desc {
|
||||
DXGI_FORMAT_R8_UNORM,
|
||||
D3D11_SRV_DIMENSION_TEXTURE1D
|
||||
};
|
||||
res_desc.Texture1D.MipLevels = 1;
|
||||
shader_resource_desc.Texture2D.MipLevels = 1;
|
||||
|
||||
shader_res_t::pointer shader_res_p;
|
||||
device->CreateShaderResourceView(tex_p, &res_desc, &shader_res_p);
|
||||
device->CreateShaderResourceView(tex_p, &shader_resource_desc, &shader_res_p);
|
||||
if(status) {
|
||||
BOOST_LOG(error) << "Failed to create render target texture for luma [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
return -1;
|
||||
}
|
||||
shift_sr.reset(shader_res_p);
|
||||
shader_res.reset(shader_res_p);
|
||||
|
||||
D3D11_RENDER_TARGET_VIEW_DESC render_target_desc {
|
||||
format,
|
||||
D3D11_RTV_DIMENSION_TEXTURE2D
|
||||
};
|
||||
|
||||
render_target_t::pointer render_target_p;
|
||||
device->CreateRenderTargetView(tex_p, &render_target_desc, &render_target_p);
|
||||
if(status) {
|
||||
BOOST_LOG(error) << "Failed to create render target view [0x"sv << util::hex(status).to_string_view() << ']';
|
||||
return -1;
|
||||
}
|
||||
render_target.reset(render_target_p);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public:
|
||||
// raster_state_t raster_state;
|
||||
|
||||
sampler_state_t sampler_linear;
|
||||
sampler_state_t sampler_point;
|
||||
|
||||
// depth_stencil_view_t depth_view;
|
||||
// depth_stencil_state_t depth_state;
|
||||
|
||||
shader_res_t chromaCB_sr;
|
||||
shader_res_t chromaCR_sr;
|
||||
shader_res_t luma_sr;
|
||||
shader_res_t shift_sr;
|
||||
|
||||
input_layout_t input_layout;
|
||||
// texture2d_t depth_stencil;
|
||||
|
||||
render_target_t luma_rt;
|
||||
render_target_t nv12_rt;
|
||||
render_target_t chromaCB_rt;
|
||||
render_target_t chromaCR_rt;
|
||||
render_target_t nv12_Y_rt;
|
||||
render_target_t nv12_UV_rt;
|
||||
|
||||
blend_t blend;
|
||||
|
||||
img_d3d_t img;
|
||||
|
||||
vs_t merge_UV_vs;
|
||||
ps_t merge_UV_ps;
|
||||
vs_t screen_vs;
|
||||
ps_t screen_ps;
|
||||
ps_t YCrCb_ps;
|
||||
ps_t ChromaCbCr_ps;
|
||||
vs_t merge_Y_vs;
|
||||
ps_t merge_Y_ps;
|
||||
|
||||
bool cursor_visible;
|
||||
|
||||
@ -816,36 +680,6 @@ std::shared_ptr<platf::hwdevice_t> display_vram_t::make_hwdevice(int width, int
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if(!screen_ps_hlsl) {
|
||||
BOOST_LOG(info) << "Compiling shaders..."sv;
|
||||
screen_vs_hlsl = compile_vertex_shader(SUNSHINE_ASSETS_DIR "/ScreenVS.hlsl");
|
||||
if(!screen_vs_hlsl) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
screen_ps_hlsl = compile_pixel_shader(SUNSHINE_ASSETS_DIR "/ScreenPS.hlsl");
|
||||
if(!screen_ps_hlsl) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
YCrCb_ps_hlsl = compile_pixel_shader(SUNSHINE_ASSETS_DIR "/YCbCrPS.hlsl");
|
||||
if(!YCrCb_ps_hlsl) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
merge_UV_ps_hlsl = compile_pixel_shader(SUNSHINE_ASSETS_DIR "/MergeUVPS.hlsl");
|
||||
if(!merge_UV_ps_hlsl) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
merge_UV_vs_hlsl = compile_vertex_shader(SUNSHINE_ASSETS_DIR "/MergeUVVS.hlsl");
|
||||
if(!merge_UV_vs_hlsl) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BOOST_LOG(info) << "Compiled shaders"sv;
|
||||
}
|
||||
|
||||
auto hwdevice = std::make_shared<hwdevice_t>(&hwdevices);
|
||||
|
||||
auto ret = hwdevice->init(
|
||||
@ -868,4 +702,30 @@ std::shared_ptr<platf::hwdevice_t> display_vram_t::make_hwdevice(int width, int
|
||||
|
||||
return hwdevice;
|
||||
}
|
||||
|
||||
int init() {
|
||||
BOOST_LOG(info) << "Compiling shaders..."sv;
|
||||
merge_Y_vs_hlsl = compile_vertex_shader(SUNSHINE_ASSETS_DIR "/MergeYVS.hlsl");
|
||||
if(!merge_Y_vs_hlsl) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
merge_Y_ps_hlsl = compile_pixel_shader(SUNSHINE_ASSETS_DIR "/MergeYPS.hlsl");
|
||||
if(!merge_Y_ps_hlsl) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
merge_UV_ps_hlsl = compile_pixel_shader(SUNSHINE_ASSETS_DIR "/MergeUVPS.hlsl");
|
||||
if(!merge_UV_ps_hlsl) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
merge_UV_vs_hlsl = compile_vertex_shader(SUNSHINE_ASSETS_DIR "/MergeUVVS.hlsl");
|
||||
if(!merge_UV_vs_hlsl) {
|
||||
return -1;
|
||||
}
|
||||
BOOST_LOG(info) << "Compiled shaders"sv;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -622,6 +622,7 @@ std::optional<session_t> make_session(const encoder_t &encoder, const config_t &
|
||||
case 0:
|
||||
default:
|
||||
// Rec. 601
|
||||
BOOST_LOG(info) << "Color coding [Rec. 601]"sv;
|
||||
ctx->color_primaries = AVCOL_PRI_SMPTE170M;
|
||||
ctx->color_trc = AVCOL_TRC_SMPTE170M;
|
||||
ctx->colorspace = AVCOL_SPC_SMPTE170M;
|
||||
@ -630,6 +631,7 @@ std::optional<session_t> make_session(const encoder_t &encoder, const config_t &
|
||||
|
||||
case 1:
|
||||
// Rec. 709
|
||||
BOOST_LOG(info) << "Color coding [Rec. 709]"sv;
|
||||
ctx->color_primaries = AVCOL_PRI_BT709;
|
||||
ctx->color_trc = AVCOL_TRC_BT709;
|
||||
ctx->colorspace = AVCOL_SPC_BT709;
|
||||
@ -638,6 +640,7 @@ std::optional<session_t> make_session(const encoder_t &encoder, const config_t &
|
||||
|
||||
case 2:
|
||||
// Rec. 2020
|
||||
BOOST_LOG(info) << "Color coding [Rec. 2020]"sv;
|
||||
ctx->color_primaries = AVCOL_PRI_BT2020;
|
||||
ctx->color_trc = AVCOL_TRC_BT2020_10;
|
||||
ctx->colorspace = AVCOL_SPC_BT2020_NCL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user