Cleanup.
This commit is contained in:
parent
7d0c5e5abc
commit
d9d0806a65
@ -87,7 +87,7 @@ namespace bgfx { namespace mtl
|
|||||||
{
|
{
|
||||||
[m_obj addScheduledHandler:^(id <MTLCommandBuffer>){ _cb(_data); }];
|
[m_obj addScheduledHandler:^(id <MTLCommandBuffer>){ _cb(_data); }];
|
||||||
}
|
}
|
||||||
|
|
||||||
void addCompletedHandler(mtlCallback _cb, void* _data)
|
void addCompletedHandler(mtlCallback _cb, void* _data)
|
||||||
{
|
{
|
||||||
[m_obj addCompletedHandler:^(id <MTLCommandBuffer>){ _cb(_data); }];
|
[m_obj addCompletedHandler:^(id <MTLCommandBuffer>){ _cb(_data); }];
|
||||||
@ -762,24 +762,24 @@ namespace bgfx { namespace mtl
|
|||||||
TextureHandle m_depthHandle;
|
TextureHandle m_depthHandle;
|
||||||
uint8_t m_num; // number of color handles
|
uint8_t m_num; // number of color handles
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TimerQueryMtl
|
struct TimerQueryMtl
|
||||||
{
|
{
|
||||||
TimerQueryMtl()
|
TimerQueryMtl()
|
||||||
: m_control(4)
|
: m_control(4)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void shutdown();
|
void shutdown();
|
||||||
void addHandlers(CommandBuffer& _commandBuffer);
|
void addHandlers(CommandBuffer& _commandBuffer);
|
||||||
bool get();
|
bool get();
|
||||||
|
|
||||||
uint64_t m_begin;
|
uint64_t m_begin;
|
||||||
uint64_t m_end;
|
uint64_t m_end;
|
||||||
uint64_t m_elapsed;
|
uint64_t m_elapsed;
|
||||||
uint64_t m_frequency;
|
uint64_t m_frequency;
|
||||||
|
|
||||||
uint64_t m_result[4*2];
|
uint64_t m_result[4*2];
|
||||||
bx::RingBufferControl m_control;
|
bx::RingBufferControl m_control;
|
||||||
};
|
};
|
||||||
|
@ -48,14 +48,14 @@ Known issues(driver problems??):
|
|||||||
- remove sync points at texture/mesh update
|
- remove sync points at texture/mesh update
|
||||||
- merge views with same fb and no fullscreen clear
|
- merge views with same fb and no fullscreen clear
|
||||||
- capture: 07-callback
|
- capture: 07-callback
|
||||||
|
|
||||||
- finish savescreenshot with screenshotbegin/end
|
- finish savescreenshot with screenshotbegin/end
|
||||||
|
|
||||||
- support multiple windows: 22-windows
|
- support multiple windows: 22-windows
|
||||||
- multithreading with multiple commandbuffer
|
- multithreading with multiple commandbuffer
|
||||||
|
|
||||||
- compute and drawindirect: 24-nbody (needs comnpute shaders)
|
- compute and drawindirect: 24-nbody (needs comnpute shaders)
|
||||||
|
|
||||||
INFO:
|
INFO:
|
||||||
- 15-shadowmaps-simple (example needs modification mtxCrop znew = z * 0.5 + 0.5 is not needed ) could be hacked in shader too
|
- 15-shadowmaps-simple (example needs modification mtxCrop znew = z * 0.5 + 0.5 is not needed ) could be hacked in shader too
|
||||||
|
|
||||||
@ -426,7 +426,7 @@ namespace bgfx { namespace mtl
|
|||||||
}
|
}
|
||||||
m_uniformBufferVertexOffset = 0;
|
m_uniformBufferVertexOffset = 0;
|
||||||
m_uniformBufferFragmentOffset = 0;
|
m_uniformBufferFragmentOffset = 0;
|
||||||
|
|
||||||
const char* vshSource =
|
const char* vshSource =
|
||||||
"using namespace metal;\n"
|
"using namespace metal;\n"
|
||||||
"struct xlatMtlShaderOutput { float4 gl_Position [[position]]; float2 v_texcoord0; }; \n"
|
"struct xlatMtlShaderOutput { float4 gl_Position [[position]]; float2 v_texcoord0; }; \n"
|
||||||
@ -921,14 +921,14 @@ namespace bgfx { namespace mtl
|
|||||||
{
|
{
|
||||||
if ( m_renderCommandEncoder )
|
if ( m_renderCommandEncoder )
|
||||||
m_renderCommandEncoder.endEncoding();
|
m_renderCommandEncoder.endEncoding();
|
||||||
|
|
||||||
RenderPassDescriptor renderPassDescriptor = newRenderPassDescriptor();
|
RenderPassDescriptor renderPassDescriptor = newRenderPassDescriptor();
|
||||||
|
|
||||||
setFrameBuffer(renderPassDescriptor, fbh);
|
setFrameBuffer(renderPassDescriptor, fbh);
|
||||||
|
|
||||||
renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionLoad;
|
renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionLoad;
|
||||||
renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore;
|
renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore;
|
||||||
|
|
||||||
rce = m_commandBuffer.renderCommandEncoderWithDescriptor(renderPassDescriptor);
|
rce = m_commandBuffer.renderCommandEncoderWithDescriptor(renderPassDescriptor);
|
||||||
m_renderCommandEncoder = rce;
|
m_renderCommandEncoder = rce;
|
||||||
m_renderCommandEncoderFrameBufferHandle = fbh;
|
m_renderCommandEncoderFrameBufferHandle = fbh;
|
||||||
@ -1048,7 +1048,7 @@ namespace bgfx { namespace mtl
|
|||||||
? 16
|
? 16
|
||||||
: 1
|
: 1
|
||||||
;
|
;
|
||||||
|
|
||||||
//TODO: there should be a way to specify if backbuffer needs stencil/depth.
|
//TODO: there should be a way to specify if backbuffer needs stencil/depth.
|
||||||
//TODO: support msaa
|
//TODO: support msaa
|
||||||
const uint32_t maskFlags = ~(0
|
const uint32_t maskFlags = ~(0
|
||||||
@ -1057,7 +1057,7 @@ namespace bgfx { namespace mtl
|
|||||||
| BGFX_RESET_DEPTH_CLAMP
|
| BGFX_RESET_DEPTH_CLAMP
|
||||||
| BGFX_RESET_SUSPEND
|
| BGFX_RESET_SUSPEND
|
||||||
);
|
);
|
||||||
|
|
||||||
if (m_resolution.m_width != _resolution.m_width
|
if (m_resolution.m_width != _resolution.m_width
|
||||||
|| m_resolution.m_height != _resolution.m_height
|
|| m_resolution.m_height != _resolution.m_height
|
||||||
|| (m_resolution.m_flags&maskFlags) != (_resolution.m_flags&maskFlags) )
|
|| (m_resolution.m_flags&maskFlags) != (_resolution.m_flags&maskFlags) )
|
||||||
@ -1067,7 +1067,7 @@ namespace bgfx { namespace mtl
|
|||||||
? MTLPixelFormatBGRA8Unorm_sRGB
|
? MTLPixelFormatBGRA8Unorm_sRGB
|
||||||
: MTLPixelFormatBGRA8Unorm
|
: MTLPixelFormatBGRA8Unorm
|
||||||
;
|
;
|
||||||
|
|
||||||
m_resolution = _resolution;
|
m_resolution = _resolution;
|
||||||
m_resolution.m_flags &= ~BGFX_RESET_INTERNAL_FORCE;
|
m_resolution.m_flags &= ~BGFX_RESET_INTERNAL_FORCE;
|
||||||
|
|
||||||
@ -1411,7 +1411,7 @@ namespace bgfx { namespace mtl
|
|||||||
retain(m_drawable); // keep alive to be useable at 'flip'
|
retain(m_drawable); // keep alive to be useable at 'flip'
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_drawable;
|
return m_drawable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2356,9 +2356,9 @@ namespace bgfx { namespace mtl
|
|||||||
{
|
{
|
||||||
m_control.consume(1);
|
m_control.consume(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t offset = m_control.m_current * 2 + 0;
|
uint32_t offset = m_control.m_current * 2 + 0;
|
||||||
|
|
||||||
_commandBuffer.addScheduledHandler(setTimestamp, &m_result[offset]);
|
_commandBuffer.addScheduledHandler(setTimestamp, &m_result[offset]);
|
||||||
_commandBuffer.addCompletedHandler(setTimestamp, &m_result[offset+1]);
|
_commandBuffer.addCompletedHandler(setTimestamp, &m_result[offset+1]);
|
||||||
m_control.commit(1);
|
m_control.commit(1);
|
||||||
@ -2372,12 +2372,12 @@ namespace bgfx { namespace mtl
|
|||||||
m_begin = m_result[offset+0];
|
m_begin = m_result[offset+0];
|
||||||
m_end = m_result[offset+1];
|
m_end = m_result[offset+1];
|
||||||
m_elapsed = m_end - m_begin;
|
m_elapsed = m_end - m_begin;
|
||||||
|
|
||||||
m_control.consume(1);
|
m_control.consume(1);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2434,10 +2434,10 @@ namespace bgfx { namespace mtl
|
|||||||
m_commandBuffer = m_commandQueue.commandBuffer();
|
m_commandBuffer = m_commandQueue.commandBuffer();
|
||||||
retain(m_commandBuffer); // keep alive to be useable at 'flip'
|
retain(m_commandBuffer); // keep alive to be useable at 'flip'
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t elapsed = -bx::getHPCounter();
|
int64_t elapsed = -bx::getHPCounter();
|
||||||
int64_t captureElapsed = 0;
|
int64_t captureElapsed = 0;
|
||||||
|
|
||||||
m_gpuTimer.addHandlers(m_commandBuffer);
|
m_gpuTimer.addHandlers(m_commandBuffer);
|
||||||
|
|
||||||
if ( m_blitCommandEncoder )
|
if ( m_blitCommandEncoder )
|
||||||
@ -2447,7 +2447,7 @@ namespace bgfx { namespace mtl
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateResolution(_render->m_resolution);
|
updateResolution(_render->m_resolution);
|
||||||
|
|
||||||
if ( m_saveScreenshot )
|
if ( m_saveScreenshot )
|
||||||
{
|
{
|
||||||
if ( m_screenshotTarget )
|
if ( m_screenshotTarget )
|
||||||
@ -3122,24 +3122,24 @@ namespace bgfx { namespace mtl
|
|||||||
|
|
||||||
int64_t now = bx::getHPCounter();
|
int64_t now = bx::getHPCounter();
|
||||||
elapsed += now;
|
elapsed += now;
|
||||||
|
|
||||||
static int64_t last = now;
|
static int64_t last = now;
|
||||||
|
|
||||||
Stats& perfStats = _render->m_perfStats;
|
Stats& perfStats = _render->m_perfStats;
|
||||||
perfStats.cpuTimeBegin = last;
|
perfStats.cpuTimeBegin = last;
|
||||||
|
|
||||||
int64_t frameTime = now - last;
|
int64_t frameTime = now - last;
|
||||||
last = now;
|
last = now;
|
||||||
|
|
||||||
static int64_t min = frameTime;
|
static int64_t min = frameTime;
|
||||||
static int64_t max = frameTime;
|
static int64_t max = frameTime;
|
||||||
min = bx::int64_min(min, frameTime);
|
min = bx::int64_min(min, frameTime);
|
||||||
max = bx::int64_max(max, frameTime);
|
max = bx::int64_max(max, frameTime);
|
||||||
|
|
||||||
static uint32_t maxGpuLatency = 0;
|
static uint32_t maxGpuLatency = 0;
|
||||||
static double maxGpuElapsed = 0.0f;
|
static double maxGpuElapsed = 0.0f;
|
||||||
double elapsedGpuMs = 0.0;
|
double elapsedGpuMs = 0.0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
double toGpuMs = 1000.0 / double(m_gpuTimer.m_frequency);
|
double toGpuMs = 1000.0 / double(m_gpuTimer.m_frequency);
|
||||||
@ -3147,11 +3147,11 @@ namespace bgfx { namespace mtl
|
|||||||
maxGpuElapsed = elapsedGpuMs > maxGpuElapsed ? elapsedGpuMs : maxGpuElapsed;
|
maxGpuElapsed = elapsedGpuMs > maxGpuElapsed ? elapsedGpuMs : maxGpuElapsed;
|
||||||
}
|
}
|
||||||
while (m_gpuTimer.get() );
|
while (m_gpuTimer.get() );
|
||||||
|
|
||||||
maxGpuLatency = bx::uint32_imax(maxGpuLatency, m_gpuTimer.m_control.available()-1);
|
maxGpuLatency = bx::uint32_imax(maxGpuLatency, m_gpuTimer.m_control.available()-1);
|
||||||
|
|
||||||
const int64_t timerFreq = bx::getHPFrequency();
|
const int64_t timerFreq = bx::getHPFrequency();
|
||||||
|
|
||||||
perfStats.cpuTimeEnd = now;
|
perfStats.cpuTimeEnd = now;
|
||||||
perfStats.cpuTimerFreq = timerFreq;
|
perfStats.cpuTimerFreq = timerFreq;
|
||||||
perfStats.gpuTimeBegin = m_gpuTimer.m_begin;
|
perfStats.gpuTimeBegin = m_gpuTimer.m_begin;
|
||||||
|
Loading…
Reference in New Issue
Block a user