浏览代码

more apis

Nicolas Cannasse 3 年之前
父节点
当前提交
f61d16ba3b
共有 2 个文件被更改,包括 445 次插入12 次删除
  1. 254 12
      libs/directx/dx/Dx12.hx
  2. 191 0
      libs/directx/dx12.cpp

+ 254 - 12
libs/directx/dx/Dx12.hx

@@ -36,6 +36,8 @@ abstract Resource(hl.Abstract<"dx_resource">) {
 abstract GpuResource(Resource) {
 	@:hlNative("dx12","resource_get_gpu_virtual_address")
 	public function getGpuVirtualAddress() : Int64 { return 0; }
+	@:hlNative("dx12","get_required_intermediate_size")
+	public function getRequiredIntermediateSize( subRes : Int, resCount : Int ) : Int64 { return 0; }
 	public function map( subResource : Int, range : Range ) : hl.Bytes { return null; }
 	public function unmap( subResource : Int, writtenRange : Range ) {}
 	@:to inline function to() : Resource { return cast this; }
@@ -111,6 +113,47 @@ enum abstract PrimitiveTopology(Int) {
 	}
 }
 
+@:struct class Box {
+	public var left : Int;
+	public var top : Int;
+	public var front : Int;
+	public var right : Int;
+	public var bottom : Int;
+	public var back : Int;
+	public function new() {
+	}
+}
+
+enum abstract TextureCopyType(Int) {
+	var SUBRESOURCE_INDEX = 0;
+	var PLACED_FOOTPRINT = 1;
+}
+
+@:struct class SubresourceFootprint {
+	public var format : DxgiFormat;
+	public var width : Int;
+	public var height : Int;
+	public var depth : Int;
+	public var rowPitch : Int;
+	public function new() {
+	}
+}
+
+@:struct class TextureCopyLocation {
+	public var res : GpuResource;
+	public var type : TextureCopyType;
+	var __unionPadding : Int;
+
+	public var subResourceIndex(get,set) : Int;
+	inline function get_subResourceIndex() : Int return offset.low & 0xFF;
+	inline function set_subResourceIndex(v: Int) { offset = v; return v; }
+
+	public var offset : Int64;
+	@:packed public var footprint(default,null) : SubresourceFootprint;
+	public function new() {
+	}
+}
+
 @:hlNative("dx12","command_list_")
 abstract CommandList(Resource) {
 	public function new(type,alloc,state) {
@@ -124,9 +167,15 @@ abstract CommandList(Resource) {
 	public function reset( alloc : CommandAllocator, state : PipelineState ) {}
 	public function resourceBarrier( b : ResourceBarrier ) {}
 	public function setPipelineState( state : PipelineState ) {}
+	public function setDescriptorHeaps( heaps : hl.NativeArray<DescriptorHeap> ) {}
+	public function copyBufferRegion( dst : GpuResource, dstOffset : Int64, src : GpuResource, srcOffset : Int64, size : Int64 ) {}
+	public function copyTextureRegion( dst : TextureCopyLocation, dstX : Int, dstY : Int, dstZ : Int, src : TextureCopyLocation, srcBox : Box ) {}
+
 	public function setGraphicsRootSignature( sign : RootSignature ) {}
 	public function setGraphicsRoot32BitConstants( index : Int, numValues : Int, data : hl.Bytes, dstOffset : Int ) {}
-	public function copyBufferRegion( dst : GpuResource, dstOffset : Int64, src : GpuResource, srcOffset : Int64, size : Int64 ) {}
+	public function setGraphicsRootConstantBufferView( index : Int, address : Address ) {}
+	public function setGraphicsRootDescriptorTable( index : Int, address : Address ) {}
+	public function setGraphicsRootShaderResourceView( index : Int, address : Address ) {}
 
 	public function iaSetPrimitiveTopology( top : PrimitiveTopology ) {}
 	public function iaSetVertexBuffers( startSlot : Int, numViews : Int, views : VertexBufferView ) {}
@@ -136,6 +185,7 @@ abstract CommandList(Resource) {
 	public function drawIndexedInstanced( indexCountPerInstance : Int, instanceCount : Int, startIndexLocation : Int, baseVertexLocation : Int, startInstanceLocation : Int ) {}
 
 	public function omSetRenderTargets( count : Int, handles : hl.BytesAccess<Address>, flag : Bool32, depthStencils : hl.BytesAccess<Address> ) {}
+	public function omSetStencilRef( value : Int ) {}
 
 	public function rsSetViewports( count : Int, viewports : Viewport ) {}
 	public function rsSetScissorRects( count : Int, rects : Rect ) {}
@@ -194,6 +244,15 @@ enum abstract DescriptorHeapFlags(Int) {
 }
 
 abstract Address(Int64) from Int64 {
+
+	public var value(get,never) : Int64;
+
+	public inline function new( v : Int64 ) {
+		this = v;
+	}
+
+	inline function get_value() return this;
+
 	public inline function offset( delta : Int ) : Address {
 		return cast this + delta;
 	}
@@ -254,7 +313,7 @@ enum abstract ResourceState(Int) {
 	public var PIXEL_SHADER_RESOURCE = 0x80;
 	public var STREAM_OUT = 0x100;
 	public var INDIRECT_ARGUMENT = 0x200;
-	public var COPY_DESC = 0x400;
+	public var COPY_DEST = 0x400;
 	public var COPY_SOURCE = 0x800;
 	public var RESOLVE_DESC = 0x1000;
 	public var RESOLVE_SOURCE = 0x2000;
@@ -263,7 +322,7 @@ enum abstract ResourceState(Int) {
 	public var GENERIC_READ = 0x1 | 0x2 | 0x40  | 0x80  | 0x200  | 0x800;
 	public var ALL_SHADER_RESOURCE = 0x40 | 0x80;
 	public var PRESENT = 0;
-	public var PREDICATIOn = 0x200;
+	public var PREDICATION = 0x200;
 	public var VIDE_DECODE_READ = 0x10000;
 	public var VIDE_DECODE_WRITE = 0x20000;
 	public var VIDE_PROCESS_READ = 0x40000;
@@ -272,7 +331,7 @@ enum abstract ResourceState(Int) {
 	public var VIDE_ENCODE_WRITE = 0x800000;
 }
 
-@:struct class ClearColor {
+@:struct class Color {
 	public var r : Single;
 	public var g : Single;
 	public var b : Single;
@@ -281,6 +340,8 @@ enum abstract ResourceState(Int) {
 	}
 }
 
+typedef ClearColor = Color;
+
 @:struct class ResourceBarrier {
 	var type : ResourceBarrierType;
 	public var flags : ResourceBarrierFlags;
@@ -1082,17 +1143,14 @@ enum ResourceFlag {
 
 @:struct class ClearValue {
 	public var format : DxgiFormat;
-	public var red : Single;
-	public var green : Single;
-	public var blue : Single;
-	public var alpha : Single;
+	@:packed public var color(default,never) : Color;
 	public var depth(get,set) : Float;
 	public var stencil(get,set) : Int;
-	inline function get_depth() return red;
-	inline function set_depth(v) return red = v;
-	function get_stencil() return haxe.io.FPHelper.floatToI32(green);
+	inline function get_depth() return color.r;
+	inline function set_depth(v) return color.r = v;
+	function get_stencil() return haxe.io.FPHelper.floatToI32(color.g);
 	function set_stencil(v) {
-		green = haxe.io.FPHelper.i32ToFloat(v);
+		color.g = haxe.io.FPHelper.i32ToFloat(v);
 		return v;
 	}
 }
@@ -1129,6 +1187,180 @@ enum abstract ResourceStates(Int) {
 }
 
 
+enum abstract SrvDimension(Int) {
+	var UNKNOWN = 0;
+	var BUFFER = 1;
+	var TEXTURE1D = 2;
+	var TEXTURE1DARRAY = 3;
+	var TEXTURE2D = 4;
+	var TEXTURE2DARRAY = 5;
+	var TEXTURE2DMS = 6;
+	var TEXTURE2DMSARRAY = 7;
+	var TEXTURE3D = 8;
+	var TEXTURECUBE = 9;
+	var TEXTURECUBEARRAY = 10;
+	var RAYTRACING_ACCELERATION_STRUCTURE = 11;
+}
+
+enum abstract ShaderComponentValue(Int) {
+	var R = 0;
+	var G = 1;
+	var B = 2;
+	var A = 3;
+	var ZERO = 4;
+	var ONE = 5;
+}
+
+abstract ShaderComponentMapping(Int) {
+	public var red(get,set) : ShaderComponentValue;
+	public var green(get,set) : ShaderComponentValue;
+	public var blue(get,set) : ShaderComponentValue;
+	public var alpha(get,set) : ShaderComponentValue;
+	public function new() {
+		this = 1 << 12;
+	}
+	inline function get_red() : ShaderComponentValue { return cast (this & 7); }
+	inline function get_green() : ShaderComponentValue { return cast ((this >> 3) & 7); }
+	inline function get_blue() : ShaderComponentValue { return cast ((this >> 6) & 7); }
+	inline function get_alpha() : ShaderComponentValue { return cast ((this >> 9) & 7); }
+	inline function set_red(v : ShaderComponentValue) { this = (this & ~(3<<0)) | ((cast v : Int) << 0); return v; }
+	inline function set_green(v : ShaderComponentValue) { this = (this & ~(3<<3)) | ((cast v : Int) << 3); return v; }
+	inline function set_blue(v : ShaderComponentValue) { this = (this & ~(3<<6)) | ((cast v : Int) << 6); return v; }
+	inline function set_alpha(v : ShaderComponentValue) { this = (this & ~(3<<9)) | ((cast v : Int) << 9); return v; }
+
+	public static inline var DEFAULT : ShaderComponentMapping = cast 0x1688;
+}
+
+@:struct class ShaderResourceViewDesc {
+	public var format : DxgiFormat;
+	public var dimension : SrvDimension;
+	public var shader4ComponentMapping : ShaderComponentMapping;
+	var __unionPadding : Int;
+}
+
+enum abstract BufferSRVFlags(Int) {
+	var NONE = 0;
+	var RAW = 1;
+}
+
+@:struct class BufferSRV extends ShaderResourceViewDesc {
+	public var firstElement : Int64;
+	public var numElements : Int;
+	public var structureByteStride : Int;
+	public var flags : BufferSRVFlags;
+	var unused : Int;
+	public function new() {
+		dimension = BUFFER;
+	}
+}
+
+@:struct class Text1DSRV extends ShaderResourceViewDesc {
+	public var mostDetailedMip : Int;
+	public var mipLevels : Int;
+	public var resourceMinLODClamp : Single;
+	var unused1 : Int;
+	var unused2 : Int;
+	var unused3 : Int;
+	public function new() {
+		dimension = TEXTURE1D;
+	}
+}
+
+@:struct class Text1DArraySRV extends ShaderResourceViewDesc {
+	public var mostDetailedMip : Int;
+	public var mipLevels : Int;
+	public var firstArraySlice : Int;
+	public var arraySize : Int;
+	public var resourceMinLODClamp : Single;
+	var unused1 : Int;
+	public function new() {
+		dimension = TEXTURE1DARRAY;
+	}
+}
+
+@:struct class Text2DSRV extends ShaderResourceViewDesc {
+	public var mostDetailedMip : Int;
+	public var mipLevels : Int;
+	public var planeSlice : Int;
+	public var resourceMinLODClamp : Single;
+	var unused1 : Int;
+	var unused2 : Int;
+	public function new() {
+		dimension = TEXTURE2D;
+	}
+}
+
+@:struct class Text2DArraySRV extends ShaderResourceViewDesc {
+	public var mostDetailedMip : Int;
+	public var mipLevels : Int;
+	public var firstArraySlice : Int;
+	public var arraySize : Int;
+	public var planeSlice : Int;
+	public var resourceMinLODClamp : Single;
+	public function new() {
+		dimension = TEXTURE2DARRAY;
+	}
+}
+
+@:struct class Text3DSRV extends ShaderResourceViewDesc {
+	public var mostDetailedMip : Int;
+	public var mipLevels : Int;
+	public var resourceMinLODClamp : Single;
+	var unused1 : Int;
+	var unused2 : Int;
+	var unused3 : Int;
+	public function new() {
+		dimension = TEXTURE3D;
+	}
+}
+
+@:struct class TextCubeSRV extends ShaderResourceViewDesc {
+	public var mostDetailedMip : Int;
+	public var mipLevels : Int;
+	public var resourceMinLODClamp : Single;
+	var unused1 : Int;
+	var unused2 : Int;
+	var unused3 : Int;
+	public function new() {
+		dimension = TEXTURECUBE;
+	}
+}
+
+@:struct class TextCubeArraySRV extends ShaderResourceViewDesc {
+	public var mostDetailedMip : Int;
+	public var mipLevels : Int;
+	public var first2DArrayFace : Int;
+	public var numCubes : Int;
+	public var resourceMinLODClamp : Single;
+	var unused1 : Int;
+	public function new() {
+		dimension = TEXTURECUBEARRAY;
+	}
+}
+
+@:struct class SamplerDesc {
+	public var filter : Filter;
+	public var addressU : AddressMode;
+	public var addressV : AddressMode;
+	public var addressW : AddressMode;
+	public var mipLODBias : Float;
+	public var maxAnisotropy : Int;
+	public var comparisonFunc : ComparisonFunc;
+	@:packed public var borderColor(default,never) : Color;
+	public var minLod : Single;
+	public var maxLod : Single;
+	public function new() {
+	}
+}
+
+@:struct class SubResourceData {
+	public var data : hl.Bytes;
+	public var rowPitch : Int64;
+	public var slicePitch : Int64;
+	public function new() {
+	}
+}
+
 @:hlNative("dx12")
 class Dx12 {
 
@@ -1165,6 +1397,12 @@ class Dx12 {
 	public static function createDepthStencilView( buffer : Resource, desc : DepthStencilViewDesc, target : Address ) {
 	}
 
+	public static function createShaderResourceView( resource : Resource, desc : ShaderResourceViewDesc, target : Address ) {
+	}
+
+	public static function createSampler( desc : SamplerDesc, target : Address ) {
+	}
+
 	public static function createCommittedResource( heapProperties : HeapProperties, heapFlags : haxe.EnumFlags<HeapFlag>, desc : ResourceDesc, initialState : ResourceStates, clearValue : ClearValue ) : GpuResource {
 		return null;
 	}
@@ -1172,6 +1410,10 @@ class Dx12 {
 	public static function resize( width : Int, height : Int, bufferCount : Int, format : DxgiFormat ) {
 	}
 
+	public static function updateSubResource( commandList : CommandList, dst : GpuResource, src : GpuResource, srcOffset : Int64, first : Int, count : Int, data : SubResourceData ) : Bool {
+		return false;
+	}
+
 	public static function signal( fence : Fence, value : Int64 ) {
 	}
 

+ 191 - 0
libs/directx/dx12.cpp

@@ -179,6 +179,143 @@ DEFINE_PRIM(_VOID, signal, _RES _I64);
 DEFINE_PRIM(_VOID, flush_messages, _NO_ARG);
 DEFINE_PRIM(_BYTES, get_device_name, _NO_ARG);
 
+/// --- utilities (from d3dx12.h)
+
+struct CD3DX12_TEXTURE_COPY_LOCATION : public D3D12_TEXTURE_COPY_LOCATION
+{
+    CD3DX12_TEXTURE_COPY_LOCATION() = default;
+    explicit CD3DX12_TEXTURE_COPY_LOCATION(const D3D12_TEXTURE_COPY_LOCATION &o) noexcept :
+        D3D12_TEXTURE_COPY_LOCATION(o)
+    {}
+    CD3DX12_TEXTURE_COPY_LOCATION(_In_ ID3D12Resource* pRes) noexcept
+    {
+        pResource = pRes;
+        Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
+        PlacedFootprint = {};
+    }
+    CD3DX12_TEXTURE_COPY_LOCATION(_In_ ID3D12Resource* pRes, D3D12_PLACED_SUBRESOURCE_FOOTPRINT const& Footprint) noexcept
+    {
+        pResource = pRes;
+        Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
+        PlacedFootprint = Footprint;
+    }
+    CD3DX12_TEXTURE_COPY_LOCATION(_In_ ID3D12Resource* pRes, UINT Sub) noexcept
+    {
+        pResource = pRes;
+        Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
+        PlacedFootprint = {};
+        SubresourceIndex = Sub;
+    }
+};
+
+inline void MemcpySubresource(
+    _In_ const D3D12_MEMCPY_DEST* pDest,
+    _In_ const D3D12_SUBRESOURCE_DATA* pSrc,
+    SIZE_T RowSizeInBytes,
+    UINT NumRows,
+    UINT NumSlices) noexcept
+{
+    for (UINT z = 0; z < NumSlices; ++z)
+    {
+        auto pDestSlice = static_cast<BYTE*>(pDest->pData) + pDest->SlicePitch * z;
+        auto pSrcSlice = static_cast<const BYTE*>(pSrc->pData) + pSrc->SlicePitch * LONG_PTR(z);
+        for (UINT y = 0; y < NumRows; ++y)
+        {
+            memcpy(pDestSlice + pDest->RowPitch * y,
+                   pSrcSlice + pSrc->RowPitch * LONG_PTR(y),
+                   RowSizeInBytes);
+        }
+    }
+}
+
+inline UINT64 UpdateSubresources(
+    _In_ ID3D12GraphicsCommandList* pCmdList,
+    _In_ ID3D12Resource* pDestinationResource,
+    _In_ ID3D12Resource* pIntermediate,
+    _In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
+    _In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources,
+    UINT64 RequiredSize,
+    _In_reads_(NumSubresources) const D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts,
+    _In_reads_(NumSubresources) const UINT* pNumRows,
+    _In_reads_(NumSubresources) const UINT64* pRowSizesInBytes,
+    _In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData) noexcept
+{
+    // Minor validation
+    auto IntermediateDesc = pIntermediate->GetDesc();
+    auto DestinationDesc = pDestinationResource->GetDesc();
+    if (IntermediateDesc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER ||
+        IntermediateDesc.Width < RequiredSize + pLayouts[0].Offset ||
+        RequiredSize > SIZE_T(-1) ||
+        (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER &&
+            (FirstSubresource != 0 || NumSubresources != 1)))
+    {
+        return 0;
+    }
+
+    BYTE* pData;
+    HRESULT hr = pIntermediate->Map(0, nullptr, reinterpret_cast<void**>(&pData));
+    if (FAILED(hr))
+    {
+        return 0;
+    }
+
+    for (UINT i = 0; i < NumSubresources; ++i)
+    {
+        if (pRowSizesInBytes[i] > SIZE_T(-1)) return 0;
+        D3D12_MEMCPY_DEST DestData = { pData + pLayouts[i].Offset, pLayouts[i].Footprint.RowPitch, SIZE_T(pLayouts[i].Footprint.RowPitch) * SIZE_T(pNumRows[i]) };
+        MemcpySubresource(&DestData, &pSrcData[i], static_cast<SIZE_T>(pRowSizesInBytes[i]), pNumRows[i], pLayouts[i].Footprint.Depth);
+    }
+    pIntermediate->Unmap(0, nullptr);
+
+    if (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
+    {
+        pCmdList->CopyBufferRegion(
+            pDestinationResource, 0, pIntermediate, pLayouts[0].Offset, pLayouts[0].Footprint.Width);
+    }
+    else
+    {
+        for (UINT i = 0; i < NumSubresources; ++i)
+        {
+            CD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource, i + FirstSubresource);
+            CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]);
+            pCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src, nullptr);
+        }
+    }
+    return RequiredSize;
+}
+
+inline UINT64 UpdateSubresources(
+    _In_ ID3D12GraphicsCommandList* pCmdList,
+    _In_ ID3D12Resource* pDestinationResource,
+    _In_ ID3D12Resource* pIntermediate,
+    UINT64 IntermediateOffset,
+    _In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
+    _In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources,
+    _In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData) noexcept
+{
+    UINT64 RequiredSize = 0;
+    auto MemToAlloc = static_cast<UINT64>(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(UINT) + sizeof(UINT64)) * NumSubresources;
+    if (MemToAlloc > SIZE_MAX)
+    {
+       return 0;
+    }
+    void* pMem = HeapAlloc(GetProcessHeap(), 0, static_cast<SIZE_T>(MemToAlloc));
+    if (pMem == nullptr)
+    {
+       return 0;
+    }
+    auto pLayouts = static_cast<D3D12_PLACED_SUBRESOURCE_FOOTPRINT*>(pMem);
+    auto pRowSizesInBytes = reinterpret_cast<UINT64*>(pLayouts + NumSubresources);
+    auto pNumRows = reinterpret_cast<UINT*>(pRowSizesInBytes + NumSubresources);
+
+    auto Desc = pDestinationResource->GetDesc();
+    static_driver->device->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, pLayouts, pNumRows, pRowSizesInBytes, &RequiredSize);
+
+    UINT64 Result = UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, pLayouts, pNumRows, pRowSizesInBytes, pSrcData);
+    HeapFree(GetProcessHeap(), 0, pMem);
+    return Result;
+}
+
 // ---- RESOURCES
 
 ID3D12Resource *HL_NAME(get_back_buffer)( int index ) {
@@ -201,6 +338,14 @@ void HL_NAME(create_depth_stencil_view)( ID3D12Resource *res, D3D12_DEPTH_STENCI
 	static_driver->device->CreateDepthStencilView(res,desc,descriptor);
 }
 
+void HL_NAME(create_sampler)( D3D12_SAMPLER_DESC *desc, D3D12_CPU_DESCRIPTOR_HANDLE descriptor ) {
+	static_driver->device->CreateSampler(desc,descriptor);
+}
+
+void HL_NAME(create_shader_resource_view)( ID3D12Resource *res, D3D12_SHADER_RESOURCE_VIEW_DESC *desc, D3D12_CPU_DESCRIPTOR_HANDLE descriptor ) {
+	static_driver->device->CreateShaderResourceView(res,desc,descriptor);
+}
+
 int64 HL_NAME(resource_get_gpu_virtual_address)( ID3D12Resource *res ) {
 	return res->GetGPUVirtualAddress();
 }
@@ -219,14 +364,30 @@ void HL_NAME(resource_unmap)( ID3D12Resource *res, int subres, D3D12_RANGE *rang
 	res->Unmap(subres, range);
 }
 
+int64 HL_NAME(get_required_intermediate_size)( ID3D12Resource *res, int first, int count ) {
+    auto desc = res->GetDesc();
+    UINT64 size = 0;
+    static_driver->device->GetCopyableFootprints(&desc, first, count, 0, NULL, NULL, NULL, &size);
+    return size;
+}
+
+bool HL_NAME(update_sub_resource)( ID3D12GraphicsCommandList *cmd, ID3D12Resource *res, ID3D12Resource *tmp, int64 tmpOffs, int first, int count, D3D12_SUBRESOURCE_DATA *data ) {
+	return UpdateSubresources(cmd,res,tmp,(UINT64)tmpOffs,(UINT)first,(UINT)count,data) != 0;
+}
+
 DEFINE_PRIM(_VOID, create_render_target_view, _RES _STRUCT _I64);
 DEFINE_PRIM(_VOID, create_depth_stencil_view, _RES _STRUCT _I64);
+DEFINE_PRIM(_VOID, create_shader_resource_view, _RES _STRUCT _I64);
+DEFINE_PRIM(_VOID, create_sampler, _STRUCT _I64);
 DEFINE_PRIM(_RES, create_committed_resource, _STRUCT _I32 _STRUCT _I32 _STRUCT);
 DEFINE_PRIM(_RES, get_back_buffer, _I32);
 DEFINE_PRIM(_VOID, resource_release, _RES);
 DEFINE_PRIM(_I64, resource_get_gpu_virtual_address, _RES);
 DEFINE_PRIM(_BYTES, resource_map, _RES _I32 _STRUCT);
 DEFINE_PRIM(_VOID, resource_unmap, _RES _I32 _STRUCT);
+DEFINE_PRIM(_I64, get_required_intermediate_size, _RES _I32 _I32);
+DEFINE_PRIM(_BOOL, update_sub_resource, _RES _RES _RES _I64 _I32 _I32 _STRUCT);
+
 
 // ---- SHADERS
 
@@ -438,10 +599,18 @@ void HL_NAME(command_list_copy_buffer_region)( ID3D12GraphicsCommandList *l, ID3
 	l->CopyBufferRegion(dst, dstOffset, src, srcOffset, numBytes);
 }
 
+void HL_NAME(command_list_copy_texture_region)( ID3D12GraphicsCommandList *l, D3D12_TEXTURE_COPY_LOCATION *dst, int dstX, int dstY, int dstZ, D3D12_TEXTURE_COPY_LOCATION *src, D3D12_BOX *srcBox ) {
+	l->CopyTextureRegion(dst, dstX, dstY, dstZ, src, srcBox);
+}
+
 void HL_NAME(command_list_om_set_render_targets)( ID3D12GraphicsCommandList *l, int count, D3D12_CPU_DESCRIPTOR_HANDLE *handles, BOOL flag, D3D12_CPU_DESCRIPTOR_HANDLE *depthStencils ) {
 	l->OMSetRenderTargets(count,handles,flag,depthStencils);
 }
 
+void HL_NAME(command_list_om_set_stencil_ref)( ID3D12GraphicsCommandList *l, int value ) {
+	l->OMSetStencilRef(value);
+}
+
 void HL_NAME(command_list_rs_set_viewports)( ID3D12GraphicsCommandList *l, int count, D3D12_VIEWPORT *viewports ) {
 	l->RSSetViewports(count, viewports);
 }
@@ -450,6 +619,22 @@ void HL_NAME(command_list_rs_set_scissor_rects)( ID3D12GraphicsCommandList *l, i
 	l->RSSetScissorRects(count, rects);
 }
 
+void HL_NAME(command_list_set_descriptor_heaps)( ID3D12GraphicsCommandList *l, varray *heaps ) {
+	l->SetDescriptorHeaps(heaps->size,hl_aptr(heaps,ID3D12DescriptorHeap*));
+}
+
+void HL_NAME(command_list_set_graphics_root_constant_buffer_view)( ID3D12GraphicsCommandList *l, int index, D3D12_GPU_VIRTUAL_ADDRESS address ) {
+	l->SetGraphicsRootConstantBufferView(index,address);
+}
+
+void HL_NAME(command_list_set_graphics_root_descriptor_table)( ID3D12GraphicsCommandList *l, int index, D3D12_GPU_DESCRIPTOR_HANDLE handle ) {
+	l->SetGraphicsRootDescriptorTable(index,handle);
+}
+
+void HL_NAME(command_list_set_graphics_root_shader_resource_view)( ID3D12GraphicsCommandList *l, int index, D3D12_GPU_VIRTUAL_ADDRESS handle ) {
+	l->SetGraphicsRootShaderResourceView(index,handle);
+}
+
 DEFINE_PRIM(_RES, command_allocator_create, _I32);
 DEFINE_PRIM(_VOID, command_allocator_reset, _RES);
 DEFINE_PRIM(_RES, command_list_create, _I32 _RES _RES);
@@ -463,11 +648,17 @@ DEFINE_PRIM(_VOID, command_list_draw_instanced, _RES _I32 _I32 _I32 _I32);
 DEFINE_PRIM(_VOID, command_list_draw_indexed_instanced, _RES _I32 _I32 _I32 _I32 _I32);
 DEFINE_PRIM(_VOID, command_list_set_graphics_root_signature, _RES _RES);
 DEFINE_PRIM(_VOID, command_list_set_graphics_root32_bit_constants, _RES _I32 _I32 _BYTES _I32);
+DEFINE_PRIM(_VOID, command_list_set_graphics_root_constant_buffer_view, _RES _I32 _I64);
+DEFINE_PRIM(_VOID, command_list_set_graphics_root_descriptor_table, _RES _I32 _I64);
+DEFINE_PRIM(_VOID, command_list_set_graphics_root_shader_resource_view, _RES _I32 _I64);
+DEFINE_PRIM(_VOID, command_list_set_descriptor_heaps, _RES _ARR);
 DEFINE_PRIM(_VOID, command_list_set_pipeline_state, _RES _RES);
 DEFINE_PRIM(_VOID, command_list_ia_set_vertex_buffers, _RES _I32 _I32 _STRUCT);
 DEFINE_PRIM(_VOID, command_list_ia_set_index_buffer, _RES _STRUCT);
 DEFINE_PRIM(_VOID, command_list_ia_set_primitive_topology, _RES _I32);
 DEFINE_PRIM(_VOID, command_list_copy_buffer_region, _RES _RES _I64 _RES _I64 _I64);
+DEFINE_PRIM(_VOID, command_list_copy_texture_region, _RES _STRUCT _I32 _I32 _I32 _STRUCT _STRUCT);
 DEFINE_PRIM(_VOID, command_list_om_set_render_targets, _RES _I32 _BYTES _I32 _BYTES);
+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);