Member rename: src/backend/metal
This commit is contained in:
parent
e00385af73
commit
b0c75a5b68
|
@ -40,7 +40,7 @@ namespace metal {
|
|||
void UnmapImpl() override;
|
||||
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) override;
|
||||
|
||||
id<MTLBuffer> mtlBuffer = nil;
|
||||
id<MTLBuffer> mMtlBuffer = nil;
|
||||
};
|
||||
|
||||
class BufferView : public BufferViewBase {
|
||||
|
@ -57,14 +57,14 @@ namespace metal {
|
|||
void Tick(Serial finishedSerial);
|
||||
|
||||
private:
|
||||
Device* device;
|
||||
Device* mDevice;
|
||||
|
||||
struct Request {
|
||||
Ref<Buffer> buffer;
|
||||
uint32_t mapSerial;
|
||||
uint32_t offset;
|
||||
};
|
||||
SerialQueue<Request> inflightRequests;
|
||||
SerialQueue<Request> mInflightRequests;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -30,27 +30,27 @@ namespace metal {
|
|||
storageMode = MTLResourceStorageModePrivate;
|
||||
}
|
||||
|
||||
mtlBuffer = [ToBackend(GetDevice())->GetMTLDevice() newBufferWithLength:GetSize()
|
||||
mMtlBuffer = [ToBackend(GetDevice())->GetMTLDevice() newBufferWithLength:GetSize()
|
||||
options:storageMode];
|
||||
}
|
||||
|
||||
Buffer::~Buffer() {
|
||||
[mtlBuffer release];
|
||||
mtlBuffer = nil;
|
||||
[mMtlBuffer release];
|
||||
mMtlBuffer = nil;
|
||||
}
|
||||
|
||||
id<MTLBuffer> Buffer::GetMTLBuffer() {
|
||||
return mtlBuffer;
|
||||
return mMtlBuffer;
|
||||
}
|
||||
|
||||
void Buffer::OnMapReadCommandSerialFinished(uint32_t mapSerial, uint32_t offset) {
|
||||
const char* data = reinterpret_cast<const char*>([mtlBuffer contents]);
|
||||
const char* data = reinterpret_cast<const char*>([mMtlBuffer contents]);
|
||||
CallMapReadCallback(mapSerial, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, data + offset);
|
||||
}
|
||||
|
||||
void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) {
|
||||
auto* uploader = ToBackend(GetDevice())->GetResourceUploader();
|
||||
uploader->BufferSubData(mtlBuffer, start * sizeof(uint32_t), count * sizeof(uint32_t), data);
|
||||
uploader->BufferSubData(mMtlBuffer, start * sizeof(uint32_t), count * sizeof(uint32_t), data);
|
||||
}
|
||||
|
||||
void Buffer::MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t) {
|
||||
|
@ -70,11 +70,11 @@ namespace metal {
|
|||
}
|
||||
|
||||
MapReadRequestTracker::MapReadRequestTracker(Device* device)
|
||||
: device(device) {
|
||||
: mDevice(device) {
|
||||
}
|
||||
|
||||
MapReadRequestTracker::~MapReadRequestTracker() {
|
||||
ASSERT(inflightRequests.Empty());
|
||||
ASSERT(mInflightRequests.Empty());
|
||||
}
|
||||
|
||||
void MapReadRequestTracker::Track(Buffer* buffer, uint32_t mapSerial, uint32_t offset) {
|
||||
|
@ -83,14 +83,14 @@ namespace metal {
|
|||
request.mapSerial = mapSerial;
|
||||
request.offset = offset;
|
||||
|
||||
inflightRequests.Enqueue(std::move(request), device->GetPendingCommandSerial());
|
||||
mInflightRequests.Enqueue(std::move(request), mDevice->GetPendingCommandSerial());
|
||||
}
|
||||
|
||||
void MapReadRequestTracker::Tick(Serial finishedSerial) {
|
||||
for (auto& request : inflightRequests.IterateUpTo(finishedSerial)) {
|
||||
for (auto& request : mInflightRequests.IterateUpTo(finishedSerial)) {
|
||||
request.buffer->OnMapReadCommandSerialFinished(request.mapSerial, request.offset);
|
||||
}
|
||||
inflightRequests.ClearUpTo(finishedSerial);
|
||||
mInflightRequests.ClearUpTo(finishedSerial);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@ namespace metal {
|
|||
void FillCommands(id<MTLCommandBuffer> commandBuffer);
|
||||
|
||||
private:
|
||||
Device* device;
|
||||
CommandIterator commands;
|
||||
Device* mDevice;
|
||||
CommandIterator mCommands;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -149,12 +149,12 @@ namespace metal {
|
|||
}
|
||||
|
||||
CommandBuffer::CommandBuffer(CommandBufferBuilder* builder)
|
||||
: CommandBufferBase(builder), device(ToBackend(builder->GetDevice())),
|
||||
commands(builder->AcquireCommands()) {
|
||||
: CommandBufferBase(builder), mDevice(ToBackend(builder->GetDevice())),
|
||||
mCommands(builder->AcquireCommands()) {
|
||||
}
|
||||
|
||||
CommandBuffer::~CommandBuffer() {
|
||||
FreeCommands(&commands);
|
||||
FreeCommands(&mCommands);
|
||||
}
|
||||
|
||||
void CommandBuffer::FillCommands(id<MTLCommandBuffer> commandBuffer) {
|
||||
|
@ -165,16 +165,16 @@ namespace metal {
|
|||
uint32_t indexBufferOffset = 0;
|
||||
|
||||
CurrentEncoders encoders;
|
||||
encoders.device = device;
|
||||
encoders.device = mDevice;
|
||||
|
||||
PerStage<std::array<uint32_t, kMaxPushConstants>> pushConstants;
|
||||
|
||||
uint32_t currentSubpass = 0;
|
||||
while (commands.NextCommandId(&type)) {
|
||||
while (mCommands.NextCommandId(&type)) {
|
||||
switch (type) {
|
||||
case Command::BeginComputePass:
|
||||
{
|
||||
commands.NextCommand<BeginComputePassCmd>();
|
||||
mCommands.NextCommand<BeginComputePassCmd>();
|
||||
encoders.BeginCompute(commandBuffer);
|
||||
|
||||
pushConstants[nxt::ShaderStage::Compute].fill(0);
|
||||
|
@ -186,7 +186,7 @@ namespace metal {
|
|||
|
||||
case Command::BeginRenderPass:
|
||||
{
|
||||
BeginRenderPassCmd* beginRenderPassCmd = commands.NextCommand<BeginRenderPassCmd>();
|
||||
BeginRenderPassCmd* beginRenderPassCmd = mCommands.NextCommand<BeginRenderPassCmd>();
|
||||
encoders.currentRenderPass = ToBackend(beginRenderPassCmd->renderPass.Get());
|
||||
encoders.currentFramebuffer = ToBackend(beginRenderPassCmd->framebuffer.Get());
|
||||
encoders.EnsureNoBlitEncoder();
|
||||
|
@ -196,7 +196,7 @@ namespace metal {
|
|||
|
||||
case Command::BeginRenderSubpass:
|
||||
{
|
||||
commands.NextCommand<BeginRenderSubpassCmd>();
|
||||
mCommands.NextCommand<BeginRenderSubpassCmd>();
|
||||
encoders.BeginSubpass(commandBuffer, currentSubpass);
|
||||
|
||||
pushConstants[nxt::ShaderStage::Vertex].fill(0);
|
||||
|
@ -213,7 +213,7 @@ namespace metal {
|
|||
|
||||
case Command::CopyBufferToBuffer:
|
||||
{
|
||||
CopyBufferToBufferCmd* copy = commands.NextCommand<CopyBufferToBufferCmd>();
|
||||
CopyBufferToBufferCmd* copy = mCommands.NextCommand<CopyBufferToBufferCmd>();
|
||||
auto& src = copy->source;
|
||||
auto& dst = copy->destination;
|
||||
|
||||
|
@ -229,7 +229,7 @@ namespace metal {
|
|||
|
||||
case Command::CopyBufferToTexture:
|
||||
{
|
||||
CopyBufferToTextureCmd* copy = commands.NextCommand<CopyBufferToTextureCmd>();
|
||||
CopyBufferToTextureCmd* copy = mCommands.NextCommand<CopyBufferToTextureCmd>();
|
||||
auto& src = copy->source;
|
||||
auto& dst = copy->destination;
|
||||
Buffer* buffer = ToBackend(src.buffer.Get());
|
||||
|
@ -261,7 +261,7 @@ namespace metal {
|
|||
|
||||
case Command::CopyTextureToBuffer:
|
||||
{
|
||||
CopyTextureToBufferCmd* copy = commands.NextCommand<CopyTextureToBufferCmd>();
|
||||
CopyTextureToBufferCmd* copy = mCommands.NextCommand<CopyTextureToBufferCmd>();
|
||||
auto& src = copy->source;
|
||||
auto& dst = copy->destination;
|
||||
Texture* texture = ToBackend(src.texture.Get());
|
||||
|
@ -293,7 +293,7 @@ namespace metal {
|
|||
|
||||
case Command::Dispatch:
|
||||
{
|
||||
DispatchCmd* dispatch = commands.NextCommand<DispatchCmd>();
|
||||
DispatchCmd* dispatch = mCommands.NextCommand<DispatchCmd>();
|
||||
ASSERT(encoders.compute);
|
||||
|
||||
[encoders.compute dispatchThreadgroups:MTLSizeMake(dispatch->x, dispatch->y, dispatch->z)
|
||||
|
@ -303,7 +303,7 @@ namespace metal {
|
|||
|
||||
case Command::DrawArrays:
|
||||
{
|
||||
DrawArraysCmd* draw = commands.NextCommand<DrawArraysCmd>();
|
||||
DrawArraysCmd* draw = mCommands.NextCommand<DrawArraysCmd>();
|
||||
|
||||
ASSERT(encoders.render);
|
||||
[encoders.render
|
||||
|
@ -317,7 +317,7 @@ namespace metal {
|
|||
|
||||
case Command::DrawElements:
|
||||
{
|
||||
DrawElementsCmd* draw = commands.NextCommand<DrawElementsCmd>();
|
||||
DrawElementsCmd* draw = mCommands.NextCommand<DrawElementsCmd>();
|
||||
|
||||
ASSERT(encoders.render);
|
||||
[encoders.render
|
||||
|
@ -334,20 +334,20 @@ namespace metal {
|
|||
|
||||
case Command::EndComputePass:
|
||||
{
|
||||
commands.NextCommand<EndComputePassCmd>();
|
||||
mCommands.NextCommand<EndComputePassCmd>();
|
||||
encoders.EndCompute();
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::EndRenderPass:
|
||||
{
|
||||
commands.NextCommand<EndRenderPassCmd>();
|
||||
mCommands.NextCommand<EndRenderPassCmd>();
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::EndRenderSubpass:
|
||||
{
|
||||
commands.NextCommand<EndRenderSubpassCmd>();
|
||||
mCommands.NextCommand<EndRenderSubpassCmd>();
|
||||
encoders.EndSubpass();
|
||||
currentSubpass += 1;
|
||||
}
|
||||
|
@ -355,7 +355,7 @@ namespace metal {
|
|||
|
||||
case Command::SetComputePipeline:
|
||||
{
|
||||
SetComputePipelineCmd* cmd = commands.NextCommand<SetComputePipelineCmd>();
|
||||
SetComputePipelineCmd* cmd = mCommands.NextCommand<SetComputePipelineCmd>();
|
||||
lastComputePipeline = ToBackend(cmd->pipeline).Get();
|
||||
|
||||
ASSERT(encoders.compute);
|
||||
|
@ -365,7 +365,7 @@ namespace metal {
|
|||
|
||||
case Command::SetRenderPipeline:
|
||||
{
|
||||
SetRenderPipelineCmd* cmd = commands.NextCommand<SetRenderPipelineCmd>();
|
||||
SetRenderPipelineCmd* cmd = mCommands.NextCommand<SetRenderPipelineCmd>();
|
||||
lastRenderPipeline = ToBackend(cmd->pipeline).Get();
|
||||
|
||||
ASSERT(encoders.render);
|
||||
|
@ -377,8 +377,8 @@ namespace metal {
|
|||
|
||||
case Command::SetPushConstants:
|
||||
{
|
||||
SetPushConstantsCmd* cmd = commands.NextCommand<SetPushConstantsCmd>();
|
||||
uint32_t* values = commands.NextData<uint32_t>(cmd->count);
|
||||
SetPushConstantsCmd* cmd = mCommands.NextCommand<SetPushConstantsCmd>();
|
||||
uint32_t* values = mCommands.NextData<uint32_t>(cmd->count);
|
||||
|
||||
for (auto stage : IterateStages(cmd->stages)) {
|
||||
memcpy(&pushConstants[stage][cmd->offset], values, cmd->count * sizeof(uint32_t));
|
||||
|
@ -412,7 +412,7 @@ namespace metal {
|
|||
|
||||
case Command::SetStencilReference:
|
||||
{
|
||||
SetStencilReferenceCmd* cmd = commands.NextCommand<SetStencilReferenceCmd>();
|
||||
SetStencilReferenceCmd* cmd = mCommands.NextCommand<SetStencilReferenceCmd>();
|
||||
|
||||
ASSERT(encoders.render);
|
||||
|
||||
|
@ -422,7 +422,7 @@ namespace metal {
|
|||
|
||||
case Command::SetBlendColor:
|
||||
{
|
||||
SetBlendColorCmd* cmd = commands.NextCommand<SetBlendColorCmd>();
|
||||
SetBlendColorCmd* cmd = mCommands.NextCommand<SetBlendColorCmd>();
|
||||
|
||||
ASSERT(encoders.render);
|
||||
|
||||
|
@ -436,7 +436,7 @@ namespace metal {
|
|||
|
||||
case Command::SetBindGroup:
|
||||
{
|
||||
SetBindGroupCmd* cmd = commands.NextCommand<SetBindGroupCmd>();
|
||||
SetBindGroupCmd* cmd = mCommands.NextCommand<SetBindGroupCmd>();
|
||||
BindGroup* group = ToBackend(cmd->group.Get());
|
||||
uint32_t groupIndex = cmd->index;
|
||||
|
||||
|
@ -550,7 +550,7 @@ namespace metal {
|
|||
|
||||
case Command::SetIndexBuffer:
|
||||
{
|
||||
SetIndexBufferCmd* cmd = commands.NextCommand<SetIndexBufferCmd>();
|
||||
SetIndexBufferCmd* cmd = mCommands.NextCommand<SetIndexBufferCmd>();
|
||||
auto b = ToBackend(cmd->buffer.Get());
|
||||
indexBuffer = b->GetMTLBuffer();
|
||||
indexBufferOffset = cmd->offset;
|
||||
|
@ -559,9 +559,9 @@ namespace metal {
|
|||
|
||||
case Command::SetVertexBuffers:
|
||||
{
|
||||
SetVertexBuffersCmd* cmd = commands.NextCommand<SetVertexBuffersCmd>();
|
||||
auto buffers = commands.NextData<Ref<BufferBase>>(cmd->count);
|
||||
auto offsets = commands.NextData<uint32_t>(cmd->count);
|
||||
SetVertexBuffersCmd* cmd = mCommands.NextCommand<SetVertexBuffersCmd>();
|
||||
auto buffers = mCommands.NextData<Ref<BufferBase>>(cmd->count);
|
||||
auto offsets = mCommands.NextData<uint32_t>(cmd->count);
|
||||
|
||||
std::array<id<MTLBuffer>, kMaxVertexInputs> mtlBuffers;
|
||||
std::array<NSUInteger, kMaxVertexInputs> mtlOffsets;
|
||||
|
@ -584,7 +584,7 @@ namespace metal {
|
|||
|
||||
case Command::TransitionBufferUsage:
|
||||
{
|
||||
TransitionBufferUsageCmd* cmd = commands.NextCommand<TransitionBufferUsageCmd>();
|
||||
TransitionBufferUsageCmd* cmd = mCommands.NextCommand<TransitionBufferUsageCmd>();
|
||||
|
||||
cmd->buffer->UpdateUsageInternal(cmd->usage);
|
||||
}
|
||||
|
@ -592,7 +592,7 @@ namespace metal {
|
|||
|
||||
case Command::TransitionTextureUsage:
|
||||
{
|
||||
TransitionTextureUsageCmd* cmd = commands.NextCommand<TransitionTextureUsageCmd>();
|
||||
TransitionTextureUsageCmd* cmd = mCommands.NextCommand<TransitionTextureUsageCmd>();
|
||||
|
||||
cmd->texture->UpdateUsageInternal(cmd->usage);
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ namespace metal {
|
|||
MTLSize GetLocalWorkGroupSize() const;
|
||||
|
||||
private:
|
||||
id<MTLComputePipelineState> mtlComputePipelineState = nil;
|
||||
MTLSize localWorkgroupSize;
|
||||
id<MTLComputePipelineState> mMtlComputePipelineState = nil;
|
||||
MTLSize mLocalWorkgroupSize;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace metal {
|
|||
auto compilationData = module->GetFunction(entryPoint.c_str(), ToBackend(GetLayout()));
|
||||
|
||||
NSError *error = nil;
|
||||
mtlComputePipelineState = [mtlDevice
|
||||
mMtlComputePipelineState = [mtlDevice
|
||||
newComputePipelineStateWithFunction:compilationData.function error:&error];
|
||||
if (error != nil) {
|
||||
NSLog(@" error => %@", error);
|
||||
|
@ -40,19 +40,19 @@ namespace metal {
|
|||
}
|
||||
|
||||
// Copy over the local workgroup size as it is passed to dispatch explicitly in Metal
|
||||
localWorkgroupSize = compilationData.localWorkgroupSize;
|
||||
mLocalWorkgroupSize = compilationData.localWorkgroupSize;
|
||||
}
|
||||
|
||||
ComputePipeline::~ComputePipeline() {
|
||||
[mtlComputePipelineState release];
|
||||
[mMtlComputePipelineState release];
|
||||
}
|
||||
|
||||
void ComputePipeline::Encode(id<MTLComputeCommandEncoder> encoder) {
|
||||
[encoder setComputePipelineState:mtlComputePipelineState];
|
||||
[encoder setComputePipelineState:mMtlComputePipelineState];
|
||||
}
|
||||
|
||||
MTLSize ComputePipeline::GetLocalWorkGroupSize() const {
|
||||
return localWorkgroupSize;
|
||||
return mLocalWorkgroupSize;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace metal {
|
|||
id<MTLDepthStencilState> GetMTLDepthStencilState();
|
||||
|
||||
private:
|
||||
id<MTLDepthStencilState> mtlDepthStencilState = nil;
|
||||
id<MTLDepthStencilState> mMtlDepthStencilState = nil;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -97,17 +97,17 @@ namespace metal {
|
|||
}
|
||||
|
||||
auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice();
|
||||
mtlDepthStencilState = [mtlDevice newDepthStencilStateWithDescriptor:mtlDepthStencilDescriptor];
|
||||
mMtlDepthStencilState = [mtlDevice newDepthStencilStateWithDescriptor:mtlDepthStencilDescriptor];
|
||||
[mtlDepthStencilDescriptor release];
|
||||
}
|
||||
|
||||
DepthStencilState::~DepthStencilState() {
|
||||
[mtlDepthStencilState release];
|
||||
mtlDepthStencilState = nil;
|
||||
[mMtlDepthStencilState release];
|
||||
mMtlDepthStencilState = nil;
|
||||
}
|
||||
|
||||
id<MTLDepthStencilState> DepthStencilState::GetMTLDepthStencilState() {
|
||||
return mtlDepthStencilState;
|
||||
return mMtlDepthStencilState;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace metal {
|
|||
MTLVertexDescriptor* GetMTLVertexDescriptor();
|
||||
|
||||
private:
|
||||
MTLVertexDescriptor* mtlVertexDescriptor = nil;
|
||||
MTLVertexDescriptor* mMtlVertexDescriptor = nil;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace metal {
|
|||
|
||||
InputState::InputState(InputStateBuilder* builder)
|
||||
: InputStateBase(builder) {
|
||||
mtlVertexDescriptor = [MTLVertexDescriptor new];
|
||||
mMtlVertexDescriptor = [MTLVertexDescriptor new];
|
||||
|
||||
const auto& attributesSetMask = GetAttributesSetMask();
|
||||
for (uint32_t i = 0; i < attributesSetMask.size(); ++i) {
|
||||
|
@ -59,7 +59,7 @@ namespace metal {
|
|||
attribDesc.format = VertexFormatType(info.format);
|
||||
attribDesc.offset = info.offset;
|
||||
attribDesc.bufferIndex = kMaxBindingsPerGroup + info.bindingSlot;
|
||||
mtlVertexDescriptor.attributes[i] = attribDesc;
|
||||
mMtlVertexDescriptor.attributes[i] = attribDesc;
|
||||
[attribDesc release];
|
||||
}
|
||||
|
||||
|
@ -81,18 +81,18 @@ namespace metal {
|
|||
layoutDesc.stride = info.stride;
|
||||
}
|
||||
// TODO(cwallez@chromium.org): make the offset depend on the pipeline layout
|
||||
mtlVertexDescriptor.layouts[kMaxBindingsPerGroup + i] = layoutDesc;
|
||||
mMtlVertexDescriptor.layouts[kMaxBindingsPerGroup + i] = layoutDesc;
|
||||
[layoutDesc release];
|
||||
}
|
||||
}
|
||||
|
||||
InputState::~InputState() {
|
||||
[mtlVertexDescriptor release];
|
||||
mtlVertexDescriptor = nil;
|
||||
[mMtlVertexDescriptor release];
|
||||
mMtlVertexDescriptor = nil;
|
||||
}
|
||||
|
||||
MTLVertexDescriptor* InputState::GetMTLVertexDescriptor() {
|
||||
return mtlVertexDescriptor;
|
||||
return mMtlVertexDescriptor;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -124,14 +124,14 @@ namespace metal {
|
|||
private:
|
||||
void OnCompletedHandler();
|
||||
|
||||
id<MTLDevice> mtlDevice = nil;
|
||||
id<MTLCommandQueue> commandQueue = nil;
|
||||
MapReadRequestTracker* mapReadTracker;
|
||||
ResourceUploader* resourceUploader;
|
||||
id<MTLDevice> mMtlDevice = nil;
|
||||
id<MTLCommandQueue> mCommandQueue = nil;
|
||||
MapReadRequestTracker* mMapReadTracker;
|
||||
ResourceUploader* mResourceUploader;
|
||||
|
||||
Serial finishedCommandSerial = 0;
|
||||
Serial pendingCommandSerial = 1;
|
||||
id<MTLCommandBuffer> pendingCommands = nil;
|
||||
Serial mFinishedCommandSerial = 0;
|
||||
Serial mPendingCommandSerial = 1;
|
||||
id<MTLCommandBuffer> mPendingCommands = nil;
|
||||
};
|
||||
|
||||
class BindGroup : public BindGroupBase {
|
||||
|
@ -161,7 +161,7 @@ namespace metal {
|
|||
void Submit(uint32_t numCommands, CommandBuffer* const * commands);
|
||||
|
||||
private:
|
||||
id<MTLCommandQueue> commandQueue = nil;
|
||||
id<MTLCommandQueue> mCommandQueue = nil;
|
||||
};
|
||||
|
||||
class RenderPass : public RenderPassBase {
|
||||
|
|
|
@ -45,10 +45,10 @@ namespace metal {
|
|||
// Device
|
||||
|
||||
Device::Device(id<MTLDevice> mtlDevice)
|
||||
: mtlDevice(mtlDevice), mapReadTracker(new MapReadRequestTracker(this)),
|
||||
resourceUploader(new ResourceUploader(this)) {
|
||||
[mtlDevice retain];
|
||||
commandQueue = [mtlDevice newCommandQueue];
|
||||
: mMtlDevice(mtlDevice), mMapReadTracker(new MapReadRequestTracker(this)),
|
||||
mResourceUploader(new ResourceUploader(this)) {
|
||||
[mMtlDevice retain];
|
||||
mCommandQueue = [mMtlDevice newCommandQueue];
|
||||
}
|
||||
|
||||
Device::~Device() {
|
||||
|
@ -58,25 +58,25 @@ namespace metal {
|
|||
// SubmitPendingCommandBuffer then wait for it to be passed. Instead we submit and
|
||||
// wait for the serial before the next pendingCommandSerial.
|
||||
SubmitPendingCommandBuffer();
|
||||
while (finishedCommandSerial != pendingCommandSerial - 1) {
|
||||
while (mFinishedCommandSerial != mPendingCommandSerial - 1) {
|
||||
usleep(100);
|
||||
}
|
||||
Tick();
|
||||
|
||||
[pendingCommands release];
|
||||
pendingCommands = nil;
|
||||
[mPendingCommands release];
|
||||
mPendingCommands = nil;
|
||||
|
||||
delete mapReadTracker;
|
||||
mapReadTracker = nullptr;
|
||||
delete mMapReadTracker;
|
||||
mMapReadTracker = nullptr;
|
||||
|
||||
delete resourceUploader;
|
||||
resourceUploader = nullptr;
|
||||
delete mResourceUploader;
|
||||
mResourceUploader = nullptr;
|
||||
|
||||
[mtlDevice release];
|
||||
mtlDevice = nil;
|
||||
[mMtlDevice release];
|
||||
mMtlDevice = nil;
|
||||
|
||||
[commandQueue release];
|
||||
commandQueue = nil;
|
||||
[mCommandQueue release];
|
||||
mCommandQueue = nil;
|
||||
}
|
||||
|
||||
BindGroupBase* Device::CreateBindGroup(BindGroupBuilder* builder) {
|
||||
|
@ -138,8 +138,8 @@ namespace metal {
|
|||
}
|
||||
|
||||
void Device::TickImpl() {
|
||||
resourceUploader->Tick(finishedCommandSerial);
|
||||
mapReadTracker->Tick(finishedCommandSerial);
|
||||
mResourceUploader->Tick(mFinishedCommandSerial);
|
||||
mMapReadTracker->Tick(mFinishedCommandSerial);
|
||||
|
||||
// Code above might have added GPU work, submit it. This also makes sure
|
||||
// that even when no GPU work is happening, the serial number keeps incrementing.
|
||||
|
@ -147,34 +147,34 @@ namespace metal {
|
|||
}
|
||||
|
||||
id<MTLDevice> Device::GetMTLDevice() {
|
||||
return mtlDevice;
|
||||
return mMtlDevice;
|
||||
}
|
||||
|
||||
id<MTLCommandBuffer> Device::GetPendingCommandBuffer() {
|
||||
if (pendingCommands == nil) {
|
||||
pendingCommands = [commandQueue commandBuffer];
|
||||
[pendingCommands retain];
|
||||
if (mPendingCommands == nil) {
|
||||
mPendingCommands = [mCommandQueue commandBuffer];
|
||||
[mPendingCommands retain];
|
||||
}
|
||||
return pendingCommands;
|
||||
return mPendingCommands;
|
||||
}
|
||||
|
||||
void Device::SubmitPendingCommandBuffer() {
|
||||
if (pendingCommands == nil) {
|
||||
if (mPendingCommands == nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ok, ObjC blocks are weird. My understanding is that local variables are captured by value
|
||||
// so this-> works as expected. However it is unclear how members are captured, (are they
|
||||
// captured using this-> or by value?) so we make a copy of the pendingCommandSerial on the stack.
|
||||
Serial pendingSerial = pendingCommandSerial;
|
||||
[pendingCommands addCompletedHandler:^(id<MTLCommandBuffer>) {
|
||||
this->finishedCommandSerial = pendingSerial;
|
||||
Serial pendingSerial = mPendingCommandSerial;
|
||||
[mPendingCommands addCompletedHandler:^(id<MTLCommandBuffer>) {
|
||||
this->mFinishedCommandSerial = pendingSerial;
|
||||
}];
|
||||
|
||||
[pendingCommands commit];
|
||||
[pendingCommands release];
|
||||
pendingCommands = nil;
|
||||
pendingCommandSerial ++;
|
||||
[mPendingCommands commit];
|
||||
[mPendingCommands release];
|
||||
mPendingCommands = nil;
|
||||
mPendingCommandSerial ++;
|
||||
}
|
||||
|
||||
uint64_t Device::GetPendingCommandSerial() {
|
||||
|
@ -183,15 +183,15 @@ namespace metal {
|
|||
// enqueued on the next Tick() and eventually increments the serial. Otherwise if no GPU work
|
||||
// happens we could be waiting for this serial forever.
|
||||
GetPendingCommandBuffer();
|
||||
return pendingCommandSerial;
|
||||
return mPendingCommandSerial;
|
||||
}
|
||||
|
||||
MapReadRequestTracker* Device::GetMapReadTracker() const {
|
||||
return mapReadTracker;
|
||||
return mMapReadTracker;
|
||||
}
|
||||
|
||||
ResourceUploader* Device::GetResourceUploader() const {
|
||||
return resourceUploader;
|
||||
return mResourceUploader;
|
||||
}
|
||||
|
||||
// Bind Group
|
||||
|
@ -220,16 +220,16 @@ namespace metal {
|
|||
Queue::Queue(QueueBuilder* builder)
|
||||
: QueueBase(builder) {
|
||||
Device* device = ToBackend(builder->GetDevice());
|
||||
commandQueue = [device->GetMTLDevice() newCommandQueue];
|
||||
mCommandQueue = [device->GetMTLDevice() newCommandQueue];
|
||||
}
|
||||
|
||||
Queue::~Queue() {
|
||||
[commandQueue release];
|
||||
commandQueue = nil;
|
||||
[mCommandQueue release];
|
||||
mCommandQueue = nil;
|
||||
}
|
||||
|
||||
id<MTLCommandQueue> Queue::GetMTLCommandQueue() {
|
||||
return commandQueue;
|
||||
return mCommandQueue;
|
||||
}
|
||||
|
||||
void Queue::Submit(uint32_t numCommands, CommandBuffer* const * commands) {
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace metal {
|
|||
const BindingIndexInfo& GetBindingIndexInfo(nxt::ShaderStage stage) const;
|
||||
|
||||
private:
|
||||
PerStage<BindingIndexInfo> indexInfo;
|
||||
PerStage<BindingIndexInfo> mIndexInfo;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -41,15 +41,15 @@ namespace metal {
|
|||
switch (groupInfo.types[binding]) {
|
||||
case nxt::BindingType::UniformBuffer:
|
||||
case nxt::BindingType::StorageBuffer:
|
||||
indexInfo[stage][group][binding] = bufferIndex;
|
||||
mIndexInfo[stage][group][binding] = bufferIndex;
|
||||
bufferIndex++;
|
||||
break;
|
||||
case nxt::BindingType::Sampler:
|
||||
indexInfo[stage][group][binding] = samplerIndex;
|
||||
mIndexInfo[stage][group][binding] = samplerIndex;
|
||||
samplerIndex++;
|
||||
break;
|
||||
case nxt::BindingType::SampledTexture:
|
||||
indexInfo[stage][group][binding] = textureIndex;
|
||||
mIndexInfo[stage][group][binding] = textureIndex;
|
||||
textureIndex++;
|
||||
break;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ namespace metal {
|
|||
}
|
||||
|
||||
const PipelineLayout::BindingIndexInfo& PipelineLayout::GetBindingIndexInfo(nxt::ShaderStage stage) const {
|
||||
return indexInfo[stage];
|
||||
return mIndexInfo[stage];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,9 +33,9 @@ namespace metal {
|
|||
void Encode(id<MTLRenderCommandEncoder> encoder);
|
||||
|
||||
private:
|
||||
MTLIndexType mtlIndexType;
|
||||
MTLPrimitiveType mtlPrimitiveTopology;
|
||||
id<MTLRenderPipelineState> mtlRenderPipelineState = nil;
|
||||
MTLIndexType mMtlIndexType;
|
||||
MTLPrimitiveType mMtlPrimitiveTopology;
|
||||
id<MTLRenderPipelineState> mMtlRenderPipelineState = nil;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -66,8 +66,8 @@ namespace metal {
|
|||
|
||||
RenderPipeline::RenderPipeline(RenderPipelineBuilder* builder)
|
||||
: RenderPipelineBase(builder),
|
||||
mtlIndexType(MTLIndexFormat(GetIndexFormat())),
|
||||
mtlPrimitiveTopology(MTLPrimitiveTopology(GetPrimitiveTopology())) {
|
||||
mMtlIndexType(MTLIndexFormat(GetIndexFormat())),
|
||||
mMtlPrimitiveTopology(MTLPrimitiveTopology(GetPrimitiveTopology())) {
|
||||
|
||||
auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice();
|
||||
|
||||
|
@ -116,7 +116,7 @@ namespace metal {
|
|||
// TODO(kainino@chromium.org): push constants, textures, samplers
|
||||
|
||||
NSError *error = nil;
|
||||
mtlRenderPipelineState = [mtlDevice
|
||||
mMtlRenderPipelineState = [mtlDevice
|
||||
newRenderPipelineStateWithDescriptor:descriptor error:&error];
|
||||
if (error != nil) {
|
||||
NSLog(@" error => %@", error);
|
||||
|
@ -129,19 +129,19 @@ namespace metal {
|
|||
}
|
||||
|
||||
RenderPipeline::~RenderPipeline() {
|
||||
[mtlRenderPipelineState release];
|
||||
[mMtlRenderPipelineState release];
|
||||
}
|
||||
|
||||
MTLIndexType RenderPipeline::GetMTLIndexType() const {
|
||||
return mtlIndexType;
|
||||
return mMtlIndexType;
|
||||
}
|
||||
|
||||
MTLPrimitiveType RenderPipeline::GetMTLPrimitiveTopology() const {
|
||||
return mtlPrimitiveTopology;
|
||||
return mMtlPrimitiveTopology;
|
||||
}
|
||||
|
||||
void RenderPipeline::Encode(id<MTLRenderCommandEncoder> encoder) {
|
||||
[encoder setRenderPipelineState:mtlRenderPipelineState];
|
||||
[encoder setRenderPipelineState:mMtlRenderPipelineState];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ namespace metal {
|
|||
void Tick(Serial finishedSerial);
|
||||
|
||||
private:
|
||||
Device* device;
|
||||
SerialQueue<id<MTLBuffer>> inflightUploadBuffers;
|
||||
Device* mDevice;
|
||||
SerialQueue<id<MTLBuffer>> mInflightUploadBuffers;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -20,20 +20,20 @@ namespace backend {
|
|||
namespace metal {
|
||||
|
||||
ResourceUploader::ResourceUploader(Device* device)
|
||||
: device(device) {
|
||||
: mDevice(device) {
|
||||
}
|
||||
|
||||
ResourceUploader::~ResourceUploader() {
|
||||
ASSERT(inflightUploadBuffers.Empty());
|
||||
ASSERT(mInflightUploadBuffers.Empty());
|
||||
}
|
||||
|
||||
void ResourceUploader::BufferSubData(id<MTLBuffer> buffer, uint32_t start, uint32_t size, const void* data) {
|
||||
// TODO(cwallez@chromium.org) use a ringbuffer instead of creating a small buffer for each update
|
||||
id<MTLBuffer> uploadBuffer = [device->GetMTLDevice() newBufferWithLength:size
|
||||
id<MTLBuffer> uploadBuffer = [mDevice->GetMTLDevice() newBufferWithLength:size
|
||||
options:MTLResourceStorageModeShared];
|
||||
memcpy([uploadBuffer contents], data, size);
|
||||
|
||||
id<MTLCommandBuffer> commandBuffer = device->GetPendingCommandBuffer();
|
||||
id<MTLCommandBuffer> commandBuffer = mDevice->GetPendingCommandBuffer();
|
||||
id<MTLBlitCommandEncoder> encoder = [commandBuffer blitCommandEncoder];
|
||||
[encoder copyFromBuffer:uploadBuffer
|
||||
sourceOffset:0
|
||||
|
@ -42,14 +42,14 @@ namespace metal {
|
|||
size:size];
|
||||
[encoder endEncoding];
|
||||
|
||||
inflightUploadBuffers.Enqueue(uploadBuffer, device->GetPendingCommandSerial());
|
||||
mInflightUploadBuffers.Enqueue(uploadBuffer, mDevice->GetPendingCommandSerial());
|
||||
}
|
||||
|
||||
void ResourceUploader::Tick(Serial finishedSerial) {
|
||||
for (id<MTLBuffer> buffer : inflightUploadBuffers.IterateUpTo(finishedSerial)) {
|
||||
for (id<MTLBuffer> buffer : mInflightUploadBuffers.IterateUpTo(finishedSerial)) {
|
||||
[buffer release];
|
||||
}
|
||||
inflightUploadBuffers.ClearUpTo(finishedSerial);
|
||||
mInflightUploadBuffers.ClearUpTo(finishedSerial);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace metal {
|
|||
id<MTLSamplerState> GetMTLSamplerState();
|
||||
|
||||
private:
|
||||
id<MTLSamplerState> mtlSamplerState = nil;
|
||||
id<MTLSamplerState> mMtlSamplerState = nil;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -49,15 +49,15 @@ namespace metal {
|
|||
|
||||
// TODO(kainino@chromium.org): wrap modes
|
||||
auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice();
|
||||
mtlSamplerState = [mtlDevice newSamplerStateWithDescriptor:desc];
|
||||
mMtlSamplerState = [mtlDevice newSamplerStateWithDescriptor:desc];
|
||||
}
|
||||
|
||||
Sampler::~Sampler() {
|
||||
[mtlSamplerState release];
|
||||
[mMtlSamplerState release];
|
||||
}
|
||||
|
||||
id<MTLSamplerState> Sampler::GetMTLSamplerState() {
|
||||
return mtlSamplerState;
|
||||
return mMtlSamplerState;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace metal {
|
|||
// Calling compile on CompilerMSL somehow changes internal state that makes subsequent
|
||||
// compiles return invalid MSL. We keep the spirv around and recreate the compiler everytime
|
||||
// we need to use it.
|
||||
std::vector<uint32_t> spirv;
|
||||
std::vector<uint32_t> mSpirv;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -42,14 +42,14 @@ namespace metal {
|
|||
}
|
||||
|
||||
ShaderModule::ShaderModule(ShaderModuleBuilder* builder)
|
||||
: ShaderModuleBase(builder), spirv(builder->AcquireSpirv()) {
|
||||
spirv_cross::CompilerMSL compiler(spirv);
|
||||
: ShaderModuleBase(builder), mSpirv(builder->AcquireSpirv()) {
|
||||
spirv_cross::CompilerMSL compiler(mSpirv);
|
||||
ExtractSpirvInfo(compiler);
|
||||
}
|
||||
|
||||
ShaderModule::MetalFunctionData ShaderModule::GetFunction(const char* functionName,
|
||||
const PipelineLayout* layout) const {
|
||||
spirv_cross::CompilerMSL compiler(spirv);
|
||||
spirv_cross::CompilerMSL compiler(mSpirv);
|
||||
|
||||
// By default SPIRV-Cross will give MSL resources indices in increasing order.
|
||||
// To make the MSL indices match the indices chosen in the PipelineLayout, we build
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace metal {
|
|||
void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) override;
|
||||
|
||||
private:
|
||||
id<MTLTexture> mtlTexture = nil;
|
||||
id<MTLTexture> mMtlTexture = nil;
|
||||
};
|
||||
|
||||
class TextureView : public TextureViewBase {
|
||||
|
|
|
@ -74,20 +74,20 @@ namespace metal {
|
|||
desc.storageMode = MTLStorageModePrivate;
|
||||
|
||||
auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice();
|
||||
mtlTexture = [mtlDevice newTextureWithDescriptor:desc];
|
||||
mMtlTexture = [mtlDevice newTextureWithDescriptor:desc];
|
||||
}
|
||||
|
||||
Texture::Texture(TextureBuilder* builder, id<MTLTexture> mtlTexture)
|
||||
: TextureBase(builder), mtlTexture(mtlTexture) {
|
||||
[mtlTexture retain];
|
||||
: TextureBase(builder), mMtlTexture(mtlTexture) {
|
||||
[mMtlTexture retain];
|
||||
}
|
||||
|
||||
Texture::~Texture() {
|
||||
[mtlTexture release];
|
||||
[mMtlTexture release];
|
||||
}
|
||||
|
||||
id<MTLTexture> Texture::GetMTLTexture() {
|
||||
return mtlTexture;
|
||||
return mMtlTexture;
|
||||
}
|
||||
|
||||
void Texture::TransitionUsageImpl(nxt::TextureUsageBit, nxt::TextureUsageBit) {
|
||||
|
|
Loading…
Reference in New Issue