本文整理汇总了C++中CD3DX12_HEAP_PROPERTIES函数的典型用法代码示例。如果您正苦于以下问题:C++ CD3DX12_HEAP_PROPERTIES函数的具体用法?C++ CD3DX12_HEAP_PROPERTIES怎么用?C++ CD3DX12_HEAP_PROPERTIES使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CD3DX12_HEAP_PROPERTIES函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CheckHR
XFBEncoder::XFBEncoder()
{
ID3D12Resource* texture;
CheckHR(D3D::device->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
D3D12_HEAP_FLAG_NONE,
&CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, XFB_TEXTURE_WIDTH, XFB_TEXTURE_HEIGHT, 1, 1, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET),
D3D12_RESOURCE_STATE_RENDER_TARGET,
nullptr,
IID_PPV_ARGS(&texture)));
m_yuyv_texture = new D3DTexture2D(texture,
TEXTURE_BIND_FLAG_SHADER_RESOURCE | TEXTURE_BIND_FLAG_RENDER_TARGET,
DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_R8G8B8A8_UNORM);
SAFE_RELEASE(texture);
CheckHR(D3D::device->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_READBACK),
D3D12_HEAP_FLAG_NONE,
&CD3DX12_RESOURCE_DESC::Buffer(ROUND_UP(XFB_TEXTURE_WIDTH * sizeof(u32), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT) * MAX_XFB_HEIGHT),
D3D12_RESOURCE_STATE_COPY_DEST,
nullptr,
IID_PPV_ARGS(&m_readback_buffer)));
m_upload_buffer = std::make_unique<D3DStreamBuffer>(XFB_UPLOAD_BUFFER_SIZE, XFB_UPLOAD_BUFFER_SIZE, nullptr);
m_encode_params_buffer = std::make_unique<D3DStreamBuffer>(XFB_ENCODER_PARAMS_BUFFER_SIZE, XFB_ENCODER_PARAMS_BUFFER_SIZE, nullptr);
}
示例2: ThrowIfFailed
void DX12Texture::Upload()
{
CD3DX12_RESOURCE_DESC textureDesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, m_Width, m_Height,
1U, 1U);
ThrowIfFailed(m_Renderer.GetDevice().CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
D3D12_HEAP_FLAG_NONE, &textureDesc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&m_GPUResource)));
const uint32 subresourceCount = textureDesc.DepthOrArraySize * textureDesc.MipLevels;
const uint64 uploadBufferSize = GetRequiredIntermediateSize(m_GPUResource.Get(), 0, subresourceCount);
ThrowIfFailed(m_Renderer.GetDevice().CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
D3D12_HEAP_FLAG_NONE, &CD3DX12_RESOURCE_DESC::Buffer(uploadBufferSize), D3D12_RESOURCE_STATE_GENERIC_READ,
nullptr, IID_PPV_ARGS(&m_UploadResource)));
// Copy data to the intermediate upload heap and then schedule a copy
// from the upload heap to the Texture2D.
D3D12_SUBRESOURCE_DATA textureData = {};
textureData.pData = m_Data.get();
textureData.RowPitch = m_Width * 4;
textureData.SlicePitch = m_Width * m_Height * 4;
UpdateSubresources(&m_Renderer.GetCommandList().GetCommandList(), m_GPUResource.Get(), m_UploadResource.Get(), 0, 0, subresourceCount,
&textureData);
m_Renderer.GetCommandList().GetCommandList().ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_GPUResource.Get(),
D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE));
}
示例3: sizeof
void Application::CreateVertexBuffer()
{
struct Vertex
{
float position[2];
float texcoord[2];
};
// Define the geometry for a quad.
float screenAspectRatio = static_cast<float>(window->GetWidth()) / window->GetHeight();
Vertex quadVertices[] =
{
{ { -0.25f, -0.25f * screenAspectRatio }, { 0.0f, 0.0f } },
{ { -0.25f, 0.25f * screenAspectRatio },{ 0.0f, 1.0f } },
{ { 0.25f, -0.25f * screenAspectRatio },{ 1.0f, 0.0f } },
{ { 0.25f, 0.25f * screenAspectRatio },{ 1.0f, 1.0f } }
};
const unsigned int vertexBufferSize = sizeof(quadVertices);
// Create an upload heap for the
ComPtr<ID3D12Resource> uploadHeap;
if (FAILED(device->GetD3D12Device()->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD), D3D12_HEAP_FLAG_NONE,
&CD3DX12_RESOURCE_DESC::Buffer(sizeof(quadVertices)), D3D12_RESOURCE_STATE_GENERIC_READ, // D3D12_RESOURCE_STATE_GENERIC_READ is the only possible for D3D12_HEAP_TYPE_UPLOAD.
nullptr, IID_PPV_ARGS(&uploadHeap))))
{
CRITICAL_ERROR("Failed to create upload heap.");
}
// Copy the triangle data to the vertex buffer.
UINT8* pVertexDataBegin;
if (FAILED(uploadHeap->Map(0, nullptr, reinterpret_cast<void**>(&pVertexDataBegin))))
CRITICAL_ERROR("Failed to map vertex buffer");
memcpy(pVertexDataBegin, quadVertices, sizeof(quadVertices));
uploadHeap->Unmap(0, nullptr);
// Create vertex buffer.
if (FAILED(device->GetD3D12Device()->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE,
&CD3DX12_RESOURCE_DESC::Buffer(sizeof(quadVertices)), D3D12_RESOURCE_STATE_COPY_DEST,
nullptr, IID_PPV_ARGS(&vertexBuffer))))
{
CRITICAL_ERROR("Failed to create vertex buffer.");
}
// Copy over and wait until its done.
commandList->Reset(commandAllocator[0].Get(), nullptr);
commandList->CopyResource(vertexBuffer.Get(), uploadHeap.Get());
commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(vertexBuffer.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER));
commandList->Close();
ID3D12CommandList* ppCommandLists[] = { commandList.Get() };
device->GetDirectCommandQueue()->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);
device->WaitForIdleGPU();
// Initialize the vertex buffer view.
vertexBufferView.BufferLocation = vertexBuffer->GetGPUVirtualAddress();
vertexBufferView.StrideInBytes = sizeof(Vertex);
vertexBufferView.SizeInBytes = vertexBufferSize;
}
示例4: CD3DX12_HEAP_PROPERTIES
void ae3d::VertexBuffer::UploadVB( void* faces, void* vertices, unsigned ibSize )
{
auto uploadProp = CD3DX12_HEAP_PROPERTIES( D3D12_HEAP_TYPE_UPLOAD );
auto bufferProp = CD3DX12_RESOURCE_DESC::Buffer( ibOffset + ibSize );
HRESULT hr = GfxDeviceGlobal::device->CreateCommittedResource(
&uploadProp,
D3D12_HEAP_FLAG_NONE,
&bufferProp,
D3D12_RESOURCE_STATE_GENERIC_READ,
nullptr,
IID_PPV_ARGS( &vb ) );
if (FAILED( hr ))
{
ae3d::System::Assert( false, "Unable to create vertex buffer!\n" );
return;
}
vb->SetName( L"VertexBuffer" );
Global::vbs.push_back( vb );
char* vbUploadPtr = nullptr;
hr = vb->Map( 0, nullptr, reinterpret_cast<void**>(&vbUploadPtr) );
if (FAILED( hr ))
{
ae3d::System::Assert( false, "Unable to map vertex buffer!\n" );
return;
}
memcpy_s( vbUploadPtr, ibOffset, vertices, ibOffset );
memcpy_s( vbUploadPtr + ibOffset, ibSize, faces, ibSize );
vb->Unmap( 0, nullptr );
}
示例5: CD3DX12_HEAP_PROPERTIES
BitonicSort::BitonicSort(ID3D12Device *pDevice, UINT nodeMask)
{
auto defaultHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);
auto indirectArgBufferDesc = CD3DX12_RESOURCE_DESC::Buffer(cIndirectArgStride * 22 * 23 / 2, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
ThrowInternalFailure(pDevice->CreateCommittedResource(
&defaultHeapProperties,
D3D12_HEAP_FLAG_NONE,
&indirectArgBufferDesc,
D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT,
nullptr,
IID_PPV_ARGS(&m_pDispatchArgs)));
CD3DX12_ROOT_PARAMETER1 parameters[NumParameters];
parameters[ShaderSpecificConstants].InitAsConstants(2, 0);
parameters[OutputUAV].InitAsUnorderedAccessView(0);
parameters[IndexBufferUAV].InitAsUnorderedAccessView(1);
parameters[GenericConstants].InitAsConstants(2, 1);
auto rootSignatureDesc = CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(ARRAYSIZE(parameters), parameters);
CreateRootSignatureHelper(pDevice, rootSignatureDesc, &m_pRootSignature);
CreatePSOHelper(pDevice, nodeMask, m_pRootSignature, COMPILED_SHADER(g_pBitonicIndirectArgsCS),&m_pBitonicIndirectArgsCS);
CreatePSOHelper(pDevice, nodeMask, m_pRootSignature, COMPILED_SHADER(g_pBitonicInnerSortCS), &m_pBitonicInnerSortCS);
CreatePSOHelper(pDevice, nodeMask, m_pRootSignature, COMPILED_SHADER(g_pBitonicOuterSortCS), &m_pBitonicOuterSortCS);
CreatePSOHelper(pDevice, nodeMask, m_pRootSignature, COMPILED_SHADER(g_pBitonicPreSortCS), &m_pBitonicPreSortCS);
D3D12_INDIRECT_ARGUMENT_DESC indirectArgDesc = {};
indirectArgDesc.Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH;
D3D12_COMMAND_SIGNATURE_DESC commandSignatureDesc;
commandSignatureDesc.NodeMask = nodeMask;
commandSignatureDesc.pArgumentDescs = &indirectArgDesc;
commandSignatureDesc.ByteStride = sizeof(D3D12_DISPATCH_ARGUMENTS);
commandSignatureDesc.NumArgumentDescs = 1;
pDevice->CreateCommandSignature(&commandSignatureDesc, nullptr, IID_PPV_ARGS(&m_pCommandSignature));
}
示例6: ZeroMemory
void ShadowMap::BuildResource()
{
// Note, compressed formats cannot be used for UAV. We get error like:
// ERROR: ID3D11Device::CreateTexture2D: The format (0x4d, BC3_UNORM)
// cannot be bound as an UnorderedAccessView, or cast to a format that
// could be bound as an UnorderedAccessView. Therefore this format
// does not support D3D11_BIND_UNORDERED_ACCESS.
D3D12_RESOURCE_DESC texDesc;
ZeroMemory(&texDesc, sizeof(D3D12_RESOURCE_DESC));
texDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
texDesc.Alignment = 0;
texDesc.Width = mWidth;
texDesc.Height = mHeight;
texDesc.DepthOrArraySize = 1;
texDesc.MipLevels = 1;
texDesc.Format = mFormat;
texDesc.SampleDesc.Count = 1;
texDesc.SampleDesc.Quality = 0;
texDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
texDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
D3D12_CLEAR_VALUE optClear;
optClear.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
optClear.DepthStencil.Depth = 1.0f;
optClear.DepthStencil.Stencil = 0;
ThrowIfFailed(md3dDevice->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
D3D12_HEAP_FLAG_NONE,
&texDesc,
D3D12_RESOURCE_STATE_GENERIC_READ,
&optClear,
IID_PPV_ARGS(&mShadowMap)));
}
示例7: m_fenceValue
FrameResource::FrameResource(ID3D12Device* pDevice, UINT cityRowCount, UINT cityColumnCount) :
m_fenceValue(0),
m_cityRowCount(cityRowCount),
m_cityColumnCount(cityColumnCount)
{
m_modelMatrices.resize(m_cityRowCount * m_cityColumnCount);
// The command allocator is used by the main sample class when
// resetting the command list in the main update loop. Each frame
// resource needs a command allocator because command allocators
// cannot be reused until the GPU is done executing the commands
// associated with it.
ThrowIfFailed(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&m_commandAllocator)));
ThrowIfFailed(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_BUNDLE, IID_PPV_ARGS(&m_bundleAllocator)));
// Create an upload heap for the constant buffers.
ThrowIfFailed(pDevice->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
D3D12_HEAP_FLAG_NONE,
&CD3DX12_RESOURCE_DESC::Buffer(sizeof(SceneConstantBuffer) * m_cityRowCount * m_cityColumnCount),
D3D12_RESOURCE_STATE_GENERIC_READ,
nullptr,
IID_PPV_ARGS(&m_cbvUploadHeap)));
// Map the constant buffers. Note that unlike D3D11, the resource
// does not need to be unmapped for use by the GPU. In this sample,
// the resource stays 'permenantly' mapped to avoid overhead with
// mapping/unmapping each frame.
CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU.
ThrowIfFailed(m_cbvUploadHeap->Map(0, &readRange, reinterpret_cast<void**>(&m_pConstantBuffers)));
// Update all of the model matrices once; our cities don't move so
// we don't need to do this ever again.
SetCityPositions(8.0f, -8.0f);
}
示例8: TCacheEntry
TextureCacheBase::TCacheEntryBase* TextureCache::CreateTexture(const TCacheEntryConfig& config)
{
if (config.rendertarget)
{
D3DTexture2D* texture = D3DTexture2D::Create(config.width, config.height,
static_cast<D3D11_BIND_FLAG>((static_cast<int>(D3D11_BIND_RENDER_TARGET) | static_cast<int>(D3D11_BIND_SHADER_RESOURCE))),
D3D11_USAGE_DEFAULT, DXGI_FORMAT_R8G8B8A8_UNORM, 1, config.layers);
TCacheEntry* entry = new TCacheEntry(config, texture);
entry->m_texture_srv_cpu_handle = texture->GetSRV12CPU();
entry->m_texture_srv_gpu_handle = texture->GetSRV12GPU();
entry->m_texture_srv_gpu_handle_cpu_shadow = texture->GetSRV12GPUCPUShadow();
return entry;
}
else
{
ID3D12Resource* texture_resource = nullptr;
D3D12_RESOURCE_DESC texture_resource_desc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM,
config.width, config.height, 1, config.levels);
CheckHR(
D3D::device12->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
D3D12_HEAP_FLAG_NONE,
&CD3DX12_RESOURCE_DESC(texture_resource_desc),
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
nullptr,
IID_PPV_ARGS(&texture_resource)
)
);
D3DTexture2D* texture = new D3DTexture2D(
texture_resource,
D3D11_BIND_SHADER_RESOURCE,
DXGI_FORMAT_UNKNOWN,
DXGI_FORMAT_UNKNOWN,
DXGI_FORMAT_UNKNOWN,
false,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE
);
TCacheEntry* const entry = new TCacheEntry(
config, texture
);
entry->m_texture_srv_cpu_handle = texture->GetSRV12CPU();
entry->m_texture_srv_gpu_handle = texture->GetSRV12GPU();
entry->m_texture_srv_gpu_handle_cpu_shadow = texture->GetSRV12GPUCPUShadow();
// EXISTINGD3D11TODO: better debug names
D3D::SetDebugObjectName12(entry->m_texture->GetTex12(), "a texture of the TextureCache");
SAFE_RELEASE(texture_resource);
return entry;
}
}
示例9: afCreateTexture2D
SRVID afCreateTexture2D(AFDTFormat format, const IVec2& size, void *image)
{
D3D12_RESOURCE_DESC textureDesc = {};
textureDesc.MipLevels = 1;
textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
textureDesc.Width = size.x;
textureDesc.Height = size.y;
textureDesc.Flags = D3D12_RESOURCE_FLAG_NONE;
textureDesc.DepthOrArraySize = 1;
textureDesc.SampleDesc.Count = 1;
textureDesc.SampleDesc.Quality = 0;
textureDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
SRVID id;
HRESULT hr = deviceMan.GetDevice()->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
D3D12_HEAP_FLAG_NONE,
&textureDesc,
D3D12_RESOURCE_STATE_GENERIC_READ,
nullptr,
IID_PPV_ARGS(&id));
TexDesc texDesc;
texDesc.size = size;
afWriteTexture(id, texDesc, image);
return id;
}
示例10: num_query
timestamp_query::timestamp_query(device const& dvc, dx12u::cmd_queue const& q, int gpu_ordinal, std::size_t max_num_query) : num_query(max_num_query)
{
if (!dvc.Get())
{
throw error{ "null device" };
}
std::uint32_t gpu_mask = gpu_ordinal < 0 ? 1 : (1u << static_cast<std::uint32_t>(gpu_ordinal));
// alloc query buffer
size_t buf_aligned_sz = (num_query * sizeof(std::uint64_t) + 4095) & ~4095; // page aligned
auto heap_read_back = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_READBACK, gpu_mask, gpu_mask);
auto buffer_desc = CD3DX12_RESOURCE_DESC::Buffer(buf_aligned_sz);
auto r = dvc->CreateCommittedResource(&heap_read_back, D3D12_HEAP_FLAG_NONE,
&buffer_desc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&buffer));
dx12u::throw_if_error(r, "timestamp resource creation failure");
// query heap
D3D12_QUERY_HEAP_DESC heap_desc{};
heap_desc.Type = D3D12_QUERY_HEAP_TYPE_TIMESTAMP;
heap_desc.Count = static_cast<std::uint32_t>(num_query);
heap_desc.NodeMask = gpu_mask;
r = dvc->CreateQueryHeap(&heap_desc, IID_PPV_ARGS(&qh));
dx12u::throw_if_error(r, "timestamp query heap creation failure");
// clock frequency
dvc->SetStablePowerState(true);
q.get_com_ptr()->GetTimestampFrequency(&clock_freq);
}
示例11: D3D12RHIDeviceChild
D3D12GpuTexture::D3D12GpuTexture(Device::Ptr pDevice, rhi::TextureDesc const & Desc)
: D3D12RHIDeviceChild(pDevice)
{
if (Desc.IsTex2D())
{
m_Desc.Dimension = D3D12_RESOURCE_DIMENSION::D3D12_RESOURCE_DIMENSION_TEXTURE2D;
}
else if (Desc.IsTex1D())
{
m_Desc.Dimension = D3D12_RESOURCE_DIMENSION::D3D12_RESOURCE_DIMENSION_TEXTURE1D;
}
else if (Desc.IsTex3D())
{
m_Desc.Dimension = D3D12_RESOURCE_DIMENSION::D3D12_RESOURCE_DIMENSION_TEXTURE3D;
}
m_Desc.Width = Desc.Width;
m_Desc.Height = Desc.Height;
m_Desc.DepthOrArraySize = static_cast<const UINT16>(Desc.Depth);
m_Desc.MipLevels = static_cast<const UINT16>(Desc.MipLevels);
m_Desc.Format = g_DXGIFormatTable[Desc.Format];
m_Desc.SampleDesc.Count = 1;
m_Desc.SampleDesc.Quality = 0;
CD3DX12_HEAP_PROPERTIES HeapProp = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);
ThrowIfFailed(GetParentDeviceRef().Get()->CreateCommittedResource(&HeapProp, D3D12_HEAP_FLAG_NONE, &m_Desc,
D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(m_Resource.GetAddressOf())));
}
示例12: texDesc
void KRenderTarget::CreateRenderTargetArray(uint32 num_slices, DXGI_FORMAT tex_format, int32 width, int32 height, const float clear_color[4] /*= 0*/)
{
// Create the renderTargetTexture
CD3DX12_RESOURCE_DESC texDesc(
D3D12_RESOURCE_DIMENSION_TEXTURE2D,
0, // alignment
width, height, num_slices,
1, // mip levels
tex_format,
1, 0, // sample count/quality
D3D12_TEXTURE_LAYOUT_UNKNOWN,
D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET);
// Performance tip: Tell the runtime at resource creation the desired clear value.
D3D12_CLEAR_VALUE clearValue;
clearValue.Format = tex_format;
if (clear_color == 0)
{
float clearColor[] = { 0, 0, 0, 1 };
memcpy(&clearValue.Color[0], &clearColor[0], 4 * sizeof(float));
}
else
memcpy(&clearValue.Color[0], &clear_color[0], 4 * sizeof(float));
shared_context.gfx_device->GetDevice()->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT, 0, 0),
D3D12_HEAP_FLAG_NONE,
&texDesc,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
&clearValue,
IID_PPV_ARGS(&m_RTResource));
D3D12_RENDER_TARGET_VIEW_DESC RTVDesc;
ZeroMemory(&RTVDesc, sizeof(RTVDesc));
RTVDesc.Format = tex_format;
RTVDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DARRAY;
RTVDesc.Texture2DArray.ArraySize = num_slices;
m_RTVCPUHandle = shared_context.gfx_device->GetDescHeapRTV()->GetNewCPUHandle();
m_RTVGPUHandle = shared_context.gfx_device->GetDescHeapRTV()->GetGPUHandleAtHead();
shared_context.gfx_device->GetDevice()->CreateRenderTargetView(m_RTResource, &RTVDesc, m_RTVCPUHandle);
D3D12_SHADER_RESOURCE_VIEW_DESC SRVDesc;
ZeroMemory(&SRVDesc, sizeof(SRVDesc));
SRVDesc.Format = tex_format;
SRVDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DARRAY;
SRVDesc.Texture2DArray.ArraySize = num_slices;
SRVDesc.Texture2DArray.MipLevels = 1;
SRVDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
m_SRVCPUHandle = shared_context.gfx_device->GetDescHeapCBV_SRV()->GetNewCPUHandle();
m_SRVGPUHandle = shared_context.gfx_device->GetDescHeapCBV_SRV()->GetGPUHandleAtHead();
shared_context.gfx_device->GetDevice()->CreateShaderResourceView(m_RTResource, &SRVDesc, m_SRVCPUHandle);
}
示例13: CheckHR
void VertexManager::CreateDeviceObjects()
{
m_vertexDrawOffset = 0;
m_indexDrawOffset = 0;
CheckHR(
D3D::device12->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
D3D12_HEAP_FLAG_NONE,
&CD3DX12_RESOURCE_DESC::Buffer(MAX_VBUFFER_SIZE),
D3D12_RESOURCE_STATE_GENERIC_READ,
nullptr,
IID_PPV_ARGS(&m_vertexBuffer)
)
);
D3D::SetDebugObjectName12(m_vertexBuffer, "Vertex Buffer of VertexManager");
CheckHR(m_vertexBuffer->Map(0, nullptr, &m_vertexBufferData));
CheckHR(
D3D::device12->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
D3D12_HEAP_FLAG_NONE,
&CD3DX12_RESOURCE_DESC::Buffer(MAX_IBUFFER_SIZE),
D3D12_RESOURCE_STATE_GENERIC_READ,
nullptr,
IID_PPV_ARGS(&m_indexBuffer)
)
);
D3D::SetDebugObjectName12(m_indexBuffer, "Index Buffer of VertexManager");
CheckHR(m_indexBuffer->Map(0, nullptr, &m_indexBufferData));
SetIndexBuffer();
// Use CPU-only memory if the GPU won't be reading from the buffers,
// since reading upload heaps on the CPU is slow..
vertexCpuBuffer = new u8[MAXVBUFFERSIZE];
indexCpuBuffer = new u8[MAXIBUFFERSIZE];
}
示例14: memset
void BBox::Init()
{
memset(s_bbox_shadow_copy, 0, sizeof(s_bbox_shadow_copy));
s_bbox_cpu_dirty = true;
s_bbox_gpu_dirty = true;
CD3DX12_RESOURCE_DESC buffer_desc(CD3DX12_RESOURCE_DESC::Buffer(BBOX_BUFFER_SIZE, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, 0));
CD3DX12_RESOURCE_DESC staging_buffer_desc(CD3DX12_RESOURCE_DESC::Buffer(BBOX_BUFFER_SIZE, D3D12_RESOURCE_FLAG_NONE, 0));
CheckHR(D3D::device->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
D3D12_HEAP_FLAG_NONE,
&buffer_desc,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
nullptr,
IID_PPV_ARGS(&s_bbox_buffer)));
s_current_bbox_state = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
CheckHR(D3D::device->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_READBACK),
D3D12_HEAP_FLAG_NONE,
&staging_buffer_desc,
D3D12_RESOURCE_STATE_COPY_DEST,
nullptr,
IID_PPV_ARGS(&s_bbox_staging_buffer)));
s_bbox_stream_buffer = std::make_unique<D3DStreamBuffer>(BBOX_STREAM_BUFFER_SIZE, BBOX_STREAM_BUFFER_SIZE, nullptr);
// D3D12 root signature UAV must be raw or structured buffers, not typed. Since we used a typed buffer,
// we have to use a descriptor table. Luckily, we only have to allocate this once, and it never changes.
D3D12_CPU_DESCRIPTOR_HANDLE cpu_descriptor_handle;
if (!D3D::gpu_descriptor_heap_mgr->Allocate(&cpu_descriptor_handle, &s_bbox_descriptor_handle, nullptr, false))
PanicAlert("Failed to create bounding box UAV descriptor");
D3D12_UNORDERED_ACCESS_VIEW_DESC view_desc = { DXGI_FORMAT_R32_SINT, D3D12_UAV_DIMENSION_BUFFER };
view_desc.Buffer.FirstElement = 0;
view_desc.Buffer.NumElements = 4;
view_desc.Buffer.StructureByteStride = 0;
view_desc.Buffer.CounterOffsetInBytes = 0;
view_desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
D3D::device->CreateUnorderedAccessView(s_bbox_buffer, nullptr, &view_desc, cpu_descriptor_handle);
Bind();
}
示例15: CheckHR
D3DTexture2D* D3DTexture2D::Create(unsigned int width, unsigned int height, D3D11_BIND_FLAG bind, D3D11_USAGE usage, DXGI_FORMAT fmt, unsigned int levels, unsigned int slices, D3D12_SUBRESOURCE_DATA* data)
{
ID3D12Resource* texture12 = nullptr;
D3D12_RESOURCE_DESC texdesc12 = CD3DX12_RESOURCE_DESC::Tex2D(
fmt,
width,
height,
slices,
levels
);
D3D12_CLEAR_VALUE optimized_clear_value = {};
optimized_clear_value.Format = fmt;
if (bind & D3D11_BIND_RENDER_TARGET)
{
texdesc12.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
optimized_clear_value.Color[0] = 0.0f;
optimized_clear_value.Color[1] = 0.0f;
optimized_clear_value.Color[2] = 0.0f;
optimized_clear_value.Color[3] = 1.0f;
}
if (bind & D3D11_BIND_DEPTH_STENCIL)
{
texdesc12.Flags |= D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
optimized_clear_value.DepthStencil.Depth = 0.0f;
optimized_clear_value.DepthStencil.Stencil = 0;
}
CheckHR(
D3D::device12->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
D3D12_HEAP_FLAG_NONE,
&CD3DX12_RESOURCE_DESC(texdesc12),
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
&optimized_clear_value,
IID_PPV_ARGS(&texture12)
)
);
D3D::SetDebugObjectName12(texture12, "Texture created via D3DTexture2D::Create");
D3DTexture2D* ret = new D3DTexture2D(texture12, bind, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, false, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
if (data)
{
DX12::D3D::ReplaceRGBATexture2D(texture12, reinterpret_cast<const u8*>(data->pData), width, height, static_cast<unsigned int>(data->RowPitch), 0, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
}
SAFE_RELEASE(texture12);
return ret;
}