From 1b7e103ef62d80465982bfee593e65f8b68135c4 Mon Sep 17 00:00:00 2001 From: loki Date: Tue, 4 May 2021 10:21:56 +0200 Subject: [PATCH] Allow resizing the image during conversion --- assets/MergeYPS.hlsl | 2 +- assets/MergeYVS.hlsl | 5 +++- sunshine/video.cpp | 65 +++++++------------------------------------- 3 files changed, 15 insertions(+), 57 deletions(-) diff --git a/assets/MergeYPS.hlsl b/assets/MergeYPS.hlsl index 4a015f04..66c53afd 100644 --- a/assets/MergeYPS.hlsl +++ b/assets/MergeYPS.hlsl @@ -22,7 +22,7 @@ struct PS_INPUT //-------------------------------------------------------------------------------------- float PS(PS_INPUT frag_in) : SV_Target { - float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb; + float3 rgb = image.Sample(def_sampler, frag_in.tex, 0).rgb; float y = dot(color_vec_y.xyz, rgb) + color_vec_y.w; return y; diff --git a/assets/MergeYVS.hlsl b/assets/MergeYVS.hlsl index d95ed7b4..f38bb3bf 100644 --- a/assets/MergeYVS.hlsl +++ b/assets/MergeYVS.hlsl @@ -15,8 +15,11 @@ PS_INPUT VS(uint vI : SV_VERTEXID) float x = idHigh * 4.0 - 1.0; float y = idLow * 4.0 - 1.0; + float u = idHigh * 2.0; + float v = 1.0 - idLow * 2.0; + PS_INPUT vert_out; vert_out.pos = float4(x, y, 0.0, 1.0); - vert_out.tex = float2(idHigh, idLow); + vert_out.tex = float2(u, v); return vert_out; } \ No newline at end of file diff --git a/sunshine/video.cpp b/sunshine/video.cpp index b41ffb17..986ef05f 100644 --- a/sunshine/video.cpp +++ b/sunshine/video.cpp @@ -82,10 +82,10 @@ platf::dev_type_e map_dev_type(AVHWDeviceType type); platf::pix_fmt_e map_pix_fmt(AVPixelFormat fmt); void sw_img_to_frame(const platf::img_t &img, frame_t &frame); -void nv_d3d_img_to_frame(const platf::img_t &img, frame_t &frame); -util::Either nv_d3d_make_hwdevice_ctx(platf::hwdevice_t *hwdevice_ctx); -void amd_d3d_img_to_frame(const platf::img_t &img, frame_t &frame); -util::Either amd_d3d_make_hwdevice_ctx(platf::hwdevice_t *hwdevice_ctx); +void dxgi_img_to_frame(const platf::img_t &img, frame_t &frame); +util::Either dxgi_make_hwdevice_ctx(platf::hwdevice_t *hwdevice_ctx); +void dxgi_img_to_frame(const platf::img_t &img, frame_t &frame); +util::Either dxgi_make_hwdevice_ctx(platf::hwdevice_t *hwdevice_ctx); util::Either make_hwdevice_ctx(AVHWDeviceType type, void *hwdevice_ctx); int hwframe_ctx(ctx_t &ctx, buffer_t &hwdevice, AVPixelFormat format); @@ -297,8 +297,8 @@ static encoder_t nvenc { false, true, - nv_d3d_img_to_frame, - nv_d3d_make_hwdevice_ctx + dxgi_img_to_frame, + dxgi_make_hwdevice_ctx }; static encoder_t amdvce { @@ -331,8 +331,8 @@ static encoder_t amdvce { false, true, - amd_d3d_img_to_frame, - amd_d3d_make_hwdevice_ctx + dxgi_img_to_frame, + dxgi_make_hwdevice_ctx }; #endif @@ -1304,7 +1304,7 @@ int hwframe_ctx(ctx_t &ctx, buffer_t &hwdevice, AVPixelFormat format) { void sw_img_to_frame(const platf::img_t &img, frame_t &frame) {} #ifdef _WIN32 -void nv_d3d_img_to_frame(const platf::img_t &img, frame_t &frame) { +void dxgi_img_to_frame(const platf::img_t &img, frame_t &frame) { if(img.data == frame->data[0]) { return; } @@ -1327,31 +1327,7 @@ void nv_d3d_img_to_frame(const platf::img_t &img, frame_t &frame) { frame->width = img.width; } -void amd_d3d_img_to_frame(const platf::img_t &img, frame_t &frame) { - if(img.data == frame->data[0]) { - return; - } - - // Need to have something refcounted - if(!frame->buf[0]) { - frame->buf[0] = av_buffer_allocz(sizeof(AVD3D11FrameDescriptor)); - } - - auto desc = (AVD3D11FrameDescriptor*)frame->buf[0]->data; - desc->texture = (ID3D11Texture2D*)img.data; - desc->index = 0; - - frame->data[0] = img.data; - frame->data[1] = 0; - - frame->linesize[0] = img.row_pitch; - - frame->height = img.height; - frame->width = img.width; -} - - -util::Either nv_d3d_make_hwdevice_ctx(platf::hwdevice_t *hwdevice_ctx) { +util::Either dxgi_make_hwdevice_ctx(platf::hwdevice_t *hwdevice_ctx) { buffer_t ctx_buf { av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_D3D11VA) }; auto ctx = (AVD3D11VADeviceContext*)((AVHWDeviceContext*)ctx_buf->data)->hwctx; @@ -1371,27 +1347,6 @@ util::Either nv_d3d_make_hwdevice_ctx(platf::hwdevice_t *hwdevice return ctx_buf; } - -util::Either amd_d3d_make_hwdevice_ctx(platf::hwdevice_t *hwdevice_ctx) { - buffer_t ctx_buf { av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_D3D11VA) }; - auto ctx = (AVD3D11VADeviceContext*)((AVHWDeviceContext*)ctx_buf->data)->hwctx; - - std::fill_n((std::uint8_t*)ctx, sizeof(AVD3D11VADeviceContext), 0); - - auto device = (ID3D11Device*)hwdevice_ctx->data; - device->AddRef(); - ctx->device = device; - - auto err = av_hwdevice_ctx_init(ctx_buf.get()); - if(err) { - char err_str[AV_ERROR_MAX_STRING_SIZE] {0}; - BOOST_LOG(error) << "Failed to create FFMpeg amddech: "sv << av_make_error_string(err_str, AV_ERROR_MAX_STRING_SIZE, err); - - return err; - } - - return ctx_buf; -} #endif int start_capture_async(capture_thread_async_ctx_t &capture_thread_ctx) {