Skip to content

Commit abbdedb

Browse files
Merge pull request #466 from mbucchia/feature/cas-upscaler
re-enable CAS upscaling and fix black screen issue
2 parents 76c7235 + 75a03dd commit abbdedb

File tree

4 files changed

+54
-36
lines changed

4 files changed

+54
-36
lines changed

XR_APILAYER_MBUCCHIA_toolkit/cas.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,19 @@ namespace {
4444
uint32_t Const1[4];
4545
};
4646

47-
class CASSharpener : public IImageProcessor {
47+
class CASUpscaler : public IImageProcessor {
4848
public:
49-
CASSharpener(std::shared_ptr<IConfigManager> configManager,
50-
std::shared_ptr<IDevice> graphicsDevice)
51-
: m_configManager(configManager), m_device(graphicsDevice) {
52-
initializeSharpener();
49+
CASUpscaler(std::shared_ptr<IConfigManager> configManager,
50+
std::shared_ptr<IDevice> graphicsDevice,
51+
int settingScaling,
52+
int settingAnamorphic)
53+
: m_configManager(configManager), m_device(graphicsDevice),
54+
m_isSharpenOnly(settingScaling == 100 && settingAnamorphic <= 0) {
55+
initializeUpscaler();
5356
}
5457

5558
void reload() override {
56-
initializeSharpener();
59+
initializeUpscaler();
5760
}
5861

5962
void update() override {
@@ -102,21 +105,22 @@ namespace {
102105
}
103106

104107
private:
105-
void initializeSharpener() {
108+
void initializeUpscaler() {
106109
const auto shadersDir = dllHome / "shaders";
107110
const auto shaderFile = shadersDir / "CAS.hlsl";
108111

109112
utilities::shader::Defines defines;
110113
defines.add("CAS_THREAD_GROUP_SIZE", 64);
111114
defines.add("CAS_SAMPLE_FP16", 0);
112-
defines.add("CAS_SAMPLE_SHARPEN_ONLY", 1);
115+
defines.add("CAS_SAMPLE_SHARPEN_ONLY", m_isSharpenOnly ? 1 : 0);
113116
m_shaderCAS = m_device->createComputeShader(shaderFile, "mainCS", "CAS CS", {}, defines.get());
114117

115118
m_configBuffer = m_device->createBuffer(sizeof(CASConstants), "CAS Constants CB");
116119
}
117120

118121
const std::shared_ptr<IConfigManager> m_configManager;
119122
const std::shared_ptr<IDevice> m_device;
123+
const bool m_isSharpenOnly;
120124

121125
std::shared_ptr<IComputeShader> m_shaderCAS;
122126
std::shared_ptr<IShaderBuffer> m_configBuffer;
@@ -126,9 +130,11 @@ namespace {
126130

127131
namespace toolkit::graphics {
128132

129-
std::shared_ptr<IImageProcessor> CreateCASSharpener(std::shared_ptr<IConfigManager> configManager,
130-
std::shared_ptr<IDevice> graphicsDevice) {
131-
return std::make_shared<CASSharpener>(configManager, graphicsDevice);
133+
std::shared_ptr<IImageProcessor> CreateCASUpscaler(std::shared_ptr<IConfigManager> configManager,
134+
std::shared_ptr<IDevice> graphicsDevice,
135+
int settingScaling,
136+
int settingAnamorphic) {
137+
return std::make_shared<CASUpscaler>(configManager, graphicsDevice, settingScaling, settingAnamorphic);
132138
}
133139

134140
} // namespace toolkit::graphics

XR_APILAYER_MBUCCHIA_toolkit/factories.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,11 @@ namespace toolkit {
115115
int settingScaling,
116116
int settingAnamorphic);
117117

118-
std::shared_ptr<IImageProcessor> CreateCASSharpener(
119-
std::shared_ptr<toolkit::config::IConfigManager> configManager, std::shared_ptr<IDevice> graphicsDevice);
118+
std::shared_ptr<IImageProcessor>
119+
CreateCASUpscaler(std::shared_ptr<toolkit::config::IConfigManager> configManager,
120+
std::shared_ptr<IDevice> graphicsDevice,
121+
int settingScaling,
122+
int settingAnamorphic);
120123

121124
std::shared_ptr<IVariableRateShader>
122125
CreateVariableRateShader(toolkit::OpenXrApi& openXR,
@@ -127,6 +130,7 @@ namespace toolkit {
127130
uint32_t renderHeight,
128131
uint32_t displayWidth,
129132
uint32_t displayHeight);
133+
130134

131135
bool IsDeviceSupportingFP16(std::shared_ptr<IDevice> device);
132136

XR_APILAYER_MBUCCHIA_toolkit/layer.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -600,12 +600,13 @@ namespace {
600600

601601
switch (upscaleMode) {
602602
case config::ScalingType::FSR:
603-
case config::ScalingType::NIS: {
603+
case config::ScalingType::NIS:
604+
case config::ScalingType::CAS: {
604605
std::tie(inputWidth, inputHeight) = config::GetScaledDimensions(
605606
settingScaling, settingAnamophic, m_displayWidth, m_displayHeight, 2);
606607
} break;
607608

608-
case config::ScalingType::CAS:
609+
609610
case config::ScalingType::None:
610611
break;
611612

@@ -700,7 +701,10 @@ namespace {
700701
// Initialize the other resources.
701702

702703
m_upscaleMode = m_configManager->getEnumValue<config::ScalingType>(config::SettingScalingType);
703-
if (m_upscaleMode == config::ScalingType::NIS || m_upscaleMode == config::ScalingType::FSR) {
704+
if (m_upscaleMode == config::ScalingType::NIS ||
705+
m_upscaleMode == config::ScalingType::FSR ||
706+
m_upscaleMode == config::ScalingType::CAS
707+
) {
704708
m_settingScaling = m_configManager->peekValue(config::SettingScaling);
705709
m_settingAnamorphic = m_configManager->peekValue(config::SettingAnamorphic);
706710
}
@@ -717,7 +721,8 @@ namespace {
717721
break;
718722

719723
case config::ScalingType::CAS:
720-
m_upscaler = graphics::CreateCASSharpener(m_configManager, m_graphicsDevice);
724+
m_upscaler = graphics::CreateCASUpscaler(
725+
m_configManager, m_graphicsDevice, m_settingScaling, m_settingAnamorphic);
721726
break;
722727

723728
case config::ScalingType::None:
@@ -731,7 +736,10 @@ namespace {
731736

732737
uint32_t renderWidth = m_displayWidth;
733738
uint32_t renderHeight = m_displayHeight;
734-
if (m_upscaleMode == config::ScalingType::NIS || m_upscaleMode == config::ScalingType::FSR) {
739+
if (m_upscaleMode == config::ScalingType::NIS ||
740+
m_upscaleMode == config::ScalingType::FSR ||
741+
m_upscaleMode == config::ScalingType::CAS
742+
) {
735743
std::tie(renderWidth, renderHeight) = config::GetScaledDimensions(
736744
m_settingScaling, m_settingAnamorphic, m_displayWidth, m_displayHeight, 2);
737745

@@ -1068,7 +1076,10 @@ namespace {
10681076
if (useSwapchain && !isDepth) {
10691077
// Modify the swapchain to handle our processing chain (eg: change resolution and/or usage.
10701078

1071-
if (m_upscaleMode == config::ScalingType::NIS || m_upscaleMode == config::ScalingType::FSR) {
1079+
if (m_upscaleMode == config::ScalingType::NIS ||
1080+
m_upscaleMode == config::ScalingType::FSR ||
1081+
m_upscaleMode == config::ScalingType::CAS
1082+
) {
10721083
float horizontalScaleFactor;
10731084
float verticalScaleFactor;
10741085
std::tie(horizontalScaleFactor, verticalScaleFactor) =
@@ -2420,7 +2431,10 @@ namespace {
24202431
}
24212432

24222433
// Adjust mip map biasing.
2423-
if ((m_upscaleMode == config::ScalingType::NIS || m_upscaleMode == config::ScalingType::FSR) &&
2434+
if ((m_upscaleMode == config::ScalingType::NIS ||
2435+
m_upscaleMode == config::ScalingType::FSR ||
2436+
m_upscaleMode == config::ScalingType::CAS
2437+
) &&
24242438
m_configManager->hasChanged(config::SettingMipMapBias)) {
24252439
m_graphicsDevice->setMipMapBias(
24262440
m_configManager->getEnumValue<config::MipMapBias>(config::SettingMipMapBias),
@@ -2741,7 +2755,10 @@ namespace {
27412755
float verticalScaleFactor = 1.f;
27422756
uint32_t scaledOutputWidth = view.subImage.imageRect.extent.width;
27432757
uint32_t scaledOutputHeight = view.subImage.imageRect.extent.height;
2744-
if (m_upscaleMode == config::ScalingType::NIS || m_upscaleMode == config::ScalingType::FSR) {
2758+
if (m_upscaleMode == config::ScalingType::NIS
2759+
|| m_upscaleMode == config::ScalingType::FSR
2760+
|| m_upscaleMode == config::ScalingType::CAS
2761+
) {
27452762
std::tie(horizontalScaleFactor, verticalScaleFactor) =
27462763
config::GetScalingFactors(m_settingScaling, m_settingAnamorphic);
27472764

@@ -2779,7 +2796,9 @@ namespace {
27792796

27802797
// Patch the top-left corner offset.
27812798
if (m_upscaleMode == config::ScalingType::NIS ||
2782-
m_upscaleMode == config::ScalingType::FSR) {
2799+
m_upscaleMode == config::ScalingType::FSR ||
2800+
m_upscaleMode == config::ScalingType::CAS
2801+
) {
27832802
correctedProjectionViews[eye].subImage.imageRect.offset.x = (uint32_t)std::ceil(
27842803
correctedProjectionViews[eye].subImage.imageRect.offset.x * horizontalScaleFactor);
27852804
correctedProjectionViews[eye].subImage.imageRect.offset.y = (uint32_t)std::ceil(

XR_APILAYER_MBUCCHIA_toolkit/menu.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,9 @@ namespace {
11901190
// Scaling sub-group.
11911191
{
11921192
MenuGroup upscalingGroup(this, [&] {
1193-
return getCurrentScalingType() == ScalingType::NIS || getCurrentScalingType() == ScalingType::FSR;
1193+
return getCurrentScalingType() == ScalingType::NIS
1194+
|| getCurrentScalingType() == ScalingType::FSR
1195+
|| getCurrentScalingType() == ScalingType::CAS;
11941196
});
11951197
m_menuEntries.push_back({MenuIndent::SubGroupIndent,
11961198
"Anamorphic",
@@ -1270,19 +1272,6 @@ namespace {
12701272
upscalingGroup.finalize();
12711273
}
12721274

1273-
// Sharpening Settings.
1274-
{
1275-
MenuGroup sharpeningGroup(this, [&] { return getCurrentScalingType() == ScalingType::CAS; });
1276-
m_menuEntries.push_back({MenuIndent::SubGroupIndent,
1277-
"Sharpness",
1278-
MenuEntryType::Slider,
1279-
SettingSharpness,
1280-
0,
1281-
100,
1282-
MenuEntry::FmtPercent});
1283-
sharpeningGroup.finalize();
1284-
}
1285-
12861275
// Fixed Foveated Rendering (VRS) Settings.
12871276
if (menuInfo.variableRateShaderMaxRate) {
12881277
m_menuEntries.push_back({MenuIndent::OptionIndent,

0 commit comments

Comments
 (0)