1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
internal void
PushRect(rectangle RenderRegion)
{
render_entry *Entry = Entries + EntryCount;
Entry->RenderRegion = RenderRegion;
__atomic_add_fetch(&EntryCount, 1, __ATOMIC_ACQ_REL);
SDL_SemPost(Semaphore);
}
internal void
AVX2_RenderLayer(transform_info TransformInfo, pixel_buffer *Buffer, rectangle RenderRegion);
internal void
Fallback_RenderLayer(transform_info TransformInfo, pixel_buffer *Buffer, rectangle RenderRegion);
internal bool32
CheckQueue(render_queue RenderInfo, uint16 Index)
{
bool32 Result = 0;
uint32 OriginalEntry = NextEntryToDo;
if (NextEntryToDo < EntryCount)
{
if (__atomic_compare_exchange_n(&NextEntryToDo, &OriginalEntry, NextEntryToDo + 1, true, __ATOMIC_RELEASE, __ATOMIC_ACQUIRE)) {
render_entry *Entry = Entries + OriginalEntry;
Assert(Entry->RenderRegion.Max.x != 0);
for (int16 i = 0; i < RenderInfo.State->NumberOfLayersToRender; i++) {
int16 Idx = RenderInfo.State->LayersToRender[i];
#if ARM
Fallback_RenderLayer(RenderInfo.File->Layer[Idx]->TransformInfo, RenderInfo.CompBuffer, Entry->RenderRegion);
// RenderLayerNeon(RenderInfo.File->Layer[Idx], RenderInfo.CompBuffer, Entry->RenderRegion);
#else
// printf("(RENDERING) Thread %i, region X%i Y%i\n", Index, Entry->RenderRegion.Min.x/240, Entry->RenderRegion.Min.y/135);
if (AVXEnabled)
AVX2_RenderLayer(RenderInfo.File->Layer[Idx]->TransformInfo, RenderInfo.CompBuffer, Entry->RenderRegion);
else
Fallback_RenderLayer(RenderInfo.File->Layer[Idx]->TransformInfo, RenderInfo.CompBuffer, Entry->RenderRegion);
#endif
}
// printf("(FINISHED) Thread %i, region X%i Y%i\n", Index, Entry->RenderRegion.Min.x/240, Entry->RenderRegion.Min.y/135);
__atomic_add_fetch(&CompletedJobs, 1, __ATOMIC_ACQ_REL);
Result = 1;
}
}
return Result;
}
internal int
TestThread(void *ptr)
{
thread_info *ThreadInfo = (thread_info *)ptr;
uint16 Index = ThreadInfo->Index;
for(;;)
{
if (!CheckQueue(*ThreadInfo->RenderInfo, Index))
{
SDL_SemWait(Semaphore);
}
}
}
|