Metal: Implement push constants
This commit is contained in:
parent
30beb65a7b
commit
4122b2e3f9
|
@ -149,6 +149,8 @@ namespace metal {
|
||||||
CurrentEncoders encoders;
|
CurrentEncoders encoders;
|
||||||
encoders.device = device;
|
encoders.device = device;
|
||||||
|
|
||||||
|
PerStage<std::array<uint32_t, kMaxPushConstants>> pushConstants;
|
||||||
|
|
||||||
uint32_t currentSubpass = 0;
|
uint32_t currentSubpass = 0;
|
||||||
while (commands.NextCommandId(&type)) {
|
while (commands.NextCommandId(&type)) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -156,6 +158,11 @@ namespace metal {
|
||||||
{
|
{
|
||||||
commands.NextCommand<BeginComputePassCmd>();
|
commands.NextCommand<BeginComputePassCmd>();
|
||||||
encoders.BeginCompute(commandBuffer);
|
encoders.BeginCompute(commandBuffer);
|
||||||
|
|
||||||
|
pushConstants[nxt::ShaderStage::Compute].fill(0);
|
||||||
|
[encoders.compute setBytes: &pushConstants[nxt::ShaderStage::Compute]
|
||||||
|
length: sizeof(uint32_t) * kMaxPushConstants
|
||||||
|
atIndex: 0];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -173,6 +180,16 @@ namespace metal {
|
||||||
{
|
{
|
||||||
commands.NextCommand<BeginRenderSubpassCmd>();
|
commands.NextCommand<BeginRenderSubpassCmd>();
|
||||||
encoders.BeginSubpass(commandBuffer, currentSubpass);
|
encoders.BeginSubpass(commandBuffer, currentSubpass);
|
||||||
|
|
||||||
|
pushConstants[nxt::ShaderStage::Vertex].fill(0);
|
||||||
|
pushConstants[nxt::ShaderStage::Fragment].fill(0);
|
||||||
|
|
||||||
|
[encoders.render setVertexBytes: &pushConstants[nxt::ShaderStage::Vertex]
|
||||||
|
length: sizeof(uint32_t) * kMaxPushConstants
|
||||||
|
atIndex: 0];
|
||||||
|
[encoders.render setFragmentBytes: &pushConstants[nxt::ShaderStage::Fragment]
|
||||||
|
length: sizeof(uint32_t) * kMaxPushConstants
|
||||||
|
atIndex: 0];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -343,8 +360,35 @@ namespace metal {
|
||||||
case Command::SetPushConstants:
|
case Command::SetPushConstants:
|
||||||
{
|
{
|
||||||
SetPushConstantsCmd* cmd = commands.NextCommand<SetPushConstantsCmd>();
|
SetPushConstantsCmd* cmd = commands.NextCommand<SetPushConstantsCmd>();
|
||||||
commands.NextData<uint32_t>(cmd->count);
|
uint32_t* values = commands.NextData<uint32_t>(cmd->count);
|
||||||
// TODO(kainino@chromium.org): implement SetPushConstants
|
|
||||||
|
for (auto stage : IterateStages(cmd->stages)) {
|
||||||
|
memcpy(&pushConstants[stage][cmd->offset], values, cmd->count * sizeof(uint32_t));
|
||||||
|
|
||||||
|
switch (stage) {
|
||||||
|
case nxt::ShaderStage::Compute:
|
||||||
|
ASSERT(encoders.compute);
|
||||||
|
[encoders.compute setBytes: &pushConstants[nxt::ShaderStage::Compute]
|
||||||
|
length: sizeof(uint32_t) * kMaxPushConstants
|
||||||
|
atIndex: 0];
|
||||||
|
break;
|
||||||
|
case nxt::ShaderStage::Fragment:
|
||||||
|
ASSERT(encoders.render);
|
||||||
|
[encoders.render setFragmentBytes: &pushConstants[nxt::ShaderStage::Fragment]
|
||||||
|
length: sizeof(uint32_t) * kMaxPushConstants
|
||||||
|
atIndex: 0];
|
||||||
|
break;
|
||||||
|
case nxt::ShaderStage::Vertex:
|
||||||
|
ASSERT(encoders.render);
|
||||||
|
[encoders.render setVertexBytes: &pushConstants[nxt::ShaderStage::Vertex]
|
||||||
|
length: sizeof(uint32_t) * kMaxPushConstants
|
||||||
|
atIndex: 0];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue