Sync3DReceive

Demonstrates how to receive notifications of changes in 3D settings using ADLX. To receive the event, another application must be used to change these settings, such as AntiLag.

Sample Path

/Samples/C/ReceivingEventsNotifications/Sync3DReceive

Code

Copied!

//
// Copyright (c) 2021 - 2025 Advanced Micro Devices, Inc. All rights reserved.
//
//-------------------------------------------------------------------------------------------------


#include "SDK/ADLXHelper/Windows/C/ADLXHelper.h"
#include "SDK/Include/I3DSettings.h"
#include "SDK/Include/I3DSettings1.h"
#include "SDK/Include/I3DSettings2.h"
#include "conio.h"

// Block event to verify call back
HANDLE blockEvent = NULL;
HANDLE quitEvent = NULL;

// Get the GPU unique name
void GPUUniqueName(IADLXGPU* gpu, char* uniqueName);

// Call back to handle changed events
adlx_bool ADLX_STD_CALL On3DSettingsChanged(IADLX3DSettingsChangedListener *pThis, IADLX3DSettingsChangedEvent* p3DSettingsChangedEvent)
{
    // Get the GPU interface
    IADLXGPU* gpu = NULL;
    p3DSettingsChangedEvent->pVtbl->GetGPU(p3DSettingsChangedEvent, &gpu);

    IADLX3DSettingsChangedEvent1* p3DSettingsChangedEvent1 = NULL;
    p3DSettingsChangedEvent->pVtbl->QueryInterface(p3DSettingsChangedEvent, IID_IADLX3DSettingsChangedEvent1(), &p3DSettingsChangedEvent1);
    if (p3DSettingsChangedEvent1 == NULL)
    {
        printf("3DSettingsChangedEvent1 not supported\\n");
    }

    IADLX3DSettingsChangedEvent2* p3DSettingsChangedEvent2 = NULL;
    p3DSettingsChangedEvent->pVtbl->QueryInterface(p3DSettingsChangedEvent, IID_IADLX3DSettingsChangedEvent2(), &p3DSettingsChangedEvent2);
    if (p3DSettingsChangedEvent2 == NULL)
    {
        printf("3DSettingsChangedEvent2 not supported\\n");
    }

    //RadeonSuperResolution is a global feature (the GPU interface is NULL); skip printing its name
    if (!p3DSettingsChangedEvent->pVtbl->IsRadeonSuperResolutionChanged(p3DSettingsChangedEvent))
    {
        char uniqueName[128] = "Unknown";
        GPUUniqueName(gpu, uniqueName);
        printf("GPU: %s get sync event\\n", uniqueName);
    }
    ADLX_SYNC_ORIGIN  origin = p3DSettingsChangedEvent->pVtbl->GetOrigin(p3DSettingsChangedEvent);
    if (origin == SYNC_ORIGIN_EXTERNAL )
    {
        if (p3DSettingsChangedEvent->pVtbl->IsAntiLagChanged(p3DSettingsChangedEvent))
        {
            printf("\\tAnti-Lag is changed\\n");
        }
        else if (p3DSettingsChangedEvent->pVtbl->IsChillChanged(p3DSettingsChangedEvent))
        {
            printf("\\tChill is changed\\n");
        }
        else if (p3DSettingsChangedEvent->pVtbl->IsBoostChanged(p3DSettingsChangedEvent))
        {
            printf("\\tBoost is changed\\n");
        }
        else if (p3DSettingsChangedEvent->pVtbl->IsImageSharpeningChanged(p3DSettingsChangedEvent))
        {
            printf("\\tImage Sharpening is changed\\n");
        }
        else if (p3DSettingsChangedEvent->pVtbl->IsEnhancedSyncChanged(p3DSettingsChangedEvent))
        {
            printf("\\tEnhanced Sync is changed\\n");
        }
        else if (p3DSettingsChangedEvent->pVtbl->IsWaitForVerticalRefreshChanged(p3DSettingsChangedEvent))
        {
            printf("\\tWait For Vertical Refresh is changed\\n");
        }
        else if (p3DSettingsChangedEvent->pVtbl->IsFrameRateTargetControlChanged(p3DSettingsChangedEvent))
        {
            printf("\\tFRTC is changed\\n");
        }
        else if (p3DSettingsChangedEvent->pVtbl->IsAntiAliasingChanged(p3DSettingsChangedEvent))
        {
            printf("\\tAnti-Aliasing is changed\\n");
        }
        else if (p3DSettingsChangedEvent->pVtbl->IsMorphologicalAntiAliasingChanged(p3DSettingsChangedEvent))
        {
            printf("\\tMorphological Anti-Aliasing is changed\\n");
        }
        else if (p3DSettingsChangedEvent->pVtbl->IsAnisotropicFilteringChanged(p3DSettingsChangedEvent))
        {
            printf("\\tAnisotropic Filtering is changed\\n");
        }
        else if (p3DSettingsChangedEvent->pVtbl->IsTessellationModeChanged(p3DSettingsChangedEvent))
        {
            printf("\\tTessellation Mode is changed\\n");
        }
        else if (p3DSettingsChangedEvent->pVtbl->IsResetShaderCache(p3DSettingsChangedEvent))
        {
            printf("\\tResetShaderCache\\n");
        }
        else if (p3DSettingsChangedEvent2->pVtbl->IsImageSharpenDesktopChanged(p3DSettingsChangedEvent2))
        {
            printf("\\tImage Sharpening 2 is changed\\n");
        }
    }

    if (origin == SYNC_ORIGIN_UNKNOWN )
    {
        if (p3DSettingsChangedEvent->pVtbl->IsRadeonSuperResolutionChanged(p3DSettingsChangedEvent))
        {
            printf("\\tget sync event, RSR changed\\n");
        }
        else if (p3DSettingsChangedEvent1->pVtbl->IsAMDFluidMotionFramesChanged(p3DSettingsChangedEvent1))
        {
            printf("\\tAMDFluidMotionFrames changed\\n");
        }
    }

    // Release the GPU interface
    if (gpu != NULL)
    {
        gpu->pVtbl->Release(gpu);
        gpu = NULL;
    }
    // Release the IADLX3DSettingsChangedEvent1 interface
    if (p3DSettingsChangedEvent1 != NULL)
    {
        p3DSettingsChangedEvent1->pVtbl->Release(p3DSettingsChangedEvent1);
        p3DSettingsChangedEvent1 = NULL;
    }

    // Release the IADLX3DSettingsChangedEvent2 interface
    if (p3DSettingsChangedEvent2 != NULL)
    {
        p3DSettingsChangedEvent2->pVtbl->Release(p3DSettingsChangedEvent2);
        p3DSettingsChangedEvent2 = NULL;
    }

    SetEvent(blockEvent);

    // Return true for ADLX to continue notifying the next listener, or false to stop notification
    return true;
}

