<commit_before>/*
 * D3D11GraphicsPipeline.cpp
 * 
 * This file is part of the "LLGL" project (Copyright (c) 2015 by <NAME>)
 * See "LICENSE.txt" for license information.
 */

#include "D3D11GraphicsPipeline.h"
#include "../D3D11RenderSystem.h"
#include "../D3D11Types.h"
#include "../Shader/D3D11ShaderProgram.h"
#include "../Shader/D3D11Shader.h"
#include "../../DXCommon/DXCore.h"
#include "../../CheckedCast.h"
#include "../../Assertion.h"
#include "../../../Core/Helper.h"
#include <algorithm>


namespace LLGL
{


D3D11GraphicsPipeline::D3D11GraphicsPipeline(
    ID3D11Device* device, const GraphicsPipelineDescriptor& desc)
{
    /* Validate pointers and get D3D shader objects */
    LLGL_ASSERT_PTR(desc.shaderProgram);

    shaderProgram_ = LLGL_CAST(D3D11ShaderProgram*, desc.shaderProgram);
    GetShaderObjects(*shaderProgram_);

    if (!shaderProgram_->GetInputLayout())
        throw std::runtime_error("can not create graphics pipeline while shader program has no D3D11 input layout");

    /* Store D3D primitive topology */
    primitiveTopology_ = D3D11Types::Map(desc.primitiveTopology);

    /* Store D3D stencil reference value */
    stencilRef_ = desc.stencil.front.reference;

    /* Create D3D11 render state objects */
    CreateDepthStencilState(device, desc.depth, desc.stencil);
    CreateRasterizerState(device, desc.rasterizer);
    CreateBlendState(device, desc.blend);
}

void D3D11GraphicsPipeline::Bind(ID3D11DeviceContext* context)
{
    /* Setup input-assembly states */
    context->IASetPrimitiveTopology(primitiveTopology_);
    context->IASetInputLayout(shaderProgram_->GetInputLayout());

    /* Setup shader states */
    if (vs_)
        context->VSSetShader(vs_.Get(), nullptr, 0);
    if (hs_ && ds_)
    {
        context->HSSetShader(hs_.Get(), nullptr, 0);
        context->DSSetShader(ds_.Get(), nullptr, 0);
    }
    if (gs_)
        context->GSSetShader(gs_.Get(), nullptr, 0);
    if (ps_)
        context->PSSetShader(ps_.Get(), nullptr, 0);

    /* Setup render states */
    context->RSSetState(rasterizerState_.Get());
    context->OMSetDepthStencilState(depthStencilState_.Get(), stencilRef_);
    context->OMSetBlendState(blendState_.Get(), blendFactor_, sampleMask_);
}


/*
 * ======= Private: =======
 */

void D3D11GraphicsPipeline::GetShaderObjects(D3D11ShaderProgram& shaderProgramD3D)
{
    if (shaderProgramD3D.GetVS()) { vs_ = shaderProgramD3D.GetVS()->GetHardwareShader().vs; }
    if (shaderProgramD3D.GetHS()) { hs_ = shaderProgramD3D.GetHS()->GetHardwareShader().hs; }
    if (shaderProgramD3D.GetDS()) { ds_ = shaderProgramD3D.GetDS()->GetHardwareShader().ds; }
    if (shaderProgramD3D.GetGS()) { gs_ = shaderProgramD3D.GetGS()->GetHardwareShader().gs; }<commit_msg>Fixed shader stage setting in D3D11GraphicsPipeline class.<commit_after>/*
 * D3D11GraphicsPipeline.cpp
 * 
 * This file is part of the "LLGL" project (Copyright (c) 2015 by <NAME>)
 * See "LICENSE.txt" for license information.
 */

#include "D3D11GraphicsPipeline.h"
#include "../D3D11RenderSystem.h"
#include "../D3D11Types.h"
#include "../Shader/D3D11ShaderProgram.h"
#include "../Shader/D3D11Shader.h"
#include "../../DXCommon/DXCore.h"
#include "../../CheckedCast.h"
#include "../../Assertion.h"
#include "../../../Core/Helper.h"
#include <algorithm>


namespace LLGL
{


D3D11GraphicsPipeline::D3D11GraphicsPipeline(
    ID3D11Device* device, const GraphicsPipelineDescriptor& desc)
{
    /* Validate pointers and get D3D shader objects */
    LLGL_ASSERT_PTR(desc.shaderProgram);

    shaderProgram_ = LLGL_CAST(D3D11ShaderProgram*, desc.shaderProgram);
    GetShaderObjects(*shaderProgram_);

    if (!shaderProgram_->GetInputLayout())
        throw std::runtime_error("can not create graphics pipeline while shader program has no D3D11 input layout");

    /* Store D3D primitive topology */
    primitiveTopology_ = D3D11Types::Map(desc.primitiveTopology);

    /* Store D3D stencil reference value */
    stencilRef_ = desc.stencil.front.reference;

    /* Create D3D11 render state objects */
    CreateDepthStencilState(device, desc.depth, desc.stencil);
    CreateRasterizerState(device, desc.rasterizer);
    CreateBlendState(device, desc.blend);
}

void D3D11GraphicsPipeline::Bind(ID3D11DeviceContext* context)
{
    /* Setup input-assembly states */
    context->IASetPrimitiveTopology(primitiveTopology_);
    context->IASetInputLayout(shaderProgram_->GetInputLayout());

    /* Setup shader states */
    context->VSSetShader(vs_.Get(), nullptr, 0);
    context->HSSetShader(hs_.Get(), nullptr, 0);
    context->DSSetShader(ds_.Get(), nullptr, 0);
    context->GSSetShader(gs_.Get(), nullptr, 0);
    context->PSSetShader(ps_.Get(), nullptr, 0);

    /* Setup render states */
    context->RSSetState(rasterizerState_.Get());
    context->OMSetDepthStencilState(depthStencilState_.Get(), stencilRef_);
    context->OMSetBlendState(blendState_.Get(), blendFactor_, sampleMask_);
}


/*
 * ======= Private: =======
 */

void D3D11GraphicsPipeline::GetShaderObjects(D3D11ShaderProgram& shaderProgramD3D)
{
    if (shaderProgramD3D.GetVS()) { vs_ = shaderProgramD3D.GetVS()->GetHardwareShader().vs; }
    if (shaderProgramD3D.GetHS()) { hs_ = shaderProgramD3D.GetHS()->GetHardwareShader().hs; }
    if (shaderProgramD3D.GetDS()) { ds_ = shaderProgramD3D.GetDS()->GetHardwareShader().ds; }
    if (shaderProgramD3D.GetGS()) { gs_ = shaderProgramD3D.GetGS()->GetHardwareShader().gs; }
{'fraction_non_alphanumeric': 0.14755604557148108, 'fraction_numerical': 0.02701212789415656, 'mean_word_length': 4.357283464566929, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6743567', 'n_tokens_mistral': 1829, 'n_tokens_neox': 1754, 'n_words': 327}