瀏覽代碼

added queries

Nicolas Cannasse 3 年之前
父節點
當前提交
d33e2a5ade
共有 2 個文件被更改,包括 88 次插入0 次删除
  1. 54 0
      libs/directx/dx/Dx12.hx
  2. 34 0
      libs/directx/dx12.cpp

+ 54 - 0
libs/directx/dx/Dx12.hx

@@ -205,6 +205,12 @@ abstract CommandList(Resource) {
 	public function rsSetViewports( count : Int, viewports : Viewport ) {}
 	public function rsSetScissorRects( count : Int, rects : Rect ) {}
 
+	public function beginQuery( heap : QueryHeap, type : QueryType, index : Int ) {}
+	public function endQuery( heap : QueryHeap, type : QueryType, index : Int ) {}
+	public function resolveQueryData( heap : QueryHeap, type : QueryType, index : Int, count : Int, dest : Resource, offset : Int64 ) {}
+
+	public function setPredication( res : Resource, offset : Int64, op : PredicationOp ) {}
+
 	static function create( type : CommandListType, alloc : CommandAllocator, state : PipelineState ) : Resource { return null; }
 }
 
@@ -1430,6 +1436,45 @@ enum abstract IndirectArgumentType(Int) {
 	}
 }
 
+enum abstract QueryType(Int) {
+	var OCCLUSION = 0;
+	var BINARY_OCCLUSION = 1;
+	var TIMESTAMP = 2;
+	var PIPELINE_STATISTICS = 3;
+	var SO_STATISTICS_STREAM0 = 4;
+	var SO_STATISTICS_STREAM1 = 5;
+	var SO_STATISTICS_STREAM2 = 6;
+	var SO_STATISTICS_STREAM3 = 7;
+	var VIDEO_DECODE_STATISTICS = 8;
+}
+
+enum abstract QueryHeapType(Int) {
+	var OCCLUSION = 0;
+	var TIMESTAMP = 1;
+	var PIPELINE_STATISTICS = 2;
+	var SO_STATISTICS = 3;
+	var VIDEO_DECODE_STATISTICS = 4;
+	var COPY_QUEUE_TIMESTAMP = 5;
+}
+
+@:struct class QueryHeapDesc {
+	public var type : QueryHeapType;
+	public var count : Int;
+	public var nodeMask : Int;
+	public function new() {
+	}
+}
+
+@:forward(release)
+abstract QueryHeap(Resource) {
+}
+
+enum abstract PredicationOp(Int) {
+	var EQUAL_ZERO = 0;
+	var NOT_EQUAL_ZERO = 1;
+}
+
+
 @:hlNative("dx12")
 class Dx12 {
 
@@ -1472,6 +1517,10 @@ class Dx12 {
 	public static function createShaderResourceView( resource : Resource, desc : ShaderResourceViewDesc, target : Address ) {
 	}
 
+	public static function createQueryHeap( desc : QueryHeapDesc ) : QueryHeap {
+		return null;
+	}
+
 	public static function getCopyableFootprints( srcDesc : ResourceDesc, firstSubResource : Int, numSubResources : Int, baseOffset : Int64, layouts : PlacedSubresourceFootprint, numRows : hl.BytesAccess<Int>, rowSizeInBytes : hl.BytesAccess<Int64>, totalBytes : hl.BytesAccess<Int64> ) : Void {
 	}
 
@@ -1513,6 +1562,11 @@ class Dx12 {
 		return out;
 	}
 
+	@:hlNative("dx12","get_timestamp_frequency")
+	public static function getTimestampFrequency() : Int64 {
+		return 0;
+	}
+
 	@:hlNative("dx12", "list_devices")
 	static function dxListDevices() : hl.NativeArray<hl.Bytes> {
 		return null;

+ 34 - 0
libs/directx/dx12.cpp

@@ -191,6 +191,12 @@ uchar *HL_NAME(get_device_name)() {
 	return (uchar*)hl_copy_bytes((vbyte*)desc.Description,(int)(ustrlen((uchar*)desc.Description)+1)*2);
 }
 
+int64 HL_NAME(get_timestamp_frequency)() {
+	UINT64 f = 0;
+	CHKERR(static_driver->commandQueue->GetTimestampFrequency(&f))
+	return (int64)f;
+}
+
 #define _DRIVER _ABSTRACT(dx_driver)
 #define _RES _ABSTRACT(dx_resource)
 
@@ -202,6 +208,7 @@ DEFINE_PRIM(_I32, get_current_back_buffer_index, _NO_ARG);
 DEFINE_PRIM(_VOID, signal, _RES _I64);
 DEFINE_PRIM(_VOID, flush_messages, _NO_ARG);
 DEFINE_PRIM(_BYTES, get_device_name, _NO_ARG);
+DEFINE_PRIM(_I64, get_timestamp_frequency, _NO_ARG);
 
 /// --- utilities (from d3dx12.h)
 
@@ -529,9 +536,16 @@ int64 HL_NAME(descriptor_heap_get_handle)( ID3D12DescriptorHeap *heap, bool gpu
 	return handle; 
 }
 
+ID3D12QueryHeap *HL_NAME(create_query_heap)( D3D12_QUERY_HEAP_DESC *desc ) {
+	ID3D12QueryHeap *heap = NULL;
+	DXERR(static_driver->device->CreateQueryHeap(desc,IID_PPV_ARGS(&heap)));
+	return heap;
+}
+
 DEFINE_PRIM(_RES, descriptor_heap_create, _STRUCT);
 DEFINE_PRIM(_I32, get_descriptor_handle_increment_size, _I32);
 DEFINE_PRIM(_I64, descriptor_heap_get_handle, _RES _BOOL);
+DEFINE_PRIM(_RES, create_query_heap, _STRUCT);
 
 // ---- SYNCHRO
 
@@ -684,6 +698,22 @@ void HL_NAME(command_list_execute_indirect)( ID3D12GraphicsCommandList *l, ID3D1
 	l->ExecuteIndirect(sign, maxCommandCount, args, argsOffset, count, countOffset);
 }
 
+void HL_NAME(command_list_begin_query)( ID3D12GraphicsCommandList *l, ID3D12QueryHeap *heap, D3D12_QUERY_TYPE type, int index ) {
+	l->BeginQuery(heap, type, index);
+}
+
+void HL_NAME(command_list_end_query)( ID3D12GraphicsCommandList *l, ID3D12QueryHeap *heap, D3D12_QUERY_TYPE type, int index ) {
+	l->EndQuery(heap, type, index);
+}
+
+void HL_NAME(command_list_resolve_query_data)( ID3D12GraphicsCommandList *l, ID3D12QueryHeap *heap, D3D12_QUERY_TYPE type, int index, int count, ID3D12Resource *dest, int64 offset ) {
+	l->ResolveQueryData(heap,type,index,count,dest,offset);
+}
+
+void HL_NAME(command_list_set_predication)( ID3D12GraphicsCommandList *l, ID3D12Resource *res, int64 offset, D3D12_PREDICATION_OP op ) {
+	l->SetPredication(res,offset,op);
+}
+
 DEFINE_PRIM(_RES, command_allocator_create, _I32);
 DEFINE_PRIM(_VOID, command_allocator_reset, _RES);
 DEFINE_PRIM(_RES, command_list_create, _I32 _RES _RES);
@@ -712,3 +742,7 @@ DEFINE_PRIM(_VOID, command_list_om_set_stencil_ref, _RES _I32);
 DEFINE_PRIM(_VOID, command_list_rs_set_viewports, _RES _I32 _STRUCT);
 DEFINE_PRIM(_VOID, command_list_rs_set_scissor_rects, _RES _I32 _STRUCT);
 DEFINE_PRIM(_VOID, command_list_execute_indirect, _RES _RES _I32 _RES _I64 _RES _I64);
+DEFINE_PRIM(_VOID, command_list_begin_query, _RES _RES _I32 _I32);
+DEFINE_PRIM(_VOID, command_list_end_query, _RES _RES _I32 _I32);
+DEFINE_PRIM(_VOID, command_list_resolve_query_data, _RES _RES _I32 _I32 _I32 _RES _I64);
+DEFINE_PRIM(_VOID, command_list_set_predication, _RES _RES _I64 _I32);