// TODO: PERF make this do 3 blocks 8 bytes at once for better perf // TODO: PERF use HashCode.Add not Combine private static uint Crc32CElseHashCodeCombine(byte *first, nuint length) { uint value = ~0u; var leadingBytes = MathHelpers.AlignUp(first, 8); // handle leading bytes until 8 byte aligned while (first < leadingBytes) { value = Hash(value, *first++); length--; } ulong *pLong = (ulong *)first; byte * last = first + length; byte * alignedLast = first + MathHelpers.AlignDown(length, 8); // handle main in 8 byte chunks until we can't anymore ulong tmpValue = value; while (pLong < alignedLast) { tmpValue = Hash8(tmpValue, *pLong++); } value = (uint)tmpValue; // handle trailing first = (byte *)pLong; while (first < last) { value = Hash(value, *first++); } return(value);
public BasicSceneRenderer(GraphicsDevice device) { _device = device; _rtvs = _device.CreateDescriptorHeap(DescriptorHeapType.RenderTargetView, 1); _dsvs = _device.CreateDescriptorHeap(DescriptorHeapType.RenderTargetView, 1); _textureHandle = _device.AllocateResourceDescriptors(2); _texturedObjects = ModelLoader.LoadGl_Old("Assets/Gltf/Handgun_NoTangent.gltf"); //_texturedObjects = new[] { GeometryGenerator.CreateCube(0.5f) }; var texture = TextureLoader.LoadTextureDesc("Assets/Textures/handgun_c.dds"); var normals = TextureLoader.LoadTextureDesc("Assets/Textures/handgun_n.dds"); _vertexBuffer = new Buffer[_texturedObjects.Length]; _indexBuffer = new Buffer[_texturedObjects.Length]; using (var list = _device.BeginUploadContext()) { for (var i = 0; i < _texturedObjects.Length; i++) { _vertexBuffer[i] = list.UploadBuffer(_texturedObjects[i].Vertices); _vertexBuffer[i].SetName("VertexBuffer"); _indexBuffer[i] = list.UploadBuffer(_texturedObjects[i].Indices); _indexBuffer[i].SetName("IndexBuffer"); } _texture = list.UploadTexture(texture); _texture.SetName("Gun texture"); } //list.UploadTexture(normals.Data.Span, normals.SubresourceData.Span, normals.Desc, ResourceState.PixelShaderResource, out _normals); //_normals.SetName("Gun normals"); _device.CreateShaderResourceView(_texture, _textureHandle[0]); //_normalHandle = _device.CreateShaderResourceView(_normals); _objectConstants = new ObjectConstants[_texturedObjects.Length]; _obj = _device.Allocator.AllocateBuffer(MathHelpers.AlignUp(sizeof(ObjectConstants), 256) * _texturedObjects.Length, MemoryAccess.CpuUpload); _obj.SetName("ObjectConstants buffer"); _frame = _device.Allocator.AllocateBuffer(sizeof(FrameConstants), MemoryAccess.CpuUpload); _frame.SetName("FrameConstants buffer"); _light = _device.Allocator.AllocateBuffer(sizeof(LightConstants), MemoryAccess.CpuUpload); _light.SetName("LightConstants buffer"); CreatePipelines(); InitializeConstants(); }
public static void DebugStream(D3D12_PIPELINE_STATE_STREAM_DESC *pDesc) { nint bytesParsed = 0; byte *pStart = (byte *)pDesc->pPipelineStateSubobjectStream; while (bytesParsed < (nint)pDesc->SizeInBytes) { var element = *(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE *)&pStart[bytesParsed]; bytesParsed += sizeof(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE); Console.WriteLine($"Element {element}"); bytesParsed += MathHelpers.AlignUp(GetSubobjectSize(element), sizeof(void *)); } }