1 module dcl.commandqueue; 2 3 import dcl.base; 4 import dcl.device; 5 import dcl.context; 6 7 /// 8 class CLCommandQueue : CLObject 9 { 10 protected: 11 static CLCommandQueue[cl_command_queue] used; 12 13 this( cl_command_queue id ) 14 { 15 enforce( id !is null, new CLException( "can't create command queue with null id" ) ); 16 enforce( id !in used, new CLException( "can't create existing command queue" ) ); 17 this.id = id; 18 used[id] = this; 19 checkCall!clRetainCommandQueue(id); 20 21 _context = reqContext; 22 _device = reqDevice; 23 } 24 25 /// 26 CLContext _context; 27 /// 28 CLDevice _device; 29 30 package: 31 /// 32 cl_command_queue id; 33 34 public: 35 36 /// compatible with mixinfo as parameter 37 static CLCommandQueue getFromID( cl_command_queue id ) 38 { 39 if( id is null ) return null; 40 if( id in used ) return used[id]; 41 return new CLCommandQueue(id); 42 } 43 44 CLContext context() @property { return _context; } 45 CLDevice device() @property { return _device; } 46 47 /// 48 enum Properties 49 { 50 OUT_OF_ORDER = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, /// 51 PROFILING = CL_QUEUE_PROFILING_ENABLE, /// 52 } 53 54 /// 55 this( CLContext ctx, size_t devID, Properties[] prop=[] ) 56 in { assert( ctx !is null ); } body 57 { this( ctx, ctx.devices[devID], prop ); } 58 59 /// 60 this( CLContext ctx, CLDevice dev, Properties[] prop=[] ) 61 in 62 { 63 assert( ctx !is null ); 64 assert( dev !is null ); 65 } 66 body 67 { 68 enforce( find( ctx.devices, dev ), "device is not in context" ); 69 70 this( checkCode!clCreateCommandQueue( ctx.id, dev.id, buildFlags(prop) ) ); 71 } 72 73 static CLCommandQueue[] forAllDevices( CLContext ctx, Properties[] prop=[] ) 74 { 75 auto ret = new CLCommandQueue[]( ctx.devices.length ); 76 foreach( i; 0 .. ret.length ) 77 ret[i] = new CLCommandQueue( ctx, i, prop ); 78 return ret; 79 } 80 81 /// `clFlush` 82 void flush() { checkCall!clFlush(id); } 83 /// `clFinish` 84 void finish() { checkCall!clFinish(id); } 85 86 /// `clEnqueueBarrierWithWaitList` 87 void barrier( CLEvent[] wl=[], CLEvent* ev=null ) 88 { checkCallWL!clEnqueueBarrierWithWaitList(id,wl,ev); } 89 90 static private enum info_list = 91 [ 92 "cl_context:CLContext context:reqContext", 93 "cl_device_id:CLDevice device:reqDevice", 94 "cl_command_queue_properties properties", 95 "uint reference_count:refcount" 96 ]; 97 98 mixin( infoMixin( "command_queue", "queue", info_list ) ); 99 100 protected: 101 102 override void selfDestroy() 103 { 104 used.remove(id); 105 checkCall!clReleaseCommandQueue(id); 106 } 107 }