UnorderedAccessView::UnorderedAccessView(UnderlyingResource resource, Flags::BitField field) { if (!resource) { Throw(::Exceptions::BasicLabel("NULL resource passed to DepthStencilView constructor")); } intrusive_ptr<ID3D::UnorderedAccessView> view; D3DBufferDesc bufferDesc(resource); auto buffer = QueryInterfaceCast<ID3D::Buffer>(resource); if (buffer) { D3D11_UNORDERED_ACCESS_VIEW_DESC viewDesc; viewDesc.Format = DXGI_FORMAT_UNKNOWN; viewDesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; viewDesc.Buffer.FirstElement = 0; viewDesc.Buffer.NumElements = bufferDesc.ByteWidth / bufferDesc.StructureByteStride; viewDesc.Buffer.Flags = 0; if (field & Flags::AttachedCounter) { viewDesc.Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_COUNTER; } view = ObjectFactory(*resource).CreateUnorderedAccessView(resource, &viewDesc); } else { view = ObjectFactory(*resource).CreateUnorderedAccessView(resource); } _underlying = std::move(view); }
UnorderedAccessView::UnorderedAccessView(UnderlyingResource resource, NativeFormat::Enum format, unsigned mipSlice, bool appendBuffer, bool forceArray) { if (!resource) { Throw(::Exceptions::BasicLabel("NULL resource passed to UnorderedAccessView constructor")); } intrusive_ptr<ID3D::UnorderedAccessView> view = nullptr; if (format == NativeFormat::Unknown && mipSlice == 0 && !appendBuffer && !forceArray) { view = ObjectFactory(*resource).CreateUnorderedAccessView(resource); } else { D3D11_UNORDERED_ACCESS_VIEW_DESC viewDesc; viewDesc.Format = AsDXGIFormat(format); TextureDesc2D textureDesc(resource); if (textureDesc.Width > 0) { if (textureDesc.ArraySize > 1 || forceArray) { viewDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2DARRAY; viewDesc.Texture2DArray.MipSlice = mipSlice; viewDesc.Texture2DArray.FirstArraySlice = 0; viewDesc.Texture2DArray.ArraySize = textureDesc.ArraySize; } else { viewDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D; viewDesc.Texture2D.MipSlice = mipSlice; } } else { TextureDesc3D t3dDesc(resource); if (t3dDesc.Width > 0) { viewDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE3D; viewDesc.Texture3D.MipSlice = mipSlice; viewDesc.Texture3D.FirstWSlice = 0; viewDesc.Texture3D.WSize = (UINT)-1; } else { TextureDesc1D t1dDesc(resource); if (t1dDesc.Width > 0) { viewDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE1D; viewDesc.Texture1D.MipSlice = mipSlice; } else { D3DBufferDesc bufferDesc(resource); viewDesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; viewDesc.Buffer.FirstElement = 0; viewDesc.Buffer.NumElements = bufferDesc.StructureByteStride ? (bufferDesc.ByteWidth/bufferDesc.StructureByteStride) : bufferDesc.ByteWidth; viewDesc.Buffer.Flags = appendBuffer ? D3D11_BUFFER_UAV_FLAG_APPEND : 0; } } } view = ObjectFactory(*resource).CreateUnorderedAccessView(resource, &viewDesc); } _underlying = std::move(view); }
GeometryShader::GeometryShader(const CompiledShaderByteCode& compiledShader, const StreamOutputInitializers& soInitializers) { if (compiledShader.GetStage() != ShaderStage::Null) { assert(compiledShader.GetStage() == ShaderStage::Geometry); auto byteCode = compiledShader.GetByteCode(); intrusive_ptr<ID3D::GeometryShader> underlying; if (soInitializers._outputBufferCount == 0) { underlying = ObjectFactory().CreateGeometryShader(byteCode.first, byteCode.second); } else { assert(soInitializers._outputBufferCount <= D3D11_SO_BUFFER_SLOT_COUNT); D3D11_SO_DECLARATION_ENTRY nativeDeclaration[D3D11_SO_STREAM_COUNT * D3D11_SO_OUTPUT_COMPONENT_COUNT]; auto delcCount = BuildNativeDeclaration(nativeDeclaration, dimof(nativeDeclaration), soInitializers); ObjectFactory objFactory; auto featureLevel = objFactory.GetUnderlying()->GetFeatureLevel(); underlying = objFactory.CreateGeometryShaderWithStreamOutput( byteCode.first, byteCode.second, nativeDeclaration, delcCount, soInitializers._outputBufferStrides, soInitializers._outputBufferCount, // Note -- "NO_RASTERIZED_STREAM" is only supported on feature level 11. For other feature levels // we must disable the rasterization step some other way (featureLevel>=D3D_FEATURE_LEVEL_11_0)?D3D11_SO_NO_RASTERIZED_STREAM:0); } _underlying = std::move(underlying); } }
HullShader::HullShader(const CompiledShaderByteCode& compiledShader) { if (compiledShader.GetStage() != ShaderStage::Null) { assert(compiledShader.GetStage() == ShaderStage::Hull); auto byteCode = compiledShader.GetByteCode(); _underlying = ObjectFactory().CreateHullShader(byteCode.first, byteCode.second); } _validationCallback = std::make_shared<Assets::DependencyValidation>(); Assets::RegisterAssetDependency(_validationCallback, compiledShader.GetDependencyValidation()); }
DepthStencilView::DepthStencilView( UnderlyingResource resource, NativeFormat::Enum format, const SubResourceSlice& arraySlice) { if (!resource) { Throw(::Exceptions::BasicLabel("NULL resource passed to DepthStencilView constructor")); } intrusive_ptr<ID3D::DepthStencilView> view; if (format == NativeFormat::Unknown) { view = ObjectFactory(*resource).CreateDepthStencilView(resource); } else { TextureDesc2D textureDesc(resource); D3D11_DEPTH_STENCIL_VIEW_DESC viewDesc; viewDesc.Format = AsDXGIFormat(format); viewDesc.Flags = 0; if (arraySlice._arraySize == 0) { if (textureDesc.SampleDesc.Count > 1) { viewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS; } else { viewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; viewDesc.Texture2D.MipSlice = 0; } } else { if (textureDesc.SampleDesc.Count > 1) { viewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY; viewDesc.Texture2DMSArray.ArraySize = arraySlice._arraySize; viewDesc.Texture2DMSArray.FirstArraySlice = arraySlice._firstArraySlice; } else { viewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY; viewDesc.Texture2DArray.ArraySize = arraySlice._arraySize; viewDesc.Texture2DArray.FirstArraySlice = arraySlice._firstArraySlice; viewDesc.Texture2DArray.MipSlice = 0; } } view = ObjectFactory(*resource).CreateDepthStencilView(resource, &viewDesc); } _underlying = std::move(view); }
HullShader::HullShader(const ResChar initializer[], const ResChar definesTable[]) { ResChar temp[MaxPath]; if (!XlFindStringI(initializer, "hs_")) { StringMeldInPlace(temp) << initializer << ":" HS_DefShaderModel; initializer = temp; } const auto& compiledShader = ::Assets::GetAssetComp<CompiledShaderByteCode>(initializer, definesTable?definesTable:""); assert(compiledShader.GetStage() == ShaderStage::Hull); auto byteCode = compiledShader.GetByteCode(); _underlying = ObjectFactory().CreateHullShader(byteCode.first, byteCode.second); _validationCallback = std::make_shared<Assets::DependencyValidation>(); Assets::RegisterAssetDependency(_validationCallback, compiledShader.GetDependencyValidation()); }
GeometryShader::GeometryShader( const ResChar initializer[], const StreamOutputInitializers& soInitializers) { // // We have to append the shader model to the resource name // (if it's not already there) // ResChar temp[MaxPath]; if (!XlFindStringI(initializer, "gs_")) { StringMeldInPlace(temp) << initializer << ":" GS_DefShaderModel; initializer = temp; } intrusive_ptr<ID3D::GeometryShader> underlying; if (soInitializers._outputBufferCount == 0) { const auto& compiledShader = ::Assets::GetAssetComp<CompiledShaderByteCode>(initializer); assert(compiledShader.GetStage() == ShaderStage::Geometry); auto byteCode = compiledShader.GetByteCode(); underlying = ObjectFactory().CreateGeometryShader(byteCode.first, byteCode.second); } else { assert(soInitializers._outputBufferCount < D3D11_SO_BUFFER_SLOT_COUNT); D3D11_SO_DECLARATION_ENTRY nativeDeclaration[D3D11_SO_STREAM_COUNT * D3D11_SO_OUTPUT_COMPONENT_COUNT]; auto delcCount = BuildNativeDeclaration(nativeDeclaration, dimof(nativeDeclaration), soInitializers); ObjectFactory objFactory; auto featureLevel = objFactory.GetUnderlying()->GetFeatureLevel(); const auto& compiledShader = ::Assets::GetAssetComp<CompiledShaderByteCode>(initializer); assert(compiledShader.GetStage() == ShaderStage::Geometry); auto byteCode = compiledShader.GetByteCode(); underlying = objFactory.CreateGeometryShaderWithStreamOutput( byteCode.first, byteCode.second, nativeDeclaration, delcCount, soInitializers._outputBufferStrides, soInitializers._outputBufferCount, // Note -- "NO_RASTERIZED_STREAM" is only supported on feature level 11. For other feature levels // we must disable the rasterization step some other way (featureLevel>=D3D_FEATURE_LEVEL_11_0)?D3D11_SO_NO_RASTERIZED_STREAM:0); } // (creation successful; we can commit to member now) _underlying = std::move(underlying); }
PixelShader::PixelShader(const ResChar initializer[]) { // // We have to append the shader model to the resource name // (if it's not already there) // ResChar temp[MaxPath]; if (!XlFindStringI(initializer, "ps_")) { StringMeldInPlace(temp) << initializer << ":" PS_DefShaderModel; initializer = temp; } const auto& compiledShader = ::Assets::GetAssetComp<CompiledShaderByteCode>(initializer); assert(compiledShader.GetStage() == ShaderStage::Pixel); auto byteCode = compiledShader.GetByteCode(); _underlying = ObjectFactory().CreatePixelShader(byteCode.first, byteCode.second); }
IndexBuffer::IndexBuffer(const void* data, size_t byteCount) : IndexBuffer(ObjectFactory(), data, byteCount) {}
ConstantBuffer::ConstantBuffer(const void* data, size_t byteCount, bool immutable) : ConstantBuffer(ObjectFactory(), data, byteCount, immutable) {}