Skip to content

Commit

Permalink
Use different slots for different rotations
Browse files Browse the repository at this point in the history
So we won't get hard to debug errors later when we decide to support
serial processing on Windows for example.
  • Loading branch information
ns6089 committed Sep 7, 2023
1 parent 0470325 commit 85fa23e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/platform/windows/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ namespace platf::dxgi {
blend_t blend_invert;
blend_t blend_disable;

ps_t scene_ps;
vs_t scene_vs;
ps_t cursor_ps;
vs_t cursor_vs;

gpu_cursor_t cursor_alpha;
gpu_cursor_t cursor_xor;
Expand Down
18 changes: 12 additions & 6 deletions src/platform/windows/display_vram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ namespace platf::dxgi {
blob_t convert_UV_linear_ps_hlsl;
blob_t convert_UV_PQ_ps_hlsl;
blob_t scene_vs_hlsl;
blob_t cursor_vs_hlsl;
blob_t convert_Y_ps_hlsl;
blob_t convert_Y_linear_ps_hlsl;
blob_t convert_Y_PQ_ps_hlsl;
Expand Down Expand Up @@ -1239,8 +1240,8 @@ namespace platf::dxgi {
}

auto blend_cursor = [&](img_d3d_t &d3d_img) {
device_ctx->VSSetShader(scene_vs.get(), nullptr, 0);
device_ctx->PSSetShader(scene_ps.get(), nullptr, 0);
device_ctx->VSSetShader(cursor_vs.get(), nullptr, 0);
device_ctx->PSSetShader(cursor_ps.get(), nullptr, 0);
device_ctx->OMSetRenderTargets(1, &d3d_img.capture_rt, nullptr);

if (cursor_alpha.texture.get()) {
Expand Down Expand Up @@ -1360,7 +1361,7 @@ namespace platf::dxgi {
return -1;
}

status = device->CreateVertexShader(scene_vs_hlsl->GetBufferPointer(), scene_vs_hlsl->GetBufferSize(), nullptr, &scene_vs);
status = device->CreateVertexShader(cursor_vs_hlsl->GetBufferPointer(), cursor_vs_hlsl->GetBufferSize(), nullptr, &cursor_vs);
if (status) {
BOOST_LOG(error) << "Failed to create scene vertex shader [0x"sv << util::hex(status).to_string_view() << ']';
return -1;
Expand All @@ -1374,12 +1375,12 @@ namespace platf::dxgi {
BOOST_LOG(error) << "Failed to create display rotation vertex constant buffer";
return -1;
}
device_ctx->VSSetConstantBuffers(1, 1, &rotation);
device_ctx->VSSetConstantBuffers(2, 1, &rotation);
}

if (config.dynamicRange && is_hdr()) {
// This shader will normalize scRGB white levels to a user-defined white level
status = device->CreatePixelShader(scene_NW_ps_hlsl->GetBufferPointer(), scene_NW_ps_hlsl->GetBufferSize(), nullptr, &scene_ps);
status = device->CreatePixelShader(scene_NW_ps_hlsl->GetBufferPointer(), scene_NW_ps_hlsl->GetBufferSize(), nullptr, &cursor_ps);
if (status) {
BOOST_LOG(error) << "Failed to create scene pixel shader [0x"sv << util::hex(status).to_string_view() << ']';
return -1;
Expand All @@ -1398,7 +1399,7 @@ namespace platf::dxgi {
device_ctx->PSSetConstantBuffers(1, 1, &sdr_multiplier);
}
else {
status = device->CreatePixelShader(scene_ps_hlsl->GetBufferPointer(), scene_ps_hlsl->GetBufferSize(), nullptr, &scene_ps);
status = device->CreatePixelShader(scene_ps_hlsl->GetBufferPointer(), scene_ps_hlsl->GetBufferSize(), nullptr, &cursor_ps);
if (status) {
BOOST_LOG(error) << "Failed to create scene pixel shader [0x"sv << util::hex(status).to_string_view() << ']';
return -1;
Expand Down Expand Up @@ -1678,6 +1679,11 @@ namespace platf::dxgi {
return -1;
}

cursor_vs_hlsl = compile_vertex_shader(SUNSHINE_SHADERS_DIR "/CursorVS.hlsl");
if (!cursor_vs_hlsl) {
return -1;
}

convert_Y_ps_hlsl = compile_pixel_shader(SUNSHINE_SHADERS_DIR "/ConvertYPS.hlsl");
if (!convert_Y_ps_hlsl) {
return -1;
Expand Down
37 changes: 37 additions & 0 deletions src_assets/windows/assets/shaders/directx/CursorVS.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
struct PS_INPUT
{
float4 pos : SV_POSITION;
float2 tex : TEXCOORD;
};

cbuffer rotation_info : register(b2) {
int rotation;
};

PS_INPUT main_vs(uint vI : SV_VERTEXID)
{
PS_INPUT output;

if (vI == 0) {
output.pos = float4(-1, -1, 0, 1);
output.tex = float2(0, 1);
}
else if (vI == 1) {
output.pos = float4(-1, 3, 0, 1);
output.tex = float2(0, -1);
}
else if (vI == 2) {
output.pos = float4(3, -1, 0, 1);
output.tex = float2(2, 1);
}

if (rotation != 0) {
float rotation_radians = radians(90 * rotation);
float2x2 rotation_matrix = { cos(rotation_radians), -sin(rotation_radians),
sin(rotation_radians), cos(rotation_radians) };
float2 rotation_center = { 0.5, 0.5 };
output.tex = round(rotation_center + mul(rotation_matrix, output.tex - rotation_center));
}

return output;
}

0 comments on commit 85fa23e

Please sign in to comment.