flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > RDTSC Timer

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 26 Feb 2023, 19:04
Talking about games, does such precise measurement really give anything for games (well, except for increasing the system requirements unnecessarily, which, it seems, is treated by gamedevs as something to be proud of)? Will the rendered frames really differ for such small amounts of time? After all, the pixels are neither infinite in their amount, nor infinite in their size. And if/when the frames do not differ, what is the purpose of spending GPU/CPU time to redraw the same frame more frequently? Not to mention that even for frames that are slightly different the resulting video experience with large FPS is the terrible sense of crappy oversmoothness that doesn’t play well with the nature of what happens on the screen.
Post 26 Feb 2023, 19:04
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 794
Location: Adelaide
sinsi 26 Feb 2023, 20:42
It's more so the game has a "heartbeat", a consistent amount of time between actions. Try playing old DOS games on a new computer, a lot of them did their actions as fast as code would allow, on a modern computer they are unplayable because of the speed at which they run.
Post 26 Feb 2023, 20:42
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 26 Feb 2023, 21:27
Any integration across frames benefits from higher precision. Users are expecting products to operate across a dynamic range of performance characteristics. 60-300 fps, 1080p - 2160p (multiple displays) in some cases; with smooth, believable effects.

I'm getting older - can't tell any difference; but my nephew claims it effects his gameplay.
Post 26 Feb 2023, 21:27
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2565
Furs 27 Feb 2023, 12:49
I don't know. I don't particularly care about high resolutions with my 30" screen, 1080p is fine (probably because I'm getting older as well), but fps is another thing.

Obviously you'll need a 120Hz or 240Hz monitor to see its effects. But I can't go back to a standard 60Hz display anymore. It just feels sluggish in games.

It's a subconscious thing. For VR it's even more important apparently, with anything below 120Hz (and even that is cutting it close), you'll get sickness and nausea and etc.

This is especially important in games with high motion like shooting games, or others where you rotate camera fast.
Post 27 Feb 2023, 12:49
View user's profile Send private message Reply with quote
donn



Joined: 05 Mar 2010
Posts: 321
donn 27 Feb 2023, 21:44
QueryPerformanceCounter also works on Win. I didn't do any rigorous testing with it, but it worked.

https://learn.microsoft.com/en-us/windows/win32/sysinfo/acquiring-high-resolution-time-stamps
Post 27 Feb 2023, 21:44
View user's profile Send private message Reply with quote
daniel02



Joined: 21 Feb 2023
Posts: 9
daniel02 27 Feb 2023, 22:57
QueryPerformanceCounter never worked on my pc QueryPerformanceFrequency worked its return 10000000mhz

rdtsc return to 1ns so i think QueryPerformanceCounter is very slow compare to rdtsc
Post 27 Feb 2023, 22:57
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 28 Feb 2023, 07:13
daniel02 wrote:
rdtsc return to 1ns so i think QueryPerformanceCounter is very slow compare to rdtsc

Not as slow as the code that renders the graphics. And I really doubt one has at least half a billion of pixels in either direction (width/height) to see the difference between a nanosecond-perfect and 1–2-ns-off image. Additional system requirements or multiple code paths that should later be tested and maintained for no useful output. What are we chasing for?
Post 28 Feb 2023, 07:13
View user's profile Send private message Visit poster's website Reply with quote
daniel02



Joined: 21 Feb 2023
Posts: 9
daniel02 22 Apr 2023, 04:26
I wrote:


@daniel02 "jb _loop" should be jl even if the chances of wrap around are really small. There's also interrupt driven IA32_TSC_DEADLINE but maybe too much work / restrictive to impliment.



i would like to read IA32_TSC_DEADLINE in windows but seems its return to value 0 in debugview


Code:
#define IA32_APIC_BASE_MSR 0x1B
#define IA32_TSC_DEADLINE_MSR 0x6E0
#define LOCAL_APIC_LVT_TIMER_OFFSET 0x320
#define LOCAL_APIC_TIMER_MODE_MASK (1 << 17)


NTSTATUS ReadLocalApicBaseAddress(ULONG64* apic_base_address)
{
        ULONG64 ia32_apic_base = __readmsr(IA32_APIC_BASE_MSR);
        *apic_base_address = ia32_apic_base & 0xFFFFFFFFF000ULL;
        return STATUS_SUCCESS;
}

NTSTATUS MapLocalApicMmio(PVOID* apic_base_virtual, ULONG64 apic_base_address)
{
        PHYSICAL_ADDRESS apic_physical_base;
        apic_physical_base.QuadPart = apic_base_address;
        *apic_base_virtual = MmMapIoSpace(apic_physical_base, PAGE_SIZE, MmNonCached);
        return *apic_base_virtual ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
}

VOID UnmapLocalApicMmio(PVOID apic_base_virtual)
{
        MmUnmapIoSpace(apic_base_virtual, PAGE_SIZE);
}

NTSTATUS ReadTscDeadlineValue(ULONG64* tsc_deadline_value)
{
        ULONG64 apic_base_address;
        NTSTATUS status = ReadLocalApicBaseAddress(&apic_base_address);
        if (!NT_SUCCESS(status))
        {
                return status;
        }

        PVOID apic_base_virtual;
        status = MapLocalApicMmio(&apic_base_virtual, apic_base_address);
        if (!NT_SUCCESS(status))
        {
                return status;
        }

        ULONG timer_lvt = *(volatile ULONG*)((PUCHAR)apic_base_virtual + LOCAL_APIC_LVT_TIMER_OFFSET);
        if (timer_lvt & LOCAL_APIC_TIMER_MODE_MASK)
        {
                *tsc_deadline_value = __readmsr(IA32_TSC_DEADLINE_MSR);
        }
        else
        {
                status = STATUS_NOT_SUPPORTED;
        }

        UnmapLocalApicMmio(apic_base_virtual);
        return status;
}    


code to print if deadline accessible



Code:
ULONG64 tsc_deadline_value;
        status = ReadTscDeadlineValue(&tsc_deadline_value);
        if (NT_SUCCESS(status))
        {
                DbgPrint("TSC_DEADLINE value: %llu\n", tsc_deadline_value);
        }
        else
        {
                DbgPrint("Failed to read TSC_DEADLINE value, status: %08X\n", status);
        }    
Post 22 Apr 2023, 04:26
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.