OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 COMPILE_ASSERT(sizeof(CommandHeader) == 4, Sizeof_CommandHeader_is_not_4); | 100 COMPILE_ASSERT(sizeof(CommandHeader) == 4, Sizeof_CommandHeader_is_not_4); |
101 | 101 |
102 // Union that defines possible command buffer entries. | 102 // Union that defines possible command buffer entries. |
103 union CommandBufferEntry { | 103 union CommandBufferEntry { |
104 CommandHeader value_header; | 104 CommandHeader value_header; |
105 Uint32 value_uint32; | 105 Uint32 value_uint32; |
106 Int32 value_int32; | 106 Int32 value_int32; |
107 float value_float; | 107 float value_float; |
108 }; | 108 }; |
109 | 109 |
110 COMPILE_ASSERT(sizeof(CommandBufferEntry) == 4, | 110 const size_t kCommandBufferEntrySize = 4; |
| 111 |
| 112 COMPILE_ASSERT(sizeof(CommandBufferEntry) == kCommandBufferEntrySize, |
111 Sizeof_CommandBufferEntry_is_not_4); | 113 Sizeof_CommandBufferEntry_is_not_4); |
112 | 114 |
113 | |
114 // Make sure the compiler does not add extra padding to any of the command | 115 // Make sure the compiler does not add extra padding to any of the command |
115 // structures. | 116 // structures. |
116 #pragma pack(push, 1) | 117 #pragma pack(push, 1) |
117 | 118 |
118 // Gets the address of memory just after a structure in a typesafe way. This is | 119 // Gets the address of memory just after a structure in a typesafe way. This is |
119 // used for IMMEDIATE commands to get the address of the place to put the data. | 120 // used for IMMEDIATE commands to get the address of the place to put the data. |
120 // Immediate command put their data direclty in the command buffer. | 121 // Immediate command put their data direclty in the command buffer. |
121 // Parameters: | 122 // Parameters: |
122 // cmd: Address of command. | 123 // cmd: Address of command. |
123 template <typename T> | 124 template <typename T> |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 OP(Noop) /* 0 */ \ | 175 OP(Noop) /* 0 */ \ |
175 OP(SetToken) /* 1 */ \ | 176 OP(SetToken) /* 1 */ \ |
176 OP(Jump) /* 2 */ \ | 177 OP(Jump) /* 2 */ \ |
177 OP(JumpRelative) /* 3 */ \ | 178 OP(JumpRelative) /* 3 */ \ |
178 OP(Call) /* 4 */ \ | 179 OP(Call) /* 4 */ \ |
179 OP(CallRelative) /* 5 */ \ | 180 OP(CallRelative) /* 5 */ \ |
180 OP(Return) /* 6 */ \ | 181 OP(Return) /* 6 */ \ |
181 OP(SetBucketSize) /* 7 */ \ | 182 OP(SetBucketSize) /* 7 */ \ |
182 OP(SetBucketData) /* 8 */ \ | 183 OP(SetBucketData) /* 8 */ \ |
183 OP(SetBucketDataImmediate) /* 9 */ \ | 184 OP(SetBucketDataImmediate) /* 9 */ \ |
184 OP(GetResultSize) /* 10 */ \ | 185 OP(GetBucketSize) /* 10 */ \ |
185 OP(GetResultData) /* 11 */ \ | 186 OP(GetBucketData) /* 11 */ \ |
186 | 187 |
187 // Common commands. | 188 // Common commands. |
188 enum CommandId { | 189 enum CommandId { |
189 #define COMMON_COMMAND_BUFFER_CMD_OP(name) k ## name, | 190 #define COMMON_COMMAND_BUFFER_CMD_OP(name) k ## name, |
190 | 191 |
191 COMMON_COMMAND_BUFFER_CMDS(COMMON_COMMAND_BUFFER_CMD_OP) | 192 COMMON_COMMAND_BUFFER_CMDS(COMMON_COMMAND_BUFFER_CMD_OP) |
192 | 193 |
193 #undef COMMON_COMMAND_BUFFER_CMD_OP | 194 #undef COMMON_COMMAND_BUFFER_CMD_OP |
194 | 195 |
195 kNumCommands, | 196 kNumCommands, |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 Sizeof_SetBucketDataImmediate_is_not_24); | 560 Sizeof_SetBucketDataImmediate_is_not_24); |
560 COMPILE_ASSERT(offsetof(SetBucketDataImmediate, header) == 0, | 561 COMPILE_ASSERT(offsetof(SetBucketDataImmediate, header) == 0, |
561 Offsetof_SetBucketDataImmediate_header_not_0); | 562 Offsetof_SetBucketDataImmediate_header_not_0); |
562 COMPILE_ASSERT(offsetof(SetBucketDataImmediate, bucket_id) == 4, | 563 COMPILE_ASSERT(offsetof(SetBucketDataImmediate, bucket_id) == 4, |
563 Offsetof_SetBucketDataImmediate_bucket_id_not_4); | 564 Offsetof_SetBucketDataImmediate_bucket_id_not_4); |
564 COMPILE_ASSERT(offsetof(SetBucketDataImmediate, offset) == 8, | 565 COMPILE_ASSERT(offsetof(SetBucketDataImmediate, offset) == 8, |
565 Offsetof_SetBucketDataImmediate_offset_not_8); | 566 Offsetof_SetBucketDataImmediate_offset_not_8); |
566 COMPILE_ASSERT(offsetof(SetBucketDataImmediate, size) == 12, | 567 COMPILE_ASSERT(offsetof(SetBucketDataImmediate, size) == 12, |
567 Offsetof_SetBucketDataImmediate_size_not_12); | 568 Offsetof_SetBucketDataImmediate_size_not_12); |
568 | 569 |
569 // Gets the size of a result the service has available. | 570 // Gets the size of a bucket the service has available. Sending a variable size |
570 // Sending a variable size result back to the client, for example any API that | 571 // result back to the client, for example any API that returns a string, is |
571 // returns a string, is problematic since the largest thing you can send back is | 572 // problematic since the largest thing you can send back is the size of your |
572 // the size of your shared memory. This command along with GetResultData | 573 // shared memory. This command along with GetBucketData implements a way to get |
573 // implement a way to get a result a piece at a time to help solve that problem | 574 // a result a piece at a time to help solve that problem in a generic way. |
574 // in a generic way. | 575 struct GetBucketSize { |
575 struct GetResultSize { | 576 typedef GetBucketSize ValueType; |
576 typedef GetResultSize ValueType; | 577 static const CommandId kCmdId = kGetBucketSize; |
577 static const CommandId kCmdId = kGetResultSize; | |
578 static const cmd::ArgFlags kArgFlags = cmd::kFixed; | 578 static const cmd::ArgFlags kArgFlags = cmd::kFixed; |
579 | 579 |
580 void SetHeader() { | 580 void SetHeader() { |
581 header.SetCmd<ValueType>(); | 581 header.SetCmd<ValueType>(); |
582 } | 582 } |
583 | 583 |
584 void Init(uint32 _shared_memory_id, | 584 void Init(uint32 _bucket_id, |
| 585 uint32 _shared_memory_id, |
585 uint32 _shared_memory_offset) { | 586 uint32 _shared_memory_offset) { |
586 SetHeader(); | 587 SetHeader(); |
| 588 bucket_id = _bucket_id; |
587 shared_memory_id = _shared_memory_id; | 589 shared_memory_id = _shared_memory_id; |
588 shared_memory_offset = _shared_memory_offset; | 590 shared_memory_offset = _shared_memory_offset; |
589 } | 591 } |
590 static void* Set(void* cmd, | 592 static void* Set(void* cmd, |
| 593 uint32 _bucket_id, |
591 uint32 _shared_memory_id, | 594 uint32 _shared_memory_id, |
592 uint32 _shared_memory_offset) { | 595 uint32 _shared_memory_offset) { |
593 static_cast<ValueType*>(cmd)->Init( | 596 static_cast<ValueType*>(cmd)->Init( |
| 597 _bucket_id, |
594 _shared_memory_id, | 598 _shared_memory_id, |
595 _shared_memory_offset); | 599 _shared_memory_offset); |
596 return NextCmdAddress<ValueType>(cmd); | 600 return NextCmdAddress<ValueType>(cmd); |
597 } | 601 } |
598 | 602 |
599 CommandHeader header; | 603 CommandHeader header; |
| 604 uint32 bucket_id; |
600 uint32 shared_memory_id; | 605 uint32 shared_memory_id; |
601 uint32 shared_memory_offset; | 606 uint32 shared_memory_offset; |
602 }; | 607 }; |
603 | 608 |
604 COMPILE_ASSERT(sizeof(GetResultSize) == 12, Sizeof_GetResultSize_is_not_12); | 609 COMPILE_ASSERT(sizeof(GetBucketSize) == 16, Sizeof_GetBucketSize_is_not_16); |
605 COMPILE_ASSERT(offsetof(GetResultSize, header) == 0, | 610 COMPILE_ASSERT(offsetof(GetBucketSize, header) == 0, |
606 Offsetof_GetResultSize_header_not_0); | 611 Offsetof_GetBucketSize_header_not_0); |
607 COMPILE_ASSERT(offsetof(GetResultSize, shared_memory_id) == 4, | 612 COMPILE_ASSERT(offsetof(GetBucketSize, bucket_id) == 4, |
608 Offsetof_GetResultSize_shared_memory_id_not_4); | 613 Offsetof_GetBucketSize_bucket_id_not_4); |
609 COMPILE_ASSERT(offsetof(GetResultSize, shared_memory_offset) == 8, | 614 COMPILE_ASSERT(offsetof(GetBucketSize, shared_memory_id) == 8, |
610 Offsetof_GetResultSize_shared_memory_offset_not_8); | 615 Offsetof_GetBucketSize_shared_memory_id_not_8); |
| 616 COMPILE_ASSERT(offsetof(GetBucketSize, shared_memory_offset) == 12, |
| 617 Offsetof_GetBucketSize_shared_memory_offset_not_12); |
611 | 618 |
612 // Gets a piece of a result the service as available. | 619 // Gets a piece of a result the service as available. |
613 // See GetResultSize. | 620 // See GetBucketSize. |
614 struct GetResultData { | 621 struct GetBucketData { |
615 typedef GetResultData ValueType; | 622 typedef GetBucketData ValueType; |
616 static const CommandId kCmdId = kGetResultData; | 623 static const CommandId kCmdId = kGetBucketData; |
617 static const cmd::ArgFlags kArgFlags = cmd::kFixed; | 624 static const cmd::ArgFlags kArgFlags = cmd::kFixed; |
618 | 625 |
619 void SetHeader() { | 626 void SetHeader() { |
620 header.SetCmd<ValueType>(); | 627 header.SetCmd<ValueType>(); |
621 } | 628 } |
622 | 629 |
623 void Init(uint32 _offset, | 630 void Init(uint32 _bucket_id, |
| 631 uint32 _offset, |
624 uint32 _size, | 632 uint32 _size, |
625 uint32 _shared_memory_id, | 633 uint32 _shared_memory_id, |
626 uint32 _shared_memory_offset) { | 634 uint32 _shared_memory_offset) { |
627 SetHeader(); | 635 SetHeader(); |
| 636 bucket_id = _bucket_id; |
628 offset = _offset; | 637 offset = _offset; |
629 size = _size; | 638 size = _size; |
630 shared_memory_id = _shared_memory_id; | 639 shared_memory_id = _shared_memory_id; |
631 shared_memory_offset = _shared_memory_offset; | 640 shared_memory_offset = _shared_memory_offset; |
632 } | 641 } |
633 static void* Set(void* cmd, | 642 static void* Set(void* cmd, |
| 643 uint32 _bucket_id, |
634 uint32 _offset, | 644 uint32 _offset, |
635 uint32 _size, | 645 uint32 _size, |
636 uint32 _shared_memory_id, | 646 uint32 _shared_memory_id, |
637 uint32 _shared_memory_offset) { | 647 uint32 _shared_memory_offset) { |
638 static_cast<ValueType*>(cmd)->Init( | 648 static_cast<ValueType*>(cmd)->Init( |
| 649 _bucket_id, |
639 _offset, | 650 _offset, |
640 _size, | 651 _size, |
641 _shared_memory_id, | 652 _shared_memory_id, |
642 _shared_memory_offset); | 653 _shared_memory_offset); |
643 return NextCmdAddress<ValueType>(cmd); | 654 return NextCmdAddress<ValueType>(cmd); |
644 } | 655 } |
645 | 656 |
646 CommandHeader header; | 657 CommandHeader header; |
| 658 uint32 bucket_id; |
647 uint32 offset; | 659 uint32 offset; |
648 uint32 size; | 660 uint32 size; |
649 uint32 shared_memory_id; | 661 uint32 shared_memory_id; |
650 uint32 shared_memory_offset; | 662 uint32 shared_memory_offset; |
651 }; | 663 }; |
652 | 664 |
653 COMPILE_ASSERT(sizeof(GetResultData) == 20, Sizeof_GetResultData_is_not_20); | 665 COMPILE_ASSERT(sizeof(GetBucketData) == 24, Sizeof_GetBucketData_is_not_20); |
654 COMPILE_ASSERT(offsetof(GetResultData, header) == 0, | 666 COMPILE_ASSERT(offsetof(GetBucketData, header) == 0, |
655 Offsetof_GetResultData_header_not_0); | 667 Offsetof_GetBucketData_header_not_0); |
656 COMPILE_ASSERT(offsetof(GetResultData, offset) == 4, | 668 COMPILE_ASSERT(offsetof(GetBucketData, bucket_id) == 4, |
657 Offsetof_GetResultData_offset_not_4); | 669 Offsetof_GetBucketData_bucket_id_not_4); |
658 COMPILE_ASSERT(offsetof(GetResultData, size) == 8, | 670 COMPILE_ASSERT(offsetof(GetBucketData, offset) == 8, |
659 Offsetof_GetResultData_size_not_8); | 671 Offsetof_GetBucketData_offset_not_8); |
660 COMPILE_ASSERT(offsetof(GetResultData, shared_memory_id) == 12, | 672 COMPILE_ASSERT(offsetof(GetBucketData, size) == 12, |
661 Offsetof_GetResultData_shared_memory_id_not_12); | 673 Offsetof_GetBucketData_size_not_12); |
662 COMPILE_ASSERT(offsetof(GetResultData, shared_memory_offset) == 16, | 674 COMPILE_ASSERT(offsetof(GetBucketData, shared_memory_id) == 16, |
663 Offsetof_GetResultData_shared_memory_offset_not_16); | 675 Offsetof_GetBucketData_shared_memory_id_not_16); |
| 676 COMPILE_ASSERT(offsetof(GetBucketData, shared_memory_offset) == 20, |
| 677 Offsetof_GetBucketData_shared_memory_offset_not_20); |
664 | 678 |
665 } // namespace cmd | 679 } // namespace cmd |
666 | 680 |
667 #pragma pack(pop) | 681 #pragma pack(pop) |
668 | 682 |
669 } // namespace command_buffer | 683 } // namespace command_buffer |
670 | 684 |
671 #endif // GPU_COMMAND_BUFFER_COMMON_CROSS_CMD_BUFFER_COMMON_H_ | 685 #endif // GPU_COMMAND_BUFFER_COMMON_CROSS_CMD_BUFFER_COMMON_H_ |
672 | 686 |
OLD | NEW |