누군가 DirectX 11에서 다음과 같은 계산 쉐이더를 사용할 수 있는지 알려줄 수 있습니까?계산 쉐이더 : 한 스레드에서 다른 스레드로 쓰여진 데이터를 읽으시겠습니까?
버퍼 (g_positionsGrid)의 요소에 액세스하여 해당 요소를 임시 값과 설정 (비교 교환)하는 첫 번째 스레드가 어떤 조치를 취하고 있음을 나타 내기 원합니다.
이 경우 임시 값은 0xffffffff이며 첫 번째 스레드는 계속 진행하고 구조화 된 추가 버퍼 (g_positions)에서 값을 할당하고이를 해당 요소에 할당합니다.
그래도 괜찮지 만 디스패치의 다른 스레드는 비교 교환과 첫 번째 스레드의 할당 사이에 들어올 수 있으므로 할당 인덱스를 사용할 수있을 때까지 기다려야합니다. 나는 바쁜 기다림 즉 while 루프로 이것을한다.
슬프게도 이것은 첫 번째 스레드에서 작성한 값이 while 루프에 걸린 다른 스레드로 전달되지 않는다고 가정 할 때 GPU를 잠급니다.
해당 스레드에서 해당 값을 볼 수있는 방법이 있습니까?
도움 주셔서 감사합니다.
RWStructuredBuffer<float3> g_positions : register(u1);
RWBuffer<uint> g_positionsGrid : register(u2);
void AddPosition(uint address, float3 pos)
{
uint token = 0;
// Assign a temp value to signify first thread has accessed this particular element
InterlockedCompareExchange(g_positionsGrid[address], 0, 0xffffffff, token);
if(token == 0)
{
//If first thread in here allocate index and assign value which
//hopefully the other threads will pick up
uint index = g_positions.IncrementCounter();
g_positionsGrid[address] = index;
g_positions[index].m_position = pos;
}
else
{
if(token == 0xffffffff)
{
uint index = g_positionsGrid[address];
//This never meets its condition
[allow_uav_condition]
while(index == 0xffffffff)
{
//For some reason this thread never gets the assignment
//from the first thread assigned above
index = g_positionsGrid[address];
}
g_positions[index].m_position = pos;
}
else
{
//Just assign value as the first thread has already allocated a valid slot
g_positions[token].m_position = pos;
}
}
}