OSDN Git Service

Move isl to src/intel
[android-x86/external-mesa.git] / src / vulkan / genX_pipeline.c
1 /*
2  * Copyright © 2015 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23
24 #include "anv_private.h"
25
26 #if (ANV_GEN == 9)
27 #  include "genxml/gen9_pack.h"
28 #elif (ANV_GEN == 8)
29 #  include "genxml/gen8_pack.h"
30 #elif (ANV_IS_HASWELL)
31 #  include "genxml/gen75_pack.h"
32 #elif (ANV_GEN == 7)
33 #  include "genxml/gen7_pack.h"
34 #endif
35
36 VkResult
37 genX(compute_pipeline_create)(
38     VkDevice                                    _device,
39     struct anv_pipeline_cache *                 cache,
40     const VkComputePipelineCreateInfo*          pCreateInfo,
41     const VkAllocationCallbacks*                pAllocator,
42     VkPipeline*                                 pPipeline)
43 {
44    ANV_FROM_HANDLE(anv_device, device, _device);
45    struct anv_pipeline *pipeline;
46    VkResult result;
47
48    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO);
49
50    pipeline = anv_alloc2(&device->alloc, pAllocator, sizeof(*pipeline), 8,
51                          VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
52    if (pipeline == NULL)
53       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
54
55    pipeline->device = device;
56    pipeline->layout = anv_pipeline_layout_from_handle(pCreateInfo->layout);
57
58    pipeline->blend_state.map = NULL;
59
60    result = anv_reloc_list_init(&pipeline->batch_relocs,
61                                 pAllocator ? pAllocator : &device->alloc);
62    if (result != VK_SUCCESS) {
63       anv_free2(&device->alloc, pAllocator, pipeline);
64       return result;
65    }
66    pipeline->batch.next = pipeline->batch.start = pipeline->batch_data;
67    pipeline->batch.end = pipeline->batch.start + sizeof(pipeline->batch_data);
68    pipeline->batch.relocs = &pipeline->batch_relocs;
69
70    /* When we free the pipeline, we detect stages based on the NULL status
71     * of various prog_data pointers.  Make them NULL by default.
72     */
73    memset(pipeline->prog_data, 0, sizeof(pipeline->prog_data));
74    memset(pipeline->scratch_start, 0, sizeof(pipeline->scratch_start));
75
76    pipeline->vs_simd8 = NO_KERNEL;
77    pipeline->vs_vec4 = NO_KERNEL;
78    pipeline->gs_kernel = NO_KERNEL;
79
80    pipeline->active_stages = 0;
81    pipeline->total_scratch = 0;
82
83    assert(pCreateInfo->stage.stage == VK_SHADER_STAGE_COMPUTE_BIT);
84    ANV_FROM_HANDLE(anv_shader_module, module,  pCreateInfo->stage.module);
85    anv_pipeline_compile_cs(pipeline, cache, pCreateInfo, module,
86                            pCreateInfo->stage.pName,
87                            pCreateInfo->stage.pSpecializationInfo);
88
89    pipeline->use_repclear = false;
90
91    const struct brw_cs_prog_data *cs_prog_data = &pipeline->cs_prog_data;
92
93    anv_batch_emit(&pipeline->batch, GENX(MEDIA_VFE_STATE),
94                   .ScratchSpaceBasePointer = pipeline->scratch_start[MESA_SHADER_COMPUTE],
95                   .PerThreadScratchSpace = ffs(cs_prog_data->base.total_scratch / 2048),
96 #if ANV_GEN > 7
97                   .ScratchSpaceBasePointerHigh = 0,
98                   .StackSize = 0,
99 #else
100                   .GPGPUMode = true,
101 #endif
102                   .MaximumNumberofThreads = device->info.max_cs_threads - 1,
103                   .NumberofURBEntries = ANV_GEN <= 7 ? 0 : 2,
104                   .ResetGatewayTimer = true,
105 #if ANV_GEN <= 8
106                   .BypassGatewayControl = true,
107 #endif
108                   .URBEntryAllocationSize = ANV_GEN <= 7 ? 0 : 2,
109                   .CURBEAllocationSize = 0);
110
111    struct brw_cs_prog_data *prog_data = &pipeline->cs_prog_data;
112    uint32_t group_size = prog_data->local_size[0] *
113       prog_data->local_size[1] * prog_data->local_size[2];
114    pipeline->cs_thread_width_max = DIV_ROUND_UP(group_size, prog_data->simd_size);
115    uint32_t remainder = group_size & (prog_data->simd_size - 1);
116
117    if (remainder > 0)
118       pipeline->cs_right_mask = ~0u >> (32 - remainder);
119    else
120       pipeline->cs_right_mask = ~0u >> (32 - prog_data->simd_size);
121
122
123    *pPipeline = anv_pipeline_to_handle(pipeline);
124
125    return VK_SUCCESS;
126 }