RDNA3 Workaround. (#41)

This commit is contained in:
Darío 2024-06-01 14:45:50 -03:00 committed by GitHub
parent e4af592195
commit 1c9594d95b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 58 additions and 20 deletions

View File

@ -2984,6 +2984,7 @@ namespace RT64 {
capabilities.raytracing = rtSupportOption;
capabilities.raytracingStateUpdate = rtStateUpdateSupportOption;
capabilities.sampleLocations = samplePositionsOption;
description.name = win32::Utf16ToUtf8(adapterDesc.Description);
dedicatedVideoMemory = adapterDesc.DedicatedVideoMemory;
if (preferUserChoice) {
@ -3287,6 +3288,10 @@ namespace RT64 {
return capabilities;
}
const RenderDeviceDescription &D3D12Device::getDescription() const {
return description;
}
RenderSampleCounts D3D12Device::getSampleCountsSupported(RenderFormat format) const {
HRESULT res;
RenderSampleCounts countsSupported = RenderSampleCount::COUNT_0;

View File

@ -382,6 +382,7 @@ namespace RT64 {
std::unique_ptr<D3D12DescriptorHeapAllocator> colorTargetHeapAllocator;
std::unique_ptr<D3D12DescriptorHeapAllocator> depthTargetHeapAllocator;
RenderDeviceCapabilities capabilities;
RenderDeviceDescription description;
D3D12Device(D3D12Interface *renderInterface);
~D3D12Device() override;
@ -404,6 +405,7 @@ namespace RT64 {
void setTopLevelASBuildInfo(RenderTopLevelASBuildInfo &buildInfo, const RenderTopLevelASInstance *instances, uint32_t instanceCount, bool preferFastBuild, bool preferFastTrace) override;
void setShaderBindingTableInfo(RenderShaderBindingTableInfo &tableInfo, const RenderShaderBindingGroups &groups, const RenderPipeline *pipeline, RenderDescriptorSet **descriptorSets, uint32_t descriptorSetCount) override;
const RenderDeviceCapabilities &getCapabilities() const override;
const RenderDeviceDescription &getDescription() const override;
RenderSampleCounts getSampleCountsSupported(RenderFormat format) const override;
void release();
bool isValid() const;

View File

@ -16,7 +16,6 @@
# include "res/bluenoise/LDR_64_64_64_RGB1.h"
#endif
//#define TEST_RENDER_INTERFACE
//#define LOG_DISPLAY_LISTS
namespace RT64 {
@ -111,6 +110,19 @@ namespace RT64 {
}
}
# endif
// Create the application window.
const char *windowTitle = "RT64";
appWindow = std::make_unique<ApplicationWindow>();
if (core.window != RenderWindow{}) {
appWindow->setup(core.window, this, threadId);
}
else {
appWindow->setup(windowTitle, this);
}
// Detect refresh rate from the display the window is located at.
appWindow->detectRefreshRate();
// Create a render interface with the preferred backend.
switch (userConfig.graphicsAPI) {
@ -137,31 +149,36 @@ namespace RT64 {
createdGraphicsAPI = userConfig.graphicsAPI;
# ifdef TEST_RENDER_INTERFACE
// Execute a blocking test that creates a window and draws some geometry to test the render interface.
RenderInterfaceTest(renderInterface.get());
# endif
// Create the application window.
const char *windowTitle = "RT64";
appWindow = std::make_unique<ApplicationWindow>();
if (core.window != RenderWindow{}) {
appWindow->setup(core.window, this, threadId);
}
else {
appWindow->setup(windowTitle, this);
}
// Detect refresh rate from the display the window is located at.
appWindow->detectRefreshRate();
// Create the render device for the window
// Create the render device
device = renderInterface->createDevice();
if (device == nullptr) {
fprintf(stderr, "Unable to find compatible graphics device.\n");
return SetupResult::GraphicsDeviceNotFound;
}
// Driver workarounds.
//
// Wireframe artifacts have been reported when using a high-precision color format on RDNA3 GPUs in D3D12. The workaround is to switch to Vulkan if this is the case.
bool isRDNA3 = device->getDescription().name.find("AMD Radeon RX 7") != std::string::npos;
bool useHDRinD3D12 = (userConfig.graphicsAPI == UserConfiguration::GraphicsAPI::D3D12) && (userConfig.internalColorFormat == UserConfiguration::InternalColorFormat::Automatic) && device->getCapabilities().preferHDR;
if (isRDNA3 && useHDRinD3D12) {
device.reset();
renderInterface.reset();
renderInterface = CreateVulkanInterface();
if (renderInterface == nullptr) {
fprintf(stderr, "Unable to initialize graphics API.\n");
return SetupResult::GraphicsAPINotFound;
}
createdGraphicsAPI = UserConfiguration::GraphicsAPI::Vulkan;
device = renderInterface->createDevice();
if (device == nullptr) {
fprintf(stderr, "Unable to find compatible graphics device.\n");
return SetupResult::GraphicsDeviceNotFound;
}
}
// Call the init hook if one was attached.
RenderHookInit *initHook = GetRenderHookInit();
if (initHook != nullptr) {

View File

@ -208,6 +208,7 @@ namespace RT64 {
virtual void setTopLevelASBuildInfo(RenderTopLevelASBuildInfo &buildInfo, const RenderTopLevelASInstance *instances, uint32_t instanceCount, bool preferFastBuild = true, bool preferFastTrace = false) = 0;
virtual void setShaderBindingTableInfo(RenderShaderBindingTableInfo &tableInfo, const RenderShaderBindingGroups &groups, const RenderPipeline *pipeline, RenderDescriptorSet **descriptorSets, uint32_t descriptorSetCount) = 0;
virtual const RenderDeviceCapabilities &getCapabilities() const = 0;
virtual const RenderDeviceDescription &getDescription() const = 0;
virtual RenderSampleCounts getSampleCountsSupported(RenderFormat format) const = 0;
};

View File

@ -1529,6 +1529,11 @@ namespace RT64 {
RenderShaderBindingGroupsInfo groups;
};
struct RenderDeviceDescription {
std::string name = "Unknown";
uint32_t driverVersion = 0;
};
struct RenderDeviceCapabilities {
// Raytracing.
bool raytracing = false;

View File

@ -3359,6 +3359,8 @@ namespace RT64 {
bool preferOption = preferDeviceTypeScore;
if (preferOption) {
physicalDevice = physicalDevices[i];
description.name = std::string(deviceProperties.deviceName);
description.driverVersion = deviceProperties.driverVersion;
currentDeviceTypeScore = deviceTypeScore;
}
}
@ -3897,6 +3899,10 @@ namespace RT64 {
const RenderDeviceCapabilities &VulkanDevice::getCapabilities() const {
return capabilities;
}
const RenderDeviceDescription &VulkanDevice::getDescription() const {
return description;
}
RenderSampleCounts VulkanDevice::getSampleCountsSupported(RenderFormat format) const {
const bool isDepthFormat = (format == RenderFormat::D16_UNORM) || (format == RenderFormat::D32_FLOAT);

View File

@ -363,6 +363,7 @@ namespace RT64 {
uint32_t queueFamilyIndices[3] = {};
std::vector<VulkanQueueFamily> queueFamilies;
RenderDeviceCapabilities capabilities;
RenderDeviceDescription description;
VkPhysicalDeviceRayTracingPipelinePropertiesKHR rtPipelineProperties = {};
VkPhysicalDeviceSampleLocationsPropertiesEXT sampleLocationProperties = {};
bool loadStoreOpNoneSupported = false;
@ -388,6 +389,7 @@ namespace RT64 {
void setTopLevelASBuildInfo(RenderTopLevelASBuildInfo &buildInfo, const RenderTopLevelASInstance *instances, uint32_t instanceCount, bool preferFastBuild, bool preferFastTrace) override;
void setShaderBindingTableInfo(RenderShaderBindingTableInfo &tableInfo, const RenderShaderBindingGroups &groups, const RenderPipeline *pipeline, RenderDescriptorSet **descriptorSets, uint32_t descriptorSetCount) override;
const RenderDeviceCapabilities &getCapabilities() const override;
const RenderDeviceDescription &getDescription() const override;
RenderSampleCounts getSampleCountsSupported(RenderFormat format) const override;
void release();
bool isValid() const;