Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 8 additions & 50 deletions src/platform/windows/display_vram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ blob_t compile_vertex_shader(LPCSTR file) {
class hwdevice_t : public platf::hwdevice_t {
public:
int convert(platf::img_t &img_base) override {
auto &img = (img_d3d_t &)img_base;
auto back_d3d_img = (img_d3d_t *)back_img.get();
auto &img = (img_d3d_t &)img_base;

// Open the shared capture texture with our ID3D11Device
if(share_img(&img_base)) {
Expand All @@ -315,24 +314,9 @@ class hwdevice_t : public platf::hwdevice_t {
return -1;
}

// Even though this image will never have racing updates, we must acquire the
// keyed mutex for PSSetShaderResources() to succeed.
status = back_d3d_img->encoder_mutex->AcquireSync(0, INFINITE);
if(status != S_OK) {
img.encoder_mutex->ReleaseSync(0);
BOOST_LOG(error) << "Failed to acquire back_d3d_img mutex [0x"sv << util::hex(status).to_string_view() << ']';
return -1;
}

device_ctx->IASetInputLayout(input_layout.get());

_init_view_port(this->img.width, this->img.height);
device_ctx->OMSetRenderTargets(1, &nv12_Y_rt, nullptr);
device_ctx->VSSetShader(scene_vs.get(), nullptr, 0);
device_ctx->PSSetShader(convert_Y_ps.get(), nullptr, 0);
device_ctx->PSSetShaderResources(0, 1, &back_d3d_img->encoder_input_res);
device_ctx->Draw(3, 0);

device_ctx->RSSetViewports(1, &outY_view);
device_ctx->PSSetShaderResources(0, 1, &img.encoder_input_res);
device_ctx->Draw(3, 0);
Expand All @@ -341,20 +325,13 @@ class hwdevice_t : public platf::hwdevice_t {
// before rendering on the UV part of the image.
device_ctx->Flush();

_init_view_port(this->img.width / 2, this->img.height / 2);
device_ctx->OMSetRenderTargets(1, &nv12_UV_rt, nullptr);
device_ctx->VSSetShader(convert_UV_vs.get(), nullptr, 0);
device_ctx->PSSetShader(convert_UV_ps.get(), nullptr, 0);
device_ctx->PSSetShaderResources(0, 1, &back_d3d_img->encoder_input_res);
device_ctx->Draw(3, 0);

device_ctx->RSSetViewports(1, &outUV_view);
device_ctx->PSSetShaderResources(0, 1, &img.encoder_input_res);
device_ctx->Draw(3, 0);
device_ctx->Flush();

// Release encoder mutexes to allow capture code to reuse this image
back_d3d_img->encoder_mutex->ReleaseSync(0);
// Release encoder mutex to allow capture code to reuse this image
img.encoder_mutex->ReleaseSync(0);

return 0;
Expand Down Expand Up @@ -514,6 +491,12 @@ class hwdevice_t : public platf::hwdevice_t {
return -1;
}

// Clear the RTVs to ensure the aspect ratio padding is black
const float y_black[] = { 0.0f, 0.0f, 0.0f, 0.0f };
device_ctx->ClearRenderTargetView(nv12_Y_rt.get(), y_black);
const float uv_black[] = { 0.5f, 0.5f, 0.5f, 0.5f };
device_ctx->ClearRenderTargetView(nv12_UV_rt.get(), uv_black);

return 0;
}

Expand Down Expand Up @@ -609,14 +592,6 @@ class hwdevice_t : public platf::hwdevice_t {

img.display = std::move(display);

// Color the background black, so that the padding for keeping the aspect ratio
// is black
back_img = img.display->alloc_img();
if(img.display->dummy_img(back_img.get()) || share_img(back_img.get())) {
BOOST_LOG(warning) << "Couldn't create an image to set background color to black"sv;
return -1;
}

blend_disable = make_blend(device.get(), false, false);
if(!blend_disable) {
return -1;
Expand Down Expand Up @@ -649,20 +624,6 @@ class hwdevice_t : public platf::hwdevice_t {
}

private:
void _init_view_port(float x, float y, float width, float height) {
D3D11_VIEWPORT view {
x, y,
width, height,
0.0f, 1.0f
};

device_ctx->RSSetViewports(1, &view);
}

void _init_view_port(float width, float height) {
_init_view_port(0.0f, 0.0f, width, height);
}

int share_img(platf::img_t *img_base) {
auto img = (img_d3d_t *)img_base;

Expand Down Expand Up @@ -722,9 +683,6 @@ class hwdevice_t : public platf::hwdevice_t {
// The resulting image is stored here.
img_d3d_t img;

// Clear nv12 render target to black
std::shared_ptr<img_t> back_img;

vs_t convert_UV_vs;
ps_t convert_UV_ps;
ps_t convert_Y_ps;
Expand Down