// Wait for quit signal
DWORD WINAPI QuitWait(LPVOID lpParam)
{
    adlx_bool* loopFlag = (adlx_bool*)lpParam;
    while (true)
    {
        // Non-blocking checking if the I/O cache has characters
        if (_kbhit())
        {
            char c;
            if ((c = getchar()) == 'q' || c == 'Q')
            {
                *loopFlag = false;
                SetEvent(quitEvent);
                break;
            }
        }
        Sleep(100);
    }
    return 0;
}

static IADLX3DSettingsChangedListenerVtbl vtbl = {&On3DSettingsChanged};
static IADLX3DSettingsChangedListener eventListener = {&vtbl};

int main()
{
    // Define return code
    ADLX_RESULT  res = ADLX_FAIL ;

    // Initialize ADLX
    res = ADLXHelper_Initialize();
    if (ADLX_SUCCEEDED (res))
    {
        // Create block event
        blockEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
        // Create quit event
        quitEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
        // Create event array
        HANDLE eventArray[] = { blockEvent, quitEvent };

        // Get the System Services interface
        IADLXSystem *sys = ADLXHelper_GetSystemServices();

        // Get the 3D Settings Service interface
        IADLX3DSettingsServices *d3dSettingSrv = NULL;
        res = sys->pVtbl->Get3DSettingsServices(sys, &d3dSettingSrv);

        if (ADLX_SUCCEEDED (res))
        {
            // Get the Change Handle interface
            IADLX3DSettingsChangedHandling *changeHandle = NULL;;
            res = d3dSettingSrv->pVtbl->Get3DSettingsChangedHandling(d3dSettingSrv, &changeHandle);
            if (ADLX_SUCCEEDED (res))
            {
                // Add call back
                changeHandle->pVtbl->Add3DSettingsEventListener(changeHandle, &eventListener);

                // Create a thread to detect quit input
                adlx_bool loopFlag = true;
                DWORD threadId = 0;
                HANDLE hThread = CreateThread(NULL, 0, QuitWait, &loopFlag, 0, &threadId);

                printf("\\nWaiting for 3DSetting change event... Press Q/q to quit\\n");
                while (true)
                {
                    // Wait for change event or request to quit
                    DWORD waitRet = WaitForMultipleObjects(2, eventArray, FALSE, INFINITE);
                    if (!loopFlag)
                    {
                        CloseHandle(hThread);
                        break;
                    }
                    ResetEvent(blockEvent);
                }

                // Remove call back
                changeHandle->pVtbl->Remove3DSettingsEventListener(changeHandle, &eventListener);
            }
            // Release the Change Handle interface
            if (changeHandle != NULL)
            {
                changeHandle->pVtbl->Release(changeHandle);
                changeHandle = NULL;
            }
            // Release the 3DSettings Services interface
            if (d3dSettingSrv != NULL)
            {
                d3dSettingSrv->pVtbl->Release(d3dSettingSrv);
                d3dSettingSrv = NULL;
            }
        }
        else
        {
            printf("Failed to get 3DSettings Services\\n");
        }
    }
    else
    {
        printf("ADLX initialization failed\\n");
        return 0;
    }

    // Destroy ADLX
    res = ADLXHelper_Terminate();
    printf("Destroy ADLX res: %d\\n", res);

    // Close event
    if (blockEvent)
        CloseHandle(blockEvent);
    if (quitEvent)
        CloseHandle(quitEvent);

    // Pause to see the print out
    system("pause");

    return 0;
}

