ComputeBuffer* ComputeWrap::CreateBuffer(COMPUTE_BUFFER_TYPE uType, UINT uElementSize, UINT uCount, bool bSRV, bool bUAV, VOID* pInitData, bool bCreateStaging, char* debugName) { ComputeBuffer* buffer = new ComputeBuffer(); buffer->_D3DContext = mD3DDeviceContext; if(uType == STRUCTURED_BUFFER) buffer->_Resource = CreateStructuredBuffer(uElementSize, uCount, bSRV, bUAV, pInitData); else if(uType == RAW_BUFFER) buffer->_Resource = CreateRawBuffer(uElementSize * uCount, pInitData); if(buffer->_Resource != nullptr) { if(bSRV) buffer->_ResourceView = CreateBufferSRV(buffer->_Resource); if(bUAV) buffer->_UnorderedAccessView = CreateBufferUAV(buffer->_Resource); if(bCreateStaging) buffer->_Staging = CreateStagingBuffer(uElementSize * uCount); } if(debugName) { if(buffer->_Resource) SetDebugName(buffer->_Resource, debugName); if(buffer->_Staging) SetDebugName(buffer->_Staging, debugName); if(buffer->_ResourceView) SetDebugName(buffer->_ResourceView, debugName); if(buffer->_UnorderedAccessView) SetDebugName(buffer->_UnorderedAccessView, debugName); } return buffer; //return shallow copy }
bool DirectxEngine::InitialiseDepthStates() { D3D11_DEPTH_STENCIL_DESC depthDesc; depthDesc.DepthEnable = true; depthDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; depthDesc.DepthFunc = D3D11_COMPARISON_LESS; depthDesc.StencilEnable = false; if (FAILED(m_data->device->CreateDepthStencilState(&depthDesc, &m_data->writeState))) { Logger::LogError("DirectX: Failed to create write to depth buffer state"); return false; } depthDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO; if (FAILED(m_data->device->CreateDepthStencilState(&depthDesc, &m_data->noWriteState))) { Logger::LogError("DirectX: Failed to create no write to depth buffer state"); return false; } SetDebugName(m_data->writeState, "DepthWriteState"); SetDebugName(m_data->noWriteState, "NoDepthWriteState"); return true; }
// TEXTURE FUNCTIONS ComputeTexture* ComputeWrap::CreateTexture(DXGI_FORMAT dxFormat, UINT uWidth, UINT uHeight, UINT uRowPitch, VOID* pInitData, bool bCreateStaging, char* debugName) { ComputeTexture* texture = new ComputeTexture(); texture->_D3DContext = mD3DDeviceContext; texture->_Resource = CreateTextureResource(dxFormat, uWidth, uHeight, uRowPitch, pInitData); if(texture->_Resource != nullptr) { texture->_ResourceView = CreateTextureSRV(texture->_Resource); texture->_UnorderedAccessView = CreateTextureUAV(texture->_Resource); if(bCreateStaging) texture->_Staging = CreateStagingTexture(texture->_Resource); } if(debugName) { if(texture->_Resource) SetDebugName(texture->_Resource, debugName); if(texture->_Staging) SetDebugName(texture->_Staging, debugName); if(texture->_ResourceView) SetDebugName(texture->_ResourceView, debugName); if(texture->_UnorderedAccessView) SetDebugName(texture->_UnorderedAccessView, debugName); } return texture; }
// TEXTURE FUNCTIONS ComputeTexture* Compute::CreateTexture(DXGI_FORMAT dxFormat, UINT uWidth, UINT uHeight, UINT uRowPitch, VOID* initData, bool createStaging, char* debugName) { ComputeTexture* texture = new ComputeTexture(); texture->m_deviceContext = m_deviceContext; texture->m_resource = CreateTextureResource(dxFormat, uWidth, uHeight, uRowPitch, initData); if(texture->m_resource != nullptr) { texture->m_resourceView = CreateTextureSRV(texture->m_resource); texture->m_unorderedAccessView = CreateTextureUAV(texture->m_resource); if(createStaging) texture->m_staging = CreateStagingTexture(texture->m_resource); } if(debugName) { if(texture->m_resource) SetDebugName(texture->m_resource, debugName); if(texture->m_staging) SetDebugName(texture->m_staging, debugName); if(texture->m_resourceView) SetDebugName(texture->m_resourceView, debugName); if(texture->m_unorderedAccessView) SetDebugName(texture->m_unorderedAccessView, debugName); } return texture; }
bool DxRenderTarget::InitialiseDepthBuffer(ID3D11Device* device) { D3D11_TEXTURE2D_DESC textureDesc = sm_textureDesc; textureDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; textureDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; textureDesc.SampleDesc.Count = m_multisampled ? MULTISAMPLING_COUNT : 1; ID3D11Texture2D* depthTexture; if(FAILED(device->CreateTexture2D(&textureDesc, 0, &depthTexture))) { Logger::LogError("DirectX: Depth buffer texture creation failed"); return false; } D3D11_DEPTH_STENCIL_VIEW_DESC depthBufferDesc; ZeroMemory(&depthBufferDesc, sizeof(depthBufferDesc)); depthBufferDesc.Format = textureDesc.Format; depthBufferDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS; depthBufferDesc.Texture2D.MipSlice = 0; if(FAILED(device->CreateDepthStencilView( depthTexture, &depthBufferDesc, &m_depthBuffer))) { Logger::LogError("DirectX: Depth buffer creation failed"); return false; } SetDebugName(depthTexture, m_name + "DepthBufferTexture"); SetDebugName(m_depthBuffer, m_name + "DepthBuffer"); depthTexture->Release(); return true; }
bool DirectxEngine::InitialiseBlendStates() { D3D11_BLEND_DESC blendDesc = {}; blendDesc.AlphaToCoverageEnable = FALSE; for (int i = 0; i < MAX_TARGETS; ++i) { blendDesc.RenderTarget[i].BlendEnable = FALSE; blendDesc.RenderTarget[i].SrcBlend = D3D11_BLEND_ONE; blendDesc.RenderTarget[i].DestBlend = D3D11_BLEND_ZERO; blendDesc.RenderTarget[i].BlendOp = D3D11_BLEND_OP_ADD; blendDesc.RenderTarget[i].SrcBlendAlpha = D3D11_BLEND_ONE; blendDesc.RenderTarget[i].DestBlendAlpha = D3D11_BLEND_ZERO; blendDesc.RenderTarget[i].BlendOpAlpha = D3D11_BLEND_OP_ADD; blendDesc.RenderTarget[i].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; } if (FAILED(m_data->device->CreateBlendState(&blendDesc, &m_data->noBlendState))) { Logger::LogError("DirectX: Failed to create no blending state"); return false; } for (int i = 0; i < MAX_TARGETS; ++i) { blendDesc.RenderTarget[i].BlendEnable = TRUE; blendDesc.RenderTarget[i].SrcBlend = D3D11_BLEND_SRC_ALPHA; blendDesc.RenderTarget[i].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; blendDesc.RenderTarget[i].SrcBlendAlpha = D3D11_BLEND_ONE; blendDesc.RenderTarget[i].DestBlendAlpha = D3D11_BLEND_ZERO; } if (FAILED(m_data->device->CreateBlendState(&blendDesc, &m_data->alphaBlendState))) { Logger::LogError("DirectX: Failed to create alpha blending state"); return false; } for (int i = 0; i < MAX_TARGETS; ++i) { blendDesc.RenderTarget[i].SrcBlend = D3D11_BLEND_DEST_COLOR; blendDesc.RenderTarget[i].DestBlend = D3D11_BLEND_ZERO; blendDesc.RenderTarget[i].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA; blendDesc.RenderTarget[i].DestBlendAlpha = D3D11_BLEND_ZERO; } if (FAILED(m_data->device->CreateBlendState(&blendDesc, &m_data->alphaBlendMultiply))) { Logger::LogError("DirectX: Failed to create alpha blending state"); return false; } SetDebugName(m_data->noBlendState, "NoBlendState"); SetDebugName(m_data->alphaBlendState, "AlphaBlendState"); SetDebugName(m_data->alphaBlendMultiply, "AlphaBlendMultiplyState"); return true; }
bool DirectxEngine::InitialiseDrawStates() { D3D11_RASTERIZER_DESC rasterDesc; rasterDesc.AntialiasedLineEnable = false; rasterDesc.DepthBias = 0; rasterDesc.DepthBiasClamp = 0.0f; rasterDesc.DepthClipEnable = true; rasterDesc.FillMode = D3D11_FILL_SOLID; rasterDesc.FrontCounterClockwise = false; rasterDesc.MultisampleEnable = true; rasterDesc.ScissorEnable = false; rasterDesc.SlopeScaledDepthBias = 0.0f; rasterDesc.CullMode = D3D11_CULL_FRONT; // for Maya vert winding order if(FAILED(m_data->device->CreateRasterizerState( &rasterDesc, &m_data->drawStates[BACKFACE_CULL]))) { Logger::LogError("DirectX: Failed to create cull rasterizer state"); return false; } rasterDesc.FillMode = D3D11_FILL_WIREFRAME; if(FAILED(m_data->device->CreateRasterizerState( &rasterDesc, &m_data->drawStates[BACKFACE_CULL_WIRE]))) { Logger::LogError("DirectX: Failed to create cull wire rasterizer state"); return false; } rasterDesc.CullMode = D3D11_CULL_NONE; if (FAILED(m_data->device->CreateRasterizerState( &rasterDesc, &m_data->drawStates[NO_CULL_WIRE]))) { Logger::LogError("DirectX: Failed to create no cull wire rasterizer state"); return false; } rasterDesc.FillMode = D3D11_FILL_SOLID; if (FAILED(m_data->device->CreateRasterizerState( &rasterDesc, &m_data->drawStates[NO_CULL]))) { Logger::LogError("DirectX: Failed to create no cull rasterizer state"); return false; } SetDebugName(m_data->drawStates[BACKFACE_CULL], "BACKFACE_CULL"); SetDebugName(m_data->drawStates[BACKFACE_CULL_WIRE], "BACKFACE_CULL_WIRE"); SetDebugName(m_data->drawStates[NO_CULL], "NO_CULL"); SetDebugName(m_data->drawStates[NO_CULL_WIRE], "NO_CULL_WIRE"); return true; }
KDNAMESTART KDNAMEGUI KGUIWin32Wnd::KGUIWin32Wnd(void) : IGUIWindow(0, 0), m_pHandlers(0), m_pGUIFocus(0), m_pGUIHover(0), m_bResized(false), m_bActive(true), m_pOwner(0), m_nCorner(0) { #ifdef _DEBUG SetDebugName(L"KGUIWin32Wnd"); m_AllCtrlIDs.clear(); #endif m_CloseState = EBS_BUTTON_NORMAL; m_MinState = EBS_BUTTON_NORMAL; m_MaxState = EBS_BUTTON_NORMAL; m_MouseState = MOUSEDOWN_NONE; m_bCapturing = false; m_bIsMain = false; m_CapturedElement = NULL; }
//! constructor ImageLoaderX::ImageLoaderX(IDirect3DDevice9* device) : m_pID3DDevice(device) { #ifdef _DEBUG SetDebugName("ImageLoaderX"); #endif device->AddRef(); }
bool DxRenderTarget::InitialiseBackBuffer(ID3D11Device* device, IDXGISwapChain* swapchain) { swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&(m_textures[0])); if (FAILED(device->CreateRenderTargetView(m_textures[0], nullptr, &(m_targets[0])))) { Logger::LogError("DirectX: Failed to create back buffer"); return false; } m_textures[0]->GetDesc(&sm_textureDesc); SetDebugName(m_textures[0], m_name + "_Texture"); SetDebugName(m_targets[0], m_name + "_RenderTarget"); return true; }
VulkanDescriptorSet *VkPPRenderState::GetInput(VkPPRenderPassSetup *passSetup, const TArray<PPTextureInput> &textures, bool bindShadowMapBuffers) { auto fb = GetVulkanFrameBuffer(); auto pp = fb->GetPostprocess(); auto descriptors = pp->AllocateDescriptorSet(passSetup->DescriptorLayout.get()); descriptors->SetDebugName("VkPostprocess.descriptors"); WriteDescriptors write; VkImageTransition imageTransition; for (unsigned int index = 0; index < textures.Size(); index++) { const PPTextureInput &input = textures[index]; VulkanSampler *sampler = pp->GetSampler(input.Filter, input.Wrap); VkTextureImage *tex = GetTexture(input.Type, input.Texture); write.addCombinedImageSampler(descriptors.get(), index, tex->DepthOnlyView ? tex->DepthOnlyView.get() : tex->View.get(), sampler, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); imageTransition.addImage(tex, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, false); } if (bindShadowMapBuffers) { write.addBuffer(descriptors.get(), LIGHTNODES_BINDINGPOINT, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, fb->LightNodes->mBuffer.get()); write.addBuffer(descriptors.get(), LIGHTLINES_BINDINGPOINT, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, fb->LightLines->mBuffer.get()); write.addBuffer(descriptors.get(), LIGHTLIST_BINDINGPOINT, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, fb->LightList->mBuffer.get()); } write.updateSets(fb->device); imageTransition.execute(fb->GetDrawCommands()); VulkanDescriptorSet *set = descriptors.get(); fb->FrameDeleteList.Descriptors.push_back(std::move(descriptors)); return set; }
ID3D11Buffer* ComputeWrap::CreateConstantBuffer(UINT uSize, VOID* pInitData, char* debugName) { ID3D11Buffer* pBuffer = NULL; // setup creation information D3D11_BUFFER_DESC cbDesc; cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; cbDesc.ByteWidth = uSize + (16 - uSize % 16); cbDesc.CPUAccessFlags = 0; cbDesc.MiscFlags = 0; cbDesc.StructureByteStride = 0; cbDesc.Usage = D3D11_USAGE_DEFAULT; HRESULT hr = S_OK; if(pInitData) { D3D11_SUBRESOURCE_DATA InitData; InitData.pSysMem = pInitData; hr = mD3DDevice->CreateBuffer(&cbDesc, &InitData, &pBuffer); } else { hr = mD3DDevice->CreateBuffer(&cbDesc, NULL, &pBuffer); } if(debugName && pBuffer) { SetDebugName(pBuffer, debugName); } if(FAILED(hr)) Logger::log(Logger::Level::ERROR_L, (char*)hr); return pBuffer; }
//! constructor ImageLoaderPSD::ImageLoaderPSD() : m_pImageData(0) { #ifdef _DEBUG SetDebugName("ImageLoaderPSD"); #endif }
ID3D11Buffer* ComputeWrap::CreateDynamicBuffer(UINT uSize, VOID* pInitData, char* debugName) { ID3D11Buffer* pBuffer = nullptr; // setup creation information D3D11_BUFFER_DESC cbDesc; cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; bool addMod = uSize % 16 != 0 ? true : false; cbDesc.ByteWidth = uSize + (addMod ? (16 - uSize % 16) : 0); cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; cbDesc.MiscFlags = 0; cbDesc.StructureByteStride = 0; cbDesc.Usage = D3D11_USAGE_DYNAMIC; if(pInitData) { D3D11_SUBRESOURCE_DATA InitData; InitData.pSysMem = pInitData; mD3DDevice->CreateBuffer(&cbDesc, &InitData, &pBuffer); } else { mD3DDevice->CreateBuffer(&cbDesc, nullptr, &pBuffer); } if(debugName && pBuffer) { SetDebugName(pBuffer, debugName); } return pBuffer; }
HRESULT WrappedIDXGISwapChain2::GetBuffer( /* [in] */ UINT Buffer, /* [in] */ REFIID riid, /* [out][in] */ void **ppSurface) { if(ppSurface == NULL) return E_INVALIDARG; // ID3D10Texture2D UUID {9B7E4C04-342C-4106-A19F-4F2704F689F0} static const GUID ID3D10Texture2D_uuid = { 0x9b7e4c04, 0x342c, 0x4106, { 0xa1, 0x9f, 0x4f, 0x27, 0x04, 0xf6, 0x89, 0xf0 } }; // ID3D10Resource UUID {9B7E4C01-342C-4106-A19F-4F2704F689F0} static const GUID ID3D10Resource_uuid = { 0x9b7e4c01, 0x342c, 0x4106, { 0xa1, 0x9f, 0x4f, 0x27, 0x04, 0xf6, 0x89, 0xf0 } }; if(riid == ID3D10Texture2D_uuid || riid == ID3D10Resource_uuid) { RDCERR("Querying swapchain buffers via D3D10 interface UUIDs is not supported"); return E_NOINTERFACE; } else if(riid != __uuidof(ID3D11Texture2D) && riid != __uuidof(ID3D11Resource)) { RDCERR("Unsupported or unrecognised UUID passed to IDXGISwapChain::GetBuffer - %s", ToStr::Get(riid).c_str()); return E_NOINTERFACE; } RDCASSERT(riid == __uuidof(ID3D11Texture2D) || riid == __uuidof(ID3D11Resource)); HRESULT ret = m_pReal->GetBuffer(Buffer, riid, ppSurface); ID3D11Texture2D *realSurface = (ID3D11Texture2D *)*ppSurface; ID3D11Texture2D *tex = realSurface; if(FAILED(ret)) { RDCERR("Failed to get swapchain backbuffer %d: %08x", Buffer, ret); SAFE_RELEASE(realSurface); tex = NULL; } else if(m_pDevice->GetResourceManager()->HasWrapper(realSurface)) { tex = (ID3D11Texture2D *)m_pDevice->GetResourceManager()->GetWrapper(realSurface); tex->AddRef(); realSurface->Release(); } else { tex = new WrappedID3D11Texture2D(realSurface, m_pDevice, TEXDISPLAY_UNKNOWN); DXGI_SWAP_CHAIN_DESC desc; m_pReal->GetDesc(&desc); m_pDevice->SetSwapChainTexture(this, &desc, Buffer, tex); SetDebugName(tex, "Swap Chain Backbuffer"); } *ppSurface = tex; return ret; }
void CreateMeshConstantsBuffer(ID3D11Device *device) { std::vector<MeshConstants> meshConstants(GetMeshCount()); for (int i = 0; i < GetMeshCount(); ++i) { meshConstants[i].faceCount = meshes_[i]->faceCount; meshConstants[i].indexOffset = meshes_[i]->indexOffset; meshConstants[i].vertexCount = meshes_[i]->vertexCount; meshConstants[i].vertexOffset = meshes_[i]->vertexOffset; } D3D11_BUFFER_DESC bufferDesc = {}; bufferDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; bufferDesc.ByteWidth = static_cast<UINT>(meshConstants.size() * sizeof(MeshConstants)); bufferDesc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; bufferDesc.StructureByteStride = sizeof(MeshConstants); bufferDesc.Usage = D3D11_USAGE_IMMUTABLE; D3D11_SUBRESOURCE_DATA initialData; initialData.pSysMem = meshConstants.data(); initialData.SysMemPitch = bufferDesc.ByteWidth; initialData.SysMemSlicePitch = bufferDesc.ByteWidth; device->CreateBuffer(&bufferDesc, &initialData, &meshConstantsBuffer_); SetDebugName(meshConstantsBuffer_.Get(), "Mesh constants buffer"); for (std::vector<std::unique_ptr<StaticMesh>>::iterator it = meshes_.begin(), end = meshes_.end(); it != end; ++it) { (*it)->meshConstantsBuffer = meshConstantsBuffer_; } D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; srvDesc.Format = DXGI_FORMAT_UNKNOWN; srvDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; srvDesc.Buffer.ElementOffset = 0; srvDesc.Buffer.ElementWidth = GetMeshCount(); device->CreateShaderResourceView( meshConstantsBuffer_.Get(), &srvDesc, &meshConstantsBufferView_); SetDebugName(meshConstantsBufferView_.Get(), "Mesh constants buffer view"); }
ComputeTexture* ComputeWrap::CreateTexture(TCHAR* textureFilename, char* debugName) { ComputeTexture* texture = new ComputeTexture(); texture->_D3DContext = mD3DDeviceContext; if(SUCCEEDED(D3DX11CreateTextureFromFile(mD3DDevice, textureFilename, NULL, NULL, (ID3D11Resource**)&texture->_Resource, NULL))) { texture->_ResourceView = CreateTextureSRV(texture->_Resource); if(debugName) { if(texture->_Resource) SetDebugName(texture->_Resource, debugName); if(texture->_Staging) SetDebugName(texture->_Staging, debugName); if(texture->_ResourceView) SetDebugName(texture->_ResourceView, debugName); if(texture->_UnorderedAccessView) SetDebugName(texture->_UnorderedAccessView, debugName); } } return texture; }
//! constructor BSPSceneNode::BSPSceneNode(BSPTree* tree, SMesh* mesh, SceneNode* parent, SceneManager* mgr, s32 id, const vector3df& position, const vector3df& rotation, const vector3df& scale) : MeshSceneNode(mesh, parent, mgr, id, position, rotation, scale), m_pBSPTree(0), m_iLastCluster(-1) { #ifdef _DEBUG SetDebugName("BSPSceneNode"); #endif SetBSPTree(tree); }
void CreateVertexBuffer(ID3D11Device *device, const int vertexCount) { D3D11_BUFFER_DESC vbDesc = {}; vbDesc.Usage = D3D11_USAGE_DEFAULT; vbDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER | D3D11_BIND_SHADER_RESOURCE; vbDesc.ByteWidth = sizeof(float) * 3 * vertexCount; vbDesc.StructureByteStride = 0; vbDesc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS; device->CreateBuffer(&vbDesc, nullptr, &vertexBuffer_); SetDebugName(vertexBuffer_.Get(), "Global source vertex buffer"); D3D11_SHADER_RESOURCE_VIEW_DESC vbSrv; vbSrv.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX; vbSrv.BufferEx.FirstElement = 0; vbSrv.BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW; vbSrv.BufferEx.NumElements = vbDesc.ByteWidth / 4; vbSrv.Format = DXGI_FORMAT_R32_TYPELESS; device->CreateShaderResourceView(vertexBuffer_.Get(), &vbSrv, &vertexBufferSRV_); SetDebugName(vertexBufferSRV_.Get(), "Global source vertex buffer resource view"); }
void CreateIndexBuffer(ID3D11Device *device, const int indexCount) { D3D11_BUFFER_DESC ibDesc = {}; ibDesc.Usage = D3D11_USAGE_DEFAULT; ibDesc.BindFlags = D3D11_BIND_INDEX_BUFFER | D3D11_BIND_SHADER_RESOURCE; ibDesc.ByteWidth = indexCount * sizeof(int); ibDesc.StructureByteStride = sizeof(int); device->CreateBuffer(&ibDesc, nullptr, &indexBuffer_); SetDebugName(indexBuffer_.Get(), "Global index buffer"); D3D11_SHADER_RESOURCE_VIEW_DESC ibSrv; ibSrv.Format = DXGI_FORMAT_R32_UINT; ibSrv.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; ibSrv.Buffer.ElementOffset = 0; ibSrv.Buffer.ElementWidth = sizeof(int); ibSrv.Buffer.FirstElement = 0; ibSrv.Buffer.NumElements = static_cast<UINT>(indexCount); device->CreateShaderResourceView(indexBuffer_.Get(), &ibSrv, &indexBufferSRV_); SetDebugName(indexBufferSRV_.Get(), "Global source index buffer view"); }
VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &state) { FMaterial *mat = state.mMaterial; FTexture *tex = state.mMaterial->tex; int clampmode = state.mClampMode; int translation = state.mTranslation; if (tex->UseType == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER; if (tex->isHardwareCanvas()) clampmode = CLAMP_CAMTEX; else if ((tex->isWarped() || tex->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; // Textures that are already scaled in the texture lump will not get replaced by hires textures. int flags = state.mMaterial->isExpanded() ? CTF_Expand : (gl_texture_usehires && !tex->isScaled() && clampmode <= CLAMP_XY) ? CTF_CheckHires : 0; if (tex->isHardwareCanvas()) static_cast<FCanvasTexture*>(tex)->NeedUpdate(); for (auto &set : mDescriptorSets) { if (set.descriptor && set.clampmode == clampmode && set.flags == flags) return set.descriptor.get(); } int numLayers = mat->GetLayers(); auto fb = GetVulkanFrameBuffer(); auto descriptor = fb->GetRenderPassManager()->AllocateTextureDescriptorSet(numLayers); descriptor->SetDebugName("VkHardwareTexture.mDescriptorSets"); VulkanSampler *sampler = fb->GetSamplerManager()->Get(clampmode); WriteDescriptors update; update.addCombinedImageSampler(descriptor.get(), 0, GetImage(tex, translation, flags)->View.get(), sampler, mImage.Layout); for (int i = 1; i < numLayers; i++) { FTexture *layer; auto systex = static_cast<VkHardwareTexture*>(mat->GetLayer(i, 0, &layer)); update.addCombinedImageSampler(descriptor.get(), i, systex->GetImage(layer, 0, mat->isExpanded() ? CTF_Expand : 0)->View.get(), sampler, systex->mImage.Layout); } update.updateSets(fb->device); mDescriptorSets.emplace_back(clampmode, flags, std::move(descriptor)); return mDescriptorSets.back().descriptor.get(); }
void DxTexture::Initialise(ID3D11Device* device) { if (m_texture.IsRenderable()) { if (m_texture.IsCubeMap()) { InitialiseCubeMap(device); } else if (m_texture.HasPixels()) { InitialiseFromPixels(device); } else { InitialiseFromFile(device); } SetDebugName(m_view, m_texture.Name() + "_view"); } }
ID3D11Buffer* Compute::CreateConstantBuffer(UINT uSize, VOID* initData, char* debugName) { HRESULT hr; ID3D11Buffer* buffer = nullptr; // setup creation information D3D11_BUFFER_DESC cbDesc; cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; bool addMod = uSize % 16 != 0 ? true : false; cbDesc.ByteWidth = uSize + (addMod ? (16 - uSize % 16) : 0); cbDesc.CPUAccessFlags = 0; cbDesc.MiscFlags = 0; cbDesc.StructureByteStride = 0; cbDesc.Usage = D3D11_USAGE_DEFAULT; if(initData) { D3D11_SUBRESOURCE_DATA InitData; ZeroMemory(&InitData, sizeof(D3D11_SUBRESOURCE_DATA)); InitData.pSysMem = initData; hr = m_device->CreateBuffer(&cbDesc, &InitData, &buffer); if(FAILED(hr)) std::cout<< "Failed to build constant buffer!" << std::endl; } else { hr = m_device->CreateBuffer(&cbDesc, nullptr, &buffer); if(FAILED(hr)) std::cout<< "Failed to build constant buffer!" << std::endl; } if(debugName && buffer) { SetDebugName(buffer, debugName); } return buffer; }
void DxTexture::InitialiseCubeMap(ID3D11Device* device) { const std::string filePath = m_texture.Path() + ".dds"; if (!boost::filesystem::exists(filePath)) { Logger::LogError("DirectX: " + filePath + " doesn't exist"); } D3DX11_IMAGE_LOAD_INFO loadInfo; loadInfo.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE; ID3D11Texture2D* texture = nullptr; SetDebugName(texture, filePath + "_texture"); if (FAILED(D3DX11CreateTextureFromFile(device, filePath.c_str(), &loadInfo, 0, (ID3D11Resource**)&texture, 0))) { Logger::LogError("DirectX: Failed to create texture " + filePath); } D3D11_TEXTURE2D_DESC textureDesc; texture->GetDesc(&textureDesc); D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc; viewDesc.Format = textureDesc.Format; viewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; viewDesc.TextureCube.MipLevels = textureDesc.MipLevels; viewDesc.TextureCube.MostDetailedMip = 0; if (FAILED(device->CreateShaderResourceView(texture, &viewDesc, &m_view))) { Logger::LogError("DirectX: Failed to resource view " + filePath); } texture->Release(); }
bool DxRenderTarget::InitialiseRenderTarget(ID3D11Device* device, int ID) { const auto name = m_name + boost::lexical_cast<std::string>(ID); D3D11_TEXTURE2D_DESC textureDesc = sm_textureDesc; textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; textureDesc.Usage = D3D11_USAGE_DEFAULT; textureDesc.SampleDesc.Count = m_multisampled ? MULTISAMPLING_COUNT : 1; textureDesc.Format = m_highQuality[ID] ? DXGI_FORMAT_R32G32B32A32_FLOAT : DXGI_FORMAT_R8G8B8A8_UNORM; if (FAILED(device->CreateTexture2D(&textureDesc, 0, &(m_textures[ID])))) { Logger::LogError("DirectX: Failed to create texture for " + name); return false; } D3D11_RENDER_TARGET_VIEW_DESC renderTargetDesc; ZeroMemory(&renderTargetDesc, sizeof(renderTargetDesc)); renderTargetDesc.Format = textureDesc.Format; renderTargetDesc.Texture2D.MipSlice = 0; renderTargetDesc.ViewDimension = m_multisampled ? D3D11_RTV_DIMENSION_TEXTURE2DMS : D3D11_RTV_DIMENSION_TEXTURE2D; if (FAILED(device->CreateRenderTargetView(m_textures[ID], &renderTargetDesc, &(m_targets[ID])))) { Logger::LogError("DirectX: Failed to create render target for " + name); return false; } D3D11_SHADER_RESOURCE_VIEW_DESC textureViewDesc; ZeroMemory(&textureViewDesc, sizeof(textureViewDesc)); textureViewDesc.Format = textureDesc.Format; textureViewDesc.Texture2D.MipLevels = 1; textureViewDesc.Texture2D.MostDetailedMip = 0; textureViewDesc.ViewDimension = m_multisampled ? D3D11_SRV_DIMENSION_TEXTURE2DMS : D3D11_SRV_DIMENSION_TEXTURE2D; if (FAILED(device->CreateShaderResourceView(m_textures[ID], &textureViewDesc, &(m_views[ID])))) { Logger::LogError("DirectX: Failed to create texture view for " + name); return false; } SetDebugName(m_textures[ID], name + "_Texture"); SetDebugName(m_targets[ID], name + "_RenderTarget"); SetDebugName(m_views[ID], name + "_TextureView"); if (m_readWrite) { textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; if (FAILED(device->CreateTexture2D(&textureDesc, 0, &(m_copiedTextures[ID])))) { Logger::LogError("DirectX: Failed to create copy texture for " + name); return false; } if (FAILED(device->CreateShaderResourceView(m_copiedTextures[ID], &textureViewDesc, &(m_copiedViews[ID])))) { Logger::LogError("DirectX: Failed to create copy texture view for " + name); return false; } SetDebugName(m_copiedTextures[ID], name + "_CopyTexture"); SetDebugName(m_copiedViews[ID], name + "_CopyTextureView"); } return true; }
bool DirectxEngine::Initialize() { DXGI_SWAP_CHAIN_DESC scd; ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC)); scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; scd.BufferCount = 1; scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; scd.OutputWindow = m_hwnd; scd.SampleDesc.Count = MULTISAMPLING_COUNT; scd.Windowed = TRUE; scd.BufferDesc.Width = WINDOW_WIDTH; scd.BufferDesc.Height = WINDOW_HEIGHT; #ifdef _DEBUG unsigned int deviceFlags = D3D11_CREATE_DEVICE_DEBUG; #else unsigned int deviceFlags = 0; #endif if (FAILED(D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, deviceFlags, nullptr, 0, D3D11_SDK_VERSION, &scd, &m_data->swapchain, &m_data->device, nullptr, &m_data->context))) { Logger::LogError("DirectX: Device creation failed"); return false; } InitialiseDebugging(); // Create the post processing quad m_data->quad.Initialise(m_data->device, m_data->context); // Initialise all states if (!InitialiseBlendStates() || !InitialiseDrawStates() || !InitialiseSamplerStates() || !InitialiseDepthStates()) { Logger::LogError("DirectX: Failed to initialise states"); return false; } // Create the render targets. Back buffer must be initialised first. m_data->sceneTarget.SetHighQuality(DEPTH_ID); // Required for DOF if (!m_data->backBuffer.Initialise(m_data->device, m_data->swapchain) || !m_data->sceneTarget.Initialise(m_data->device, m_data->samplers[LINEAR]) || !m_data->preEffectsTarget.Initialise(m_data->device, m_data->samplers[LINEAR]) || !m_data->blurTarget.Initialise(m_data->device, m_data->samplers[LINEAR])) { Logger::LogError("DirectX: Failed to create render targets"); return false; } // Setup the directX environment m_data->drawState = NO_STATE; m_data->isAlphaBlend = true; m_data->isBlendMultiply = true; m_data->isDepthWrite = false; m_data->isWireframe = false; SetRenderState(true, false); EnableAlphaBlending(false, false); EnableDepthWrite(true); D3D11_VIEWPORT viewport; ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT)); viewport.TopLeftX = 0; viewport.TopLeftY = 0; viewport.Width = WINDOW_WIDTH; viewport.Height = WINDOW_HEIGHT; viewport.MinDepth = 0.0; viewport.MaxDepth = 1.0; m_data->context->RSSetViewports(1, &viewport); D3DXMatrixPerspectiveFovLH(&m_data->projection, (FLOAT)D3DXToRadian(FIELD_OF_VIEW), RATIO, FRUSTRUM_NEAR, FRUSTRUM_FAR); SetDebugName(m_data->device, "Device"); SetDebugName(m_data->context, "Context"); SetDebugName(m_data->swapchain, "SwapChain"); Logger::LogInfo("DirectX: D3D11 sucessful"); return true; }