void GPUUniqueName(IADLXGPU* gpu, char* uniqueName)
{
    if (NULL != gpu && NULL != uniqueName)
    {
        const char* gpuName = NULL;
        gpu->pVtbl->Name(gpu, &gpuName);
        adlx_int id;
        gpu->pVtbl->UniqueId(gpu, &id);
        sprintf_s(uniqueName, 128, "name:%s, id:%d", gpuName, id);
    }
}

Related pages

  • Visit the Adlx product page for download links and more information.

Looking for more documentation on GPUOpen?

AMD GPUOpen software blogs

Our handy software release blogs will help you make good use of our tools, SDKs, and effects, as well as sharing the latest features with new releases.

GPUOpen Manuals

Don’t miss our manual documentation! And if slide decks are what you’re after, you’ll find 100+ of our finest presentations here.

AMD GPUOpen Performance Guides

The home of great performance and optimization advice for AMD RDNA™ 2 GPUs, AMD Ryzen™ CPUs, and so much more.

Getting started: AMD GPUOpen software

New or fairly new to AMD’s tools, libraries, and effects? This is the best place to get started on GPUOpen!

AMD GPUOpen Getting Started Development and Performance

Looking for tips on getting started with developing and/or optimizing your game, whether on AMD hardware or generally? We’ve got you covered!

AMD GPUOpen Technical blogs

Browse our technical blogs, and find valuable advice on developing with AMD hardware, ray tracing, Vulkan®, DirectX®, Unreal Engine, and lots more.

Find out more about our software!

AMD GPUOpen Effects - AMD FidelityFX technologies

Create wonder. No black boxes. Meet the AMD FidelityFX SDK!

AMD GPUOpen Samples

Browse all our useful samples. Perfect for when you’re needing to get started, want to integrate one of our libraries, and much more.

AMD GPUOpen developer SDKs

Discover what our SDK technologies can offer you. Query hardware or software, manage memory, create rendering applications or machine learning, and much more!

AMD GPUOpen Developer Tools

Analyze, Optimize, Profile, Benchmark. We provide you with the developer tools you need to make sure your game is the best it can be!